Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Framasoft
PeerTube
PeerTube
Commits
67ad83d0
Verified
Commit
67ad83d0
authored
May 06, 2022
by
Chocobozzz
Browse files
Fix stats time metric
parent
f40712ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/models/view/local-video-viewer.ts
View file @
67ad83d0
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment