fix(traffic): считать общий пик по совпадающим интервалам
This commit is contained in:
1 parent
dbc3b2c947
commit
7b88416415
21 files changed
+1390
-27
No files matched your search
@@ -12,3 +12,7 @@ const stale=projectTrafficObservations({...row,observations:obs},at+90_001);asse
|
||||
assert.equal(projectTrafficObservations({...row,observations:{...obs,currentState:"error"}},at).rxNow,null)
|
||||
for(const change of [{rxNow:-1},{observations:{...obs,sampledAt:"bad"}},{observations:{...obs,sampledAt:null}},{observations:{...obs,rxSeries:[]}}])assert.throws(()=>projectTrafficObservations({...row,...change},at))
|
||||
console.log("traffic observations nullable/zero/gaps/expiry guards tests ok")
|
||||
const noPeak=projectTrafficObservations({...row,volumeUnit:"GiB",observations:{...obs,rxPeak:false,txPeak:false}},at)
|
||||
assert.equal(noPeak.rxPeak,null);assert.equal(noPeak.txPeak,null);assert.equal(noPeak.rxTotal,0)
|
||||
assert.equal(projectTrafficObservations({...row,observations:{...obs,rxPeak:true,txPeak:true}},at).rxPeak,0)
|
||||
console.log('aggregate peak confidence overrides bucket confidence; measured zero and volumes retained')
|
||||
@@ -2,6 +2,7 @@ import { z } from "zod"
|
||||
const timestamp = z.string().refine(v => Number.isFinite(Date.parse(v))).nullable()
|
||||
const rate = z.number().finite().nonnegative().nullable()
|
||||
const meta = z.object({ rxNow: z.boolean(), txNow: z.boolean(), rxSeries: z.array(z.boolean()), txSeries: z.array(z.boolean()),
|
||||
rxPeak: z.boolean().optional(), txPeak: z.boolean().optional(),
|
||||
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>
|
||||
@@ -19,7 +20,7 @@ export function projectTrafficObservations(raw: unknown, now = Date.now()) {
|
||||
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, 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,
|
||||
rxSeries, txSeries, rxPeak: (o?.rxPeak ?? rxSeries.some(v => v !== null)) ? r.rxPeak : null,
|
||||
txPeak: (o?.txPeak ?? txSeries.some(v => v !== null)) ? r.txPeak : 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