Fix performance observer usage.
[e-mobility-charging-stations-simulator.git] / src / utils / ElectricUtils.ts
CommitLineData
b2acff85
JB
1/**
2 * Targeted to AC related values calculation.
3 * To use for DC, always consider cosPhi = 1 and do not use per phase helpers
4 */
3f40bc9c 5export default class ElectricUtils {
6af9012e 6 static ampTotal(nbOfPhases: number, Iph: number): number {
3f40bc9c
JB
7 return nbOfPhases * Iph;
8 }
9
6af9012e 10 static powerPerPhase(V: number, Iph: number, cosPhi = 1): number {
3f40bc9c
JB
11 const powerPerPhase = V * Iph * cosPhi;
12 if (cosPhi === 1) {
13 return powerPerPhase;
14 }
15 return Math.round(powerPerPhase);
16 }
17
6af9012e 18 static powerTotal(nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number {
3f40bc9c
JB
19 return nbOfPhases * ElectricUtils.powerPerPhase(V, Iph, cosPhi);
20 }
21
6af9012e 22 static ampTotalFromPower(P: number, V: number, cosPhi = 1): number {
3f40bc9c
JB
23 const power = P / (V * cosPhi);
24 if (cosPhi === 1 && P % V === 0) {
25 return power;
26 }
27 return Math.round(power);
28 }
29
6af9012e 30 static ampPerPhaseFromPower(nbOfPhases: number, P: number, V: number, cosPhi = 1): number {
3f40bc9c
JB
31 const power = ElectricUtils.ampTotalFromPower(P, V, cosPhi);
32 const powerPerPhase = power / nbOfPhases;
33 if (power % nbOfPhases === 0) {
34 return powerPerPhase;
35 }
36 return Math.round(powerPerPhase);
37 }
38}