From: Jérôme Benoit Date: Sat, 1 Jul 2023 21:48:16 +0000 (+0200) Subject: docs: improve code documentation X-Git-Tag: v1.2.18~86 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=361c98f57255e5b91d123d5f2ba43ab533134b1a;p=e-mobility-charging-stations-simulator.git docs: improve code documentation Signed-off-by: Jérôme Benoit --- diff --git a/.vscode/settings.json b/.vscode/settings.json index 9b0e7390..668705a1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,7 @@ "mochaExplorer.files": ["test/**/*.test.ts"], "mochaExplorer.debuggerConfig": "Debug Simulator Unit Tests", "cSpell.words": [ + "backoff", "benoit", "bufferutil", "cacheable", diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 8b89750b..19f760e7 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -13,7 +13,7 @@ import { WorkerConstants, type WorkerMessage, WorkerMessageEvents } from '../wor const moduleName = 'ChargingStationWorker'; /** - * Create and start a charging station instance + * Creates and starts a charging station instance * * @param data - workerData */ diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 6e8592cb..55fcb924 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -28,7 +28,7 @@ export class IdTagsCache { } /** - * Get one idtag from the cache given the distribution + * Gets one idtag from the cache given the distribution * Must be called after checking the cache is not an empty array * * @param distribution - @@ -56,7 +56,7 @@ export class IdTagsCache { } /** - * Get all idtags from the cache + * Gets all idtags from the cache * Must be called after checking the cache is not an empty array * * @param file - diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 04b40d30..83c1e3f7 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -140,6 +140,14 @@ export class Utils { return Math.floor(crypto.randomInt(max + 1)); } + /** + * Rounds the given number to the given scale. + * The rounding is done using the "round half away from zero" method. + * + * @param numberValue - The number to round. + * @param scale - The scale to round to. + * @returns The rounded number. + */ public static roundTo(numberValue: number, scale: number): number { const roundPower = Math.pow(10, scale); return Math.round(numberValue * roundPower * (1 + Number.EPSILON)) / roundPower; @@ -240,6 +248,8 @@ export class Utils { `${str.slice(0, pos)}${subStr}${str.slice(pos)}`; /** + * Computes the retry delay in milliseconds using an exponential backoff algorithm. + * * @param retryNumber - the number of retries that have already been attempted * @returns delay in milliseconds */ @@ -277,7 +287,7 @@ export class Utils { } /** - * Generate a cryptographically secure random number in the [0,1[ range + * Generates a cryptographically secure random number in the [0,1[ range * * @returns */ @@ -305,7 +315,7 @@ export class Utils { } /** - * Convert websocket error code to human readable string message + * Converts websocket error code to human readable string message * * @param code - websocket error code * @returns human readable string message diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 0ef54706..7d8eebd5 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -55,15 +55,15 @@ export abstract class WorkerAbstract { } /** - * Start the worker pool/set. + * Starts the worker pool/set. */ public abstract start(): Promise; /** - * Stop the worker pool/set. + * Stops the worker pool/set. */ public abstract stop(): Promise; /** - * Add a task element to the worker pool/set. + * Adds a task element to the worker pool/set. * * @param elementData - */ diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index 4be6bd57..0af77e72 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -10,7 +10,7 @@ export class WorkerDynamicPool extends WorkerAbstract { private readonly pool: DynamicThreadPool; /** - * Create a new `WorkerDynamicPool`. + * Creates a new `WorkerDynamicPool`. * * @param workerScript - * @param workerOptions - diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 96a9901d..b76af5df 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -20,7 +20,7 @@ export class WorkerSet extends WorkerAbstract { private readonly workerSet: Set; /** - * Create a new `WorkerSet`. + * Creates a new `WorkerSet`. * * @param workerScript - * @param workerOptions - @@ -94,7 +94,7 @@ export class WorkerSet extends WorkerAbstract { } /** - * Add a new `WorkerSetElement`. + * Adds a new `WorkerSetElement`. */ private addWorkerSetElement(): WorkerSetElement { const worker = new Worker(this.workerScript, { diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 473ff3bb..e49ac261 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -10,7 +10,7 @@ export class WorkerStaticPool extends WorkerAbstract { private readonly pool: FixedThreadPool; /** - * Create a new `WorkerStaticPool`. + * Creates a new `WorkerStaticPool`. * * @param workerScript - * @param workerOptions -