Fix inaccurate percentages of PL & FL stats

This commit is contained in:
redphx 2023-08-01 08:18:03 +07:00
parent 889717be7d
commit 5facfd2348

View File

@ -196,13 +196,15 @@ class StreamStats {
// Packets Lost // Packets Lost
const packetsLost = stat.packetsLost; const packetsLost = stat.packetsLost;
const packetsReceived = stat.packetsReceived || 1; const packetsReceived = stat.packetsReceived;
StreamStats.#$pl.textContent = `${packetsLost} (${(packetsLost * 100 / packetsReceived).toFixed(2)}%)`; const packetsLostPercentage = (packetsLost * 100 / ((packetsLost + packetsReceived) || 1)).toFixed(2);
StreamStats.#$pl.textContent = `${packetsLost} (${packetsLostPercentage}%)`;
// Frames Dropped // Frames Dropped
const framesDropped = stat.framesDropped; const framesDropped = stat.framesDropped;
const framesReceived = stat.framesReceived || 1; const framesReceived = stat.framesReceived;
StreamStats.#$fl.textContent = `${framesDropped} (${(framesDropped * 100 / framesReceived).toFixed(2)}%)`; const framesDroppedPercentage = (framesDropped * 100 / ((framesDropped + framesReceived) || 1)).toFixed(2);
StreamStats.#$fl.textContent = `${framesDropped} (${framesDroppedPercentage}%)`;
if (StreamStats.#lastStat) { if (StreamStats.#lastStat) {
const lastStat = StreamStats.#lastStat; const lastStat = StreamStats.#lastStat;