feat: add `deleteChargingStations` SRPC command to UI Services
[e-mobility-charging-stations-simulator.git] / src / performance / PerformanceStatistics.ts
index 3bb72ffa5f711b2b6c3c2af6d3e2501454503f45..e90595225278d3a926059a2ca3ab7821b800d644 100644 (file)
@@ -67,20 +67,19 @@ export class PerformanceStatistics {
     objName: string | undefined,
     uri: URL | undefined
   ): PerformanceStatistics | undefined {
-    const logPfx = logPrefix(' Performance statistics')
     if (objId == null) {
       const errMsg = 'Cannot get performance statistics instance without specifying object id'
-      logger.error(`${logPfx} ${errMsg}`)
+      logger.error(`${PerformanceStatistics.logPrefix()} ${errMsg}`)
       throw new BaseError(errMsg)
     }
     if (objName == null) {
       const errMsg = 'Cannot get performance statistics instance without specifying object name'
-      logger.error(`${logPfx} ${errMsg}`)
+      logger.error(`${PerformanceStatistics.logPrefix()} ${errMsg}`)
       throw new BaseError(errMsg)
     }
     if (uri == null) {
       const errMsg = 'Cannot get performance statistics instance without specifying object uri'
-      logger.error(`${logPfx} ${errMsg}`)
+      logger.error(`${PerformanceStatistics.logPrefix()} ${errMsg}`)
       throw new BaseError(errMsg)
     }
     if (!PerformanceStatistics.instances.has(objId)) {
@@ -89,6 +88,15 @@ export class PerformanceStatistics {
     return PerformanceStatistics.instances.get(objId)
   }
 
+  public static deleteInstance (objId: string | undefined): boolean {
+    if (objId == null) {
+      const errMsg = 'Cannot delete performance statistics instance without specifying object id'
+      logger.error(`${PerformanceStatistics.logPrefix()} ${errMsg}`)
+      throw new BaseError(errMsg)
+    }
+    return PerformanceStatistics.instances.delete(objId)
+  }
+
   public static beginMeasure (id: string): string {
     const markId = `${id.charAt(0).toUpperCase()}${id.slice(1)}~${generateUUID()}`
     performance.mark(markId)
@@ -308,6 +316,10 @@ export class PerformanceStatistics {
     }
   }
 
+  private static readonly logPrefix = (): string => {
+    return logPrefix(' Performance statistics')
+  }
+
   private readonly logPrefix = (): string => {
     return logPrefix(` ${this.objName} | Performance statistics`)
   }