Playtime records from pt_events; sticky top bar, page scroll locked under the drawer

Records: the most bomb plants, defuses, knife, Zeus and headshot kills for
the last 7 days, 30 days or all time, and each player's counts, when
PlaytimeHistory 0.2.0's pt_events is there. The public site's top bar now
sticks the whole way down, Playtime comes after Server, and only the
player drawer scrolls while it's open.
This commit is contained in:
Astra 2026-10-04 21:37:42 +01:00
parent 6d0fc6e463
commit 7004945d49
9 changed files with 296 additions and 27 deletions

View file

@ -114,8 +114,23 @@ func TestPlaytimeDB(t *testing.T) {
VALUES (1, ?, 5, 0, 10, 'de_mirage'), (1, ?, 9, 0, 10, 'de_mirage'), (2, ?, 20, 0, 10, 'de_dust2')`,
ago(24*time.Hour), ago(48*time.Hour), ago(24*time.Hour))
if ok, data, err := st.State(ctx); err != nil || !ok || !data {
t.Fatalf("State with data: %v, %v, %v", ok, data, err)
// Events: Alpha plants twice (once 10 days ago), defuses once and knifes a player and a bot;
// Bravo gets a Zeus kill and a headshot.
event := func(id uint64, kind int, at time.Time, weapon any, hs any, bot any) {
t.Helper()
exec(`INSERT INTO pt_events (event_key, server_id, steamid64, kind, at, map, team, weapon, headshot, victim_bot)
VALUES (REPLACE(UUID(), '-', ''), 1, ?, ?, ?, 'de_mirage', 2, ?, ?, ?)`, id, kind, at, weapon, hs, bot)
}
event(a, EventPlanted, ago(2*time.Hour), nil, nil, nil)
event(a, EventPlanted, ago(10*24*time.Hour), nil, nil, nil)
event(a, EventDefused, ago(2*time.Hour), nil, nil, nil)
event(a, EventKill, ago(2*time.Hour), "knife_karambit", 0, 0)
event(a, EventKill, ago(2*time.Hour), "knife", 1, 1) // a bot: doesn't count, not even as a headshot
event(b, EventKill, ago(20*time.Minute), "taser", 0, 0)
event(b, EventKill, ago(20*time.Minute), "ak47", 1, 0)
if ok, data, err := st.State(ctx); err != nil || !ok || !data || !st.HasEvents() {
t.Fatalf("State with data: %v, %v, %v (events %v)", ok, data, err, st.HasEvents())
}
// The hour split must add up to exactly the segments' lengths.
@ -228,6 +243,32 @@ func TestPlaytimeDB(t *testing.T) {
t.Fatalf("Bravo's activity %+v", x)
}
rec, err := st.Records(ctx, &week, 5)
if err != nil {
t.Fatal(err)
}
one := func(name string, got []Record, who string, n int) {
t.Helper()
if len(got) != 1 || got[0].Name != who || got[0].Count != n {
t.Fatalf("%s: %+v, want %s with %d", name, got, who, n)
}
}
one("plants", rec.Plants, "Alpha", 1)
one("defuses", rec.Defuses, "Alpha", 1)
one("knife kills", rec.KnifeKills, "Alpha", 1)
one("zeus kills", rec.ZeusKills, "Bravo", 1)
one("headshots", rec.Headshots, "Bravo", 1)
if rec.Since == nil || !rec.Since.Equal(ago(10*24*time.Hour)) {
t.Fatalf("records since %v", rec.Since)
}
if rec, err = st.Records(ctx, nil, 5); err != nil {
t.Fatal(err)
}
one("plants ever", rec.Plants, "Alpha", 2)
if e := p.Events; e == nil || e.Plants != 2 || e.Defuses != 1 || e.KnifeKills != 1 || e.ZeusKills != 0 || e.Headshots != 0 {
t.Fatalf("Alpha's events %+v", e)
}
reasons, err := st.Reasons(ctx, ago(30*24*time.Hour))
if err != nil {
t.Fatal(err)