-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstats.templ
More file actions
89 lines (85 loc) · 2.44 KB
/
stats.templ
File metadata and controls
89 lines (85 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/eventstore/mmm"
"github.com/fiatjaf/pyramid/layout"
)
templ StatsPage(
loggedUser nostr.PubKey,
mainStats,
systemStats,
groupsStats,
favoritesStats,
internalStats,
personalStats,
moderatedStats,
popularStats,
uppermostStats,
inboxStats mmm.EventStats,
) {
@layout.Layout(loggedUser, "stats") {
<div class="space-y-8">
<div>
@layout.SubSectionTitle("event statistics")
@statsTable("main", mainStats)
@statsTable("inbox", inboxStats)
@statsTable("groups", groupsStats)
@statsTable("popular", popularStats)
@statsTable("uppermost", uppermostStats)
@statsTable("favorites", favoritesStats)
@statsTable("moderated", moderatedStats)
@statsTable("internal", internalStats)
@statsTable("personal", personalStats)
@statsTable("system", systemStats)
</div>
</div>
}
}
templ statsTable(name string, stats mmm.EventStats) {
<div class="mb-4 bg-white dark:bg-stone-800 rounded-lg shadow-md p-6 border border-stone-200 dark:border-stone-700">
<h3 class="text-xl font-semibold mb-4">{ name }</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<h4 class="font-medium mb-2 col-span-2">total events: { fmt.Sprintf("%d", stats.Total) }</h4>
{{ topKinds, top5Kinds := getTopKinds(stats.PerKind, 30, 5) }}
if len(topKinds) > 0 {
<div>
<h4 class="font-medium">by kind:</h4>
<table class="w-full text-sm">
<tbody>
for _, kindInfo := range topKinds {
<tr class="border-b border-stone-100 dark:border-stone-800">
<td class="py-1">{ fmt.Sprintf("%d", kindInfo.Kind) }</td>
<td class="text-right py-1">{ fmt.Sprintf("%d", kindInfo.Count) }</td>
</tr>
}
</tbody>
</table>
</div>
}
{{ topAuthors := getTopAuthors(stats.PerPubKey, 30) }}
if len(topAuthors) > 0 {
<div>
<h4 class="font-medium">by author:</h4>
<table class="w-full text-sm">
<tbody>
for _, authorInfo := range topAuthors {
<tr class="border-b border-stone-100 dark:border-stone-800">
<td class="py-1 font-mono text-xs">
@layout.ProfileLink(authorInfo.Author)
</td>
<td class="text-right py-1">{ fmt.Sprintf("%d", authorInfo.Count) }</td>
</tr>
}
</tbody>
</table>
</div>
}
</div>
if len(stats.PerWeek) > 0 {
<div class="mt-6">
@generateWeeklyChart(stats, top5Kinds, name)
</div>
}
</div>
}