diff --git a/src/routes/getTopUsers.ts b/src/routes/getTopUsers.ts index f063c6f..bc2b67b 100644 --- a/src/routes/getTopUsers.ts +++ b/src/routes/getTopUsers.ts @@ -16,14 +16,16 @@ async function generateTopUsersStats(sortBy: string, categoryStatsEnabled = fals let additionalFields = ""; if (categoryStatsEnabled) { - additionalFields += `SUM(CASE WHEN category = 'sponsor' THEN 1 ELSE 0 END) as "categorySponsor", + additionalFields += ` + SUM(CASE WHEN category = 'sponsor' THEN 1 ELSE 0 END) as "categorySumSponsor", SUM(CASE WHEN category = 'intro' THEN 1 ELSE 0 END) as "categorySumIntro", SUM(CASE WHEN category = 'outro' THEN 1 ELSE 0 END) as "categorySumOutro", SUM(CASE WHEN category = 'interaction' THEN 1 ELSE 0 END) as "categorySumInteraction", - SUM(CASE WHEN category = 'selfpromo' THEN 1 ELSE 0 END) as "categorySelfpromo", - SUM(CASE WHEN category = 'music_offtopic' THEN 1 ELSE 0 END) as "categoryMusicOfftopic", + SUM(CASE WHEN category = 'selfpromo' THEN 1 ELSE 0 END) as "categorySumSelfpromo", + SUM(CASE WHEN category = 'music_offtopic' THEN 1 ELSE 0 END) as "categorySumMusicOfftopic", SUM(CASE WHEN category = 'preview' THEN 1 ELSE 0 END) as "categorySumPreview", - SUM(CASE WHEN category = 'poi_highlight' THEN 1 ELSE 0 END) as "categorySumHighlight", `; + SUM(CASE WHEN category = 'poi_highlight' THEN 1 ELSE 0 END) as "categorySumHighlight", + SUM(CASE WHEN category = 'filler' THEN 1 ELSE 0 END) as "categorySumFiller",`; } const rows = await db.prepare("all", `SELECT COUNT(*) as "totalSubmissions", SUM(views) as "viewCount", @@ -42,14 +44,15 @@ async function generateTopUsersStats(sortBy: string, categoryStatsEnabled = fals minutesSaved[i] = rows[i].minutesSaved; if (categoryStatsEnabled) { categoryStats[i] = [ - rows[i].categorySponsor, + rows[i].categorySumSponsor, rows[i].categorySumIntro, rows[i].categorySumOutro, rows[i].categorySumInteraction, - rows[i].categorySelfpromo, - rows[i].categoryMusicOfftopic, + rows[i].categorySumSelfpromo, + rows[i].categorySumMusicOfftopic, rows[i].categorySumPreview, - rows[i].categorySumHighlight + rows[i].categorySumHighlight, + rows[i].categorySumFiller ]; } } diff --git a/src/routes/getUserStats.ts b/src/routes/getUserStats.ts index b58c611..2bd9b65 100644 --- a/src/routes/getUserStats.ts +++ b/src/routes/getUserStats.ts @@ -15,10 +15,11 @@ async function dbGetUserSummary(userID: HashedUserID, fetchCategoryStats: boolea SUM(CASE WHEN "category" = 'intro' THEN 1 ELSE 0 END) as "categorySumIntro", SUM(CASE WHEN "category" = 'outro' THEN 1 ELSE 0 END) as "categorySumOutro", SUM(CASE WHEN "category" = 'interaction' THEN 1 ELSE 0 END) as "categorySumInteraction", - SUM(CASE WHEN "category" = 'selfpromo' THEN 1 ELSE 0 END) as "categorySelfpromo", - SUM(CASE WHEN "category" = 'music_offtopic' THEN 1 ELSE 0 END) as "categoryMusicOfftopic", + SUM(CASE WHEN "category" = 'selfpromo' THEN 1 ELSE 0 END) as "categorySumSelfpromo", + SUM(CASE WHEN "category" = 'music_offtopic' THEN 1 ELSE 0 END) as "categorySumMusicOfftopic", SUM(CASE WHEN "category" = 'preview' THEN 1 ELSE 0 END) as "categorySumPreview", - SUM(CASE WHEN "category" = 'poi_highlight' THEN 1 ELSE 0 END) as "categorySumHighlight",`; + SUM(CASE WHEN "category" = 'poi_highlight' THEN 1 ELSE 0 END) as "categorySumHighlight", + SUM(CASE WHEN "category" = 'filler' THEN 1 ELSE 0 END) as "categorySumFiller",`; } if (fetchActionTypeStats) { additionalQuery += ` @@ -48,10 +49,11 @@ async function dbGetUserSummary(userID: HashedUserID, fetchCategoryStats: boolea intro: proxy.categorySumIntro, outro: proxy.categorySumOutro, interaction: proxy.categorySumInteraction, - selfpromo: proxy.categorySelfpromo, - music_offtopic: proxy.categoryMusicOfftopic, + selfpromo: proxy.categorySumSelfpromo, + music_offtopic: proxy.categorySumMusicOfftopic, preview: proxy.categorySumPreview, poi_highlight: proxy.categorySumHighlight, + filler: proxy.categorySumFiller, }; } if (fetchActionTypeStats) { diff --git a/test/cases/getUserStats.ts b/test/cases/getUserStats.ts index 900a595..7704b15 100644 --- a/test/cases/getUserStats.ts +++ b/test/cases/getUserStats.ts @@ -20,6 +20,7 @@ describe("getUserStats", () => { await db.prepare("run", sponsorTimesQuery, ["getuserstats1", 0, 60, 0, "getuserstatsuuid7", getHash("getuserstats_user_01"), 7, 7, "music_offtopic", 0]); await db.prepare("run", sponsorTimesQuery, ["getuserstats1", 11, 11, 0, "getuserstatsuuid8", getHash("getuserstats_user_01"), 8, 8, "poi_highlight", 0]); await db.prepare("run", sponsorTimesQuery, ["getuserstats1", 0, 60, -2, "getuserstatsuuid9", getHash("getuserstats_user_02"), 8, 2, "sponsor", 0]); + await db.prepare("run", sponsorTimesQuery, ["getuserstats1", 0, 60, 0, "getuserstatsuuid10", getHash("getuserstats_user_01"), 8, 2, "filler", 0]); }); @@ -48,14 +49,15 @@ describe("getUserStats", () => { preview: 1, music_offtopic: 1, poi_highlight: 1, + filler: 1 }, actionTypeCount: { mute: 0, - skip: 8 + skip: 9 }, overallStats: { - minutesSaved: 28, - segmentCount: 8 + minutesSaved: 30, + segmentCount: 9 } }; assert.ok(partialDeepEquals(res.data, expected));