Skip to content

Commit

Permalink
Merge pull request #1 from ESV-Sweetplum/metric-logging
Browse files Browse the repository at this point in the history
Create metric logging
  • Loading branch information
ESV-Sweetplum authored Jul 14, 2024
2 parents b5a4b67 + 5144a1d commit 7b52399
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

The **Quaver SV Difficulty System** (or **_QSVDS_** for short) is a player-managed database of SV charts and their respective difficulties. The site is meant to provide information to both SV beginners and SV pros, as well as for players to show off their SV prowess. QSVDS is based solely on [Quaver](https://github.com/Quaver/Quaver) and its APIs.

### Note that the current design is very incomplete. The site will undergo a complete overhaul spearheaded by zeph.

# List of Contributors

- <img src="https://github.com/ESV-Sweetplum.png" width="12"> [ESV-Sweetplum](https://github.com/ESV-Sweetplum) - Developer
Expand Down Expand Up @@ -40,9 +42,11 @@ This website is built with the [Next.js](https://nextjs.org) framework, and host
- Database hosted with [Supabase](https://supabase.com).
- API-Database connection done with [Prisma](https://www.prisma.io).
- Fetching/HTTP requests done with [axios](https://axios-http.com) (most likely going to migrate to xior for middleware support).
- Cron hosting for metrics and live updates done with [val town](https://www.val.town).

## Styling Packages

- Designs done with [Figma](https://www.figma.com).
- CSS extension done with [Sass](https://sass-lang.com).
- Components built with [Radix Themes](https://www.radix-ui.com).
- Text fitting algorithm implemented with [react-textfit](https://www.npmjs.com/package/react-textfit).
Expand Down
12 changes: 12 additions & 0 deletions prisma/migrations/20240714012729_add_metric/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "Metric" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"userCount" INTEGER NOT NULL DEFAULT 0,
"mapCount" INTEGER NOT NULL DEFAULT 0,
"ratingCount" INTEGER NOT NULL DEFAULT 0,
"scoreCount" INTEGER NOT NULL DEFAULT 0,
"categoryMapCount" INTEGER[] DEFAULT ARRAY[0, 0, 0, 0, 0]::INTEGER[],

CONSTRAINT "Metric_pkey" PRIMARY KEY ("id")
);
10 changes: 10 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ model Rating {
rating Int
}

model Metric {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
userCount Int @default(0)
mapCount Int @default(0)
ratingCount Int @default(0)
scoreCount Int @default(0)
categoryMapCount Int[] @default([0, 0, 0, 0, 0])
}

enum Category {
Reading
Hybrid
Expand Down
46 changes: 46 additions & 0 deletions src/app/api/metric/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { NextRequest } from "next/server";
import prisma from "../../../../prisma/initialize";
import { Category, Prisma } from "@prisma/client";

export async function POST(request: NextRequest) {
const authHeader = request.headers.get("authorization");

console.log(authHeader);

if (authHeader !== `Bearer ${process.env.CRON_AUTH}`)
return Response.json({
status: 401,
message: "Unauthorized",
});

const userCount = await prisma.user.count();
const mapCount = await prisma.map.count();
const ratingCount = await prisma.rating.count();

const categories: Category[] = [
"Reading",
"Hybrid",
"Memory",
"Reverse",
"Splitscroll",
];

const categoryMapCount = [];

for (let i = 0; i < categories.length; i++) {
const count = await prisma.map.count({
where: { category: categories[i] },
});
categoryMapCount.push(count);
}

await prisma.metric.create({
data: {
userCount,
mapCount,
ratingCount,
scoreCount: 0,
categoryMapCount,
},
});
}

0 comments on commit 7b52399

Please sign in to comment.