Performance statistics: add JSON file storage support.
[e-mobility-charging-stations-simulator.git] / src / utils / ElectricUtils.ts
CommitLineData
c8eeb62b
JB
1// Copyright Jerome Benoit. 2021. All Rights Reserved.
2
b2acff85 3/**
6bf6769e 4 * Rationale: https://wiki.piment-noir.org/doku.php/en:cs:modelling_multi-phased_electrical_system_interconnexion
cb31c873
JB
5 */
6
7/**
b2acff85 8 * Targeted to AC related values calculation.
b2acff85 9 */
cb31c873
JB
10export class ACElectricUtils {
11 static amperageTotal(nbOfPhases: number, Iph: number): number {
3f40bc9c
JB
12 return nbOfPhases * Iph;
13 }
14
6af9012e 15 static powerPerPhase(V: number, Iph: number, cosPhi = 1): number {
3f40bc9c
JB
16 const powerPerPhase = V * Iph * cosPhi;
17 if (cosPhi === 1) {
18 return powerPerPhase;
19 }
20 return Math.round(powerPerPhase);
21 }
22
6af9012e 23 static powerTotal(nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number {
cb31c873 24 return nbOfPhases * ACElectricUtils.powerPerPhase(V, Iph, cosPhi);
3f40bc9c
JB
25 }
26
cb31c873
JB
27 static amperageTotalFromPower(P: number, V: number, cosPhi = 1): number {
28 const amperage = P / (V * cosPhi);
3f40bc9c 29 if (cosPhi === 1 && P % V === 0) {
cb31c873 30 return amperage;
3f40bc9c 31 }
cb31c873 32 return Math.round(amperage);
3f40bc9c
JB
33 }
34
cb31c873
JB
35 static amperagePerPhaseFromPower(nbOfPhases: number, P: number, V: number, cosPhi = 1): number {
36 const amperage = ACElectricUtils.amperageTotalFromPower(P, V, cosPhi);
37 const amperagePerPhase = amperage / nbOfPhases;
38 if (amperage % nbOfPhases === 0) {
39 return amperagePerPhase;
3f40bc9c 40 }
cb31c873
JB
41 return Math.round(amperagePerPhase);
42 }
43}
44
45/**
46 * Targeted to DC related values calculation.
47 */
48export class DCElectricUtils {
49 static power(V: number, I: number): number {
50 return V * I;
51 }
52
53 static amperage(P: number, V: number): number {
54 const amperage = P / V;
55 if (P % V === 0) {
56 return amperage;
57 }
58 return Math.round(amperage);
3f40bc9c
JB
59 }
60}