From 0843d51e25fe91f752f6d9e764df144e7cbd876c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20N=C3=BDvlt?= Date: Thu, 29 Feb 2024 12:40:34 +0100 Subject: [PATCH] Add simple stats --- public/robots.txt | 2 ++ src/pages/stats.astro | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 public/robots.txt create mode 100644 src/pages/stats.astro diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..b829c8a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: /stats diff --git a/src/pages/stats.astro b/src/pages/stats.astro new file mode 100644 index 0000000..2130094 --- /dev/null +++ b/src/pages/stats.astro @@ -0,0 +1,41 @@ +--- +import { db } from "../db"; + +export const prerender = false; + +const query = db.selectFrom("letters").select(({ fn }) => [fn.count("id").as("count")]); + +const [totalSubmissions] = await query.execute(); +const [confirmedSubmissions] = await query.where("confirmed", "=", 1).execute(); + +const submissionsByLanguage = await db + .selectFrom("letters") + .groupBy("language") + .select(({ fn }) => ["language", fn.count("id").as("count")]) + .orderBy("count", "desc") + .execute(); +--- + +
+

Total submissions: {totalSubmissions.count}

+

Confirmed submissions: {confirmedSubmissions.count}

+ + + + + + + + + + { + submissionsByLanguage.map((row) => ( + + + + + )) + } + +
LangSubmissions
{row.language}{row.count}
+