From 65cd370d04b53a9f796097cabec0a1f3e2aa2a68 Mon Sep 17 00:00:00 2001 From: Niklas Linnanen Date: Tue, 7 May 2024 10:29:59 +0300 Subject: [PATCH] Fix timeseries query --- src/analytics/timeseries.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/analytics/timeseries.ts b/src/analytics/timeseries.ts index 2b75bfe..e132b0c 100644 --- a/src/analytics/timeseries.ts +++ b/src/analytics/timeseries.ts @@ -1,9 +1,10 @@ import _ from "lodash"; import { prisma } from "../../config"; import { GUILDS } from "../common/constants"; -import type { TimeSeriesData } from "../common/types"; +import type { Guild, TimeSeriesData } from "../common/types"; export const getTimeSeriesData = async (): Promise => { + console.log("Getting time series data"); const data = await prisma.$queryRaw` WITH "PointsByDate" AS ( SELECT @@ -20,17 +21,14 @@ export const getTimeSeriesData = async (): Promise => { SELECT "date", "guild", - SUM("totalPoints") OVER (ORDER BY "date") as "totalPoints" + SUM("totalPoints") OVER (PARTITION BY "guild" ORDER BY "date") as "totalPoints" FROM "PointsByDate" ORDER BY - "date" ASC + "date" ASC; + ` as TimeSeriesData; - ` as { - date: Date; - guild: string; - totalPoints: number; - }[]; + console.log(data); return data; }