From decf78db53e5d2df6ebb48c9e752e8614e7ade40 Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Thu, 3 Dec 2020 14:44:10 +0100
Subject: [PATCH] stripping data of the time to the next 5 minutes

---
 app/Http/Controllers/AdminInterface.php | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/app/Http/Controllers/AdminInterface.php b/app/Http/Controllers/AdminInterface.php
index 19efccc42..dd14d95d8 100644
--- a/app/Http/Controllers/AdminInterface.php
+++ b/app/Http/Controllers/AdminInterface.php
@@ -142,11 +142,19 @@ class AdminInterface extends Controller
         $rekordTagDate = "";
         $size = 0;
         $count = 0;
+        $logToday = 0;
 
         foreach ($logs as $key => $stats) {
             if ($key === 0) {
                 // Log for today
-                $logToday = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
+                $now = Carbon::now();
+                $now->hour = 0;
+                $now->minute = 0;
+                $now->second = 0;
+                while ($now->lessThanOrEqualTo(Carbon::now()->subMinutes(5))) {
+                    $logToday += empty($stats->time->{$now->format('H:i')}->{$interface}) ? 0 : $stats->time->{$now->format('H:i')}->{$interface};
+                    $now->addMinutes(5);
+                }
                 continue;
             }
             $insgesamt = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
@@ -156,7 +164,7 @@ class AdminInterface extends Controller
             $now->minute = 0;
             $now->second = 0;
 
-            while ($now->lessThanOrEqualTo(Carbon::now())) {
+            while ($now->lessThanOrEqualTo(Carbon::now()->subMinutes(5))) {
                 $sameTime += empty($stats->time->{$now->format('H:i')}->{$interface}) ? 0 : $stats->time->{$now->format('H:i')}->{$interface};
                 $now->addMinutes(5);
             }
@@ -190,7 +198,7 @@ class AdminInterface extends Controller
                 $sum += ($logToday - $sameTime);
             }
         }
-        
+
         $averageIncrease = 0;
         if (sizeof($sameTimes) > 0) {
             $averageIncrease = $sum / sizeof($sameTimes);
-- 
GitLab