Use toFixed(1) in stats

This commit is contained in:
redphx 2024-12-07 09:45:47 +07:00
parent 07b2e47757
commit 4648126f03
4 changed files with 18 additions and 18 deletions

View File

@ -764,7 +764,7 @@ function clearDataSet($elm) {
var FILE_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"]; var FILE_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"];
function humanFileSize(size) { function humanFileSize(size) {
let i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); let i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) + " " + FILE_SIZE_UNITS[i]; return (size / Math.pow(1024, i)).toFixed(1) + " " + FILE_SIZE_UNITS[i];
} }
function secondsToHm(seconds) { function secondsToHm(seconds) {
let h = Math.floor(seconds / 3600), m = Math.floor(seconds % 3600 / 60) + 1; let h = Math.floor(seconds / 3600), m = Math.floor(seconds % 3600 / 60) + 1;
@ -2000,7 +2000,7 @@ class StreamStatsCollector {
current: 0, current: 0,
grades: [30, 40, 60], grades: [30, 40, 60],
toString() { toString() {
return `${this.current.toFixed(2)}ms`; return `${this.current.toFixed(1)}ms`;
} }
}, },
fps: { fps: {
@ -2013,14 +2013,14 @@ class StreamStatsCollector {
btr: { btr: {
current: 0, current: 0,
toString() { toString() {
return `${this.current.toFixed(2)} Mbps`; return `${this.current.toFixed(1)} Mbps`;
} }
}, },
fl: { fl: {
received: 0, received: 0,
dropped: 0, dropped: 0,
toString() { toString() {
let framesDroppedPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(2); let framesDroppedPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(1);
return framesDroppedPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`; return framesDroppedPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`;
} }
}, },
@ -2028,7 +2028,7 @@ class StreamStatsCollector {
received: 0, received: 0,
dropped: 0, dropped: 0,
toString() { toString() {
let packetsLostPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(2); let packetsLostPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(1);
return packetsLostPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`; return packetsLostPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`;
} }
}, },
@ -2037,7 +2037,7 @@ class StreamStatsCollector {
total: 0, total: 0,
grades: [6, 9, 12], grades: [6, 9, 12],
toString() { toString() {
return isNaN(this.current) ? "??ms" : `${this.current.toFixed(2)}ms`; return isNaN(this.current) ? "??ms" : `${this.current.toFixed(1)}ms`;
} }
}, },
dl: { dl: {

View File

@ -820,7 +820,7 @@ function renderPresetsList($select, allPresets, selectedValue, addOffValue = !1)
var FILE_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"]; var FILE_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"];
function humanFileSize(size) { function humanFileSize(size) {
let i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); let i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) + " " + FILE_SIZE_UNITS[i]; return (size / Math.pow(1024, i)).toFixed(1) + " " + FILE_SIZE_UNITS[i];
} }
function secondsToHm(seconds) { function secondsToHm(seconds) {
let h = Math.floor(seconds / 3600), m = Math.floor(seconds % 3600 / 60) + 1; let h = Math.floor(seconds / 3600), m = Math.floor(seconds % 3600 / 60) + 1;
@ -2109,7 +2109,7 @@ class StreamStatsCollector {
current: 0, current: 0,
grades: [30, 40, 60], grades: [30, 40, 60],
toString() { toString() {
return `${this.current.toFixed(2)}ms`; return `${this.current.toFixed(1)}ms`;
} }
}, },
fps: { fps: {
@ -2122,14 +2122,14 @@ class StreamStatsCollector {
btr: { btr: {
current: 0, current: 0,
toString() { toString() {
return `${this.current.toFixed(2)} Mbps`; return `${this.current.toFixed(1)} Mbps`;
} }
}, },
fl: { fl: {
received: 0, received: 0,
dropped: 0, dropped: 0,
toString() { toString() {
let framesDroppedPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(2); let framesDroppedPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(1);
return framesDroppedPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`; return framesDroppedPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`;
} }
}, },
@ -2137,7 +2137,7 @@ class StreamStatsCollector {
received: 0, received: 0,
dropped: 0, dropped: 0,
toString() { toString() {
let packetsLostPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(2); let packetsLostPercentage = (this.dropped * 100 / (this.dropped + this.received || 1)).toFixed(1);
return packetsLostPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`; return packetsLostPercentage === "0.00" ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`;
} }
}, },
@ -2146,7 +2146,7 @@ class StreamStatsCollector {
total: 0, total: 0,
grades: [6, 9, 12], grades: [6, 9, 12],
toString() { toString() {
return isNaN(this.current) ? "??ms" : `${this.current.toFixed(2)}ms`; return isNaN(this.current) ? "??ms" : `${this.current.toFixed(1)}ms`;
} }
}, },
dl: { dl: {

View File

@ -300,7 +300,7 @@ export function renderPresetsList<T extends PresetRecord>($select: HTMLSelectEle
const FILE_SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB']; const FILE_SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
export function humanFileSize(size: number) { export function humanFileSize(size: number) {
const i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); const i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) + ' ' + FILE_SIZE_UNITS[i]; return (size / Math.pow(1024, i)).toFixed(1) + ' ' + FILE_SIZE_UNITS[i];
} }
export function secondsToHm(seconds: number) { export function secondsToHm(seconds: number) {

View File

@ -104,7 +104,7 @@ export class StreamStatsCollector {
current: 0, current: 0,
grades: [30, 40, 60], grades: [30, 40, 60],
toString() { toString() {
return `${this.current.toFixed(2)}ms`; return `${this.current.toFixed(1)}ms`;
}, },
}, },
@ -119,7 +119,7 @@ export class StreamStatsCollector {
[StreamStat.BITRATE]: { [StreamStat.BITRATE]: {
current: 0, current: 0,
toString() { toString() {
return `${this.current.toFixed(2)} Mbps`; return `${this.current.toFixed(1)} Mbps`;
}, },
}, },
@ -127,7 +127,7 @@ export class StreamStatsCollector {
received: 0, received: 0,
dropped: 0, dropped: 0,
toString() { toString() {
const framesDroppedPercentage = (this.dropped * 100 / ((this.dropped + this.received) || 1)).toFixed(2); const framesDroppedPercentage = (this.dropped * 100 / ((this.dropped + this.received) || 1)).toFixed(1);
return framesDroppedPercentage === '0.00' ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`; return framesDroppedPercentage === '0.00' ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`;
}, },
}, },
@ -136,7 +136,7 @@ export class StreamStatsCollector {
received: 0, received: 0,
dropped: 0, dropped: 0,
toString() { toString() {
const packetsLostPercentage = (this.dropped * 100 / ((this.dropped + this.received) || 1)).toFixed(2); const packetsLostPercentage = (this.dropped * 100 / ((this.dropped + this.received) || 1)).toFixed(1);
return packetsLostPercentage === '0.00' ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`; return packetsLostPercentage === '0.00' ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`;
}, },
}, },
@ -146,7 +146,7 @@ export class StreamStatsCollector {
total: 0, total: 0,
grades: [6, 9, 12], grades: [6, 9, 12],
toString() { toString() {
return isNaN(this.current) ? '??ms' : `${this.current.toFixed(2)}ms`; return isNaN(this.current) ? '??ms' : `${this.current.toFixed(1)}ms`;
}, },
}, },