reorder Topology generation code

This commit is contained in:
ig 2023-08-23 09:23:50 +02:00
parent d731c12f64
commit 664290c44b
4 changed files with 125 additions and 68 deletions

View File

@ -2,6 +2,7 @@ using InnovEnergy.Lib.Devices.Battery48TL.DataTypes;
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc; using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes; using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes;
using InnovEnergy.Lib.Time.Unix; using InnovEnergy.Lib.Time.Unix;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Utils;
namespace InnovEnergy.App.SaliMax.Ess; namespace InnovEnergy.App.SaliMax.Ess;
@ -26,9 +27,7 @@ public static class Controller
public static EssControl ControlEss(this StatusRecord s) public static EssControl ControlEss(this StatusRecord s)
{ {
var mode = s.SelectControlMode(); var mode = s.SelectControlMode().WriteLine();
mode.WriteLine();
if (mode is EssMode.Off or EssMode.NoGridMeter) if (mode is EssMode.Off or EssMode.NoGridMeter)
return EssControl.Default; return EssControl.Default;
@ -164,7 +163,7 @@ public static class Controller
maxChargePower = s.Battery.Devices.Sum(b => b.MaxChargePower); maxChargePower = s.Battery.Devices.Sum(b => b.MaxChargePower);
} }
maxChargePower.WriteLine(" Max Charge Power"); maxChargePower.W().ToDisplayString().WriteLine(" Max Charge Power");
return maxChargePower; return maxChargePower;
} }

View File

