Skip to content

Commit

Permalink
Filter out invalid entries in analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
nlinnanen committed May 8, 2024
1 parent bbb6025 commit 9fa81b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/analytics/rankings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const topUsersByGuild = async (guild: string, limit: number) => {
FROM
"Entry" JOIN "User" ON "Entry"."userId" = "User"."telegramUserId"
WHERE
"guild" = ${guild}
"guild" = ${guild} AND
"Entry"."valid" IS NOT FALSE
GROUP BY
"userId",
"telegramUsername",
Expand Down
10 changes: 8 additions & 2 deletions src/analytics/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export async function calculateGuildStatistics(
COUNT(DISTINCT "userId") as "uniqueParticipants"
FROM
"Entry" JOIN "User" ON "Entry"."userId" = "User"."telegramUserId"
WHERE
"Entry"."valid" IS NOT FALSE
GROUP BY
guild
`) as Aggregate[];
Expand All @@ -41,6 +43,8 @@ export async function calculateGuildStatistics(
"userId"
FROM
"Entry"
WHERE
"Entry"."valid" IS NOT FALSE
GROUP BY
"userId"
HAVING
Expand All @@ -65,7 +69,8 @@ export async function calculateGuildStatistics(
FROM
"Entry" JOIN "User" ON "Entry"."userId" = "User"."telegramUserId"
WHERE
"Entry"."createdAt" BETWEEN ${periodStart} AND ${periodEnd}
("Entry"."createdAt" BETWEEN ${periodStart} AND ${periodEnd}) AND
"Entry"."valid" IS NOT FALSE
GROUP BY
guild
),
Expand All @@ -76,7 +81,8 @@ export async function calculateGuildStatistics(
FROM
"Entry" JOIN "User" ON "Entry"."userId" = "User"."telegramUserId"
WHERE
"Entry"."createdAt" < ${periodStart}
"Entry"."createdAt" < ${periodStart} AND
"Entry"."valid" IS NOT FALSE
GROUP BY
guild
)
Expand Down
2 changes: 2 additions & 0 deletions src/analytics/timeseries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const getTimeSeriesData = async (): Promise<TimeSeriesData> => {
SUM("earnedPoints") as "totalPoints"
FROM
"Entry" JOIN "User" ON "Entry"."userId" = "User"."telegramUserId"
WHERE
"Entry"."valid" IS NOT FALSE
GROUP BY
"date",
"guild"
Expand Down
2 changes: 1 addition & 1 deletion src/launchBotDependingOnNodeEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import app, { launchServer } from "./server";
*/
async function launchLongPollBot(bot: Telegraf<Context<Update>>) {
launchServer();
await bot.launch();
// await bot.launch();
}

/**
Expand Down

0 comments on commit 9fa81b9

Please sign in to comment.