Innovenergy_trunk/csharp/Lib/Devices/Battery48TL/Battery48TlRecords.cs

50 lines
2.5 KiB
C#
Raw Normal View History

2023-06-13 10:53:52 +00:00
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Units.Power;
2023-06-13 10:53:52 +00:00
namespace InnovEnergy.Lib.Devices.Battery48TL;
public class Battery48TlRecords
{
public required DcBus Dc { get; init; }
public required Boolean Eoc { get; init; }
public required IReadOnlyList<String> Warnings { get; init; }
public required IReadOnlyList<String> Alarms { get; init; }
public required Percent Soc { get; init; }
2024-01-19 11:33:21 +00:00
public required Double SocAh { get; init; }
public required Percent CurrentMinSoc { get; init; }
public required Temperature Temperature { get; init; }
public required DcPower HeatingPower { get; init; }
public required TimeSpan TimeSinceToc { get; init; }
2023-09-01 12:14:34 +00:00
public required Boolean CalibrationChargeRequested { get; init; }
2023-08-30 14:47:28 +00:00
public required IReadOnlyList<Battery48TlRecord> Devices { get; init; }
public static Battery48TlRecords? FromBatteries(IReadOnlyList<Battery48TlRecord>? records)
2023-06-13 10:53:52 +00:00
{
2023-08-30 14:47:28 +00:00
if (records is null || records.Count == 0)
return null;
2023-06-13 10:53:52 +00:00
2023-08-30 14:47:28 +00:00
return new Battery48TlRecords
{
2023-09-01 12:14:34 +00:00
Devices = records,
Eoc = records.All(r => r.Eoc),
Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(),
Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(),
Soc = records.Average(r => r.Soc.Value),
2024-01-19 11:33:21 +00:00
SocAh = records.Average(r => r.SOCAh),
2023-09-01 12:14:34 +00:00
CurrentMinSoc = records.Min(r => r.Soc.Value),
Temperature = records.Average(b => b.Temperatures.Cells.Average.Value),
HeatingPower = records.Sum(b => b.HeatingPower),
TimeSinceToc = records.Max(r => r.TimeSinceTOC),
2024-04-11 11:57:20 +00:00
CalibrationChargeRequested = records.Any(r => r.CalibrationChargeRequested), // we changed this to Any instead of All, it's mean we wait only one battery to reach the 7 days
2023-08-31 13:16:20 +00:00
2023-08-31 12:16:09 +00:00
Dc = new()
{
Voltage = records.Average(r => r.Dc.Voltage),
Current = records.Sum(r => r.Dc.Current),
}
2023-08-30 14:47:28 +00:00
};
2023-06-13 10:53:52 +00:00
}
}