From 8631ada267ac489373cfcd9bd6e9c8cffa915a63 Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 20 Apr 2023 13:20:26 +0200 Subject: [PATCH] Delete Log and Salimax Utils(it has only Round3) function --- csharp/App/SaliMax/src/Log/Ampt.cs | 26 ----- csharp/App/SaliMax/src/Log/Battery48Tl.cs | 26 ----- csharp/App/SaliMax/src/Log/EmuMeter.cs | 46 -------- csharp/App/SaliMax/src/Log/JsonUtil.cs | 118 --------------------- csharp/App/SaliMax/src/Log/Salimax.cs | 93 ---------------- csharp/App/SaliMax/src/Log/TruConvertAc.cs | 65 ------------ csharp/App/SaliMax/src/Log/TruConvertDc.cs | 32 ------ csharp/App/SaliMax/src/Utils.cs | 11 -- 8 files changed, 417 deletions(-) delete mode 100644 csharp/App/SaliMax/src/Log/Ampt.cs delete mode 100644 csharp/App/SaliMax/src/Log/Battery48Tl.cs delete mode 100644 csharp/App/SaliMax/src/Log/EmuMeter.cs delete mode 100644 csharp/App/SaliMax/src/Log/JsonUtil.cs delete mode 100644 csharp/App/SaliMax/src/Log/Salimax.cs delete mode 100644 csharp/App/SaliMax/src/Log/TruConvertAc.cs delete mode 100644 csharp/App/SaliMax/src/Log/TruConvertDc.cs delete mode 100644 csharp/App/SaliMax/src/Utils.cs diff --git a/csharp/App/SaliMax/src/Log/Ampt.cs b/csharp/App/SaliMax/src/Log/Ampt.cs deleted file mode 100644 index efaa6e388..000000000 --- a/csharp/App/SaliMax/src/Log/Ampt.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.Lib.Devices.AMPT; -using InnovEnergy.Lib.StatusApi; - -namespace InnovEnergy.App.SaliMax.Log; - -public static class Ampt -{ - public static JsonObject? Log(this AmptStatus? s) - { - if (s is null) - return null; - - // TODO return one AMPT device to sum all the other - - return DeviceType - .PvOnDc - .CreateDevice("AMPT") - .AddProp("Current 1", s.Devices[0].Dc.Current) - .AddProp("Current 2", s.Devices[1].Dc.Current) - .AddProp("Voltage 1", s.Devices[0].Dc.Voltage) - .AddProp("Voltage 2", s.Devices[1].Dc.Voltage) - .AddProp("Power 1", s.Devices[0].Dc.Current * s.Devices[0].Dc.Voltage) - .AddProp("Power 2", s.Devices[1].Dc.Current * s.Devices[1].Dc.Voltage); - } -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Log/Battery48Tl.cs b/csharp/App/SaliMax/src/Log/Battery48Tl.cs deleted file mode 100644 index f2c85bcbf..000000000 --- a/csharp/App/SaliMax/src/Log/Battery48Tl.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.Lib.Devices.Battery48TL; -using InnovEnergy.Lib.StatusApi; - -namespace InnovEnergy.App.SaliMax.Log; - -public static class Battery48Tl -{ - public static JsonObject? Log(this Battery48TLStatus? s) - { - if (s is null) - return null; - - return DeviceType - .Battery - .CreateDevice("48TL Battery") - .AddDc48Connection(s.Dc.Current.Round3(),s.Dc.Voltage.Round3()) - .AddAlarms(s.Alarms) - .AddWarnings(s.Warnings) - .AddProp("Soc", s.Soc.Round3()) - .AddProp("HeaterOn", s.HeaterOn) - .AddProp("EocReached", s.EocReached) - .AddProp("BatteryCold", s.BatteryCold) - .AddProp("Temperature", s.Temperature); - } -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Log/EmuMeter.cs b/csharp/App/SaliMax/src/Log/EmuMeter.cs deleted file mode 100644 index bb5dbbf29..000000000 --- a/csharp/App/SaliMax/src/Log/EmuMeter.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.Lib.Devices.EmuMeter; -using InnovEnergy.Lib.StatusApi; -using InnovEnergy.Lib.Utils; -using static DecimalMath.DecimalEx; -using static InnovEnergy.App.SaliMax.Log.JsonUtil; - -namespace InnovEnergy.App.SaliMax.Log; - -public static class EmuMeter -{ - public static JsonObject? Log(this EmuMeterStatus? s, DeviceType type, String serialNb) - { - if (s is null) - return null; - - - // - - var l1 = CreateAcPhase(s.Ac.L1.Current, s.Ac.L1.Voltage, ACos(s.Ac.L1.PowerFactor)); - var l2 = CreateAcPhase(s.Ac.L2.Current, s.Ac.L2.Voltage, ACos(s.Ac.L2.PowerFactor)); - var l3 = CreateAcPhase(s.Ac.L3.Current, s.Ac.L3.Voltage, ACos(s.Ac.L3.PowerFactor)); - - var ac = new JsonObject - { - ["L1"] = l1, - ["L2"] = l2, - ["L3"] = l3, - ["Frequency"] = s.Ac.Frequency - }; - - var status = new JsonObject - { - ["Ac"] = ac, - }; - - return new JsonObject { [$"EmuMeter {serialNb}"] = status }; - } - - private static IEnumerable GetAcPhases(this EmuMeterStatus s) - { - yield return CreateAcPhase(s.Ac.L1.Current.Round3(),s.Ac.L1.Voltage.Round3(),s.Ac.L1.PowerFactor.Apply(ACos).Round3()); - yield return CreateAcPhase(s.Ac.L2.Current.Round3(),s.Ac.L2.Voltage.Round3(),s.Ac.L2.PowerFactor.Apply(ACos).Round3()); - yield return CreateAcPhase(s.Ac.L3.Current.Round3(),s.Ac.L3.Voltage.Round3(),s.Ac.L3.PowerFactor.Apply(ACos).Round3()); - } -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Log/JsonUtil.cs b/csharp/App/SaliMax/src/Log/JsonUtil.cs deleted file mode 100644 index e82f2af01..000000000 --- a/csharp/App/SaliMax/src/Log/JsonUtil.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.Lib.StatusApi; - -namespace InnovEnergy.App.SaliMax.Log; - -public static class JsonUtil -{ - public static JsonObject CreateDevice(this DeviceType deviceType, String name) - { - return new JsonObject - { - { "Name", name }, - { "Type", deviceType.ToString() } - }; - } - - - public static JsonObject AddAcConnection(this JsonObject json, Decimal frequency, IEnumerable acPhases) - { - return json.AddAcConnection(frequency, acPhases.ToArray()); - } - - public static JsonObject AddAcConnection(this JsonObject json, Decimal frequency, params JsonNode[] acPhases) - { - return json - .AddProp("Ac", new JsonArray(acPhases)) - .AddProp("Frequency", frequency); - } - - public static JsonObject AddAlarms(this JsonObject json, IEnumerable alarms) - { - return json.AddProp("Alarms", alarms.ToJsonArray()); - } - - public static JsonObject AddWarnings(this JsonObject json, IEnumerable warnings) - { - return json.AddProp("Warnings", warnings.ToJsonArray()); - } - - - public static JsonObject AddProp(this JsonObject json, String key, JsonNode? value) - { - json.Add(key, value); - return json; - } - - - public static JsonObject AddDcConnection(this JsonObject json, Decimal current, Decimal voltage) - { - return json.AddProp("Dc", CreateDcPhase(current, voltage)); - } - - public static JsonObject AddDc48Connection(this JsonObject json, Decimal current, Decimal voltage) - { - return json.AddProp("Dc48", CreateDcPhase(current, voltage)); - } - - public static JsonObject CreateAcPhase(Decimal current, Decimal voltage, Decimal phi) - { - return new JsonObject - { - ["Current"] = current, - ["Voltage"] = voltage, - ["Phi" ] = phi, - }; - } - - - public static JsonObject CreateDcPhase(Decimal current, Decimal voltage) - { - return new JsonObject - { - ["Current"] = current , - ["Voltage"] = voltage , - ["Power"] = current * voltage, - }; - } - - public static Decimal Round3(this Decimal val) - { - return Decimal.Round(val, 3); - } - - public static Decimal Round0(this Decimal val) - { - return Decimal.Round(val, 0); - } - - public static JsonObject CreateBus(String left, String top, String bottom, String right, String name) - { - return new JsonObject - { - ["Name"] = name, - ["Left"] = left, - ["Top"] = top, - ["Bottom"] = bottom, - ["Right"] = right - }; - } - - public static String Port(DeviceType dt, BusPort bp, Boolean display = true) - { - return $"{Enum.GetName(dt)}:{Enum.GetName(bp)}:{(display ? "show" : "hide")}"; - } - - - public static JsonArray ToJsonArray(this IEnumerable things) - { - var jsonValues = things - .Select(t => t!.ToString()) - .Select(t => JsonValue.Create(t)) - .OfType() - .ToArray(); - - return new JsonArray(jsonValues); - } - -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Log/Salimax.cs b/csharp/App/SaliMax/src/Log/Salimax.cs deleted file mode 100644 index 09a7de12f..000000000 --- a/csharp/App/SaliMax/src/Log/Salimax.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.App.SaliMax.Controller; -using InnovEnergy.Lib.StatusApi; -using InnovEnergy.Lib.Time.Unix; - -namespace InnovEnergy.App.SaliMax.Log; - -public static class Salimax -{ - public static JsonObject ToLog(this StatusRecord s, UnixTime timestamp) - { - return new JsonObject - { - { "TimeStamp", timestamp.ToString()! }, - { "Devices", CreateDevices(s) } - }; - } - - private static JsonArray CreateDevices(StatusRecord s) - { - var devices = GetDevices(s).Where(d => d != null).ToArray(); - return new JsonArray(devices); - } - - private static IEnumerable GetDevices(StatusRecord s) - { - yield return s.InverterStatus.Log(); - yield return s.DcDcStatus.Log("3214"); - yield return s.GridMeterStatus.Log(DeviceType.Grid , "123"); - yield return s.AcInToAcOutMeterStatus.Log(DeviceType.AcInToAcOut, "123"); - yield return s.AmptStatus.Log(); - yield return s.BatteriesStatus![0].Log(); - yield return s.BatteriesStatus[1].Log(); - } - - private static JsonArray CreateTopology() - { - var acInBusJson = JsonUtil.CreateBus - ( - name: "AcIn", - left: JsonUtil.Port(DeviceType.Grid, BusPort.Ac), - top: JsonUtil.Port(DeviceType.PvOnAcIn, BusPort.Ac), - bottom: JsonUtil.Port(DeviceType.Load, BusPort.Infer), - right: JsonUtil.Port(DeviceType.AcInToAcOut, BusPort.Ac, false) - ); - - var acOutBusJson = JsonUtil.CreateBus - ( - name: "AcOut", - left: JsonUtil.Port(DeviceType.AcInToAcOut, BusPort.Ac, false), - top: JsonUtil.Port(DeviceType.PvOnAcOut, BusPort.Ac), - bottom: JsonUtil.Port(DeviceType.CriticalLoad, BusPort.Infer), - right: JsonUtil.Port(DeviceType.Inverter, BusPort.Ac) - ); - - var inverterJson = JsonUtil.CreateBus - ( - name: "Inverter", - left: JsonUtil.Port(DeviceType.Inverter, BusPort.Ac), - top: JsonUtil.Port(DeviceType.None, BusPort.None), - bottom: JsonUtil.Port(DeviceType.Losses, BusPort.Infer), - right: JsonUtil.Port(DeviceType.Inverter, BusPort.Dc) - ); - - var dcBusJson = JsonUtil.CreateBus - ( - name: "Dc", - left: JsonUtil.Port(DeviceType.Inverter, BusPort.Dc), - top: JsonUtil.Port(DeviceType.PvOnDc, BusPort.Dc), - bottom: JsonUtil.Port(DeviceType.DcLoad, BusPort.Infer), - right: JsonUtil.Port(DeviceType.DcDc, BusPort.Dc) - ); - - var dcDcJson = JsonUtil.CreateBus - ( - name: "DcDc", - left: JsonUtil.Port(DeviceType.DcDc, BusPort.Dc), - top: JsonUtil.Port(DeviceType.None, BusPort.None), - bottom: JsonUtil.Port(DeviceType.Losses, BusPort.Infer), - right: JsonUtil.Port(DeviceType.Battery, BusPort.Dc) - ); - - return new JsonArray(acInBusJson, acOutBusJson, inverterJson, dcBusJson, dcDcJson); - } - - public static JsonObject TopologyToLog(UnixTime timestamp) - { - return new JsonObject - { - { "Topology", CreateTopology() } - }; - } -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Log/TruConvertAc.cs b/csharp/App/SaliMax/src/Log/TruConvertAc.cs deleted file mode 100644 index af49cbc66..000000000 --- a/csharp/App/SaliMax/src/Log/TruConvertAc.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc; -using InnovEnergy.Lib.Utils; -using static DecimalMath.DecimalEx; -using static InnovEnergy.App.SaliMax.Log.JsonUtil; - -namespace InnovEnergy.App.SaliMax.Log; - -public static class TruConvertAc -{ - - public static JsonObject? Log(this TruConvertAcStatus? s) - { - if (s is null) - return null; - - var dcPower = s.Ac.ActivePower; - var dcVoltage = s.ActualDcLinkVoltageLowerHalfExt + s.ActualDcLinkVoltageUpperHalfExt; - var dcCurrent = dcVoltage != 0m - ? dcPower / dcVoltage - : 0m; - - - // TODO: acos quadrant - // TODO: total AC power - - var l1 = CreateAcPhase(s.Ac.L1.Current.Round3(), s.Ac.L1.Voltage.Round3(), s.Ac.L1.PowerFactor.Clamp(-1m, 1m).Apply(ACos).Round3()); - var l2 = CreateAcPhase(s.Ac.L2.Current.Round3(), s.Ac.L2.Voltage.Round3(), s.Ac.L1.PowerFactor.Clamp(-1m, 1m).Apply(ACos).Round3()); - var l3 = CreateAcPhase(s.Ac.L3.Current.Round3(), s.Ac.L3.Voltage.Round3(), s.Ac.L1.PowerFactor.Clamp(-1m, 1m).Apply(ACos).Round3()); - - var ac = new JsonObject - { - ["L1"] = l1, - ["L2"] = l2, - ["L3"] = l3, - ["Frequency"] = s.Ac.Frequency - }; - - var dc = CreateDcPhase(dcCurrent, dcVoltage); - - var status = new JsonObject - { - ["Ac"] = ac , - ["Dc"] = dc , - ["Warnings"] = s.Warnings.ToJsonArray() , - ["Alarms"] = s.Alarms.ToJsonArray() , - }; - - return new JsonObject { [$"TruConvertAc {s.SerialNumber}"] = status }; - } - - private static IEnumerable GetAcPhases(this TruConvertAcStatus s) - { - // Math.Acos return "NaN" if the cos phi < -1 or > 1 - // Decimal.Acos throw an exception - yield return JsonUtil.CreateAcPhase(s.Ac.L1.Current.Round3(), s.Ac.L1.Voltage.Round3(), - s.Ac.L1.PowerFactor.Clamp(-1m, 1m).Apply(ACos).Round3()); - - yield return JsonUtil.CreateAcPhase(s.Ac.L2.Current.Round3(), s.Ac.L2.Voltage.Round3(), - s.Ac.L2.PowerFactor.Clamp(-1m, 1m).Apply(ACos).Round3()); - - yield return JsonUtil.CreateAcPhase(s.Ac.L3.Current.Round3(), s.Ac.L3.Voltage.Round3(), - s.Ac.L3.PowerFactor.Clamp(-1m, 1m).Apply(ACos).Round3()); - } -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Log/TruConvertDc.cs b/csharp/App/SaliMax/src/Log/TruConvertDc.cs deleted file mode 100644 index 34c23942b..000000000 --- a/csharp/App/SaliMax/src/Log/TruConvertDc.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Text.Json.Nodes; -using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc; -using static InnovEnergy.App.SaliMax.Log.JsonUtil; - -namespace InnovEnergy.App.SaliMax.Log; - -using JO = JsonObject; - -public static class TruConvertDc -{ - // TODO: remove serialNb arg, embed TruConvertDcStatus - public static JsonObject? Log(this TruConvertDcStatus? s, String serialNb) - { - if (s is null) - return null; - - var dcCurrent = s.Dc.Current; - - return new JO - { - { - $"TruConvertDc {serialNb}", new JO - { - { "Dc" , CreateDcPhase(dcCurrent, s.Dc.Voltage) }, - { "Dc48" , CreateDcPhase(s.BatteryCurrent, s.BatteryVoltage) }, - { "Warnings", s.Warnings.ToJsonArray() }, - { "Alarms" , s.Alarms.ToJsonArray() }, - } - } - }; - } -} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Utils.cs b/csharp/App/SaliMax/src/Utils.cs deleted file mode 100644 index 1cf608f84..000000000 --- a/csharp/App/SaliMax/src/Utils.cs +++ /dev/null @@ -1,11 +0,0 @@ -using InnovEnergy.Lib.Utils; - -namespace InnovEnergy.App.SaliMax; - -public static class Utils -{ - public static Decimal Round3(this Decimal d) - { - return DecimalUtils.RoundToSignificantDigits(d, 3); - } -} \ No newline at end of file