Updated limit in site area and consumption
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -71,8 +71,8 @@ export default class MigrationHandler {
currentMigrationTasks.push(new MigrateOcpiTransactionsTask());
currentMigrationTasks.push(new UpdateChargingStationTemplatesTask());
currentMigrationTasks.push(new UpdateChargingStationStaticLimitationTask());
- // CurrentMigrationTasks.push(new AddSiteAreaLimitToConsumptionsTask());
- // currentMigrationTasks.push(new UpdateLimitsInConsumptionsTask());
+ currentMigrationTasks.push(new AddSiteAreaLimitToConsumptionsTask());
+ // CurrentMigrationTasks.push(new UpdateLimitsInConsumptionsTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

MODIFY
src/migration/tasks/AddSiteAreaLimitToConsumptionsTask.ts
src/migration/tasks/AddSiteAreaLimitToConsumptionsTask.ts
@@ -24,40 +24,32 @@ export default class AddSiteAreaLimitToConsumptionsTask extends MigrationTask {
// Get Charging Stations
const siteAreas = await SiteAreaStorage.getSiteAreas(tenant.id, { withChargingStations: true }, Constants.DB_PARAMS_MAX_LIMIT);
for (const siteArea of siteAreas.result) {
+ let limitSiteAreaWatts = 0;
+ let limitChargingStationsWatts = 0;
if (siteArea.maximumPower) {
- // Update
- const result = await global.database.getCollection(tenant.id, 'consumptions').updateMany(
- {
- siteAreaID: Utils.convertToObjectID(siteArea.id),
- },
- {
- $set: {
- limitSiteAreaAmps: siteArea.maximumPower / 230,
- limitSiteAreaWatts: siteArea.maximumPower,
- limitSiteAreaSource: SiteAreaLimitSource.SITE_AREA
- }
+ limitSiteAreaWatts = siteArea.maximumPower;
}
- );
- modifiedCount += result.modifiedCount;
- } else {
- let limitSiteAreaWatts = 0;
+ // Compute charging station power
for (const chargingStation of siteArea.chargingStations) {
- for (const connector of chargingStation.connectors) {
let limitAmps = 0;
- // Amps from chargepoint?
+ // Amps from chargepoint
if (chargingStation.chargePoints) {
- const chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
- limitAmps = Utils.getChargingStationAmperage(chargingStation, chargePoint, connector.connectorId);
+ for (const chargePoint of chargingStation.chargePoints) {
+ limitAmps += Utils.getChargingStationAmperage(chargingStation, chargePoint);
+ limitChargingStationsWatts += Utils.convertAmpToWatt(chargingStation, 0, limitAmps);
+ }
// Amps from connector
- } else if (connector.amperage) {
- limitAmps = connector.amperage;
+ } else {
+ for (const connector of chargingStation.connectors) {
+ if (connector.amperage) {
+ limitAmps += connector.amperage;
+ limitChargingStationsWatts += Utils.convertAmpToWatt(chargingStation, connector.connectorId, limitAmps);
}
- if (limitAmps) {
- limitSiteAreaWatts += Utils.convertAmpToWatt(chargingStation, connector.connectorId, limitAmps);
}
}
}
- // Update
+ // Update Consumption
+ limitSiteAreaWatts = limitSiteAreaWatts > limitChargingStationsWatts ? limitSiteAreaWatts : limitChargingStationsWatts;
const result = await global.database.getCollection(tenant.id, 'consumptions').updateMany(
{
siteAreaID: Utils.convertToObjectID(siteArea.id),
@@ -71,7 +63,20 @@ export default class AddSiteAreaLimitToConsumptionsTask extends MigrationTask {
}
);
modifiedCount += result.modifiedCount;
+ // Update Site Area
+ await global.database.getCollection(tenant.id, 'siteareas').updateOne(
+ {
+ '_id': Utils.convertToObjectID(siteArea.id)
+ },
+ {
+ $set: {
+ 'voltage': 230,
+ 'numberOfPhases': 3,
+ 'maximumPower': limitSiteAreaWatts,
}
+ },
+ { upsert: false }
+ );
}
// Log in the default tenant
if (modifiedCount > 0) {
@@ -85,7 +90,7 @@ export default class AddSiteAreaLimitToConsumptionsTask extends MigrationTask {
}
getVersion() {
- return '1.1';
+ return '1.2';
}
getName() {

MODIFY
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
@@ -37,7 +37,7 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
}
getVersion() {
- return '1.8';
+ return '1.9';
}
private async applyTemplateToChargingStations(tenant: Tenant) {

Updated limit in site area and consumption