Avena Webapp API - v0.0.1
    Preparing search index...

    Function normalizeCalibration

    • Converts a partial or unknown calibration object into a valid spec.

      The Rust CalibrationSpec accepts only finite JSON numbers and rejects the whole config when a spec is malformed. This function repairs such input instead, keeping as much of what was entered as possible, so that saving from the dashboard writes a spec Rust can read. Valid specs come out unchanged. Rules, by type:

      • Missing input or a non-string type: identity.
      • linear: a and b are kept if they are finite numbers or numeric strings (stored back as numbers), otherwise a becomes 1 and b becomes 0.
      • polynomial: coefficients that are finite numbers or numeric strings are kept as numbers and the rest dropped. An empty list stays empty and, as in Rust, evaluates to 0. A missing or non-array coeffs becomes [0, 1], the identity polynomial.
      • Any other type: identity.

      A non-blank string id or unit is carried over (trimmed) in every case except the first; blank or non-string values are left out, so the result has no undefined fields. Returns a new object and does not modify raw.

      Parameters

      • Optionalraw: Partial<CalibrationSpec> | null

        Calibration as read from config or form state, possibly partial.

      Returns CalibrationSpec

      A spec that applyCalibration can evaluate.

      normalizeCalibration({ type: "linear", a: "2", unit: "kPa" });
      // { type: "linear", a: 2, b: 0, unit: "kPa" }
      normalizeCalibration({ type: "polynomial", coeffs: [] });
      // { type: "polynomial", coeffs: [] }