Recompute all sessions' consumptions
MODIFY
src/migration/tasks/RecomputeAllTransactionsWithSimplePricingTask.ts
src/migration/tasks/RecomputeAllTransactionsWithSimplePricingTask.ts
@@ -9,7 +9,6 @@ import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
import TransactionStorage from '../../storage/mongodb/TransactionStorage';
-import Utils from '../../utils/Utils';
const TASK_NAME = 'RecomputeAllTransactionsWithSimplePricingTask';
@@ -29,7 +28,6 @@ export default class RecomputeAllTransactionsWithSimplePricingTask extends Migra
inSuccess: 0,
};
const timeTotalFrom = new Date().getTime();
- const dateOfPricingChangeTo16cts = new Date('2019-06-14');
// Get transactions
const transactionsMDB = await global.database.getCollection<any>(tenant.id, 'transactions')
.aggregate([
@@ -53,38 +51,18 @@ export default class RecomputeAllTransactionsWithSimplePricingTask extends Migra
message: `${transactionsMDB.length} Transaction(s) are going to be recomputed in Tenant '${tenant.name}' ('${tenant.subdomain}')...`,
});
await Promise.map(transactionsMDB, async (transactionMDB) => {
- let pricePerkWh = 0;
try {
// Get the transaction
const transaction = await TransactionStorage.getTransaction(tenant.id, transactionMDB._id);
// Flag the transaction as migrated
transaction.migrationTag = `${TASK_NAME}~${this.getVersion()}`;
- // Force the price to 0.16 for SLF and SLFCAH tenants
- if ((transaction.timestamp.getTime() > dateOfPricingChangeTo16cts.getTime()) &&
- (tenant.id === '5be9b03f1014d900089930d9' || tenant.id === '5be7fb271014d90008992f06')) {
- pricePerkWh = 0.16;
- }
// Rebuild the pricing
- await OCPPUtils.rebuildTransactionSimplePricing(tenant.id, transaction, pricePerkWh);
- // Double check if final pricing is correct
- if (pricePerkWh > 0) {
+ await OCPPUtils.rebuildTransactionSimplePricing(tenant.id, transaction);
+ // Read the priced transaction
const pricedTransaction = await TransactionStorage.getTransaction(tenant.id, transactionMDB._id);
- if ((Utils.computeSimplePrice(pricePerkWh, pricedTransaction.stop.totalConsumptionWh) !== pricedTransaction.stop.price)) {
// Rebuild Consumptions
await OCPPUtils.rebuildTransactionConsumptions(tenant.id, pricedTransaction);
- // Check
- const recomputedConsumptionTransaction = await TransactionStorage.getTransaction(tenant.id, transactionMDB._id);
- if (recomputedConsumptionTransaction.stop.price === Utils.computeSimplePrice(pricePerkWh, recomputedConsumptionTransaction.stop.totalConsumptionWh)) {
- transactionsUpdated.inSuccess++;
- } else {
- transactionsUpdated.inError++;
- }
- } else {
transactionsUpdated.inSuccess++;
- }
- } else {
- transactionsUpdated.inSuccess++;
- }
} catch (error) {
transactionsUpdated.inError++;
await Logging.logError({
@@ -110,7 +88,7 @@ export default class RecomputeAllTransactionsWithSimplePricingTask extends Migra
}
getVersion(): string {
- return '1.3';
+ return '1.4';
}
getName(): string {

Recompute all sessions' consumptions