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 ) : Phase(Voltage, Current) { public static AcPhase FromActiveReactive ( Decimal activePower, Decimal reactivePower, Decimal voltage, Decimal current ) { var apparentPower = Sqrt(activePower * activePower + reactivePower * reactivePower); var phi = ATan2(reactivePower, activePower); return new AcPhase ( Voltage: voltage, Current: current, Phi: phi, ApparentPower: apparentPower, ActivePower: activePower, ReactivePower: reactivePower, PowerFactor: Cos(phi) ); } public static AcPhase FromVoltageCurrentPhi(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;} }