51 lines
2.5 KiB
C#
51 lines
2.5 KiB
C#
using InnovEnergy.Lib.Units;
|
|
using InnovEnergy.Lib.Units.Composite;
|
|
using InnovEnergy.Lib.Units.Power;
|
|
|
|
namespace InnovEnergy.Lib.Devices.Battery250Up;
|
|
|
|
public class Battery250UpRecords
|
|
{
|
|
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; }
|
|
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; }
|
|
public required Boolean CalibrationChargeRequested { get; init; }
|
|
|
|
public required IReadOnlyList<Battery250UpRecord> Devices { get; init; }
|
|
|
|
public static Battery250UpRecords? FromBatteries(IReadOnlyList<Battery250UpRecord>? records)
|
|
{
|
|
if (records is null || records.Count == 0)
|
|
return null;
|
|
|
|
return new Battery250UpRecords
|
|
{
|
|
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),
|
|
SocAh = records.Average(r => r.SOCAh),
|
|
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),
|
|
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
|
|
|
|
Dc = new()
|
|
{
|
|
Voltage = records.Average(r => r.Dc.Voltage),
|
|
Current = records.Sum(r => r.Dc.Current),
|
|
}
|
|
};
|
|
}
|
|
|
|
}
|