Fixed bug in SodiStoreMax battery view.
This commit is contained in:
parent
96359fab08
commit
bcde77c567
|
|
@ -75,14 +75,14 @@ public class AggregatedData
|
||||||
var s3Path = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".json";
|
var s3Path = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".json";
|
||||||
var request = _S3Config.CreatePutRequest(s3Path);
|
var request = _S3Config.CreatePutRequest(s3Path);
|
||||||
|
|
||||||
// Compress CSV data to a byte array
|
// Compress JSON data to a byte array
|
||||||
byte[] compressedBytes;
|
byte[] compressedBytes;
|
||||||
using (var memoryStream = new MemoryStream())
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
//Create a zip directory and put the compressed file inside
|
//Create a zip directory and put the compressed file inside
|
||||||
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
|
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
|
||||||
{
|
{
|
||||||
var entry = archive.CreateEntry("data.json", CompressionLevel.SmallestSize); // Add CSV data to the ZIP archive
|
var entry = archive.CreateEntry("data.json", CompressionLevel.SmallestSize); // Add JSON data to the ZIP archive
|
||||||
using (var entryStream = entry.Open())
|
using (var entryStream = entry.Open())
|
||||||
using (var writer = new StreamWriter(entryStream))
|
using (var writer = new StreamWriter(entryStream))
|
||||||
{
|
{
|
||||||
|
|
@ -114,18 +114,4 @@ public class AggregatedData
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static HourlyData? Load(String dataFilePath)
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var csvString = File.ReadAllText(dataFilePath);
|
|
||||||
// return Deserialize<HourlyData>(jsonString)!;
|
|
||||||
// }
|
|
||||||
// catch (Exception e)
|
|
||||||
// {
|
|
||||||
// $"Failed to read config file {dataFilePath}, using default config\n{e}".WriteLine();
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,9 @@ using System.Reactive.Threading.Tasks;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using Flurl.Http;
|
using Flurl.Http;
|
||||||
using InnovEnergy.App.SodiStoreMax;
|
using InnovEnergy.App.SodiStoreMax;
|
||||||
using InnovEnergy.App.SodiStoreMax.Devices;
|
using InnovEnergy.App.SodiStoreMax.Devices;
|
||||||
|
|
@ -29,7 +32,6 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
||||||
using InnovEnergy.Lib.Units;
|
using InnovEnergy.Lib.Units;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using InnovEnergy.App.SodiStoreMax.DataTypes;
|
using InnovEnergy.App.SodiStoreMax.DataTypes;
|
||||||
using InnovEnergy.Lib.Utils.Net;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using static System.Int32;
|
using static System.Int32;
|
||||||
using static InnovEnergy.App.SodiStoreMax.AggregationService.Aggregator;
|
using static InnovEnergy.App.SodiStoreMax.AggregationService.Aggregator;
|
||||||
|
|
@ -486,6 +488,9 @@ internal static class Program
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Console.WriteLine("WARNING LIST IS" + warningList[0].Description);
|
||||||
|
|
||||||
|
|
||||||
_salimaxAlarmState = warningList.Any()
|
_salimaxAlarmState = warningList.Any()
|
||||||
? SalimaxAlarmState.Orange
|
? SalimaxAlarmState.Orange
|
||||||
: SalimaxAlarmState.Green; // this will be replaced by LedState
|
: SalimaxAlarmState.Green; // this will be replaced by LedState
|
||||||
|
|
@ -875,9 +880,7 @@ internal static class Program
|
||||||
|
|
||||||
private static async Task<Boolean> UploadCsv(StatusRecord status, DateTime timeStamp)
|
private static async Task<Boolean> UploadCsv(StatusRecord status, DateTime timeStamp)
|
||||||
{
|
{
|
||||||
|
|
||||||
var csv = status.ToCsv();
|
var csv = status.ToCsv();
|
||||||
|
|
||||||
Dictionary<string, object> jsonData = new Dictionary<string, object>();
|
Dictionary<string, object> jsonData = new Dictionary<string, object>();
|
||||||
//Console.WriteLine(csv);
|
//Console.WriteLine(csv);
|
||||||
|
|
||||||
|
|
@ -886,16 +889,12 @@ internal static class Program
|
||||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||||
|
|
||||||
string[] parts = line.Split(';');
|
string[] parts = line.Split(';');
|
||||||
//if (parts.Length < 2) continue;
|
|
||||||
|
|
||||||
string keyPath = parts[0];
|
string keyPath = parts[0];
|
||||||
string value = parts[1];
|
string value = parts[1];
|
||||||
string unit = parts.Length > 2 ? parts[2].Trim() : "";
|
string unit = parts.Length > 2 ? parts[2].Trim() : "";
|
||||||
//Console.WriteLine(line);
|
//Console.WriteLine(line);
|
||||||
// Console.WriteLine($"Key: {keyPath}, Value: {value}, Unit: {unit}");
|
// Console.WriteLine($"Key: {keyPath}, Value: {value}, Unit: {unit}");
|
||||||
|
|
||||||
InsertIntoJson(jsonData, keyPath.Split('/'), value);
|
InsertIntoJson(jsonData, keyPath.Split('/'), value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string jsonOutput = JsonConvert.SerializeObject(jsonData, Formatting.None);
|
string jsonOutput = JsonConvert.SerializeObject(jsonData, Formatting.None);
|
||||||
|
|
@ -922,13 +921,12 @@ internal static class Program
|
||||||
|
|
||||||
var s3Path = timeStamp.ToUnixTime() + ".json";
|
var s3Path = timeStamp.ToUnixTime() + ".json";
|
||||||
s3Path.WriteLine("");
|
s3Path.WriteLine("");
|
||||||
var csvToSend = logFileConcatenator.ConcatenateFiles(NbrOfFileToConcatenate);
|
var jsonToSend = logFileConcatenator.ConcatenateFiles(NbrOfFileToConcatenate);
|
||||||
|
|
||||||
var request = s3Config.CreatePutRequest(s3Path);
|
var request = s3Config.CreatePutRequest(s3Path);
|
||||||
|
|
||||||
//Use this for no compression
|
//Use this for no compression
|
||||||
//var response = await request.PutAsync(new StringContent(csv));
|
var compressedBytes = CompresseBytes(jsonToSend);
|
||||||
var compressedBytes = CompresseBytes(csvToSend);
|
|
||||||
|
|
||||||
// Encode the compressed byte array as a Base64 string
|
// Encode the compressed byte array as a Base64 string
|
||||||
string base64String = Convert.ToBase64String(compressedBytes);
|
string base64String = Convert.ToBase64String(compressedBytes);
|
||||||
|
|
@ -961,7 +959,7 @@ internal static class Program
|
||||||
{
|
{
|
||||||
var s3Bucket = Config.Load().S3?.Bucket;
|
var s3Bucket = Config.Load().S3?.Bucket;
|
||||||
var tryParse = TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
var tryParse = TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
||||||
var parse = TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
|
var parse = TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfJsonFile);
|
||||||
|
|
||||||
if (tryParse)
|
if (tryParse)
|
||||||
{
|
{
|
||||||
|
|
@ -971,27 +969,27 @@ internal static class Program
|
||||||
Product = 0, // Salimax is always 0
|
Product = 0, // Salimax is always 0
|
||||||
Status = _salimaxAlarmState,
|
Status = _salimaxAlarmState,
|
||||||
Type = MessageType.Heartbit,
|
Type = MessageType.Heartbit,
|
||||||
Timestamp = nameOfCsvFile
|
Timestamp = nameOfJsonFile
|
||||||
};
|
};
|
||||||
if (s3Bucket != null)
|
if (s3Bucket != null)
|
||||||
RabbitMqManager.InformMiddleware(returnedStatus);
|
RabbitMqManager.InformMiddleware(returnedStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Byte[] CompresseBytes(String csvToSend)
|
private static Byte[] CompresseBytes(String jsonToSend)
|
||||||
{
|
{
|
||||||
//Compress CSV data to a byte array
|
//Compress JSON data to a byte array
|
||||||
Byte[] compressedBytes;
|
Byte[] compressedBytes;
|
||||||
using (var memoryStream = new MemoryStream())
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
//Create a zip directory and put the compressed file inside
|
//Create a zip directory and put the compressed file inside
|
||||||
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
|
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
|
||||||
{
|
{
|
||||||
var entry = archive.CreateEntry("data.json", CompressionLevel.SmallestSize); // Add CSV data to the ZIP archive
|
var entry = archive.CreateEntry("data.json", CompressionLevel.SmallestSize); // Add JSON data to the ZIP archive
|
||||||
using (var entryStream = entry.Open())
|
using (var entryStream = entry.Open())
|
||||||
using (var writer = new StreamWriter(entryStream))
|
using (var writer = new StreamWriter(entryStream))
|
||||||
{
|
{
|
||||||
writer.Write(csvToSend);
|
writer.Write(jsonToSend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
|
||||||
|
|
||||||
public class BatteryDeligreenRecord
|
public class BatteryDeligreenRecord
|
||||||
{
|
{
|
||||||
public readonly BatteryDeligreenDataRecord BatteryDeligreenDataRecord;
|
public BatteryDeligreenDataRecord BatteryDeligreenDataRecord { get; }
|
||||||
public readonly BatteryDeligreenAlarmRecord BatteryDeligreenAlarmRecord;
|
public BatteryDeligreenAlarmRecord BatteryDeligreenAlarmRecord { get; }
|
||||||
|
|
||||||
public BatteryDeligreenRecord(BatteryDeligreenDataRecord batteryDeligreenDataRecord, BatteryDeligreenAlarmRecord batteryDeligreenAlarmRecord)
|
public BatteryDeligreenRecord(BatteryDeligreenDataRecord batteryDeligreenDataRecord, BatteryDeligreenAlarmRecord batteryDeligreenAlarmRecord)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue