Resources Numerical accuracy Calculation policy

Live feed values and times

Reads a value and a time from a message or poll answer of a live sensor feed.

How the precision is kept

The value is converted by numOf of assets-bim-sensors.js, which only accepts plain decimal text, so it is the nearest 64-bit number to what the feed says. A numeric time below 1e11 is taken as Unix seconds and multiplied by 1000, otherwise it is milliseconds.

Calculations under this policy

1 calculation in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.

assets-bim-live.js BimCraft 0.8.1 64-bit 1 calculation Reviewed

Tests tools/bimcraft-test/ops-feeds.mjs

Value and time of one reading

64-bit

A single reading of a feed with its time.

t = tt × 1000 if tt < 1e11, else tt

Values are not rounded or scaled. A numeric time below 1e11 is multiplied by 1000, a larger one is kept as milliseconds; a non-finite time becomes null.

  • assets-bim-live.js
  • lines 141 to 155
  • BimCraft 0.8.1
// ---------------------------------------------------------------- payloads
export function readPayload(p, { valueKey = 'value', timeKey = 'time' } = {}) {
  const s = (typeof p === 'string' ? p : dec.decode(p)).trim();
  if (!s || s.length > 64 * 1024) return null;
  const n = numOf(s);
  if (Number.isFinite(n)) return { v: n, t: null };
  if (s[0] !== '{') return null;
  let o;
  try { o = JSON.parse(s); } catch { return null; }
  const v = typeof o?.[valueKey] === 'number' ? o[valueKey] : numOf(o?.[valueKey]);
  if (!Number.isFinite(v)) return null;
  const tt = o[timeKey] ?? o.ts ?? o.timestamp;
  const t = typeof tt === 'number' ? (tt < 1e11 ? tt * 1000 : tt) : timeOf(tt);
  return { v, t: Number.isFinite(t) ? t : null };
}

In detail

Method
Value from the text or from a named key of a JSON object; time from a number or from timeOf.
Number types
64-bit numbers; times in milliseconds.
Tolerances
The seconds-or-milliseconds boundary is 1e11.
Limits
A time in milliseconds before 1973 would be read as seconds; no value is rounded.

Approach: 64-bit, direct

Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.

Every policy that takes this approach