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,88 +12,147 @@ 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
var dcBatteryPower = s.DcDc.Dc.Battery.Power; ? s.LoadOnAcIsland.Ac.Power.Active
var dcdcPower = s.DcDc.Dc.Link.Power; : 0; // TODO
var islandTopology = CreateIslandTopology(s, islandLoadPower, inverterPower);
// Power Calculated Values
ActivePower islandToGridBusPower = inverterPower + islandLoadPower;
var islandBusPv = 0.W(); // TODO if (s.GridMeter is null) // no grid meter?
var islandBusColumn = ColumnBox("Pv" , islandBusPv, return islandTopology; // we're done
"Island Bus", s.AcDc.Ac.PhasePowersActive(),
"Load" , islandLoadPower); var gridBusColumn = GridBusColumn(s);
var gridBox = CreateGridBox(s);
var dcBusLoad = 0.W(); // TODO ActivePower islandToGridBusPower = inverterPower + islandLoadPower;
var dcLinkVoltage = s.DcDc.Dc.Link.Voltage.ToDisplayString();
// return TextBlock
var pvOnDcPower = s.PvOnDc.Dc!.Power; // TODO ! // .AlignCenterVertical
var dcBusColumn = ColumnBox("Pv" , pvOnDcPower, // (
"Dc Bus", dcLinkVoltage, // gridBox , Flow.Horizontal(s.GridMeter.Ac.Power.Active),
"Load" , dcBusLoad); // 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 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);
return TextBlock
.AlignCenterVertical
(
islandBusColumn, Flow.Horizontal(inverterPower),
inverterBox , Flow.Horizontal(inverterPower),
dcBusColumn , Flow.Horizontal(dcdcPower),
dcDcBox , Flow.Horizontal(dcBatteryPower),
batteries
);
}
private static TextBlock CreateGridBox(StatusRecord statusRecord)
{
return statusRecord
.GridMeter!
.Ac
.PhasePowersActive()
.TitleBox("Grid");
}
private static TextBlock CreateDcDcBox(StatusRecord s)
{
var dc48Voltage = s.DcDc.Dc.Battery.Voltage.ToDisplayString();
return TextBlock
.AlignLeft(dc48Voltage)
.TitleBox("DC/DC");
}
private static TextBlock CreateInverterBox(StatusRecord s)
{
var inverterAcPhases = s var inverterAcPhases = s
.AcDc .AcDc
.Devices .Devices
.Select(d => d.Status.Ac.Power) .Select(d => d.Status.Ac.Power)
.ToArray(s.AcDc.Devices.Count) .ToReadOnlyList();
.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");
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 bat = s.Battery;
var batteryAvgBox = CreateAveragedBatteryBox(bat); var batteryAvgBox = CreateAveragedBatteryBox(bat);
var batteryBoxes = bat var batteryBoxes = bat
.Devices .Devices
.Select(CreateIndividualBattery) .Select(CreateIndividualBattery)
.ToArray(bat.Devices.Count) .ToReadOnlyList();
.AsReadOnlyList();
var individualBatteries = batteryBoxes.Any()
var individualBatteries = batteryBoxes.Any()
? TextBlock.AlignLeft(batteryBoxes) ? TextBlock.AlignLeft(batteryBoxes)
: TextBlock.Empty; : TextBlock.Empty;
var batteries = TextBlock
.AlignCenterVertical
(
batteryAvgBox //,
//individualBatteries // TODO
);
var islandTopology = TextBlock
.AlignCenterVertical
(
islandBusColumn, Flow.Horizontal(inverterPower),
inverterBox , Flow.Horizontal(inverterPower),
dcBusColumn , Flow.Horizontal(dcdcPower),
dcDcBox , Flow.Horizontal(dcBatteryPower),
batteries
);
if (s.GridMeter is null)
return islandTopology;
var gridMeterAc = s.GridMeter.Ac;
var gridBox = gridMeterAc.PhasePowersActive().TitleBox("Grid");
var gridToGridBus = Flow.Horizontal(gridMeterAc.Power.Active);
var gridBusColumn = GridBusColumn(s);
var gridBusToIslandBus = Flow.Horizontal(islandToGridBusPower);
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())
@ -66,7 +66,7 @@ public class TextBlock
return new TextBlock(alignedLines); return new TextBlock(alignedLines);
} }
public static TextBlock AlignTop(IReadOnlyList<Object> things) public static TextBlock AlignTop(IReadOnlyList<Object> things)
{ {
var columns = things var columns = things