Aligned consumption new meter value var namings + migration
MODIFY
src/migration/tasks/RenameTransactionsAndConsumptionsTask.ts
src/migration/tasks/RenameTransactionsAndConsumptionsTask.ts
@@ -17,21 +17,17 @@ export default class RenameTransactionsAndConsumptionsTask extends MigrationTask
}
async migrateTenant(tenant: Tenant) {
- // Rename Transaction props
- await this.renameTransactionProperties(tenant);
- // Rename Consumption props
+ // Consumptions
await this.renameConsumptionProperties(tenant);
+ await this.deleteConsumptionProperties(tenant);
}
- async renameTransactionProperties(tenant: Tenant) {
- // Renamed properties in Transactions
- const result = await global.database.getCollection<any>(tenant.id, 'transactions').updateMany(
- {
- 'stop.totalConsumptionWh': { $exists: false },
- },
+ private async deleteConsumptionProperties(tenant: Tenant) {
+ const result = await global.database.getCollection<any>(tenant.id, 'consumptions').updateMany(
+ { },
{
- $rename: {
- 'stop.totalConsumption': 'stop.totalConsumptionWh',
+ $unset: {
+ 'amperage': '',
}
},
{ upsert: false }
@@ -41,23 +37,29 @@ export default class RenameTransactionsAndConsumptionsTask extends MigrationTask
Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.MIGRATION,
- module: MODULE_NAME, method: 'migrateTenant',
- message: `${result.modifiedCount} Transactions(s) have been updated in Tenant '${tenant.name}'`
+ module: MODULE_NAME, method: 'deleteConsumptionProperties',
+ message: `${result.modifiedCount} Consumption(s) unused properties have been removed in Tenant '${tenant.name}' ('${tenant.subdomain}')`
});
}
}
- async renameConsumptionProperties(tenant: Tenant) {
+ private async renameConsumptionProperties(tenant: Tenant) {
// Renamed properties in Transactions
const result = await global.database.getCollection<any>(tenant.id, 'consumptions').updateMany(
{
- 'consumptionWh': { $exists: false },
+ 'instantVolts': { $exists: false },
},
{
$rename: {
- 'instantPower': 'instantWatts',
- 'consumption': 'consumptionWh',
- 'cumulatedConsumption': 'cumulatedConsumptionWh'
+ 'voltage': 'instantVolts',
+ 'voltageL1': 'instantVoltsL1',
+ 'voltageL2': 'instantVoltsL2',
+ 'voltageL3': 'instantVoltsL3',
+ 'voltageDC': 'instantVoltsDC',
+ 'amperageL1': 'instantAmpsL1',
+ 'amperageL2': 'instantAmpsL2',
+ 'amperageL3': 'instantAmpsL3',
+ 'amperageDC': 'instantAmpsDC',
}
},
{ upsert: false }
@@ -67,14 +69,14 @@ export default class RenameTransactionsAndConsumptionsTask extends MigrationTask
Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.MIGRATION,
- module: MODULE_NAME, method: 'migrateTenant',
+ module: MODULE_NAME, method: 'renameConsumptionProperties',
message: `${result.modifiedCount} Consumption(s) have been updated in Tenant '${tenant.name}'`
});
}
}
getVersion() {
- return '1.0';
+ return '1.1';
}
getName() {

MODIFY
src/server/rest/service/security/TransactionSecurity.ts
src/server/rest/service/security/TransactionSecurity.ts
-import sanitize from 'mongo-sanitize';
+import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpTransactionRequest, HttpTransactionsRefundRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+import Transaction, { TransactionConsumption } from '../../../../types/Transaction';
import Authorizations from '../../../../authorization/Authorizations';
+import Constants from '../../../../utils/Constants';
import Consumption from '../../../../types/Consumption';
import { DataResult } from '../../../../types/DataResult';
-import { TransactionInError } from '../../../../types/InError';
import RefundReport from '../../../../types/Refund';
-import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpTransactionRequest, HttpTransactionsRefundRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
-import Transaction, { TransactionConsumption } from '../../../../types/Transaction';
-import User from '../../../../types/User';
+import { TransactionInError } from '../../../../types/InError';
+import UserSecurity from './UserSecurity';
import UserToken from '../../../../types/UserToken';
-import Constants from '../../../../utils/Constants';
import Utils from '../../../../utils/Utils';
-import UserSecurity from './UserSecurity';
import UtilsSecurity from './UtilsSecurity';
+import sanitize from 'mongo-sanitize';
export default class TransactionSecurity {
public static filterTransactionsRefund(request: any): HttpTransactionsRefundRequest {
@@ -305,22 +304,21 @@ export default class TransactionSecurity {
date: consumption.endedAt,
instantWatts: consumption.instantWatts,
instantAmps: consumption.instantAmps,
+ instantAmpsL1: consumption.instantAmpsL1,
+ instantAmpsL2: consumption.instantAmpsL2,
+ instantAmpsL3: consumption.instantAmpsL3,
+ instantAmpsDC: consumption.instantAmpsDC,
+ instantVolts: consumption.instantVolts,
+ instantVoltsL1: consumption.instantVoltsL1,
+ instantVoltsL2: consumption.instantVoltsL2,
+ instantVoltsL3: consumption.instantVoltsL3,
+ instantVoltsDC: consumption.instantVoltsDC,
cumulatedConsumptionWh: consumption.cumulatedConsumptionWh,
cumulatedConsumptionAmps: consumption.cumulatedConsumptionAmps,
stateOfCharge: consumption.stateOfCharge,
cumulatedAmount: consumption.cumulatedAmount,
limitWatts: consumption.limitWatts,
limitAmps: consumption.limitAmps,
- voltage: consumption.voltage,
- voltageL1: consumption.voltageL1,
- voltageL2: consumption.voltageL2,
- voltageL3: consumption.voltageL3,
- voltageDC: consumption.voltageDC,
- amperage: consumption.amperage,
- amperageL1: consumption.amperageL1,
- amperageL2: consumption.amperageL2,
- amperageL3: consumption.amperageL3,
- amperageDC: consumption.amperageDC,
};
return newConsumption;
});

MODIFY
src/storage/mongodb/ConsumptionStorage.ts
src/storage/mongodb/ConsumptionStorage.ts
@@ -34,22 +34,21 @@ export default class ConsumptionStorage {
cumulatedAmount: Utils.convertToFloat(consumptionToSave.cumulatedAmount),
cumulatedConsumptionWh: Utils.convertToFloat(consumptionToSave.cumulatedConsumptionWh),
cumulatedConsumptionAmps: Utils.convertToFloat(consumptionToSave.cumulatedConsumptionAmps),
- voltage: Utils.convertToFloat(consumptionToSave.voltage),
- voltageL1: Utils.convertToFloat(consumptionToSave.voltageL1),
- voltageL2: Utils.convertToFloat(consumptionToSave.voltageL2),
- voltageL3: Utils.convertToFloat(consumptionToSave.voltageL3),
- voltageDC: Utils.convertToFloat(consumptionToSave.voltageDC),
- amperage: Utils.convertToFloat(consumptionToSave.amperage),
- amperageL1: Utils.convertToFloat(consumptionToSave.amperageL1),
- amperageL2: Utils.convertToFloat(consumptionToSave.amperageL2),
- amperageL3: Utils.convertToFloat(consumptionToSave.amperageL3),
- amperageDC: Utils.convertToFloat(consumptionToSave.amperageDC),
pricingSource: consumptionToSave.pricingSource,
amount: Utils.convertToFloat(consumptionToSave.amount),
roundedAmount: Utils.convertToFloat(consumptionToSave.roundedAmount),
currencyCode: consumptionToSave.currencyCode,
instantWatts: Utils.convertToFloat(consumptionToSave.instantWatts),
instantAmps: Utils.convertToFloat(consumptionToSave.instantAmps),
+ instantAmpsL1: Utils.convertToFloat(consumptionToSave.instantAmpsL1),
+ instantAmpsL2: Utils.convertToFloat(consumptionToSave.instantAmpsL2),
+ instantAmpsL3: Utils.convertToFloat(consumptionToSave.instantAmpsL3),
+ instantAmpsDC: Utils.convertToFloat(consumptionToSave.instantAmpsDC),
+ instantVolts: Utils.convertToFloat(consumptionToSave.instantVolts),
+ instantVoltsL1: Utils.convertToFloat(consumptionToSave.instantVoltsL1),
+ instantVoltsL2: Utils.convertToFloat(consumptionToSave.instantVoltsL2),
+ instantVoltsL3: Utils.convertToFloat(consumptionToSave.instantVoltsL3),
+ instantVoltsDC: Utils.convertToFloat(consumptionToSave.instantVoltsDC),
totalInactivitySecs: Utils.convertToInt(consumptionToSave.totalInactivitySecs),
totalDurationSecs: Utils.convertToInt(consumptionToSave.totalDurationSecs),
stateOfCharge: Utils.convertToInt(consumptionToSave.stateOfCharge),

MODIFY
src/types/Consumption.ts
src/types/Consumption.ts
@@ -20,16 +20,15 @@ export default interface Consumption {
currencyCode: string;
instantWatts: number;
instantAmps: number;
- voltage: number;
- voltageL1: number;
- voltageL2: number;
- voltageL3: number;
- voltageDC: number;
- amperage: number;
- amperageL1: number;
- amperageL2: number;
- amperageL3: number;
- amperageDC: number;
+ instantAmpsL1: number;
+ instantAmpsL2: number;
+ instantAmpsL3: number;
+ instantAmpsDC: number;
+ instantVolts: number;
+ instantVoltsL1: number;
+ instantVoltsL2: number;
+ instantVoltsL3: number;
+ instantVoltsDC: number;
totalInactivitySecs: number;
totalDurationSecs: number;
stateOfCharge: number;

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -111,20 +111,19 @@ export interface TransactionConsumption {
date: Date;
instantWatts: number;
instantAmps: number;
+ instantAmpsL1: number;
+ instantAmpsL2: number;
+ instantAmpsL3: number;
+ instantAmpsDC: number;
+ instantVolts: number;
+ instantVoltsL1: number;
+ instantVoltsL2: number;
+ instantVoltsL3: number;
+ instantVoltsDC: number;
limitWatts: number;
limitAmps: number;
cumulatedConsumptionWh: number;
cumulatedConsumptionAmps: number;
stateOfCharge: number;
cumulatedAmount: number;
- voltage: number;
- voltageL1: number;
- voltageL2: number;
- voltageL3: number;
- voltageDC: number;
- amperage: number;
- amperageL1: number;
- amperageL2: number;
- amperageL3: number;
- amperageDC: number;
}

MODIFY
test/api/OCPPCommonTests.ts
test/api/OCPPCommonTests.ts
@@ -623,17 +623,17 @@ export default class OCPPCommonTests {
// Check
expect(value).to.include({
'date': transactionCurrentTime.toISOString(),
- 'voltage': checkNewMeterValues ? this.voltageMeterValues[i] : 0,
- 'voltageL1': checkNewMeterValues ? this.voltageL1MeterValues[i] : 0,
- 'voltageL2': checkNewMeterValues ? this.voltageL2MeterValues[i] : 0,
- 'voltageL3': checkNewMeterValues ? this.voltageL3MeterValues[i] : 0,
- 'amperage': checkNewMeterValues ? this.amperageMeterValues[i] : 0,
- 'amperageL1': checkNewMeterValues ? this.amperageL1MeterValues[i] : 0,
- 'amperageL2': checkNewMeterValues ? this.amperageL2MeterValues[i] : 0,
- 'amperageL3': checkNewMeterValues ? this.amperageL3MeterValues[i] : 0,
- 'instantWatts': this.powerImportMeterValues[i],
- 'instantAmps': Utils.convertWattToAmp(this.chargingStationContext.getChargingStation(),
+ 'instantVolts': checkNewMeterValues ? this.voltageMeterValues[i] : 0,
+ 'instantVoltsL1': checkNewMeterValues ? this.voltageL1MeterValues[i] : 0,
+ 'instantVoltsL2': checkNewMeterValues ? this.voltageL2MeterValues[i] : 0,
+ 'instantVoltsL3': checkNewMeterValues ? this.voltageL3MeterValues[i] : 0,
+ 'instantAmps': checkNewMeterValues ? this.amperageMeterValues[i] :
+ Utils.convertWattToAmp(this.chargingStationContext.getChargingStation(),
null, this.newTransaction.connectorId, this.powerImportMeterValues[i]),
+ 'instantAmpsL1': checkNewMeterValues ? this.amperageL1MeterValues[i] : 0,
+ 'instantAmpsL2': checkNewMeterValues ? this.amperageL2MeterValues[i] : 0,
+ 'instantAmpsL3': checkNewMeterValues ? this.amperageL3MeterValues[i] : 0,
+ 'instantWatts': this.powerImportMeterValues[i],
'cumulatedConsumptionWh': transactionCumulatedConsumption,
'cumulatedConsumptionAmps': Utils.convertWattToAmp(this.chargingStationContext.getChargingStation(),
null, this.newTransaction.connectorId, transactionCumulatedConsumption)

Aligned consumption new meter value var namings + migration