Initial portage to TypeScript.
[e-mobility-charging-stations-simulator.git] / src / utils / ElectricUtils.ts
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 */
5 export default class ElectricUtils {
6 static ampTotal(nbOfPhases: number, Iph: number): number {
7 return nbOfPhases * Iph;
8 }
9
10 static powerPerPhase(V: number, Iph: number, cosPhi = 1): number {
11 const powerPerPhase = V * Iph * cosPhi;
12 if (cosPhi === 1) {
13 return powerPerPhase;
14 }
15 return Math.round(powerPerPhase);
16 }
17
18 static powerTotal(nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number {
19 return nbOfPhases * ElectricUtils.powerPerPhase(V, Iph, cosPhi);
20 }
21
22 static ampTotalFromPower(P: number, V: number, cosPhi = 1): number {
23 const power = P / (V * cosPhi);
24 if (cosPhi === 1 && P % V === 0) {
25 return power;
26 }
27 return Math.round(power);
28 }
29
30 static ampPerPhaseFromPower(nbOfPhases: number, P: number, V: number, cosPhi = 1): number {
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 }