From b8530cb6148b8a69a8fa5d357e26c02ed15d7451 Mon Sep 17 00:00:00 2001 From: yarnom Date: Mon, 27 Oct 2025 11:37:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9B=B7=E8=BE=BE=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E4=B8=8D=E9=99=90=E4=BA=8E=2030=20=E5=88=86?= =?UTF-8?q?=E7=9A=84=EF=BC=8C=E5=8F=AF=E5=BE=80=E5=89=8D=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/service-splitarea/main.go | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/cmd/service-splitarea/main.go b/cmd/service-splitarea/main.go index c79f716..e95684f 100644 --- a/cmd/service-splitarea/main.go +++ b/cmd/service-splitarea/main.go @@ -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")