Delete Log and Salimax Utils(it has only Round3) function
This commit is contained in:
parent
7635a8175e
commit
8631ada267
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<JsonObject> 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());
|
||||
}
|
||||
}
|
|
@ -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<JsonNode> 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<T>(this JsonObject json, IEnumerable<T> alarms)
|
||||
{
|
||||
return json.AddProp("Alarms", alarms.ToJsonArray());
|
||||
}
|
||||
|
||||
public static JsonObject AddWarnings<T>(this JsonObject json, IEnumerable<T> 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<T>(this IEnumerable<T> things)
|
||||
{
|
||||
var jsonValues = things
|
||||
.Select(t => t!.ToString())
|
||||
.Select(t => JsonValue.Create(t))
|
||||
.OfType<JsonNode>()
|
||||
.ToArray();
|
||||
|
||||
return new JsonArray(jsonValues);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<JsonNode?> 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() }
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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<JsonObject> 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());
|
||||
}
|
||||
}
|
|
@ -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() },
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue