using InnovEnergy.Lib.Units; using InnovEnergy.Lib.Units.Composite; namespace InnovEnergy.Lib.Devices.Battery48TL; public class Battery48TlRecords { public Battery48TlRecords(IReadOnlyList records) { var empty = records.Count == 0; Devices = records; Eoc = !empty && records.All(r => r.Eoc); Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(); Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(); Soc = empty ? 0 : records.Min(r => r.Soc.Value); Temperature = records.Any() ? records.Average(b => b.Temperatures.Cells.Average.Value) : 0; HeatingCurrent = records.Any() ? records.Sum(b => b.HeatingCurrent) : 0; Dc = empty ? DcBus.FromVoltageCurrent(0, 0) : DcBus.FromVoltageCurrent ( records.Average(r => r.Dc.Voltage), records.Sum(r => r.Dc.Current) ); } public DcBus Dc { get; init; } public Boolean Eoc { get; init; } public IReadOnlyList Warnings { get; init; } public IReadOnlyList Alarms { get; init; } public Percent Soc { get; init; } public Temperature Temperature { get; init; } public Current HeatingCurrent { get; init; } public IReadOnlyList Devices { get; init; } public static Battery48TlRecords Null => new Battery48TlRecords(Array.Empty()); }