type ChargingStationWorkerMessageData,
ChargingStationWorkerMessageEvents,
ConfigurationSection,
+ type InternalTemplateStatistics,
ProcedureName,
+ type SimulatorState,
type Statistics,
type StorageConfiguration,
type UIServerConfiguration,
import {
Configuration,
Constants,
+ buildTemplateStatisticsPayload,
formatDurationMilliSeconds,
generateUUID,
handleUncaughtException,
gracefulShutdownError = 4
}
-interface TemplateChargingStations {
- configured: number
- added: number
- started: number
- indexes: Set<number>
-}
-
export class Bootstrap extends EventEmitter {
private static instance: Bootstrap | null = null
private workerImplementation?: WorkerAbstract<ChargingStationWorkerData>
private readonly uiServer: AbstractUIServer
private storage?: Storage
- private readonly templatesChargingStations: Map<string, TemplateChargingStations>
+ private readonly templateStatistics: Map<string, InternalTemplateStatistics>
private readonly version: string = version
private initializedCounters: boolean
private started: boolean
this.uiServer = UIServerFactory.getUIServerImplementation(
Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
)
- this.templatesChargingStations = new Map<string, TemplateChargingStations>()
+ this.templateStatistics = new Map<string, InternalTemplateStatistics>()
this.initializedCounters = false
this.initializeCounters()
Configuration.configurationChangeCallback = async () => {
}
public get numberOfChargingStationTemplates (): number {
- return this.templatesChargingStations.size
+ return this.templateStatistics.size
}
public get numberOfConfiguredChargingStations (): number {
- return [...this.templatesChargingStations.values()].reduce(
+ return [...this.templateStatistics.values()].reduce(
(accumulator, value) => accumulator + value.configured,
0
)
}
- public getState (): { started: boolean } {
+ public getState (): SimulatorState {
return {
- started: this.started
+ version: this.version,
+ started: this.started,
+ templateStatistics: buildTemplateStatisticsPayload(this.templateStatistics)
}
}
public getLastIndex (templateName: string): number {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const indexes = [...this.templatesChargingStations.get(templateName)!.indexes]
+ const indexes = [...this.templateStatistics.get(templateName)!.indexes]
.concat(0)
.sort((a, b) => a - b)
for (let i = 0; i < indexes.length - 1; i++) {
}
private get numberOfAddedChargingStations (): number {
- return [...this.templatesChargingStations.values()].reduce(
+ return [...this.templateStatistics.values()].reduce(
(accumulator, value) => accumulator + value.added,
0
)
}
private get numberOfStartedChargingStations (): number {
- return [...this.templatesChargingStations.values()].reduce(
+ return [...this.templateStatistics.values()].reduce(
(accumulator, value) => accumulator + value.started,
0
)
for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
try {
const nbStations =
- this.templatesChargingStations.get(parse(stationTemplateUrl.file).name)?.configured ??
+ this.templateStatistics.get(parse(stationTemplateUrl.file).name)?.configured ??
stationTemplateUrl.numberOfStations
for (let index = 1; index <= nbStations; index++) {
await this.addChargingStation(index, stationTemplateUrl.file)
private readonly workerEventDeleted = (data: ChargingStationData): void => {
this.uiServer.chargingStations.delete(data.stationInfo.hashId)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const templateChargingStations = this.templatesChargingStations.get(
- data.stationInfo.templateName
- )!
- --templateChargingStations.added
- templateChargingStations.indexes.delete(data.stationInfo.templateIndex)
+ const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)!
+ --templateStatistics.added
+ templateStatistics.indexes.delete(data.stationInfo.templateIndex)
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventDeleted: Charging station ${
data.stationInfo.chargingStationId
private readonly workerEventStarted = (data: ChargingStationData): void => {
this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- ++this.templatesChargingStations.get(data.stationInfo.templateName)!.started
+ ++this.templateStatistics.get(data.stationInfo.templateName)!.started
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventStarted: Charging station ${
data.stationInfo.chargingStationId
private readonly workerEventStopped = (data: ChargingStationData): void => {
this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- --this.templatesChargingStations.get(data.stationInfo.templateName)!.started
+ --this.templateStatistics.get(data.stationInfo.templateName)!.started
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventStopped: Charging station ${
data.stationInfo.chargingStationId
if (isNotEmptyArray(stationTemplateUrls)) {
for (const stationTemplateUrl of stationTemplateUrls) {
const templateName = parse(stationTemplateUrl.file).name
- this.templatesChargingStations.set(templateName, {
+ this.templateStatistics.set(templateName, {
configured: stationTemplateUrl.numberOfStations,
added: 0,
started: 0,
})
this.uiServer.chargingStationTemplates.add(templateName)
}
- if (this.templatesChargingStations.size !== stationTemplateUrls.length) {
+ if (this.templateStatistics.size !== stationTemplateUrls.length) {
console.error(
chalk.red(
"'stationTemplateUrls' contains duplicate entries, please check your configuration"
options
})
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const templateChargingStations = this.templatesChargingStations.get(
- parse(stationTemplateFile).name
- )!
- ++templateChargingStations.added
- templateChargingStations.indexes.add(index)
+ const templateStatistics = this.templateStatistics.get(parse(stationTemplateFile).name)!
+ ++templateStatistics.added
+ templateStatistics.indexes.add(index)
}
private gracefulShutdown (): void {
"
>
{{ state.simulatorState?.started === true ? 'Stop' : 'Start' }} Simulator
+ {{ state.simulatorState?.version != null ? ` (${state.simulatorState?.version})` : '' }}
</ToggleButton>
<ToggleButton
:id="'add-charging-stations'"
import { getCurrentInstance, onMounted, ref } from 'vue'
import { useToast } from 'vue-toast-notification'
import CSTable from '@/components/charging-stations/CSTable.vue'
-import type { ResponsePayload, UIServerConfigurationSection } from '@/types'
+import type { ResponsePayload, SimulatorState, UIServerConfigurationSection } from '@/types'
import Container from '@/components/Container.vue'
import ReloadButton from '@/components/buttons/ReloadButton.vue'
import {
renderAddChargingStations: `${string}-${string}-${string}-${string}-${string}`
renderChargingStations: `${string}-${string}-${string}-${string}-${string}`
loading: boolean
- simulatorState?: { started: boolean }
+ simulatorState?: SimulatorState
uiServerIndex: number
}>({
renderSimulator: randomUUID(),
uiClient
.simulatorState()
.then((response: ResponsePayload) => {
- state.value.simulatorState = response.state as { started: boolean }
+ state.value.simulatorState = response.state as SimulatorState
})
.catch((error: Error) => {
$toast.error('Error at fetching simulator state')