From 438563fef8b40caba440340961756cd315baf541 Mon Sep 17 00:00:00 2001 From: ig Date: Thu, 23 Feb 2023 16:16:37 +0100 Subject: [PATCH] simplify AcPhase --- .../Trumpf/TruConvertAc/TruConvertAcDevice.cs | 29 ++------- csharp/lib/StatusApi/Phases/AcPhase.cs | 61 +++---------------- 2 files changed, 14 insertions(+), 76 deletions(-) diff --git a/csharp/lib/Devices/Trumpf/TruConvertAc/TruConvertAcDevice.cs b/csharp/lib/Devices/Trumpf/TruConvertAc/TruConvertAcDevice.cs index 04c1ed26f..6308553aa 100644 --- a/csharp/lib/Devices/Trumpf/TruConvertAc/TruConvertAcDevice.cs +++ b/csharp/lib/Devices/Trumpf/TruConvertAc/TruConvertAcDevice.cs @@ -218,33 +218,12 @@ public class TruConvertAcDevice ( Ac: new ThreePhaseAcConnection ( - AcPhase.FromActiveReactive( - activePower: powerAcL1, - apparentPower: apparentPowerAcL1, - voltage: gridVoltageL1, - current: phaseCurrentL1), - - AcPhase.FromActiveReactive( - activePower: powerAcL2, - apparentPower: apparentPowerAcL2, - voltage: gridVoltageL2, - current: phaseCurrentL2), - - AcPhase.FromActiveReactive( - activePower: powerAcL3, - apparentPower: apparentPowerAcL3, - voltage: gridVoltageL3, - current: phaseCurrentL3), - + new AcPhase(gridVoltageL1,phaseCurrentL1, ACos(powerAcL1/apparentPowerAcL1)), + new AcPhase(gridVoltageL2,phaseCurrentL2, ACos(powerAcL2/apparentPowerAcL2)), + new AcPhase(gridVoltageL3,phaseCurrentL3, ACos(powerAcL3/apparentPowerAcL3)), gridFrequency // Gird Frequency ), - - - Dc: new DcConnection - ( - dcVoltage, - dcCurrent - ), + Dc: new DcConnection(dcVoltage, dcCurrent), SerialNumber : acSerialNumber.GetInt32(2009).ToString(), diff --git a/csharp/lib/StatusApi/Phases/AcPhase.cs b/csharp/lib/StatusApi/Phases/AcPhase.cs index 1270527f9..068e19393 100644 --- a/csharp/lib/StatusApi/Phases/AcPhase.cs +++ b/csharp/lib/StatusApi/Phases/AcPhase.cs @@ -1,76 +1,35 @@ -using DecimalMath; using static DecimalMath.DecimalEx; namespace InnovEnergy.Lib.StatusApi.Phases; -public record AcPhase -( - Decimal Voltage, - Decimal Current, - Decimal Phi , - Decimal ApparentPower, - Decimal ActivePower, - Decimal ReactivePower, - Decimal PowerFactor -) +public record AcPhase(Decimal Voltage, Decimal Current, Decimal Phi) : Phase(Voltage, Current) { - + + public Decimal ApparentPower => Voltage * Current; + public Decimal ActivePower => ApparentPower * PowerFactor; + public Decimal ReactivePower => ApparentPower * Sin(Phi); + public Decimal PowerFactor => Cos(Phi); public static AcPhase FromActiveReactive ( Decimal activePower, - Decimal apparentPower, + Decimal reactivePower, Decimal voltage, Decimal current ) { - var reactivePower = Sqrt(Math.Abs(apparentPower * apparentPower - activePower * activePower )); - var phi = ATan2(reactivePower, activePower); + var phi = ATan2(reactivePower, activePower); return new AcPhase ( Voltage: voltage, Current: current, - Phi: phi, - ApparentPower: apparentPower, - ActivePower: activePower, - ReactivePower: reactivePower, - PowerFactor: Cos(phi) + Phi: phi ); - } - - - public static AcPhase CreateInstance(Decimal voltage, Decimal current, Decimal phi) - { - var powerFactor = Cos(phi); - var apparentPower = voltage * current; - var activePower = apparentPower * powerFactor; - var reactivePower = apparentPower * Sin(phi); - - - return new AcPhase - ( - voltage, - current, - phi, - apparentPower, - activePower, - reactivePower, - powerFactor - ); } - - //public Decimal ApparentPower => Voltage * Current; - //public Decimal ActivePower => ApparentPower * PowerFactor; - //public Decimal ReactivePower => ApparentPower * Sin(Phi); - //public Decimal PowerFactor => Cos(Phi); - - // public Decimal ReactivePower {get; init;} - // public Decimal ApparentPower {get; } - // public Decimal ActivePower {get; } - // public Decimal PowerFactor {get; init;} + } \ No newline at end of file