UNPKG

arrakis-js

Version:

Arrakis Javascript client library

28 lines (27 loc) 909 B
import { gpsToUnix } from "./utils"; export class SeriesBlock { time; time_ns; date; data; channels; constructor(time, time_ns, date, data, channels) { this.time = time; this.time_ns = time_ns; this.date = date; this.data = data; this.channels = channels; } static fromBatch(batch) { const time_ns = Number(batch.getChild("time")?.get(0) ?? 0); const time_ms = Number((batch.getChild("time")?.get(0) ?? 0) / 1000000n); const channels = batch.schema.fields .map((field) => field.name) .filter((name) => name !== "time"); const data = Object.fromEntries(channels.map((channel) => [ channel, Array.from(batch.getChild(channel)?.get(0) ?? []), ])); return new SeriesBlock(time_ms, time_ns, new Date(gpsToUnix(time_ms)), data, channels); } }