feat: 雷达数据导出不限于 30 分的,可往前回退时间。

This commit is contained in:
yarnom 2025-10-27 11:37:59 +08:00
parent 299932f01a
commit b8530cb614

View File

@ -2,6 +2,7 @@ package main
import (
"context"
"database/sql"
"encoding/csv"
"encoding/json"
"errors"
@ -185,14 +186,32 @@ func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir s
}
runAt = runAt.In(loc)
// Current hour's :30
targetLocal := runAt.Truncate(time.Hour).Add(30 * time.Minute)
// Fetch tile
rec, err := getRadarTileAt(ctx, z, y, x, targetLocal)
if err != nil {
return fmt.Errorf("load radar tile z=%d y=%d x=%d at %s: %w", z, y, x, targetLocal.Format("2006-01-02 15:04:05"), err)
// Prefer current hour's :30 tile, fallback to :24 then :00 if missing.
targetBase := runAt.Truncate(time.Hour)
candidates := []int{30, 24, 0}
var (
targetLocal time.Time
rec *radarTileRecord
)
for _, minute := range candidates {
candidate := targetBase.Add(time.Duration(minute) * time.Minute)
tile, err := getRadarTileAt(ctx, z, y, x, candidate)
if err == nil {
if minute != candidates[0] {
log.Printf("[splitarea] fallback to %02d-minute radar tile at %s", minute, candidate.Format("2006-01-02 15:04:05"))
}
targetLocal = candidate
rec = tile
break
}
if !errors.Is(err, sql.ErrNoRows) {
return fmt.Errorf("load radar tile z=%d y=%d x=%d at %s: %w", z, y, x, candidate.Format("2006-01-02 15:04:05"), err)
}
}
if rec == nil {
return fmt.Errorf("no radar tile found for z=%d y=%d x=%d near %s (checked minutes %v)", z, y, x, targetBase.Format("2006-01-02 15:04:05"), candidates)
}
// Bounds
Bw, Bs, Be, Bn, err := parseBounds(bounds)
if err != nil {
@ -226,7 +245,7 @@ func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir s
return fmt.Errorf("invalid tile data")
}
// Prepare output dir: export_data/split_area/YYYYMMDD/HH/30
// Prepare output dir: export_data/split_area/YYYYMMDD/HH/mm
ymd := targetLocal.Format("20060102")
hh := targetLocal.Format("15")
mm := targetLocal.Format("04")