aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/view/local-video-viewer.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-06 14:23:02 +0200
committerChocobozzz <me@florianbigard.com>2022-05-06 14:23:02 +0200
commitf40712abbbb74e51f06037ef02757c42736bccf8 (patch)
tree4b130c6387f9687d52d570907eb1bbac6bc04b61 /server/models/view/local-video-viewer.ts
parent49f0468d44468528c2fb2c8b0efd19cdaeeec43d (diff)
downloadPeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.tar.gz
PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.tar.zst
PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.zip
Add ability to filter overall video stats by date
Diffstat (limited to 'server/models/view/local-video-viewer.ts')
-rw-r--r--server/models/view/local-video-viewer.ts12
1 files changed, 7 insertions, 5 deletions
diff --git a/server/models/view/local-video-viewer.ts b/server/models/view/local-video-viewer.ts
index 2862f8b96..2305c7262 100644
--- a/server/models/view/local-video-viewer.ts
+++ b/server/models/view/local-video-viewer.ts
@@ -136,7 +136,7 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid
136 const watchPeakQuery = `WITH "watchPeakValues" AS ( 136 const watchPeakQuery = `WITH "watchPeakValues" AS (
137 SELECT "startDate" AS "dateBreakpoint", 1 AS "inc" 137 SELECT "startDate" AS "dateBreakpoint", 1 AS "inc"
138 FROM "localVideoViewer" 138 FROM "localVideoViewer"
139 WHERE "videoId" = :videoId 139 WHERE "videoId" = :videoId ${dateWhere}
140 UNION ALL 140 UNION ALL
141 SELECT "endDate" AS "dateBreakpoint", -1 AS "inc" 141 SELECT "endDate" AS "dateBreakpoint", -1 AS "inc"
142 FROM "localVideoViewer" 142 FROM "localVideoViewer"
@@ -165,6 +165,10 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid
165 countriesPromise 165 countriesPromise
166 ]) 166 ])
167 167
168 const viewersPeak = rowsWatchPeak.length !== 0
169 ? parseInt(rowsWatchPeak[0].concurrent) || 0
170 : 0
171
168 return { 172 return {
169 totalWatchTime: rowsWatchTime.length !== 0 173 totalWatchTime: rowsWatchTime.length !== 0
170 ? Math.round(rowsWatchTime[0].totalWatchTime) || 0 174 ? Math.round(rowsWatchTime[0].totalWatchTime) || 0
@@ -173,10 +177,8 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid
173 ? Math.round(rowsWatchTime[0].averageWatchTime) || 0 177 ? Math.round(rowsWatchTime[0].averageWatchTime) || 0
174 : 0, 178 : 0,
175 179
176 viewersPeak: rowsWatchPeak.length !== 0 180 viewersPeak,
177 ? parseInt(rowsWatchPeak[0].concurrent) || 0 181 viewersPeakDate: rowsWatchPeak.length !== 0 && viewersPeak !== 0
178 : 0,
179 viewersPeakDate: rowsWatchPeak.length !== 0
180 ? rowsWatchPeak[0].dateBreakpoint || null 182 ? rowsWatchPeak[0].dateBreakpoint || null
181 : null, 183 : null,
182 184