Fix GH actions run on dependabot PRs.
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index 293b718485350d35f1b8dd06e7c97ab42ff795d7..f453c8220fcb7a24c182ba602efe95dbdaff6ea3 100644 (file)
@@ -53,15 +53,15 @@ export default class Utils {
   }
 
   static convertToInt(value: any): number {
-    let changedValue = value;
+    let changedValue: number = value;
     if (!value) {
       return 0;
     }
     if (Number.isSafeInteger(value)) {
-      return value;
+      return changedValue;
     }
     // Check
-    if (typeof value === 'string') {
+    if (Utils.isString(value)) {
       // Create Object
       changedValue = parseInt(value);
     }
@@ -69,12 +69,12 @@ export default class Utils {
   }
 
   static convertToFloat(value: any): number {
-    let changedValue = value;
+    let changedValue: number = value;
     if (!value) {
       return 0;
     }
     // Check
-    if (typeof value === 'string') {
+    if (Utils.isString(value)) {
       // Create Object
       changedValue = parseFloat(value);
     }
@@ -125,6 +125,14 @@ export default class Utils {
     return Utils.roundTo(Utils.getRandomFloat(max), scale);
   }
 
+  static getRandomFloatFluctuatedRounded(staticValue: number, fluctuationPercent: number, scale = 2): number {
+    if (fluctuationPercent === 0) {
+      return Utils.roundTo(staticValue, scale);
+    }
+    const fluctuationRatio = fluctuationPercent / 100;
+    return Utils.getRandomFloatRounded(staticValue * (1 + fluctuationRatio), staticValue * (1 - fluctuationRatio), scale);
+  }
+
   static cloneObject<T>(object: T): T {
     return JSON.parse(JSON.stringify(object)) as T;
   }