From f94c79f8435622f9d8b1a97ae378d4749183fa50 Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Mon, 5 Aug 2024 15:23:58 +0200 Subject: [PATCH 1/2] aggregator: take care of no aggregating data in folder --- .../CerboReleaseFiles/dbus-fzsonick-48tl/aggregator.py | 5 ++++- .../VenusReleaseFiles/dbus-fzsonick-48tl/aggregator.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/firmware/Cerbo_Release/CerboReleaseFiles/dbus-fzsonick-48tl/aggregator.py b/firmware/Cerbo_Release/CerboReleaseFiles/dbus-fzsonick-48tl/aggregator.py index 1d2da45f8..ed1a9f3bc 100755 --- a/firmware/Cerbo_Release/CerboReleaseFiles/dbus-fzsonick-48tl/aggregator.py +++ b/firmware/Cerbo_Release/CerboReleaseFiles/dbus-fzsonick-48tl/aggregator.py @@ -221,7 +221,10 @@ class Aggregator: except ValueError: pass - if len(node_data) == 1: + if len(node_data) == 0: + # No data collected, return default AggregatedData with zeros + return AggregatedData(0.0, 0.0, 0.0, 0.0, 0.0) + elif len(node_data) == 1: # Directly use the values for a single node for node_number, data in node_data.items(): min_soc = data['soc'][0] if data['soc'] else 0.0 diff --git a/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/aggregator.py b/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/aggregator.py index 8b529d1b9..0f787b8ce 100755 --- a/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/aggregator.py +++ b/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/aggregator.py @@ -226,7 +226,10 @@ class Aggregator: except ValueError: pass - if len(node_data) == 1: + if len(node_data) == 0: + # No data collected, return default AggregatedData with zeros + return AggregatedData(0.0, 0.0, 0.0, 0.0, 0.0) + elif len(node_data) == 1: # Directly use the values for a single node for node_number, data in node_data.items(): min_soc = data['soc'][0] if data['soc'] else 0.0 From a47314bdf5ea554273d05e38969474ca9e9dc1f2 Mon Sep 17 00:00:00 2001 From: Noe Date: Mon, 5 Aug 2024 16:31:57 +0200 Subject: [PATCH 2/2] Fixed bug when deleting an installation Set date button works using s3cmd --- csharp/App/Backend/Backend.csproj | 6 + csharp/App/Backend/Controller.cs | 120 +++++++++--------- csharp/App/Backend/Database/Create.cs | 2 +- .../src/MiddlewareClasses/MiddlewareAgent.cs | 16 +-- .../dbus-fzsonick-48tl/config.py | 6 +- 5 files changed, 80 insertions(+), 70 deletions(-) diff --git a/csharp/App/Backend/Backend.csproj b/csharp/App/Backend/Backend.csproj index 0078c9897..518c98e37 100644 --- a/csharp/App/Backend/Backend.csproj +++ b/csharp/App/Backend/Backend.csproj @@ -226,6 +226,12 @@ + + + + + + diff --git a/csharp/App/Backend/Controller.cs b/csharp/App/Backend/Controller.cs index add1e5f17..c4be8820c 100644 --- a/csharp/App/Backend/Controller.cs +++ b/csharp/App/Backend/Controller.cs @@ -177,70 +177,76 @@ public class Controller : ControllerBase string commonPrefix = FindCommonPrefix(start.ToString(), end.ToString()); - string bucketPath = "s3://"+installation.S3BucketId + "-3e5b3069-214a-43ee-8d85-57d72000c19d/"+commonPrefix; - string configPath = "/home/ubuntu/.s3cfg"; + Int64 startTimestamp = Int64.Parse(start.ToString().Substring(0,5)); + Int64 endTimestamp = Int64.Parse(end.ToString().Substring(0,5)); - try + string configPath = "/home/ubuntu/.s3cfg"; + + while (startTimestamp <= endTimestamp) { - // Set up process start info - ProcessStartInfo startInfo = new ProcessStartInfo + string bucketPath = "s3://"+installation.S3BucketId + "-3e5b3069-214a-43ee-8d85-57d72000c19d/"+startTimestamp; + Console.WriteLine("Fetching data for "+startTimestamp); + + try { - FileName = "s3cmd", - Arguments = $"--config {configPath} ls {bucketPath}", - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true - }; - - // Start the process - Process process = new Process - { - StartInfo = startInfo - }; - - process.Start(); - - // Read the output - string output = process.StandardOutput.ReadToEnd(); - string error = process.StandardError.ReadToEnd(); - - process.WaitForExit(); - - // Check for errors - if (process.ExitCode != 0) - { - Console.WriteLine("Error executing command:"); - Console.WriteLine(error); - } - else - { - Console.WriteLine("Command output:"); - //Console.WriteLine(output); - // Define a regex pattern to match the filenames without .csv extension - var pattern = @"/([^/]+)\.csv$"; - var regex = new Regex(pattern); - - // Process each line of the output - foreach (var line in output.Split('\n')) + // Set up process start info + ProcessStartInfo startInfo = new ProcessStartInfo { - var match = regex.Match(line); - if (match.Success && long.Parse(match.Groups[1].Value)>=start && long.Parse(match.Groups[1].Value)<=end) - { - allTimestamps.Add(long.Parse(match.Groups[1].Value)); - //Console.WriteLine(match.Groups[1].Value); - } + FileName = "s3cmd", + Arguments = $"--config {configPath} ls {bucketPath}", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + // Start the process + Process process = new Process + { + StartInfo = startInfo + }; + + process.Start(); + + // Read the output + string output = process.StandardOutput.ReadToEnd(); + string error = process.StandardError.ReadToEnd(); + + process.WaitForExit(); + + // Check for errors + if (process.ExitCode != 0) + { + Console.WriteLine("Error executing command:"); + Console.WriteLine(error); } + else + { + // Define a regex pattern to match the filenames without .csv extension + var pattern = @"/([^/]+)\.csv$"; + var regex = new Regex(pattern); + // Process each line of the output + foreach (var line in output.Split('\n')) + { + var match = regex.Match(line); + if (match.Success && long.Parse(match.Groups[1].Value) >= start && long.Parse(match.Groups[1].Value) <= end) + { + allTimestamps.Add(long.Parse(match.Groups[1].Value)); + //Console.WriteLine(match.Groups[1].Value); + } + } + + } + } + catch (Exception e) + { + Console.WriteLine($"Exception: {e.Message}"); } - } - catch (Exception e) - { - Console.WriteLine($"Exception: {e.Message}"); - } - - + startTimestamp++; + } + int totalRecords = allTimestamps.Count; if (totalRecords <= sampleSize) { @@ -249,8 +255,6 @@ public class Controller : ControllerBase Console.WriteLine("SampledTimestamps = " + allTimestamps.Count); return allTimestamps; } - - int interval = totalRecords / sampleSize; var sampledTimestamps = new List(); diff --git a/csharp/App/Backend/Database/Create.cs b/csharp/App/Backend/Database/Create.cs index eadafd3dd..f697a8931 100644 --- a/csharp/App/Backend/Database/Create.cs +++ b/csharp/App/Backend/Database/Create.cs @@ -26,7 +26,7 @@ public static partial class Db public static Boolean Create(Installation installation) { - installation.S3BucketId = Installations.Count(f => f.Product == installation.Product)+1; + installation.S3BucketId = Installations.Where(inst => inst.Product == installation.Product).Max(inst => (int?)inst.S3BucketId)+1 ?? 0; // SQLite wrapper is smart and *modifies* t's Id to the one generated (autoincrement) by the insertion return Insert(installation); diff --git a/csharp/App/SaliMax/src/MiddlewareClasses/MiddlewareAgent.cs b/csharp/App/SaliMax/src/MiddlewareClasses/MiddlewareAgent.cs index 32950ff50..51688b92a 100644 --- a/csharp/App/SaliMax/src/MiddlewareClasses/MiddlewareAgent.cs +++ b/csharp/App/SaliMax/src/MiddlewareClasses/MiddlewareAgent.cs @@ -9,7 +9,7 @@ namespace InnovEnergy.App.SaliMax.MiddlewareClasses; public static class MiddlewareAgent { - private static UdpClient _udpListener = null!; + public static UdpClient UdpListener = null!; private static IPAddress? _controllerIpAddress; private static EndPoint? _endPoint; @@ -24,9 +24,9 @@ public static class MiddlewareAgent const Int32 udpPort = 9000; _endPoint = new IPEndPoint(_controllerIpAddress, udpPort); - _udpListener = new UdpClient(); - _udpListener.Client.Blocking = false; - _udpListener.Client.Bind(_endPoint); + UdpListener = new UdpClient(); + UdpListener.Client.Blocking = false; + UdpListener.Client.Bind(_endPoint); } private static IPAddress FindVpnIp() @@ -53,7 +53,7 @@ public static class MiddlewareAgent public static Configuration? SetConfigurationFile() { - if (_udpListener.Available > 0) + if (UdpListener.Available > 0) { IPEndPoint? serverEndpoint = null; @@ -61,7 +61,7 @@ public static class MiddlewareAgent var replyMessage = "ACK"; var replyData = Encoding.UTF8.GetBytes(replyMessage); - var udpMessage = _udpListener.Receive(ref serverEndpoint); + var udpMessage = UdpListener.Receive(ref serverEndpoint); var message = Encoding.UTF8.GetString(udpMessage); var config = JsonSerializer.Deserialize(message); @@ -74,13 +74,13 @@ public static class MiddlewareAgent config.CalibrationChargeDate); // Send the reply to the sender's endpoint - _udpListener.Send(replyData, replyData.Length, serverEndpoint); + UdpListener.Send(replyData, replyData.Length, serverEndpoint); Console.WriteLine($"Replied to {serverEndpoint}: {replyMessage}"); return config; } } - if (_endPoint != null && !_endPoint.Equals(_udpListener.Client.LocalEndPoint as IPEndPoint)) + if (_endPoint != null && !_endPoint.Equals(UdpListener.Client.LocalEndPoint as IPEndPoint)) { Console.WriteLine("UDP address has changed, rebinding..."); InitializeCommunicationToMiddleware(); diff --git a/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/config.py b/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/config.py index adfb28dfb..8f593e498 100755 --- a/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/config.py +++ b/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/config.py @@ -54,6 +54,6 @@ INNOVENERGY_PROTOCOL_VERSION = '48TL200V3' # S3 Credentials -S3BUCKET = "35-c0436b6a-d276-4cd8-9c44-1eae86cf5d0e" -S3KEY = "EXO2a70f415b6b387b5628020bd" -S3SECRET = "qdlYoXDZyME8LEB8BFTuCmJoTzkP2Nebr2jVmlXUzgY" +S3BUCKET = "91-c0436b6a-d276-4cd8-9c44-1eae86cf5d0e" +S3KEY = "EXOe6dce12288f11a676c2025a1" +S3SECRET = "xpqM4Eh0Gg1HaYVkzlR9X6PwYa-QNb-mVk0XUkwW3cc"