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/luasrc/view/admin_status/load.htm | |
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/luasrc/view/admin_status/load.htm')
-rw-r--r-- | modules/luci-mod-status/luasrc/view/admin_status/load.htm | 26 |
1 files changed, 12 insertions, 14 deletions
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 bced06fa22..d31d340621 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); |