Add simple stats

This commit is contained in:
Ondřej 2024-02-29 12:40:34 +01:00
parent 589dd0c328
commit 0843d51e25
2 changed files with 43 additions and 0 deletions

2
public/robots.txt Normal file
View file

@ -0,0 +1,2 @@
User-agent: *
Disallow: /stats

41
src/pages/stats.astro Normal file
View file

@ -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();
---
<div>
<p>Total submissions: {totalSubmissions.count}</p>
<p>Confirmed submissions: {confirmedSubmissions.count}</p>
<table>
<thead>
<tr>
<th>Lang</th>
<th>Submissions</th>
</tr>
</thead>
<tbody>
{
submissionsByLanguage.map((row) => (
<tr>
<th class="text-left">{row.language}</th>
<th class="text-right">{row.count}</th>
</tr>
))
}
</tbody>
</table>
</div>