History and Analytics: average speed from bytes for periods over 24 hours
The aggregate tables (stats_*) keep only bytes, and the queries returned 0 as speed, so the Speed mode was empty for 7d and 30d. Speed is now the bucket average: bytes * 8 / 1e6 / bucket seconds; for the current incomplete bucket the duration is min(bucket length, time since its start), at least 1 s. Series are labelled "RX Mbps (avg)" / "TX Mbps (avg)" for ranges over 24h. One test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KC7BXv32Jwj8mY5sKX8u2F
This commit is contained in:
1 parent
e364a40e4b
commit
b3466f9c61
17 files changed
+97
-19
No files matched your search
@@ -51,6 +51,14 @@ export const downsamplePoints = (points, maxPoints) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// Ranges of 1h/3h/24h come from raw samples (peak speed); longer ones (7d, 30d) from aggregates
|
||||
// that keep only bytes, so their speed is the average of a bucket and is labelled "(avg)".
|
||||
export const isAveragedRange = (range) => {
|
||||
const m = /^(\d+)([hd])$/.exec(range || '');
|
||||
if (!m) return false;
|
||||
return Number(m[1]) * (m[2] === 'd' ? 24 : 1) > 24;
|
||||
};
|
||||
|
||||
// Line chart of received/sent traffic bound to a canvas ref.
|
||||
// const chart = useTrafficChart(canvasRef, { maxPoints: 96 });
|
||||
// chart.render(points, { range: '24h', speedMode: false });
|
||||
@@ -93,6 +101,7 @@ export function useTrafficChart(canvasRef, { maxPoints }) {
|
||||
});
|
||||
|
||||
const { gridColor, textColor } = getThemeColors();
|
||||
const speedSuffix = isAveragedRange(range) ? ' (avg)' : '';
|
||||
const dataset = (label, data, color, fill) => ({
|
||||
label,
|
||||
data,
|
||||
@@ -110,8 +119,8 @@ export function useTrafficChart(canvasRef, { maxPoints }) {
|
||||
data: {
|
||||
labels,
|
||||
datasets: [
|
||||
dataset(speedMode ? 'RX Mbps' : 'Received (MB)', dataRx, COLOR_RX, 'rgba(22, 82, 184, 0.15)'),
|
||||
dataset(speedMode ? 'TX Mbps' : 'Sent (MB)', dataTx, COLOR_TX, 'rgba(236, 124, 49, 0.15)')
|
||||
dataset(speedMode ? `RX Mbps${speedSuffix}` : 'Received (MB)', dataRx, COLOR_RX, 'rgba(22, 82, 184, 0.15)'),
|
||||
dataset(speedMode ? `TX Mbps${speedSuffix}` : 'Sent (MB)', dataTx, COLOR_TX, 'rgba(236, 124, 49, 0.15)')
|
||||
]
|
||||
},
|
||||
options: {
|
||||
|
||||
Reference in new issue
Block a user