@ -128,7 +128,6 @@ internal static class Program
var loadOnDc = new DcPowerDevice { Power = dcPower} ; var loadOnDc = new DcPowerDevice { Power = dcPower} ;
return new StatusRecord return new StatusRecord
{ {
AcDc = acDc ?? AcDcDevicesRecord.Null, AcDc = acDc ?? AcDcDevicesRecord.Null,

View File

@ -12,62 +12,61 @@ public static class Topology
{ {
public static TextBlock From(this StatusRecord s) public static TextBlock From(this StatusRecord s)
{ {
// Topology is built up from right to left
// Power Measurement Values // Power Measurement Values
var inverterPower = s.AcDc.Ac.Power.Active; var inverterPower = s.AcDc.Ac.Power.Active;
var islandLoadPower = s.LoadOnAcIsland is not null ? s.LoadOnAcIsland.Ac.Power.Active : 0; var islandLoadPower = s.LoadOnAcIsland is not null
? s.LoadOnAcIsland.Ac.Power.Active
: 0; // TODO
var islandTopology = CreateIslandTopology(s, islandLoadPower, inverterPower);
if (s.GridMeter is null) // no grid meter?
return islandTopology; // we're done
var gridBusColumn = GridBusColumn(s);
var gridBox = CreateGridBox(s);
ActivePower islandToGridBusPower = inverterPower + islandLoadPower;
// return TextBlock
// .AlignCenterVertical
// (
// gridBox , Flow.Horizontal(s.GridMeter.Ac.Power.Active),
// gridBusColumn, Flow.Horizontal(islandToGridBusPower),
// islandTopology
// );
var gridTopology = TextBlock
.AlignCenterVertical
(
gridBox,
Flow.Horizontal(s.GridMeter.Ac.Power.Active),
gridBusColumn
);
return TextBlock.AlignCenterVertical
(
gridTopology,
Flow.Horizontal(islandToGridBusPower),
islandTopology
);
}
private static TextBlock CreateIslandTopology(StatusRecord s, ActivePower islandLoadPower, ActivePower inverterPower)
{
var dcBatteryPower = s.DcDc.Dc.Battery.Power; var dcBatteryPower = s.DcDc.Dc.Battery.Power;
var dcdcPower = s.DcDc.Dc.Link.Power; var dcdcPower = s.DcDc.Dc.Link.Power;
var batteries = CreateBatteryColumn(s);
var dcBusColumn = CreateDcBusColumn(s);
var islandBusColumn = CreateIslandBusColumn(s, islandLoadPower);
var inverterBox = CreateInverterBox(s);
var dcDcBox = CreateDcDcBox(s);
// Power Calculated Values return TextBlock
ActivePower islandToGridBusPower = inverterPower + islandLoadPower;
var islandBusPv = 0.W(); // TODO
var islandBusColumn = ColumnBox("Pv" , islandBusPv,
"Island Bus", s.AcDc.Ac.PhasePowersActive(),
"Load" , islandLoadPower);
var dcBusLoad = 0.W(); // TODO
var dcLinkVoltage = s.DcDc.Dc.Link.Voltage.ToDisplayString();
var pvOnDcPower = s.PvOnDc.Dc!.Power; // TODO !
var dcBusColumn = ColumnBox("Pv" , pvOnDcPower,
"Dc Bus", dcLinkVoltage,
"Load" , dcBusLoad);
var inverterAcPhases = s
.AcDc
.Devices
.Select(d => d.Status.Ac.Power)
.ToArray(s.AcDc.Devices.Count)
.AsReadOnlyList();
var inverterBox = TextBlock.AlignLeft(inverterAcPhases).TitleBox("AC/DC");
var dc48Voltage = s.DcDc.Dc.Battery.Voltage.ToDisplayString();
var dcDcBox = TextBlock.AlignLeft(dc48Voltage) .TitleBox("DC/DC");
var bat = s.Battery;
var batteryAvgBox = CreateAveragedBatteryBox(bat);
var batteryBoxes = bat
.Devices
.Select(CreateIndividualBattery)
.ToArray(bat.Devices.Count)
.AsReadOnlyList();
var individualBatteries = batteryBoxes.Any()
? TextBlock.AlignLeft(batteryBoxes)
: TextBlock.Empty;
var batteries = TextBlock
.AlignCenterVertical
(
batteryAvgBox //,
//individualBatteries // TODO
);
var islandTopology = TextBlock
.AlignCenterVertical .AlignCenterVertical
( (
islandBusColumn, Flow.Horizontal(inverterPower), islandBusColumn, Flow.Horizontal(inverterPower),
@ -76,24 +75,84 @@ public static class Topology
dcDcBox , Flow.Horizontal(dcBatteryPower), dcDcBox , Flow.Horizontal(dcBatteryPower),
batteries batteries
); );
}
if (s.GridMeter is null) private static TextBlock CreateGridBox(StatusRecord statusRecord)
return islandTopology; {
return statusRecord
.GridMeter!
.Ac
.PhasePowersActive()
.TitleBox("Grid");
}
var gridMeterAc = s.GridMeter.Ac; private static TextBlock CreateDcDcBox(StatusRecord s)
var gridBox = gridMeterAc.PhasePowersActive().TitleBox("Grid"); {
var gridToGridBus = Flow.Horizontal(gridMeterAc.Power.Active); var dc48Voltage = s.DcDc.Dc.Battery.Voltage.ToDisplayString();
var gridBusColumn = GridBusColumn(s);
var gridBusToIslandBus = Flow.Horizontal(islandToGridBusPower); return TextBlock
.AlignLeft(dc48Voltage)
.TitleBox("DC/DC");
}
private static TextBlock CreateInverterBox(StatusRecord s)
{
var inverterAcPhases = s
.AcDc
.Devices
.Select(d => d.Status.Ac.Power)
.ToReadOnlyList();
return TextBlock
.AlignLeft(inverterAcPhases)
.TitleBox("AC/DC");
}
private static TextBlock CreateIslandBusColumn(StatusRecord s, ActivePower islandLoadPower)
{
var islandBusPv = 0.W(); // TODO
return ColumnBox
(
"Pv", islandBusPv,
"Island Bus", s.AcDc.Ac.PhasePowersActive(),
"Load", islandLoadPower
);
}
private static TextBlock CreateDcBusColumn(StatusRecord s)
{
var dcBusLoad = 0.W(); // TODO
var pvOnDcPower = s.PvOnDc.Dc!.Power; // TODO !
var dcLinkVoltage = s.DcDc.Dc.Link.Voltage.ToDisplayString();
return ColumnBox
(
"Pv" , pvOnDcPower,
"Dc Bus", dcLinkVoltage,
"Load" , dcBusLoad
);
}
private static TextBlock CreateBatteryColumn(StatusRecord s)
{
var bat = s.Battery;
var batteryAvgBox = CreateAveragedBatteryBox(bat);
var batteryBoxes = bat
.Devices
.Select(CreateIndividualBattery)
.ToReadOnlyList();
var individualBatteries = batteryBoxes.Any()
? TextBlock.AlignLeft(batteryBoxes)
: TextBlock.Empty;
return TextBlock return TextBlock
.AlignCenterVertical .AlignCenterVertical
( (
gridBox, batteryAvgBox //,
gridToGridBus, //individualBatteries // TODO
gridBusColumn,
gridBusToIslandBus,
islandTopology
); );
} }

View File

@ -10,11 +10,11 @@ public class TextBlock
public static TextBlock Empty { get; } = new TextBlock(); public static TextBlock Empty { get; } = new TextBlock();
public static TextBlock AlignLeft(IReadOnlyList<Object> things) public static TextBlock AlignLeft(IEnumerable<Object> things)
{ {
var lines = things var lines = things
.SelectMany(GetLines) .SelectMany(GetLines)
.Where(l => !String.IsNullOrEmpty(l)) .Unless(String.IsNullOrEmpty)
.ToList(); .ToList();
if (!lines.Any()) if (!lines.Any())
@ -33,7 +33,7 @@ public class TextBlock
{ {
var lines = things var lines = things
.SelectMany(GetLines) .SelectMany(GetLines)
.Where(l => !String.IsNullOrEmpty(l)) .Unless(String.IsNullOrEmpty)
.ToList(); .ToList();
if (!lines.Any()) if (!lines.Any())