use "required"
This commit is contained in:
parent
71ba569085
commit
d09c53ad92
|
@ -8,24 +8,14 @@ public class Battery48TlDevices
|
||||||
|
|
||||||
public Battery48TlDevices(IReadOnlyList<Battery48TlDevice> devices) => _Devices = devices;
|
public Battery48TlDevices(IReadOnlyList<Battery48TlDevice> devices) => _Devices = devices;
|
||||||
|
|
||||||
public Battery48TlRecords Read()
|
public Battery48TlRecords? Read()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var records = _Devices
|
var records = _Devices
|
||||||
.Select(TryRead)
|
.Select(TryRead)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.ToArray(_Devices.Count);
|
.ToList();
|
||||||
|
|
||||||
return new Battery48TlRecords(records);
|
return Battery48TlRecords.FromBatteries(records);
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Failed to read Battery data \n" + e.Message);
|
|
||||||
// TODO: log
|
|
||||||
|
|
||||||
return Battery48TlRecords.Null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Battery48TlRecord? TryRead(Battery48TlDevice d)
|
private static Battery48TlRecord? TryRead(Battery48TlDevice d)
|
||||||
|
|
|
@ -6,38 +6,39 @@ namespace InnovEnergy.Lib.Devices.Battery48TL;
|
||||||
|
|
||||||
public class Battery48TlRecords
|
public class Battery48TlRecords
|
||||||
{
|
{
|
||||||
public Battery48TlRecords(IReadOnlyList<Battery48TlRecord> records)
|
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 Percent CurrentMinSoc { get; init; }
|
||||||
|
public required Temperature Temperature { get; init; }
|
||||||
|
public required DcPower HeatingPower { get; init; }
|
||||||
|
|
||||||
|
public required IReadOnlyList<Battery48TlRecord> Devices { get; init; }
|
||||||
|
|
||||||
|
public static Battery48TlRecords? FromBatteries(IReadOnlyList<Battery48TlRecord>? records)
|
||||||
{
|
{
|
||||||
var empty = records.Count == 0;
|
if (records is null || records.Count == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
Devices = records;
|
return new Battery48TlRecords
|
||||||
Eoc = !empty && records.All(r => r.Eoc);
|
{
|
||||||
Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList();
|
Devices = records,
|
||||||
Alarms = records.SelectMany(r => r.Alarms) .Distinct().ToList();
|
Eoc = records.All(r => r.Eoc),
|
||||||
Soc = empty ? 0 : records.Average(r => r.Soc.Value);
|
Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(),
|
||||||
CurrentMinSoc = empty ? 0 : records.Min(r => r.Soc.Value);
|
Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(),
|
||||||
Temperature = records.Any() ? records.Average(b => b.Temperatures.Cells.Average.Value) : 0;
|
Soc = records.Average(r => r.Soc.Value),
|
||||||
HeatingPower = records.Any() ? records.Sum(b => b.HeatingPower) : 0;
|
CurrentMinSoc = records.Min(r => r.Soc.Value),
|
||||||
|
Temperature = records.Average(b => b.Temperatures.Cells.Average.Value),
|
||||||
|
HeatingPower = records.Sum(b => b.HeatingPower),
|
||||||
|
|
||||||
Dc = empty
|
Dc = DcBus.FromVoltageCurrent
|
||||||
? DcBus.Null
|
|
||||||
: DcBus.FromVoltageCurrent
|
|
||||||
(
|
(
|
||||||
records.Average(r => r.Dc.Voltage),
|
records.Average(r => r.Dc.Voltage),
|
||||||
records.Sum(r => r.Dc.Current)
|
records.Sum(r => r.Dc.Current)
|
||||||
);
|
)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public DcBus Dc { get; init; }
|
|
||||||
public Boolean Eoc { get; init; }
|
|
||||||
public IReadOnlyList<String> Warnings { get; init; }
|
|
||||||
public IReadOnlyList<String> Alarms { get; init; }
|
|
||||||
public Percent Soc { get; init; }
|
|
||||||
public Percent CurrentMinSoc { get; init; }
|
|
||||||
public Temperature Temperature { get; init; }
|
|
||||||
public DcPower HeatingPower { get; init; }
|
|
||||||
|
|
||||||
public IReadOnlyList<Battery48TlRecord> Devices { get; init; }
|
|
||||||
|
|
||||||
public static Battery48TlRecords Null => new Battery48TlRecords(Array.Empty<Battery48TlRecord>());
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue