35 lines
799 B
C#
35 lines
799 B
C#
|
using static DecimalMath.DecimalEx;
|
||
|
|
||
|
namespace InnovEnergy.Lib.StatusApi.Phases;
|
||
|
|
||
|
|
||
|
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 reactivePower,
|
||
|
Decimal voltage,
|
||
|
Decimal current
|
||
|
)
|
||
|
{
|
||
|
var phi = ATan2(reactivePower, activePower);
|
||
|
|
||
|
return new AcPhase
|
||
|
(
|
||
|
Voltage: voltage,
|
||
|
Current: current,
|
||
|
Phi: phi
|
||
|
);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|