reorder Topology generation code
This commit is contained in:
parent
d731c12f64
commit
664290c44b
|
@ -2,6 +2,7 @@ using InnovEnergy.Lib.Devices.Battery48TL.DataTypes;
|
|||
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
|
||||
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes;
|
||||
using InnovEnergy.Lib.Time.Unix;
|
||||
using InnovEnergy.Lib.Units;
|
||||
using InnovEnergy.Lib.Utils;
|
||||
|
||||
namespace InnovEnergy.App.SaliMax.Ess;
|
||||
|
@ -26,9 +27,7 @@ public static class Controller
|
|||
|
||||
public static EssControl ControlEss(this StatusRecord s)
|
||||
{
|
||||
var mode = s.SelectControlMode();
|
||||
|
||||
mode.WriteLine();
|
||||
var mode = s.SelectControlMode().WriteLine();
|
||||
|
||||
if (mode is EssMode.Off or EssMode.NoGridMeter)
|
||||
return EssControl.Default;
|
||||
|
@ -164,7 +163,7 @@ public static class Controller
|
|||
maxChargePower = s.Battery.Devices.Sum(b => b.MaxChargePower);
|
||||
}
|
||||
|
||||
maxChargePower.WriteLine(" Max Charge Power");
|
||||
maxChargePower.W().ToDisplayString().WriteLine(" Max Charge Power");
|
||||
|
||||
return maxChargePower;
|
||||
}
|
||||
|
|
|
@ -128,7 +128,6 @@ internal static class Program
|
|||
|
||||
var loadOnDc = new DcPowerDevice { Power = dcPower} ;
|
||||
|
||||
|
||||
return new StatusRecord
|
||||
{
|
||||
AcDc = acDc ?? AcDcDevicesRecord.Null,
|
||||
|
|
|
@ -12,88 +12,147 @@ public static class Topology
|
|||
{
|
||||
public static TextBlock From(this StatusRecord s)
|
||||
{
|
||||
// Topology is built up from right to left
|
||||
|
||||
// Power Measurement Values
|
||||
|
||||
var inverterPower = s.AcDc.Ac.Power.Active;
|
||||
var islandLoadPower = s.LoadOnAcIsland is not null ? s.LoadOnAcIsland.Ac.Power.Active : 0;
|
||||
var dcBatteryPower = s.DcDc.Dc.Battery.Power;
|
||||
var dcdcPower = s.DcDc.Dc.Link.Power;
|
||||
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);
|
||||
|
||||
// Power Calculated Values
|
||||
ActivePower islandToGridBusPower = inverterPower + islandLoadPower;
|
||||
|
||||
var islandBusPv = 0.W(); // TODO
|
||||
var islandBusColumn = ColumnBox("Pv" , islandBusPv,
|
||||
"Island Bus", s.AcDc.Ac.PhasePowersActive(),
|
||||
"Load" , islandLoadPower);
|
||||
// return TextBlock
|
||||
// .AlignCenterVertical
|
||||
// (
|
||||
// gridBox , Flow.Horizontal(s.GridMeter.Ac.Power.Active),
|
||||
// gridBusColumn, Flow.Horizontal(islandToGridBusPower),
|
||||
// islandTopology
|
||||
// );
|
||||
|
||||
var dcBusLoad = 0.W(); // TODO
|
||||
var dcLinkVoltage = s.DcDc.Dc.Link.Voltage.ToDisplayString();
|
||||
var gridTopology = TextBlock
|
||||
.AlignCenterVertical
|
||||
(
|
||||
gridBox,
|
||||
Flow.Horizontal(s.GridMeter.Ac.Power.Active),
|
||||
gridBusColumn
|
||||
);
|
||||
|
||||
var pvOnDcPower = s.PvOnDc.Dc!.Power; // TODO !
|
||||
var dcBusColumn = ColumnBox("Pv" , pvOnDcPower,
|
||||
"Dc Bus", dcLinkVoltage,
|
||||
"Load" , dcBusLoad);
|
||||
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
|
||||
.AcDc
|
||||
.Devices
|
||||
.Select(d => d.Status.Ac.Power)
|
||||
.ToArray(s.AcDc.Devices.Count)
|
||||
.AsReadOnlyList();
|
||||
.ToReadOnlyList();
|
||||
|
||||
var inverterBox = TextBlock.AlignLeft(inverterAcPhases).TitleBox("AC/DC");
|
||||
return TextBlock
|
||||
.AlignLeft(inverterAcPhases)
|
||||
.TitleBox("AC/DC");
|
||||
}
|
||||
|
||||
var dc48Voltage = s.DcDc.Dc.Battery.Voltage.ToDisplayString();
|
||||
var dcDcBox = TextBlock.AlignLeft(dc48Voltage) .TitleBox("DC/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)
|
||||
.ToArray(bat.Devices.Count)
|
||||
.AsReadOnlyList();
|
||||
.ToReadOnlyList();
|
||||
|
||||
var individualBatteries = batteryBoxes.Any()
|
||||
? TextBlock.AlignLeft(batteryBoxes)
|
||||
: 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
|
||||
.AlignCenterVertical
|
||||
(
|
||||
gridBox,
|
||||
gridToGridBus,
|
||||
gridBusColumn,
|
||||
gridBusToIslandBus,
|
||||
islandTopology
|
||||
batteryAvgBox //,
|
||||
//individualBatteries // TODO
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ public class 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
|
||||
.SelectMany(GetLines)
|
||||
.Where(l => !String.IsNullOrEmpty(l))
|
||||
.Unless(String.IsNullOrEmpty)
|
||||
.ToList();
|
||||
|
||||
if (!lines.Any())
|
||||
|
@ -33,7 +33,7 @@ public class TextBlock
|
|||
{
|
||||
var lines = things
|
||||
.SelectMany(GetLines)
|
||||
.Where(l => !String.IsNullOrEmpty(l))
|
||||
.Unless(String.IsNullOrEmpty)
|
||||
.ToList();
|
||||
|
||||
if (!lines.Any())
|
||||
|
|
Loading…
Reference in New Issue