From: Jérôme Benoit Date: Mon, 13 Nov 2023 10:15:21 +0000 (+0100) Subject: refactor: factor out voltage phase line to line computation X-Git-Tag: v1.2.25~28 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4c14964327482ed9c9282177d6110b9ef033de1d;p=e-mobility-charging-stations-simulator.git refactor: factor out voltage phase line to line computation Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index a752ac99..502fd6a5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -194,6 +194,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ? (phase + 1) % chargingStation.getNumberOfPhases() : chargingStation.getNumberOfPhases() }`; + const voltagePhaseLineToLineValueRounded = roundTo( + Math.sqrt(chargingStation.getNumberOfPhases()) * + chargingStation.stationInfo.voltageOut!, + 2, + ); const voltagePhaseLineToLineSampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate( chargingStation, @@ -207,11 +212,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { voltagePhaseLineToLineSampledValueTemplate.value, ) ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) - : roundTo( - Math.sqrt(chargingStation.getNumberOfPhases()) * - chargingStation.stationInfo.voltageOut!, - 2, - ); + : voltagePhaseLineToLineValueRounded; const fluctuationPhaseLineToLinePercent = voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; @@ -221,8 +222,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ); } const defaultVoltagePhaseLineToLineMeasurandValue = getRandomFloatFluctuatedRounded( - Math.sqrt(chargingStation.getNumberOfPhases()) * - chargingStation.stationInfo.voltageOut!, + voltagePhaseLineToLineValueRounded, fluctuationPercent, ); meterValue.sampledValue.push(