fix: 更改时间桶的收集逻辑

This commit is contained in:
yarnom 2025-08-20 11:42:32 +08:00
parent a206138362
commit 03d42ac3eb

View File

@ -112,11 +112,11 @@ func getStationData(w http.ResponseWriter, r *http.Request) {
intervalSQL = "1 hour"
}
// 构建查询SQL - 使用时间窗口聚合
// 构建查询SQL - 使用时间窗口聚合,显示上一个时间段的数据
query = fmt.Sprintf(`
WITH time_series AS (
SELECT
date_trunc('hour', timestamp) +
date_trunc('hour', timestamp) + INTERVAL '1 hour' +
INTERVAL '%s' * FLOOR(EXTRACT(EPOCH FROM timestamp - date_trunc('hour', timestamp)) / EXTRACT(EPOCH FROM INTERVAL '%s')) as time_bucket,
temperature,
humidity,