From: Jérôme Benoit Date: Tue, 4 Jul 2023 18:42:08 +0000 (+0200) Subject: refactor: cleanup performance statistics code X-Git-Tag: v1.2.18~79 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a8735ef9770a6dc8f7ed19c7df5fdf607da0834c;p=e-mobility-charging-stations-simulator.git refactor: cleanup performance statistics code Signed-off-by: Jérôme Benoit --- diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index a111eb45..80f53e54 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -204,26 +204,18 @@ export class PerformanceStatistics { // Update current statistics this.statistics.updatedAt = new Date(); this.statistics.statisticsData.get(entryName).countTimeMeasurement = - this.statistics.statisticsData.get(entryName)?.countTimeMeasurement - ? this.statistics.statisticsData.get(entryName).countTimeMeasurement + 1 - : 1; + (this.statistics.statisticsData.get(entryName)?.countTimeMeasurement ?? 0) + 1; this.statistics.statisticsData.get(entryName).currentTimeMeasurement = entry.duration; - this.statistics.statisticsData.get(entryName).minTimeMeasurement = - this.statistics.statisticsData.get(entryName)?.minTimeMeasurement - ? this.statistics.statisticsData.get(entryName).minTimeMeasurement > entry.duration - ? entry.duration - : this.statistics.statisticsData.get(entryName).minTimeMeasurement - : entry.duration; - this.statistics.statisticsData.get(entryName).maxTimeMeasurement = - this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement - ? this.statistics.statisticsData.get(entryName).maxTimeMeasurement < entry.duration - ? entry.duration - : this.statistics.statisticsData.get(entryName).maxTimeMeasurement - : entry.duration; + this.statistics.statisticsData.get(entryName).minTimeMeasurement = Math.min( + entry.duration, + this.statistics.statisticsData.get(entryName)?.minTimeMeasurement ?? Infinity + ); + this.statistics.statisticsData.get(entryName).maxTimeMeasurement = Math.max( + entry.duration, + this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement ?? -Infinity + ); this.statistics.statisticsData.get(entryName).totalTimeMeasurement = - this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement - ? this.statistics.statisticsData.get(entryName).totalTimeMeasurement + entry.duration - : entry.duration; + (this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement ?? 0) + entry.duration; this.statistics.statisticsData.get(entryName).avgTimeMeasurement = this.statistics.statisticsData.get(entryName).totalTimeMeasurement / this.statistics.statisticsData.get(entryName).countTimeMeasurement;