Skip to content

Commit 85c2ea3

Browse files
committed
Fix MirrorMeterReading reading time period aligns to minute boundaries
Instead of using the sample data to calculate the time period which may be subject to sampling latency and not align to minute boundaries Fix for CACTUS test
1 parent 0193ef4 commit 85c2ea3

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
11
export type SampleBase = {
22
date: Date;
33
};
4-
5-
export type SampleTimePeriod = {
6-
start: Date;
7-
end: Date;
8-
durationSeconds: number;
9-
};
10-
11-
export function getSampleTimePeriod<T extends SampleBase>(
12-
samples: T[],
13-
): SampleTimePeriod {
14-
if (samples.length === 0) {
15-
throw new Error('No samples to calculate time period');
16-
}
17-
18-
const start = samples.at(0)!.date;
19-
const end = samples.at(-1)!.date;
20-
const durationSeconds = Math.round(
21-
(end.getTime() - start.getTime()) / 1000,
22-
);
23-
24-
return {
25-
start,
26-
end,
27-
durationSeconds,
28-
};
29-
}

src/sep2/helpers/mirrorUsagePointBase.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { objectToXml } from './xml.js';
1414
import { type Logger } from 'pino';
1515
import { numberWithPow10 } from '../../helpers/number.js';
1616
import { type SampleBase } from '../../coordinator/helpers/sampleBase.js';
17-
import { getSampleTimePeriod } from '../../coordinator/helpers/sampleBase.js';
1817
import { objectEntriesWithType } from '../../helpers/object.js';
1918
import { addMilliseconds } from 'date-fns';
2019
import { isNetworkError, isRetryableError } from 'axios-retry';
@@ -181,13 +180,11 @@ export abstract class MirrorUsagePointHelperBase<
181180
// we won't know what reading types we have
182181
if (samples.length > 0) {
183182
const now = new Date();
183+
const nextUpdateMilliseconds = getNextUpdateMilliseconds();
184184
const reading = this.getReadingFromSamples(samples);
185-
const sampleTimePeriod = getSampleTimePeriod(samples);
185+
const sampleDurationSeconds = nextUpdateMilliseconds / 1000;
186186
const lastUpdateTime = now;
187-
const nextUpdateTime = addMilliseconds(
188-
now,
189-
getNextUpdateMilliseconds(),
190-
);
187+
const nextUpdateTime = addMilliseconds(now, nextUpdateMilliseconds);
191188
const mirrorMeterReadings = this.getReadingValues({
192189
reading,
193190
});
@@ -219,8 +216,8 @@ export abstract class MirrorUsagePointHelperBase<
219216
),
220217

221218
timePeriod: {
222-
start: sampleTimePeriod.start,
223-
duration: sampleTimePeriod.durationSeconds,
219+
start: now,
220+
duration: sampleDurationSeconds,
224221
},
225222
},
226223
};

src/sep2/models/mirrorMeterReading.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export function generateMirrorMeterReadingObject(
8888
: undefined,
8989
timePeriod: Reading.timePeriod
9090
? {
91-
duration: Reading.timePeriod.duration,
91+
// ensure integer value
92+
duration: Math.round(Reading.timePeriod.duration),
9293
start: dateToStringSeconds(
9394
Reading.timePeriod.start,
9495
),

0 commit comments

Comments
 (0)