fix(traffic): проверять live-срез и прекращать опрос выключенных устройств
This commit is contained in:
1 parent
1275dd7b9b
commit
2358ecef60
29 files changed
+1620
-114
No files matched your search
@@ -0,0 +1,6 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { fmtRate } from "./fmt-rate.js"
|
||||
assert.equal(fmtRate(null),"—");assert.equal(fmtRate(undefined),"—");assert.equal(fmtRate(0),"0 Кбит/с")
|
||||
assert.equal(fmtRate(0.000001),"<1 Кбит/с");assert.equal(fmtRate(0.001),"1 Кбит/с")
|
||||
assert.equal(fmtRate(1),"1.00 Мбит/с");assert.equal(fmtRate(1000),"1.00 Гбит/с")
|
||||
console.log("rate formatting unknown/zero/positive-small/units tests ok")
|
||||
@@ -2,6 +2,7 @@
|
||||
export function fmtRate(v: number | null | undefined): string {
|
||||
if (v == null) return "—"
|
||||
if (!Number.isFinite(v) || v <= 0) return "0 Кбит/с"
|
||||
if (v < 0.0005) return "<1 Кбит/с"
|
||||
if (v >= 1000) return `${(v / 1000).toFixed(2)} Гбит/с`
|
||||
if (v < 1) return `${Math.round(v * 1000)} Кбит/с`
|
||||
if (v < 10) return `${v.toFixed(2)} Мбит/с`
|
||||
|
||||
Reference in new issue
Block a user