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