Use consumption end date to calculate lacroix consumption
MODIFY
src/integration/asset/lacroix/LacroixAssetIntegration.ts
src/integration/asset/lacroix/LacroixAssetIntegration.ts
@@ -107,7 +107,7 @@ export default class LacroixAssetIntegration extends AssetIntegration<AssetSetti
if ((moment().diff(moment(asset.lastConsumption?.timestamp), 'minutes')) > 1) {
const consumptionsDB = await ConsumptionStorage.getSiteAreaChargingStationConsumptions(this.tenant,
{ siteAreaID: asset.siteAreaID, startDate: asset.lastConsumption.timestamp, endDate: consumptions[consumptions.length - 1].lastConsumption.timestamp },
- Constants.DB_PARAMS_MAX_LIMIT, ['instantWatts', 'instantWattsL1','instantWattsL2','instantWattsL3', 'startedAt']);
+ Constants.DB_PARAMS_MAX_LIMIT, ['instantWatts', 'instantWattsL1','instantWattsL2','instantWattsL3', 'endedAt']);
for (const consumption of consumptions) {
const timestamp = consumption.lastConsumption.timestamp;
const consumptionToSubtract = consumptionsDB.result.find((consumptionDB) =>

MODIFY
src/storage/mongodb/ConsumptionStorage.ts
src/storage/mongodb/ConsumptionStorage.ts
@@ -296,11 +296,11 @@ export default class ConsumptionStorage {
}
// Start date
if (params.startDate) {
- filters.startedAt.$gte = Utils.convertToDate(params.startDate);
+ filters.endedAt.$gte = Utils.convertToDate(params.startDate);
}
// End date
if (params.endDate) {
- filters.startedAt.$lte = Utils.convertToDate(params.endDate);
+ filters.endedAt.$lte = Utils.convertToDate(params.endDate);
}
// Check that charging station is set
filters.chargeBoxID = { '$ne': null };
@@ -325,11 +325,11 @@ export default class ConsumptionStorage {
aggregation.push({
$group: {
_id: {
- year: { '$year': '$startedAt' },
- month: { '$month': '$startedAt' },
- day: { '$dayOfMonth': '$startedAt' },
- hour: { '$hour': '$startedAt' },
- minute: { '$minute': '$startedAt' }
+ year: { '$year': '$endedAt' },
+ month: { '$month': '$endedAt' },
+ day: { '$dayOfMonth': '$endedAt' },
+ hour: { '$hour': '$endedAt' },
+ minute: { '$minute': '$endedAt' }
},
instantWatts: { $sum: '$instantWatts' },
instantWattsL1: { $sum: '$instantWattsL1' },
@@ -343,7 +343,7 @@ export default class ConsumptionStorage {
// Rebuild the date
aggregation.push({
$addFields: {
- startedAt: {
+ endedAt: {
$dateFromParts: { 'year': '$_id.year', 'month': '$_id.month', 'day': '$_id.day', 'hour': '$_id.hour', 'minute': '$_id.minute' }
}
}

Use consumption end date to calculate lacroix consumption