diff options
-rw-r--r-- | client/src/app/+stats/video/video-stats.component.ts | 8 | ||||
-rw-r--r-- | server/models/view/local-video-viewer.ts | 14 | ||||
-rw-r--r-- | server/tests/api/views/video-views-overall-stats.ts | 79 | ||||
-rw-r--r-- | shared/models/videos/stats/video-stats-overall.model.ts | 5 | ||||
-rw-r--r-- | support/doc/api/openapi.yaml | 8 |
5 files changed, 23 insertions, 91 deletions
diff --git a/client/src/app/+stats/video/video-stats.component.ts b/client/src/app/+stats/video/video-stats.component.ts index 09ed37799..a5435fe23 100644 --- a/client/src/app/+stats/video/video-stats.component.ts +++ b/client/src/app/+stats/video/video-stats.component.ts | |||
@@ -137,15 +137,11 @@ export class VideoStatsComponent implements OnInit { | |||
137 | this.overallStatCards = [ | 137 | this.overallStatCards = [ |
138 | { | 138 | { |
139 | label: $localize`Views`, | 139 | label: $localize`Views`, |
140 | value: this.numberFormatter.transform(overallStats.views) | 140 | value: this.numberFormatter.transform(this.video.views) |
141 | }, | ||
142 | { | ||
143 | label: $localize`Comments`, | ||
144 | value: this.numberFormatter.transform(overallStats.comments) | ||
145 | }, | 141 | }, |
146 | { | 142 | { |
147 | label: $localize`Likes`, | 143 | label: $localize`Likes`, |
148 | value: this.numberFormatter.transform(overallStats.likes) | 144 | value: this.numberFormatter.transform(this.video.likes) |
149 | }, | 145 | }, |
150 | { | 146 | { |
151 | label: $localize`Average watch time`, | 147 | label: $localize`Average watch time`, |
diff --git a/server/models/view/local-video-viewer.ts b/server/models/view/local-video-viewer.ts index b6ddcbb57..5928ba5f6 100644 --- a/server/models/view/local-video-viewer.ts +++ b/server/models/view/local-video-viewer.ts | |||
@@ -134,9 +134,6 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid | |||
134 | FETCH FIRST 1 ROW ONLY` | 134 | FETCH FIRST 1 ROW ONLY` |
135 | const watchPeakPromise = LocalVideoViewerModel.sequelize.query<any>(watchPeakQuery, options) | 135 | const watchPeakPromise = LocalVideoViewerModel.sequelize.query<any>(watchPeakQuery, options) |
136 | 136 | ||
137 | const commentsQuery = `SELECT COUNT(*) AS comments FROM "videoComment" WHERE "videoId" = :videoId` | ||
138 | const commentsPromise = LocalVideoViewerModel.sequelize.query<any>(commentsQuery, options) | ||
139 | |||
140 | const countriesQuery = `SELECT country, COUNT(country) as viewers ` + | 137 | const countriesQuery = `SELECT country, COUNT(country) as viewers ` + |
141 | `FROM "localVideoViewer" ` + | 138 | `FROM "localVideoViewer" ` + |
142 | `WHERE "videoId" = :videoId AND country IS NOT NULL ` + | 139 | `WHERE "videoId" = :videoId AND country IS NOT NULL ` + |
@@ -144,10 +141,9 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid | |||
144 | `ORDER BY viewers DESC` | 141 | `ORDER BY viewers DESC` |
145 | const countriesPromise = LocalVideoViewerModel.sequelize.query<any>(countriesQuery, options) | 142 | const countriesPromise = LocalVideoViewerModel.sequelize.query<any>(countriesQuery, options) |
146 | 143 | ||
147 | const [ rowsWatchTime, rowsWatchPeak, rowsComment, rowsCountries ] = await Promise.all([ | 144 | const [ rowsWatchTime, rowsWatchPeak, rowsCountries ] = await Promise.all([ |
148 | watchTimePromise, | 145 | watchTimePromise, |
149 | watchPeakPromise, | 146 | watchPeakPromise, |
150 | commentsPromise, | ||
151 | countriesPromise | 147 | countriesPromise |
152 | ]) | 148 | ]) |
153 | 149 | ||
@@ -166,14 +162,6 @@ export class LocalVideoViewerModel extends Model<Partial<AttributesOnly<LocalVid | |||
166 | ? rowsWatchPeak[0].dateBreakpoint || null | 162 | ? rowsWatchPeak[0].dateBreakpoint || null |
167 | : null, | 163 | : null, |
168 | 164 | ||
169 | views: video.views, | ||
170 | likes: video.likes, | ||
171 | dislikes: video.dislikes, | ||
172 | |||
173 | comments: rowsComment.length !== 0 | ||
174 | ? parseInt(rowsComment[0].comments) || 0 | ||
175 | : 0, | ||
176 | |||
177 | countries: rowsCountries.map(r => ({ | 165 | countries: rowsCountries.map(r => ({ |
178 | isoCode: r.country, | 166 | isoCode: r.country, |
179 | viewers: r.viewers | 167 | viewers: r.viewers |
diff --git a/server/tests/api/views/video-views-overall-stats.ts b/server/tests/api/views/video-views-overall-stats.ts index a70d6185e..72b072c96 100644 --- a/server/tests/api/views/video-views-overall-stats.ts +++ b/server/tests/api/views/video-views-overall-stats.ts | |||
@@ -17,57 +17,6 @@ describe('Test views overall stats', function () { | |||
17 | servers = await prepareViewsServers() | 17 | servers = await prepareViewsServers() |
18 | }) | 18 | }) |
19 | 19 | ||
20 | describe('Test rates and comments of local videos on VOD', function () { | ||
21 | let vodVideoId: string | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(120000); | ||
25 | |||
26 | ({ vodVideoId } = await prepareViewsVideos({ servers, live: false, vod: true })) | ||
27 | }) | ||
28 | |||
29 | it('Should have the appropriate likes', async function () { | ||
30 | this.timeout(60000) | ||
31 | |||
32 | await servers[0].videos.rate({ id: vodVideoId, rating: 'like' }) | ||
33 | await servers[1].videos.rate({ id: vodVideoId, rating: 'like' }) | ||
34 | |||
35 | await waitJobs(servers) | ||
36 | |||
37 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) | ||
38 | |||
39 | expect(stats.likes).to.equal(2) | ||
40 | expect(stats.dislikes).to.equal(0) | ||
41 | }) | ||
42 | |||
43 | it('Should have the appropriate dislikes', async function () { | ||
44 | this.timeout(60000) | ||
45 | |||
46 | await servers[0].videos.rate({ id: vodVideoId, rating: 'dislike' }) | ||
47 | await servers[1].videos.rate({ id: vodVideoId, rating: 'dislike' }) | ||
48 | |||
49 | await waitJobs(servers) | ||
50 | |||
51 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) | ||
52 | |||
53 | expect(stats.likes).to.equal(0) | ||
54 | expect(stats.dislikes).to.equal(2) | ||
55 | }) | ||
56 | |||
57 | it('Should have the appropriate comments', async function () { | ||
58 | this.timeout(60000) | ||
59 | |||
60 | await servers[0].comments.createThread({ videoId: vodVideoId, text: 'root' }) | ||
61 | await servers[0].comments.addReplyToLastThread({ text: 'reply' }) | ||
62 | await servers[1].comments.createThread({ videoId: vodVideoId, text: 'root' }) | ||
63 | |||
64 | await waitJobs(servers) | ||
65 | |||
66 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) | ||
67 | expect(stats.comments).to.equal(3) | ||
68 | }) | ||
69 | }) | ||
70 | |||
71 | describe('Test watch time stats of local videos on live and VOD', function () { | 20 | describe('Test watch time stats of local videos on live and VOD', function () { |
72 | let vodVideoId: string | 21 | let vodVideoId: string |
73 | let liveVideoId: string | 22 | let liveVideoId: string |
@@ -82,8 +31,9 @@ describe('Test views overall stats', function () { | |||
82 | it('Should display overall stats of a video with no viewers', async function () { | 31 | it('Should display overall stats of a video with no viewers', async function () { |
83 | for (const videoId of [ liveVideoId, vodVideoId ]) { | 32 | for (const videoId of [ liveVideoId, vodVideoId ]) { |
84 | const stats = await servers[0].videoStats.getOverallStats({ videoId }) | 33 | const stats = await servers[0].videoStats.getOverallStats({ videoId }) |
34 | const video = await servers[0].videos.get({ id: videoId }) | ||
85 | 35 | ||
86 | expect(stats.views).to.equal(0) | 36 | expect(video.views).to.equal(0) |
87 | expect(stats.averageWatchTime).to.equal(0) | 37 | expect(stats.averageWatchTime).to.equal(0) |
88 | expect(stats.totalWatchTime).to.equal(0) | 38 | expect(stats.totalWatchTime).to.equal(0) |
89 | } | 39 | } |
@@ -100,8 +50,9 @@ describe('Test views overall stats', function () { | |||
100 | 50 | ||
101 | for (const videoId of [ liveVideoId, vodVideoId ]) { | 51 | for (const videoId of [ liveVideoId, vodVideoId ]) { |
102 | const stats = await servers[0].videoStats.getOverallStats({ videoId }) | 52 | const stats = await servers[0].videoStats.getOverallStats({ videoId }) |
53 | const video = await servers[0].videos.get({ id: videoId }) | ||
103 | 54 | ||
104 | expect(stats.views).to.equal(0) | 55 | expect(video.views).to.equal(0) |
105 | expect(stats.averageWatchTime).to.equal(1) | 56 | expect(stats.averageWatchTime).to.equal(1) |
106 | expect(stats.totalWatchTime).to.equal(1) | 57 | expect(stats.totalWatchTime).to.equal(1) |
107 | } | 58 | } |
@@ -118,14 +69,18 @@ describe('Test views overall stats', function () { | |||
118 | 69 | ||
119 | { | 70 | { |
120 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) | 71 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) |
121 | expect(stats.views).to.equal(1) | 72 | const video = await servers[0].videos.get({ id: vodVideoId }) |
73 | |||
74 | expect(video.views).to.equal(1) | ||
122 | expect(stats.averageWatchTime).to.equal(2) | 75 | expect(stats.averageWatchTime).to.equal(2) |
123 | expect(stats.totalWatchTime).to.equal(4) | 76 | expect(stats.totalWatchTime).to.equal(4) |
124 | } | 77 | } |
125 | 78 | ||
126 | { | 79 | { |
127 | const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId }) | 80 | const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId }) |
128 | expect(stats.views).to.equal(1) | 81 | const video = await servers[0].videos.get({ id: liveVideoId }) |
82 | |||
83 | expect(video.views).to.equal(1) | ||
129 | expect(stats.averageWatchTime).to.equal(21) | 84 | expect(stats.averageWatchTime).to.equal(21) |
130 | expect(stats.totalWatchTime).to.equal(41) | 85 | expect(stats.totalWatchTime).to.equal(41) |
131 | } | 86 | } |
@@ -143,16 +98,18 @@ describe('Test views overall stats', function () { | |||
143 | 98 | ||
144 | { | 99 | { |
145 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) | 100 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) |
101 | const video = await servers[0].videos.get({ id: vodVideoId }) | ||
146 | 102 | ||
147 | expect(stats.views).to.equal(1) | 103 | expect(video.views).to.equal(1) |
148 | expect(stats.averageWatchTime).to.equal(2) | 104 | expect(stats.averageWatchTime).to.equal(2) |
149 | expect(stats.totalWatchTime).to.equal(6) | 105 | expect(stats.totalWatchTime).to.equal(6) |
150 | } | 106 | } |
151 | 107 | ||
152 | { | 108 | { |
153 | const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId }) | 109 | const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId }) |
110 | const video = await servers[0].videos.get({ id: liveVideoId }) | ||
154 | 111 | ||
155 | expect(stats.views).to.equal(1) | 112 | expect(video.views).to.equal(1) |
156 | expect(stats.averageWatchTime).to.equal(14) | 113 | expect(stats.averageWatchTime).to.equal(14) |
157 | expect(stats.totalWatchTime).to.equal(43) | 114 | expect(stats.totalWatchTime).to.equal(43) |
158 | } | 115 | } |
@@ -167,14 +124,18 @@ describe('Test views overall stats', function () { | |||
167 | 124 | ||
168 | { | 125 | { |
169 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) | 126 | const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId }) |
170 | expect(stats.views).to.equal(2) | 127 | const video = await servers[0].videos.get({ id: vodVideoId }) |
128 | |||
129 | expect(video.views).to.equal(2) | ||
171 | expect(stats.averageWatchTime).to.equal(3) | 130 | expect(stats.averageWatchTime).to.equal(3) |
172 | expect(stats.totalWatchTime).to.equal(11) | 131 | expect(stats.totalWatchTime).to.equal(11) |
173 | } | 132 | } |
174 | 133 | ||
175 | { | 134 | { |
176 | const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId }) | 135 | const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId }) |
177 | expect(stats.views).to.equal(2) | 136 | const video = await servers[0].videos.get({ id: liveVideoId }) |
137 | |||
138 | expect(video.views).to.equal(2) | ||
178 | expect(stats.averageWatchTime).to.equal(22) | 139 | expect(stats.averageWatchTime).to.equal(22) |
179 | expect(stats.totalWatchTime).to.equal(88) | 140 | expect(stats.totalWatchTime).to.equal(88) |
180 | } | 141 | } |
diff --git a/shared/models/videos/stats/video-stats-overall.model.ts b/shared/models/videos/stats/video-stats-overall.model.ts index f2a0470ef..c532c8173 100644 --- a/shared/models/videos/stats/video-stats-overall.model.ts +++ b/shared/models/videos/stats/video-stats-overall.model.ts | |||
@@ -5,11 +5,6 @@ export interface VideoStatsOverall { | |||
5 | viewersPeak: number | 5 | viewersPeak: number |
6 | viewersPeakDate: string | 6 | viewersPeakDate: string |
7 | 7 | ||
8 | views: number | ||
9 | likes: number | ||
10 | dislikes: number | ||
11 | comments: number | ||
12 | |||
13 | countries: { | 8 | countries: { |
14 | isoCode: string | 9 | isoCode: string |
15 | viewers: number | 10 | viewers: number |
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index 3a8b481d3..95670925f 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml | |||
@@ -6220,14 +6220,6 @@ components: | |||
6220 | viewersPeakDate: | 6220 | viewersPeakDate: |
6221 | type: string | 6221 | type: string |
6222 | format: date-time | 6222 | format: date-time |
6223 | views: | ||
6224 | type: number | ||
6225 | likes: | ||
6226 | type: number | ||
6227 | dislikes: | ||
6228 | type: number | ||
6229 | comments: | ||
6230 | type: number | ||
6231 | countries: | 6223 | countries: |
6232 | type: array | 6224 | type: array |
6233 | items: | 6225 | items: |