diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-11-17 14:54:43 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-11-17 14:57:08 +0100 |
commit | e5f9e3ff25418f4bea774a9bc748d24020725483 (patch) | |
tree | 790eac1834ee665cb5beb99c00df74cf8bac1ae4 /modules/luci-mod-status | |
parent | 93fdac8560f219d022f22784b43dced05f86210d (diff) |
luci-mod-status: fix average calculations
Calculate the average over the actual data and not over the entire timeframe.
Fixes #2301
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-status')
4 files changed, 43 insertions, 46 deletions
diff --git a/modules/luci-mod-status/luasrc/view/admin_status/bandwidth.htm b/modules/luci-mod-status/luasrc/view/admin_status/bandwidth.htm index 3bb55f905..5cc661ad1 100644 --- a/modules/luci-mod-status/luasrc/view/admin_status/bandwidth.htm +++ b/modules/luci-mod-status/luasrc/view/admin_status/bandwidth.htm @@ -1,5 +1,5 @@ <%# - Copyright 2010 Jo-Philipp Wich <jow@openwrt.org> + Copyright 2010-2018 Jo-Philipp Wich <jo@mein.io> Licensed to the public under the Apache License 2.0. -%> @@ -34,7 +34,7 @@ var step = 5; var data_wanted = Math.floor(width / step); - var data_fill = 0; + var data_fill = 1; var data_stamp = 0; var data_rx = [ ]; @@ -178,6 +178,8 @@ if (data[i][TIME] <= data_stamp) continue; + data_fill++; + /* normalize difference against time interval */ if (i > 0) { @@ -193,6 +195,7 @@ /* cut off outdated entries */ data_rx = data_rx.slice(data_rx.length - data_wanted, data_rx.length); data_tx = data_tx.slice(data_tx.length - data_wanted, data_tx.length); + data_fill = Math.min(data_fill, data_wanted); /* find peak */ for (var i = 0; i < data_rx.length; i++) @@ -207,8 +210,8 @@ data_tx_avg += data_tx[i]; } - data_rx_avg = (data_rx_avg / Math.max(data_rx.length, 1)); - data_tx_avg = (data_tx_avg / Math.max(data_tx.length, 1)); + data_rx_avg = (data_rx_avg / data_fill); + data_tx_avg = (data_tx_avg / data_fill); var size = Math.floor(Math.log2(data_max)), div = Math.pow(2, size - (size % 10)), diff --git a/modules/luci-mod-status/luasrc/view/admin_status/connections.htm b/modules/luci-mod-status/luasrc/view/admin_status/connections.htm index 0a0db3be7..d9099aa07 100644 --- a/modules/luci-mod-status/luasrc/view/admin_status/connections.htm +++ b/modules/luci-mod-status/luasrc/view/admin_status/connections.htm @@ -1,5 +1,5 @@ <%# - Copyright 2010 Jo-Philipp Wich <jow@openwrt.org> + Copyright 2010-2018 Jo-Philipp Wich <jo@mein.io> Licensed to the public under the Apache License 2.0. -%> @@ -19,7 +19,7 @@ var step = 5; var data_wanted = Math.floor(width / step); - var data_fill = 0; + var data_fill = 1; var data_stamp = 0; var data_udp = [ ]; @@ -202,12 +202,15 @@ if (data[i][TIME] <= data_stamp) continue; + data_fill++; + data_udp.push(data[i][UDP]); data_tcp.push(data[i][TCP]); data_otr.push(data[i][OTHER]); } /* cut off outdated entries */ + data_fill = Math.min(data_fill, data_wanted); data_udp = data_udp.slice(data_udp.length - data_wanted, data_udp.length); data_tcp = data_tcp.slice(data_tcp.length - data_wanted, data_tcp.length); data_otr = data_otr.slice(data_otr.length - data_wanted, data_otr.length); @@ -223,20 +226,15 @@ data_tcp_peak = Math.max(data_tcp_peak, data_tcp[i]); data_otr_peak = Math.max(data_otr_peak, data_otr[i]); - if (i > 0) - { - data_udp_avg = (data_udp_avg + data_udp[i]) / 2; - data_tcp_avg = (data_tcp_avg + data_tcp[i]) / 2; - data_otr_avg = (data_otr_avg + data_otr[i]) / 2; - } - else - { - data_udp_avg = data_udp[i]; - data_tcp_avg = data_tcp[i]; - data_otr_avg = data_otr[i]; - } + data_udp_avg += data_udp[i]; + data_tcp_avg += data_tcp[i]; + data_otr_avg += data_otr[i]; } + data_udp_avg = data_udp_avg / data_fill; + data_tcp_avg = data_tcp_avg / data_fill; + data_otr_avg = data_otr_avg / data_fill; + /* remember current timestamp, calculate horizontal scale */ data_stamp = data[data.length-1][TIME]; data_scale = height / (data_max * 1.1); diff --git a/modules/luci-mod-status/luasrc/view/admin_status/load.htm b/modules/luci-mod-status/luasrc/view/admin_status/load.htm index bced06fa2..d31d34062 100644 --- a/modules/luci-mod-status/luasrc/view/admin_status/load.htm +++ b/modules/luci-mod-status/luasrc/view/admin_status/load.htm @@ -1,5 +1,5 @@ <%# - Copyright 2010 Jo-Philipp Wich <jow@openwrt.org> + Copyright 2010-2018 Jo-Philipp Wich <jo@mein.io> Licensed to the public under the Apache License 2.0. -%> @@ -19,7 +19,7 @@ var step = 5; var data_wanted = Math.floor(width / step); - var data_fill = 0; + var data_fill = 1; var data_stamp = 0; var data_01 = [ ]; @@ -148,12 +148,15 @@ if (data[i][TIME] <= data_stamp) continue; + data_fill++; + data_01.push(data[i][L01]); data_05.push(data[i][L05]); data_15.push(data[i][L15]); } /* cut off outdated entries */ + data_fill = Math.min(data_fill, data_wanted); data_01 = data_01.slice(data_01.length - data_wanted, data_01.length); data_05 = data_05.slice(data_05.length - data_wanted, data_05.length); data_15 = data_15.slice(data_15.length - data_wanted, data_15.length); @@ -169,20 +172,15 @@ data_05_peak = Math.max(data_05_peak, data_05[i]); data_15_peak = Math.max(data_15_peak, data_15[i]); - if (i > 0) - { - data_01_avg = (data_01_avg + data_01[i]) / 2; - data_05_avg = (data_05_avg + data_05[i]) / 2; - data_15_avg = (data_15_avg + data_15[i]) / 2; - } - else - { - data_01_avg = data_01[i]; - data_05_avg = data_05[i]; - data_15_avg = data_15[i]; - } + data_01_avg += data_01[i]; + data_05_avg += data_05[i]; + data_15_avg += data_15[i]; } + data_01_avg = data_01_avg / data_fill; + data_05_avg = data_05_avg / data_fill; + data_15_avg = data_15_avg / data_fill; + /* remember current timestamp, calculate horizontal scale */ data_stamp = data[data.length-1][TIME]; data_scale = height / (data_max * 1.1); diff --git a/modules/luci-mod-status/luasrc/view/admin_status/wireless.htm b/modules/luci-mod-status/luasrc/view/admin_status/wireless.htm index 03ea2bef0..5ac2eb462 100644 --- a/modules/luci-mod-status/luasrc/view/admin_status/wireless.htm +++ b/modules/luci-mod-status/luasrc/view/admin_status/wireless.htm @@ -1,5 +1,5 @@ <%# - Copyright 2011 Jo-Philipp Wich <jow@openwrt.org> + Copyright 2011-2018 Jo-Philipp Wich <jo@mein.io> Licensed to the public under the Apache License 2.0. -%> @@ -33,7 +33,7 @@ var step = 5; var data_wanted = Math.floor(width / step); - var data_fill = 0; + var data_fill = 1; var data_stamp = 0; var data_rssi = [ ]; @@ -201,12 +201,15 @@ if (data[i][TIME] <= data_stamp) continue; + data_fill++; + data_rssi.push(data[i][RSSI] - noise_floor); data_noise.push(data[i][NOISE] - noise_floor); data_rate.push(Math.floor(data[i][RATE] / 1000)); } /* cut off outdated entries */ + data_fill = Math.min(data_fill, data_wanted); data_rssi = data_rssi.slice(data_rssi.length - data_wanted, data_rssi.length); data_noise = data_noise.slice(data_noise.length - data_wanted, data_noise.length); data_rate = data_rate.slice(data_rate.length - data_wanted, data_rate.length); @@ -221,20 +224,15 @@ data_noise_peak = Math.max(data_noise_peak, data_noise[i]); data_rate_peak = Math.max(data_rate_peak, data_rate[i]); - if (i > 0) - { - data_rssi_avg = (data_rssi_avg + data_rssi[i]) / 2; - data_noise_avg = (data_noise_avg + data_noise[i]) / 2; - data_rate_avg = (data_rate_avg + data_rate[i]) / 2; - } - else - { - data_rssi_avg = data_rssi[i]; - data_noise_avg = data_noise[i]; - data_rate_avg = data_rate[i]; - } + data_rssi_avg += data_rssi[i]; + data_noise_avg += data_noise[i]; + data_rate_avg += data_rate[i]; } + data_rssi_avg = data_rssi_avg / data_fill; + data_noise_avg = data_noise_avg / data_fill; + data_rate_avg = data_rate_avg / data_fill; + /* remember current timestamp, calculate horizontal scale */ data_stamp = data[data.length-1][TIME]; data_scale = (height / (data_max * 1.1)).toFixed(1); |