Skip to content

Commit

Permalink
feat: add table with area visit stats
Browse files Browse the repository at this point in the history
SchutteJan committed Jul 25, 2024
1 parent 86c77f2 commit a605326
Showing 2 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions frontend/src/models/schemas.ts
Original file line number Diff line number Diff line change
@@ -59,5 +59,7 @@ export interface WhoResponse {
role: UserRoleEnum
}
export interface VisitStats {
bar_visits_by_area: [string, number][]
distinct_bar_visits: number
total_bars_by_area: [string, number][]
}
36 changes: 30 additions & 6 deletions frontend/src/routes/me/+page.svelte
Original file line number Diff line number Diff line change
@@ -15,6 +15,14 @@
})
}
function zipVistsByArea(total_bars: [string, number][], visit_bars: [string, number][]) {
let areaMap = new Map<string, [number, number]>()
// zip two array together using map: a.map((k, i) => [k, b[i]])
// this assumes that the two arrays are sorted in the same order
total_bars.map((k, i) => areaMap.set(k[0], [k[1], visit_bars[i][1]]))
return areaMap
}
onMount(async () => {
get_bar_visit_stats()
.then((response) => {
@@ -42,17 +50,33 @@
<p>This could've been you.</p>
<p>Uhuh not sure who you are, are you even <a href="/login">logged in</a>?</p>
{/if}

<h3>Statistics</h3>
{#if visitStats && userData}
<p>Visits:</p>
<ul>
<li>Total bars visited: {visitStats.distinct_bar_visits}</li>
</ul>
Total bars visited: {visitStats.distinct_bar_visits}

<table class="striped">
<thead>
<tr>
<th>Area</th>
<th>Total</th>
<th>Visits</th>
</tr>
</thead>
<tbody>
{#each zipVistsByArea(visitStats.total_bars_by_area, visitStats.bar_visits_by_area).entries() as [name, [total, count]]}
<tr>
<td>{name}</td>
<td>{total}</td>
<td>{count}</td>
</tr>
{/each}
</tbody>
</table>
{:else if userData}
<p>Fetching visit stats...</p>
<progress />
{/if}

<h3>Management</h3>
{#if userData}
<button on:click={handleLogout} class="outline">Logout</button>
{/if}

0 comments on commit a605326

Please sign in to comment.