fix overwrite issues

The $jsonobj array is iterated from the back, so the first entries overwrite the newest entries (that is, the ones from the back). So it happens that instead of the traffic for today 16 o'clock ,the traffic from the day before yesterday 16 o'clock ends up in the array $data_template and is displayed in the graph. But this should not be like this!
This commit is contained in:
Lukas 2022-04-22 18:50:18 +02:00 committed by Federico Frigo
parent 945d8587c8
commit f789647e82
1 changed files with 1 additions and 1 deletions

View File

@ -41,7 +41,7 @@ if (filter_input(INPUT_GET, 'tu') == 'h') {
$jsonobj = json_decode($jsonstdoutvnstat[0], true)['interfaces'][0];
$jsonData = $jsonobj['traffic']['hour'];
for ($i = count($jsonData) - 1; $i >= 0; --$i) {
for ($i = count($jsonData) - 1; $i >= 0 && $i >= count($jsonData)-25; --$i) {
$data_template[$jsonData[$i]['time']['hour']]['rx'] = round($jsonData[$i]['rx'] / 1024, 0);
$data_template[$jsonData[$i]['time']['hour']]['tx'] = round($jsonData[$i]['tx'] / 1024, 0);
}