Aggreagte data for Sinexcel installation
This commit is contained in:
parent
88b5591066
commit
efa8454ddd
|
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace InnovEnergy.App.GrowattCommunication.AggregationService;
|
||||
|
||||
|
||||
public class HourlyEnergyData
|
||||
{
|
||||
public String Type { get; set; } = "Hourly";
|
||||
public DateTime Timestamp { get; set; }
|
||||
|
||||
public double SelfGeneratedElectricity { get; set; }
|
||||
public double ElectricityPurchased { get; set; }
|
||||
public double ElectricityFed { get; set; }
|
||||
public double BatteryChargeEnergy { get; set; }
|
||||
public double BatteryDischargeEnergy { get; set; }
|
||||
public double LoadPowerConsumption { get; set; }
|
||||
}
|
||||
|
||||
public class DailyEnergyData
|
||||
{
|
||||
public String Type { get; set; } = "Daily";
|
||||
public DateTime Timestamp { get; set; }
|
||||
|
||||
public double DailySelfGeneratedElectricity { get; set; }
|
||||
public double DailyElectricityPurchased { get; set; }
|
||||
public double DailyElectricityFed { get; set; }
|
||||
public double BatteryDailyChargeEnergy { get; set; }
|
||||
public double BatteryDailyDischargeEnergy { get; set; }
|
||||
public double DailyLoadPowerConsumption { get; set; }
|
||||
}
|
||||
|
||||
public static class AggregatedDataFileWriter
|
||||
{
|
||||
private static bool _folderCreated = false;
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = false
|
||||
};
|
||||
|
||||
public static void AppendHourlyData(HourlyEnergyData data, string baseFolder)
|
||||
{
|
||||
var filePath = GetDailyFilePath(data.Timestamp, baseFolder);
|
||||
AppendJsonLine(filePath, data);
|
||||
Console.WriteLine($"Hourly data appended to {filePath}");
|
||||
}
|
||||
|
||||
public static void AppendDailyData(DailyEnergyData data, string baseFolder)
|
||||
{
|
||||
var filePath = GetDailyFilePath(data.Timestamp, baseFolder);
|
||||
AppendJsonLine(filePath, data);
|
||||
Console.WriteLine($"Daily data appended to {filePath}");
|
||||
}
|
||||
|
||||
private static string GetDailyFilePath(DateTime timestamp, string baseFolder)
|
||||
{
|
||||
var folder = Path.Combine(baseFolder, "AggregatedData");
|
||||
|
||||
if (!_folderCreated)
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
_folderCreated = true;
|
||||
}
|
||||
|
||||
var fileName = timestamp.ToString("ddMMyyyy") + ".json";
|
||||
return Path.Combine(folder, fileName);
|
||||
}
|
||||
|
||||
private static void AppendJsonLine<T>(string filePath, T data)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(data, JsonOptions);
|
||||
File.AppendAllText(filePath, json + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace InnovEnergy.App.SinexcelCommunication.AggregationService;
|
||||
|
||||
public class HourlyEnergyData
|
||||
{
|
||||
public String Type { get; set; } = "Hourly";
|
||||
public DateTime Timestamp { get; set; }
|
||||
|
||||
public double SelfGeneratedElectricity { get; set; }
|
||||
public double ElectricityPurchased { get; set; }
|
||||
public double ElectricityFed { get; set; }
|
||||
public double BatteryChargeEnergy { get; set; }
|
||||
public double BatteryDischargeEnergy { get; set; }
|
||||
public double LoadPowerConsumption { get; set; }
|
||||
}
|
||||
|
||||
public class DailyEnergyData
|
||||
{
|
||||
public String Type { get; set; } = "Daily";
|
||||
public DateTime Timestamp { get; set; }
|
||||
|
||||
public double DailySelfGeneratedElectricity { get; set; }
|
||||
public double DailyElectricityPurchased { get; set; }
|
||||
public double DailyElectricityFed { get; set; }
|
||||
public double BatteryDailyChargeEnergy { get; set; }
|
||||
public double BatteryDailyDischargeEnergy { get; set; }
|
||||
public double DailyLoadPowerConsumption { get; set; }
|
||||
}
|
||||
|
||||
public static class AggregatedDataFileWriter
|
||||
{
|
||||
private static bool _folderCreated = false;
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = false
|
||||
};
|
||||
|
||||
public static void AppendHourlyData(HourlyEnergyData data, string baseFolder)
|
||||
{
|
||||
var filePath = GetDailyFilePath(data.Timestamp, baseFolder);
|
||||
AppendJsonLine(filePath, data);
|
||||
Console.WriteLine($"Hourly data appended to {filePath}");
|
||||
}
|
||||
|
||||
public static void AppendDailyData(DailyEnergyData data, string baseFolder)
|
||||
{
|
||||
var filePath = GetDailyFilePath(data.Timestamp, baseFolder);
|
||||
AppendJsonLine(filePath, data);
|
||||
Console.WriteLine($"Daily data appended to {filePath}");
|
||||
}
|
||||
|
||||
private static string GetDailyFilePath(DateTime timestamp, string baseFolder)
|
||||
{
|
||||
var folder = Path.Combine(baseFolder, "AggregatedData");
|
||||
|
||||
if (!_folderCreated)
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
_folderCreated = true;
|
||||
}
|
||||
|
||||
var fileName = timestamp.ToString("ddMMyyyy") + ".json";
|
||||
return Path.Combine(folder, fileName);
|
||||
}
|
||||
|
||||
private static void AppendJsonLine<T>(string filePath, T data)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(data, JsonOptions);
|
||||
File.AppendAllText(filePath, json + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ public static class Aggregator
|
|||
dailyAggregatedData.Save("DailyData");
|
||||
if (await dailyAggregatedData.PushToS3())
|
||||
{
|
||||
DeleteHourlyData("HourlyData",currentTime.ToUnixTime());
|
||||
//DeleteHourlyData("HourlyData",currentTime.ToUnixTime());
|
||||
//AggregatedData.DeleteDailyData("DailyData");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue