Verified Commit 67ad83d0 authored by Chocobozzz's avatar Chocobozzz
Browse files

Fix stats time metric

parent f40712ab
......@@ -236,6 +236,16 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid
aggregateWatchTime: 'SUM("localVideoViewer"."watchTime")'
}
const intervalWhere: { [ id in VideoStatsTimeserieMetric ]: string } = {
// Viewer is still in the interval. Overlap algorithm
viewers: '"localVideoViewer"."startDate" <= "intervals"."endDate" ' +
'AND "localVideoViewer"."endDate" >= "intervals"."startDate"',
// We do an aggregation, so only sum things once. Arbitrary we use the end date for that purpose
aggregateWatchTime: '"localVideoViewer"."endDate" >= "intervals"."startDate" ' +
'AND "localVideoViewer"."endDate" <= "intervals"."endDate"'
}
const query = `WITH "intervals" AS (
SELECT
"time" AS "startDate", "time" + :groupInterval::interval as "endDate"
......@@ -246,7 +256,7 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid
FROM
intervals
LEFT JOIN "localVideoViewer" ON "localVideoViewer"."videoId" = :videoId
AND "localVideoViewer"."startDate" >= "intervals"."startDate" AND "localVideoViewer"."startDate" <= "intervals"."endDate"
AND ${intervalWhere[metric]}
GROUP BY
"intervals"."startDate"
ORDER BY
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment