feat: 统计页支持一年时段和按日趋势

在线人数在新的有效访问后尽快刷新,历史查询保留一年并画出每日连接数。
This commit is contained in:
nixevol
2026-09-28 11:08:28 +08:00
parent 28170a7fe2
commit fe24a88bac
12 changed files with 358 additions and 36 deletions
+20
View File
@@ -44,6 +44,26 @@ func TestEstimate(t *testing.T) {
}
}
func TestMergePending(t *testing.T) {
rows := []sessionRow{{table: "grid", sid: "A", fp: "fp", first: 10, last: 10}}
hits := []hitKey{{minute: 12, table: "grid", sid: "A"}, {minute: 12, table: "road", sid: "B"}, {minute: 1, table: "old", sid: "C"}}
sessions := map[string]sessionAgg{
"A": {fp: "fp", first: 10, last: 12},
"B": {fp: "fp2", first: 12, last: 12},
"C": {fp: "fp3", first: 1, last: 1},
}
got := mergePending(rows, hits, sessions, 10, 12)
if len(got) != 2 {
t.Fatalf("len %d", len(got))
}
if got[0].last != 12 {
t.Fatalf("extended last %d", got[0].last)
}
if got[1].table != "road" || got[1].sid != "B" {
t.Fatalf("new row %+v", got[1])
}
}
func TestSortedTables(t *testing.T) {
got := sortedTables(map[string]int{"b": 1, "a": 2, "c": 2, "z": 0})
if len(got) != 3 || got[0].Table != "a" || got[0].Count != 2 || got[1].Table != "c" || got[2].Table != "b" {