From d2e1c01ec71af6d0a48ca685748d54a3f57053da Mon Sep 17 00:00:00 2001 From: clare <57052+clare@users.noreply.github.com> Date: Wed, 30 Jun 2021 09:10:16 +1200 Subject: [PATCH] Updated monitoring paging to use duration. (#391) Co-authored-by: Clare McLennan <> Co-authored-by: Jon Hardie --- api/V1/monitoringPage.ts | 8 ++++---- api/middleware.ts | 1 - .../recordings/monitoring_paging.ts | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/api/V1/monitoringPage.ts b/api/V1/monitoringPage.ts index 14520d66..a5d53b33 100644 --- a/api/V1/monitoringPage.ts +++ b/api/V1/monitoringPage.ts @@ -28,9 +28,9 @@ const BEFORE_CACOPHONY = new Date(2017, 1, 1); const LAST_TIMES_TABLE = `with lasttimes as (select "recordingDateTime", "DeviceId", "GroupId", - LAG("recordingDateTime", 1) OVER - (PARTITION BY "DeviceId" ORDER BY "recordingDateTime") - lasttime from "Recordings" + LAG("recordingDateTime", 1) OVER (PARTITION BY "DeviceId" ORDER BY "recordingDateTime") lasttime, + LAG("duration", 1) OVER (PARTITION BY "DeviceId" ORDER BY "recordingDateTime") lastduration + from "Recordings" where "recordingDateTime" is not NULL and type = 'thermalRaw' and duration > 0 @@ -40,7 +40,7 @@ const LAST_TIMES_TABLE = `with lasttimes as )`; const WHERE_IS_VISIT_START = `where "lasttime" is NULL -or extract(epoch from "recordingDateTime") - extract(epoch from "lasttime") > 600`; +or extract(epoch from "recordingDateTime") - extract(epoch from "lasttime") - "lastduration" > 600`; const VISITS_COUNT_SQL = `${LAST_TIMES_TABLE} select count(*) from "lasttimes" ${WHERE_IS_VISIT_START}`; diff --git a/api/middleware.ts b/api/middleware.ts index da15d427..757cee3b 100644 --- a/api/middleware.ts +++ b/api/middleware.ts @@ -96,7 +96,6 @@ export const toIdArray = function (fieldName: string): ValidationChain { const convertToIdArray = function (idsAsString: string): number[] { if (idsAsString) { - console.log(`value is ${idsAsString}`); try { const val = JSON.parse(idsAsString); if (Array.isArray(val)) { diff --git a/test-cypress/cypress/integration/recordings/monitoring_paging.ts b/test-cypress/cypress/integration/recordings/monitoring_paging.ts index a2ef75cf..2fdf8eb1 100644 --- a/test-cypress/cypress/integration/recordings/monitoring_paging.ts +++ b/test-cypress/cypress/integration/recordings/monitoring_paging.ts @@ -11,7 +11,6 @@ describe("Monitoring : pagings", () => { it("recordings are broken into approximate pages by start date", () => { const camera = "basic"; - const firstRecording = "10:03"; cy.apiCreateCamera(camera, group); cy.uploadRecordingsAtTimes(camera, [ @@ -118,4 +117,23 @@ describe("Monitoring : pagings", () => { [{ start: "21:03", incomplete: "true" }, { start: "21:40" }] ); }); + + it("paging is correct even when time limit is only met by taking duration of video into account.", () => { + const camera = "visits-not-just-start"; + cy.apiCreateCamera(camera, group); + + cy.uploadRecording(camera, { time: "21:03", duration: 62 }); + cy.uploadRecordingsAtTimes(camera, ["21:14", "21:50", "22:20"]); + + cy.checkMonitoringWithFilter( + Veronica, + camera, + { "page-size": 3, page: 1 }, + [ + { recordings: 2, start: "21:03" }, + { start: "21:50" }, + { start: "22:20" } + ] + ); + }); });