luci-mod-admin-full: fix average traffic calculation in realtime bandwidth
authorJo-Philipp Wich <jo@mein.io>
Mon, 25 Jun 2018 07:33:07 +0000 (09:33 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 25 Jun 2018 07:33:07 +0000 (09:33 +0200)
Fixes #1908.
Suggested-by: "mgalyean"
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm

index f0ef5e7a2cbebdbe619e676f6b0dfddb346e64cf..b7594bfd45c8aa6f20074d7c7c25ac71ebc58926 100644 (file)
                                                        data_rx_peak = Math.max(data_rx_peak, data_rx[i]);
                                                        data_tx_peak = Math.max(data_tx_peak, data_tx[i]);
 
-                                                       if (i > 0)
-                                                       {
-                                                               data_rx_avg = (data_rx_avg + data_rx[i]) / 2;
-                                                               data_tx_avg = (data_tx_avg + data_tx[i]) / 2;
-                                                       }
-                                                       else
-                                                       {
-                                                               data_rx_avg = data_rx[i];
-                                                               data_tx_avg = data_tx[i];
-                                                       }
+                                                       data_rx_avg += data_rx[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));
+
                                                /* remember current timestamp, calculate horizontal scale */
                                                data_stamp = data[data.length-1][TIME];
                                                data_scale = height / (data_max * 1.1);