fix: 固定24分的雷达数据瓦片

This commit is contained in:
yarnom 2025-10-28 09:40:30 +08:00
parent b8530cb614
commit abb45a13ec

View File

@ -2,7 +2,6 @@ package main
import ( import (
"context" "context"
"database/sql"
"encoding/csv" "encoding/csv"
"encoding/json" "encoding/json"
"errors" "errors"
@ -186,30 +185,13 @@ func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir s
} }
runAt = runAt.In(loc) runAt = runAt.In(loc)
// Prefer current hour's :30 tile, fallback to :24 then :00 if missing. // Current hour's :30
targetBase := runAt.Truncate(time.Hour) targetLocal := runAt.Truncate(time.Hour).Add(24 * time.Minute)
candidates := []int{30, 24, 0}
var ( // Fetch tile
targetLocal time.Time rec, err := getRadarTileAt(ctx, z, y, x, targetLocal)
rec *radarTileRecord 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)
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 // Bounds
@ -245,11 +227,10 @@ func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir s
return fmt.Errorf("invalid tile data") return fmt.Errorf("invalid tile data")
} }
// Prepare output dir: export_data/split_area/YYYYMMDD/HH/mm // Prepare output dir: export_data/split_area/YYYYMMDD/HH/30 (keep legacy minute path)
ymd := targetLocal.Format("20060102") ymd := targetLocal.Format("20060102")
hh := targetLocal.Format("15") hh := targetLocal.Format("15")
mm := targetLocal.Format("04") dir := filepath.Join(outDir, ymd, hh, "30")
dir := filepath.Join(outDir, ymd, hh, mm)
if err := os.MkdirAll(dir, 0o755); err != nil { if err := os.MkdirAll(dir, 0o755); err != nil {
return err return err
} }