Calculate the average over the actual data and not over the entire timeframe.
Fixes #2301
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
<%#
- 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.
-%>
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 = [ ];
if (data[i][TIME] <= data_stamp)
continue;
+ data_fill++;
+
/* normalize difference against time interval */
if (i > 0)
{
/* 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++)
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)),
<%#
- 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.
-%>
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 = [ ];
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);
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);
<%#
- 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.
-%>
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 = [ ];
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);
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);
<%#
- 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.
-%>
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 = [ ];
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);
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);