Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lastMeasuredAt #387

Open
wants to merge 2 commits into
base: 3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/modules/measure/MeasureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export class MeasureService extends BaseService {
device._source.measures = {};
}

let lastMeasuredAt = 0;
let lastMeasuredAt = device._source.lastMeasuredAt ?? 0;

for (const measurement of measurements) {
if (measurement.origin.type !== "device") {
Expand Down Expand Up @@ -564,7 +564,7 @@ export class MeasureService extends BaseService {
asset._source.measures = {};
}

let lastMeasuredAt = 0;
let lastMeasuredAt = asset._source.lastMeasuredAt ?? 0;

for (const measurement of measurements) {
if (measurement.origin.type === "computed") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,69 @@ describe("Ingestion Pipeline: process before", () => {

expect(asset._source.lastMeasuredAt).toBe(1680096420000);
});

it("should not update lastMeasuredAt if measures are older than current lastMeasure", async () => {
const now = Date.now();
await sendDummyTempPositionPayloads(sdk, [
{
deviceEUI: "linked2",
temperature: {
value: 21,
measuredAt: now,
},
location: {
value: {
lat: 21,
lon: 21,
},
measuredAt: now,
},
},
]);

let device = await sdk.document.get<DeviceContent>(
"engine-ayse",
"devices",
"DummyTempPosition-linked2",
);
expect(device._source.lastMeasuredAt).toBeGreaterThanOrEqual(now);
let asset = await sdk.document.get<ContainerAssetContent>(
"engine-ayse",
"assets",
"Container-linked2",
);
expect(asset._source.lastMeasuredAt).toBeGreaterThanOrEqual(now);

await sendDummyTempPositionPayloads(sdk, [
{
deviceEUI: "linked2",
temperature: {
value: 21,
measuredAt: now - 100000,
},
location: {
value: {
lat: 21,
lon: 21,
},
measuredAt: now - 100000,
},
},
]);
device = await sdk.document.get<DeviceContent>(
"engine-ayse",
"devices",
"DummyTempPosition-linked2",
);

expect(device._source.lastMeasuredAt).toBeGreaterThanOrEqual(now);

asset = await sdk.document.get<ContainerAssetContent>(
"engine-ayse",
"assets",
"Container-linked2",
);

expect(asset._source.lastMeasuredAt).toBeGreaterThanOrEqual(now);
});
});