pricing - chunks of extra inactivity!
MODIFY
src/integration/pricing/ConsumptionPricer.ts
src/integration/pricing/ConsumptionPricer.ts
@@ -50,6 +50,7 @@ export default class ConsumptionPricer {
const startedAt = moment(consumptionData.startedAt);
const endedAt = moment(consumptionData.endedAt);
const durationSecs = endedAt.diff(startedAt, 'seconds');
+ const inactivitySecs = consumptionData.inactivitySecs || 0;
if (durationSecs <= 60) {
yield {
startedAt: consumptionData.startedAt,
@@ -63,11 +64,19 @@ export default class ConsumptionPricer {
// Well - we got data for more than 1 minute! - we need to handle chunks!
const nbSeconds = endedAt.diff(startedAt, 'seconds');
let secondsAlreadyPriced = 0;
+ let inactivityToPrice;
let chunkCumulatedConsumptionWh = Utils.createDecimal(consumptionData.cumulatedConsumptionWh).minus(consumptionData.consumptionWh);
let chunkTotalDurationSecs = Utils.createDecimal(consumptionData.totalDurationSecs).minus(durationSecs);
+ let chunkTotalInactivitySecs = Utils.createDecimal(consumptionData.totalInactivitySecs).minus(inactivitySecs);
while (secondsAlreadyPriced < nbSeconds) {
// Number of seconds for the current chunk
const secondsToPrice = Utils.minValue(nbSeconds - secondsAlreadyPriced, 60);
+ if (consumptionData.consumptionWh === 0 && inactivitySecs === nbSeconds) {
+ // Specific-situation for the extraInactivity
+ inactivityToPrice = secondsToPrice;
+ } else {
+ inactivityToPrice = 0;
+ }
// Chunk dates
const chunkStartedAt = moment(startedAt).add(secondsAlreadyPriced, 'seconds');
const chunkEndedAt = moment(startedAt).add(secondsAlreadyPriced + secondsToPrice, 'seconds');
@@ -76,6 +85,7 @@ export default class ConsumptionPricer {
// Chunk accumulated data
chunkCumulatedConsumptionWh = chunkCumulatedConsumptionWh.add(chunkConsumptionWh);
chunkTotalDurationSecs = chunkTotalDurationSecs.plus(secondsToPrice);
+ chunkTotalInactivitySecs = chunkTotalInactivitySecs.plus(inactivityToPrice);
// Create the consumption chunk
const consumptionChunk = {
startedAt: chunkStartedAt.toDate(),
@@ -83,7 +93,7 @@ export default class ConsumptionPricer {
consumptionWh: chunkConsumptionWh.toNumber(),
cumulatedConsumptionWh: chunkCumulatedConsumptionWh.toNumber(),
totalDurationSecs: chunkTotalDurationSecs.toNumber(),
- totalInactivitySecs: 0 // TO BE CLARIFIED
+ totalInactivitySecs: chunkTotalInactivitySecs.toNumber()
};
// Number of seconds already priced
secondsAlreadyPriced += secondsToPrice;

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -214,14 +214,18 @@ export default class OCPPUtils {
public static async buildExtraConsumptionInactivity(tenant: Tenant, chargingStation: ChargingStation, transaction: Transaction): Promise<Consumption> {
// Extra inactivity
- if (transaction.stop.extraInactivitySecs > 0) {
+ const extraInactivitySecs = transaction.stop?.extraInactivitySecs || 0;
+ if (extraInactivitySecs > 0) {
// Get the last Consumption
const lastConsumption = await ConsumptionStorage.getLastTransactionConsumption(tenant, { transactionId: transaction.id });
if (lastConsumption) {
delete lastConsumption.id;
// Create the extra consumption with inactivity
lastConsumption.startedAt = transaction.stop.timestamp;
- lastConsumption.endedAt = moment(transaction.stop.timestamp).add(transaction.stop.extraInactivitySecs, 's').toDate();
+ lastConsumption.endedAt = moment(transaction.stop.timestamp).add(extraInactivitySecs, 's').toDate();
+ lastConsumption.inactivitySecs = extraInactivitySecs;
+ lastConsumption.totalDurationSecs = Utils.createDecimal(lastConsumption.totalDurationSecs).add(extraInactivitySecs).toNumber();
+ lastConsumption.totalInactivitySecs = Utils.createDecimal(lastConsumption.totalInactivitySecs).add(extraInactivitySecs).toNumber();
// Set inactivity
lastConsumption.consumptionAmps = 0;
lastConsumption.consumptionWh = 0;

pricing - chunks of extra inactivity!