fix(traffic): сохранять точность объёмов и обозначать бинарные единицы
This commit is contained in:
1 parent
2358ecef60
commit
2b3d583e3b
29 files changed
+1452
-39
No files matched your search
@@ -5,7 +5,7 @@ const meta = z.object({ rxNow: z.boolean(), txNow: z.boolean(), rxSeries: z.arra
|
||||
sampledAt: timestamp, expiresAt: timestamp.optional(), lastAttemptAt: timestamp.optional(), lastSucceededAt: timestamp.optional(), error: z.string().nullable().optional(),
|
||||
currentState: z.enum(["current", "unknown", "pending", "error", "stale", "disabled"]).optional() })
|
||||
export type TrafficObservationMeta = z.infer<typeof meta>
|
||||
const metrics = z.object({ rxNow: rate, txNow: rate, rxPeak: rate, txPeak: rate, rxTotal: rate, txTotal: rate,
|
||||
const metrics = z.object({ volumeUnit: z.literal("GiB").optional(), rxNow: rate, txNow: rate, rxPeak: rate, txPeak: rate, rxTotal: rate, txTotal: rate,
|
||||
rxSeries: z.array(rate), txSeries: z.array(rate), observations: meta.optional() }).refine(r =>
|
||||
(!r.observations || r.observations.rxSeries.length === r.rxSeries.length && r.observations.txSeries.length === r.txSeries.length &&
|
||||
(!(r.observations.rxNow || r.observations.txNow || r.observations.rxSeries.some(Boolean) || r.observations.txSeries.some(Boolean)) || r.observations.sampledAt !== null)))
|
||||
@@ -18,8 +18,8 @@ export function projectTrafficObservations(raw: unknown, now = Date.now()) {
|
||||
const current = !o?.currentState || o.currentState === "current"
|
||||
const rxSeries = r.rxSeries.map((v, i) => o?.rxSeries[i] ? v : null)
|
||||
const txSeries = r.txSeries.map((v, i) => o?.txSeries[i] ? v : null)
|
||||
return { observations: o, rxNow: current && o?.rxNow ? r.rxNow : null, txNow: current && o?.txNow ? r.txNow : null,
|
||||
return { observations: o, volumeUnit: r.volumeUnit, rxNow: current && o?.rxNow ? r.rxNow : null, txNow: current && o?.txNow ? r.txNow : null,
|
||||
rxSeries, txSeries, rxPeak: rxSeries.some(v => v !== null) ? r.rxPeak : null,
|
||||
txPeak: txSeries.some(v => v !== null) ? r.txPeak : null,
|
||||
rxTotal: rxSeries.some(v => v !== null) ? r.rxTotal : null, txTotal: txSeries.some(v => v !== null) ? r.txTotal : null }
|
||||
rxTotal: r.volumeUnit && rxSeries.some(v => v !== null) ? r.rxTotal : null, txTotal: r.volumeUnit && txSeries.some(v => v !== null) ? r.txTotal : null }
|
||||
}
|
||||
Reference in new issue
Block a user