feat: 统计页支持一年时段和按日趋势
在线人数在新的有效访问后尽快刷新,历史查询保留一年并画出每日连接数。
This commit is contained in:
@@ -303,6 +303,42 @@ func TestOnlyQGISOverHTTPSCounted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDailySeries(t *testing.T) {
|
||||
now := time.Date(2026, 9, 23, 12, 0, 0, 0, cst)
|
||||
app := newTestApp(t, func() time.Time { return now })
|
||||
d1 := time.Date(2026, 9, 21, 9, 0, 0, 0, cst).Unix() / 60
|
||||
d2 := time.Date(2026, 9, 22, 9, 0, 0, 0, cst).Unix() / 60
|
||||
_, err := app.store.WriteBatch(context.Background(), []hitKey{
|
||||
{minute: d1, table: "grid", sid: "A"},
|
||||
{minute: d2, table: "grid", sid: "B"},
|
||||
}, map[string]*sessionAgg{
|
||||
"A": {fp: "fp", first: d1, last: d1},
|
||||
"B": {fp: "fp", first: d2, last: d2},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
q := url.Values{}
|
||||
q.Set("start", time.Date(2026, 9, 21, 0, 0, 0, 0, cst).Format(time.RFC3339))
|
||||
q.Set("end", time.Date(2026, 9, 22, 23, 0, 0, 0, cst).Format(time.RFC3339))
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/range?"+q.Encode(), nil)
|
||||
rr := httptest.NewRecorder()
|
||||
app.Handler().ServeHTTP(rr, req)
|
||||
if rr.Code != 200 {
|
||||
t.Fatalf("%d %s", rr.Code, rr.Body)
|
||||
}
|
||||
var body rangeResp
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body.Total != 1 || len(body.Daily) != 2 {
|
||||
t.Fatalf("%+v", body)
|
||||
}
|
||||
if body.Daily[0].Date != "2026-09-21" || body.Daily[0].Count != 1 || body.Daily[1].Date != "2026-09-22" || body.Daily[1].Count != 1 {
|
||||
t.Fatalf("%+v", body.Daily)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadDoesNotRecord(t *testing.T) {
|
||||
app := newTestApp(t, func() time.Time { return time.Date(2026, 9, 23, 9, 0, 0, 0, cst) })
|
||||
ts := httptest.NewServer(app.Handler())
|
||||
@@ -431,12 +467,15 @@ func TestChineseTableAndPages(t *testing.T) {
|
||||
"datetime-local",
|
||||
"queryRange();",
|
||||
"1 小时",
|
||||
"24 小时",
|
||||
"3 天",
|
||||
"12 小时",
|
||||
"1 天",
|
||||
"1 周",
|
||||
"1 月",
|
||||
"id=\"chart\"",
|
||||
"visibilitychange",
|
||||
"document.hidden",
|
||||
"textContent",
|
||||
"30000",
|
||||
"5000",
|
||||
"encodeURIComponent",
|
||||
} {
|
||||
if !strings.Contains(html, needle) {
|
||||
|
||||
Reference in New Issue
Block a user