Skip to content

Commit

Permalink
Fix timeseries query
Browse files Browse the repository at this point in the history
  • Loading branch information
nlinnanen committed May 7, 2024
1 parent c04079a commit 65cd370
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/analytics/timeseries.ts
Original file line number Diff line number Diff line change
@@ -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<TimeSeriesData> => {
console.log("Getting time series data");
const data = await prisma.$queryRaw`
WITH "PointsByDate" AS (
SELECT
Expand All @@ -20,17 +21,14 @@ export const getTimeSeriesData = async (): Promise<TimeSeriesData> => {
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;
}

0 comments on commit 65cd370

Please sign in to comment.