Added instantAmps, started migration task
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
import AddActivePropertyToTagsTask from './tasks/AddActivePropertyToTagsTask';
import AddInactivityStatusInTransactionsTask from './tasks/AddInactivityStatusInTransactionsTask';
+import AddInstantAmpsToConsumptionsTask from './tasks/AddInstantAmpsToConsumptionsTask';
import AddIssuerFieldTask from './tasks/AddIssuerFieldTask';
import AddLastChangePropertiesToBadgeTask from './tasks/AddLastChangePropertiesToBadgeTask';
import AddLimitToConsumptionsTask from './tasks/AddLimitToConsumptionsTask';
@@ -70,6 +71,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new InitialCarImportTask());
currentMigrationTasks.push(new UpdateConsumptionsToObjectIDs());
currentMigrationTasks.push(new AddSiteAreaLimitToConsumptionsTask());
+ currentMigrationTasks.push(new AddInstantAmpsToConsumptionsTask());
currentMigrationTasks.push(new MigrateOcpiTransactionsTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();

ADD
src/migration/tasks/AddInstantAmpsToConsumptionsTask.ts
+import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
+import { ConnectorCurrentLimitSource } from '../../types/ChargingStation';
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
+import MigrationTask from '../MigrationTask';
+import { ServerAction } from '../../types/Server';
+import Tenant from '../../types/Tenant';
+import TenantStorage from '../../storage/mongodb/TenantStorage';
+import Utils from '../../utils/Utils';
+import global from '../../types/GlobalType';
+
+const MODULE_NAME = 'AddInstantAmpsToConsumptionsTask';
+
+export default class AddInstantAmpsToConsumptionsTask extends MigrationTask {
+ async migrate() {
+ const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
+ for (const tenant of tenants.result) {
+ await this.migrateTenant(tenant);
+ }
+ }
+
+ async migrateTenant(tenant: Tenant) {
+ // let modifiedCount = 0;
+ // const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id, {}, Constants.DB_PARAMS_MAX_LIMIT);
+ // for (const chargingStation of chargingStations.result) {
+ // // Update
+ // const result = await global.database.getCollection(tenant.id, 'consumptions').updateMany(
+ // {
+ // chargeBoxID: chargingStation.id,
+ // instantAmps: { $exists: false },
+ // },
+ // {
+ // $set: {
+ // instantAmps: { $mul: { '$instantPower': 0.23}}
+ // }
+ // }
+ // );
+ // modifiedCount += result.modifiedCount;
+ // console.log(modifiedCount);
+ // }
+ // // Log in the default tenant
+ // if (modifiedCount > 0) {
+ // Logging.logDebug({
+ // tenantID: Constants.DEFAULT_TENANT,
+ // action: ServerAction.MIGRATION,
+ // module: MODULE_NAME, method: 'migrateTenant',
+ // message: `${modifiedCount} Consumptions have been updated in Tenant '${tenant.name}'`
+ // });
+ // }
+ }
+
+ getVersion() {
+ return '1.0';
+ }
+
+ getName() {
+ return 'AddInstantAmpsToConsumptionsTask';
+ }
+
+ isAsynchronous() {
+ return true;
+ }
+}

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPISessionsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPISessionsService.ts
@@ -257,6 +257,7 @@ export default class OCPISessionsService {
endedAt: new Date(session.last_updated),
consumption: transaction.currentConsumptionWh,
instantPower: Math.round(transaction.currentConsumption),
+ instantAmps: Utils.convertWattToAmp(1, transaction.currentConsumption),
cumulatedConsumption: transaction.currentTotalConsumption,
totalInactivitySecs: transaction.currentTotalInactivitySecs,
totalDurationSecs: transaction.stop ?

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -1167,6 +1167,7 @@ export default class OCPPService {
} else {
consumption.consumption = transaction.currentConsumptionWh;
consumption.instantPower = Math.round(transaction.currentConsumption);
+ consumption.instantAmps = Utils.convertWattToAmp(1, transaction.currentConsumption);
consumption.cumulatedConsumption = transaction.currentTotalConsumption;
consumption.totalInactivitySecs = transaction.currentTotalInactivitySecs;
consumption.totalDurationSecs = !transaction.stop ?

MODIFY
src/server/rest/service/security/SiteAreaSecurity.ts
src/server/rest/service/security/SiteAreaSecurity.ts
@@ -151,7 +151,9 @@ export default class SiteAreaSecurity {
filteredSiteArea.values = consumptions.map((consumption) => ({
date: consumption.endedAt,
instantPower: consumption.instantPower,
- limitWatts: consumption.limitWatts
+ instantAmps: consumption.instantAmps,
+ limitWatts: consumption.limitWatts,
+ limitAmps: consumption.limitAmps
}));
return filteredSiteArea;
}

MODIFY
src/storage/mongodb/ConsumptionStorage.ts
src/storage/mongodb/ConsumptionStorage.ts
@@ -37,6 +37,7 @@ export default class ConsumptionStorage {
roundedAmount: Utils.convertToFloat(consumptionToSave.roundedAmount),
currencyCode: consumptionToSave.currencyCode,
instantPower: Utils.convertToFloat(consumptionToSave.instantPower),
+ instantAmps: Utils.convertToFloat(consumptionToSave.instantAmps),
totalInactivitySecs: Utils.convertToInt(consumptionToSave.totalInactivitySecs),
totalDurationSecs: Utils.convertToInt(consumptionToSave.totalDurationSecs),
stateOfCharge: Utils.convertToInt(consumptionToSave.stateOfCharge),
@@ -113,7 +114,9 @@ export default class ConsumptionStorage {
minute: { '$minute': '$startedAt' }
},
instantPower: { $sum: '$instantPower' },
+ instantAmps: { $sum: '$instantAmps'},
limitWatts: { $last: '$limitSiteAreaWatts' },
+ limitAmps: {$last: '$limitSiteAreaAmps'}
}
});
// Rebuild the date

MODIFY
src/types/Consumption.ts
src/types/Consumption.ts
@@ -17,6 +17,7 @@ export default interface Consumption {
roundedAmount: number;
currencyCode: string;
instantPower: number;
+ instantAmps: number;
totalInactivitySecs: number;
totalDurationSecs: number;
stateOfCharge: number;

MODIFY
src/types/SiteArea.ts
src/types/SiteArea.ts
@@ -28,5 +28,7 @@ export default interface SiteArea extends CreatedUpdatedProps {
export interface SiteAreaConsumption {
date: Date;
instantPower: number;
+ instantAmps: number;
limitWatts: number;
+ limitAmps: number;
}

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -98,7 +98,9 @@ export default interface Transaction {
export interface TransactionConsumption {
date: Date;
instantPower: number;
+ instantAmps: number;
limitWatts: number;
+ limitAmps: number;
cumulatedConsumption: number;
stateOfCharge: number;
cumulatedAmount: number;

Added instantAmps, started migration task