pricing - price consumption chunks - polish
MODIFY
src/integration/pricing/ConsumptionChunkPricer.ts
src/integration/pricing/ConsumptionChunkPricer.ts
import ConsumptionPricer, { ConsumptionChunk } from './ConsumptionPricer';
import { DimensionType, PricedConsumptionData, PricedDimensionData, PricingDimension, PricingRestriction, PricingTimeLimit, ResolvedPricingDefinition, ResolvedPricingModel } from '../../types/Pricing';
-import Consumption from '../../types/Consumption';
import Utils from '../../utils/Utils';
import moment from 'moment';
export default class ConsumptionChunkPricer {
- consumptionPricer: ConsumptionPricer;
- consumptionChunk: ConsumptionChunk;
- actualPricingDefinitions: ResolvedPricingDefinition[];
+ private consumptionPricer: ConsumptionPricer;
+ private consumptionChunk: ConsumptionChunk;
+ private actualPricingDefinitions: ResolvedPricingDefinition[];
constructor(consumptionPricer: ConsumptionPricer, consumptionChunk: ConsumptionChunk) {
this.consumptionPricer = consumptionPricer;
@@ -20,21 +19,6 @@ export default class ConsumptionChunkPricer {
this.actualPricingDefinitions = [ actualPricingDefinitions[0] ];
}
- public static convertToConsumptionChunk(consumptionData: Consumption): ConsumptionChunk {
- return {
- startedAt: consumptionData.startedAt,
- endedAt: consumptionData.endedAt,
- consumptionWh: consumptionData.consumptionWh,
- cumulatedConsumptionWh: consumptionData.cumulatedConsumptionWh,
- totalDurationSecs: consumptionData.totalDurationSecs,
- totalInactivitySecs: consumptionData.totalInactivitySecs
- };
- }
-
- public getPricingModel(): ResolvedPricingModel {
- return this.consumptionPricer.getPricingModel();
- }
-
public priceConsumptionChunk(): PricedConsumptionData {
// Price the consumption data for each dimension
const flatFee = this.priceFlatFeeConsumption();
@@ -51,6 +35,10 @@ export default class ConsumptionChunkPricer {
return pricingConsumptionData;
}
+ private getPricingModel(): ResolvedPricingModel {
+ return this.consumptionPricer.getPricingModel();
+ }
+
private checkPricingDefinitionRestrictions(pricingDefinition: ResolvedPricingDefinition) : ResolvedPricingDefinition {
if (pricingDefinition.restrictions) {
if (!this.checkDayOfWeek(pricingDefinition.restrictions)

MODIFY
src/integration/pricing/ConsumptionPricer.ts
src/integration/pricing/ConsumptionPricer.ts
-import { PricedConsumptionData, ResolvedPricingDefinition, ResolvedPricingModel } from '../../types/Pricing';
+import { PricedConsumptionData, ResolvedPricingModel } from '../../types/Pricing';
import Consumption from '../../types/Consumption';
import ConsumptionChunkPricer from './ConsumptionChunkPricer';
@@ -17,10 +17,9 @@ export interface ConsumptionChunk{
}
export default class ConsumptionPricer {
- tenant: Tenant;
- pricingModel: ResolvedPricingModel;
- consumptionData: Consumption;
- actualPricingDefinitions: ResolvedPricingDefinition[];
+ private tenant: Tenant;
+ private pricingModel: ResolvedPricingModel;
+ private consumptionData: Consumption;
constructor(tenant: Tenant, pricingModel: ResolvedPricingModel, consumptionData: Consumption) {
this.tenant = tenant;
@@ -52,7 +51,14 @@ export default class ConsumptionPricer {
const endedAt = moment(consumptionData.endedAt);
const durationSecs = endedAt.diff(startedAt, 'seconds');
if (durationSecs <= 60) {
- yield ConsumptionChunkPricer.convertToConsumptionChunk(consumptionData);
+ yield {
+ startedAt: consumptionData.startedAt,
+ endedAt: consumptionData.endedAt,
+ consumptionWh: consumptionData.consumptionWh,
+ cumulatedConsumptionWh: consumptionData.cumulatedConsumptionWh,
+ totalDurationSecs: consumptionData.totalDurationSecs,
+ totalInactivitySecs: consumptionData.totalInactivitySecs
+ };
} else {
// Well - we got data for more than 1 minute! - we need to handle chunks!
const nbSeconds = endedAt.diff(startedAt, 'seconds');

pricing - price consumption chunks - polish