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 request = _S3Config.CreatePutRequest(s3Path);
|
||||
|
||||
// Compress CSV data to a byte array
|
||||
// Compress JSON data to a byte array
|
||||
byte[] compressedBytes;
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
//Create a zip directory and put the compressed file inside
|
||||
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 writer = new StreamWriter(entryStream))
|
||||
{
|
||||
|
|
@ -114,18 +114,4 @@ public class AggregatedData
|
|||
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.Security;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Flurl.Http;
|
||||
using InnovEnergy.App.SodiStoreMax;
|
||||
using InnovEnergy.App.SodiStoreMax.Devices;
|
||||
|
|
@ -29,7 +32,6 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
|||
using InnovEnergy.Lib.Units;
|
||||
using InnovEnergy.Lib.Utils;
|
||||
using InnovEnergy.App.SodiStoreMax.DataTypes;
|
||||
using InnovEnergy.Lib.Utils.Net;
|
||||
using Newtonsoft.Json;
|
||||
using static System.Int32;
|
||||
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.Orange
|
||||
: 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)
|
||||
{
|
||||
|
||||
var csv = status.ToCsv();
|
||||
|
||||
Dictionary<string, object> jsonData = new Dictionary<string, object>();
|
||||
//Console.WriteLine(csv);
|
||||
|
||||
|
|
@ -886,16 +889,12 @@ internal static class Program
|
|||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
|
||||
string[] parts = line.Split(';');
|
||||
//if (parts.Length < 2) continue;
|
||||
|
||||
string keyPath = parts[0];
|
||||
string value = parts[1];
|
||||
string unit = parts.Length > 2 ? parts[2].Trim() : "";
|
||||
//Console.WriteLine(line);
|
||||
// Console.WriteLine($"Key: {keyPath}, Value: {value}, Unit: {unit}");
|
||||
|
||||
InsertIntoJson(jsonData, keyPath.Split('/'), value);
|
||||
|
||||
}
|
||||
|
||||
string jsonOutput = JsonConvert.SerializeObject(jsonData, Formatting.None);
|
||||
|
|
@ -922,13 +921,12 @@ internal static class Program
|
|||
|
||||
var s3Path = timeStamp.ToUnixTime() + ".json";
|
||||
s3Path.WriteLine("");
|
||||
var csvToSend = logFileConcatenator.ConcatenateFiles(NbrOfFileToConcatenate);
|
||||
var jsonToSend = logFileConcatenator.ConcatenateFiles(NbrOfFileToConcatenate);
|
||||
|
||||
var request = s3Config.CreatePutRequest(s3Path);
|
||||
|
||||
//Use this for no compression
|
||||
//var response = await request.PutAsync(new StringContent(csv));
|
||||
var compressedBytes = CompresseBytes(csvToSend);
|
||||
var compressedBytes = CompresseBytes(jsonToSend);
|
||||
|
||||
// Encode the compressed byte array as a Base64 string
|
||||
string base64String = Convert.ToBase64String(compressedBytes);
|
||||
|
|
@ -961,7 +959,7 @@ internal static class Program
|
|||
{
|
||||
var s3Bucket = Config.Load().S3?.Bucket;
|
||||
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)
|
||||
{
|
||||
|
|
@ -971,27 +969,27 @@ internal static class Program
|
|||
Product = 0, // Salimax is always 0
|
||||
Status = _salimaxAlarmState,
|
||||
Type = MessageType.Heartbit,
|
||||
Timestamp = nameOfCsvFile
|
||||
Timestamp = nameOfJsonFile
|
||||
};
|
||||
if (s3Bucket != null)
|
||||
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;
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
//Create a zip directory and put the compressed file inside
|
||||
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 writer = new StreamWriter(entryStream))
|
||||
{
|
||||
writer.Write(csvToSend);
|
||||
writer.Write(jsonToSend);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
|
|||
|
||||
public class BatteryDeligreenRecord
|
||||
{
|
||||
public readonly BatteryDeligreenDataRecord BatteryDeligreenDataRecord;
|
||||
public readonly BatteryDeligreenAlarmRecord BatteryDeligreenAlarmRecord;
|
||||
public BatteryDeligreenDataRecord BatteryDeligreenDataRecord { get; }
|
||||
public BatteryDeligreenAlarmRecord BatteryDeligreenAlarmRecord { get; }
|
||||
|
||||
public BatteryDeligreenRecord(BatteryDeligreenDataRecord batteryDeligreenDataRecord, BatteryDeligreenAlarmRecord batteryDeligreenAlarmRecord)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue