feat: 雷达数据导出不限于 30 分的,可往前回退时间。
This commit is contained in:
parent
299932f01a
commit
b8530cb614
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@ -185,14 +186,32 @@ func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir s
|
|||||||
}
|
}
|
||||||
runAt = runAt.In(loc)
|
runAt = runAt.In(loc)
|
||||||
|
|
||||||
// Current hour's :30
|
// Prefer current hour's :30 tile, fallback to :24 then :00 if missing.
|
||||||
targetLocal := runAt.Truncate(time.Hour).Add(30 * time.Minute)
|
targetBase := runAt.Truncate(time.Hour)
|
||||||
|
candidates := []int{30, 24, 0}
|
||||||
// Fetch tile
|
var (
|
||||||
rec, err := getRadarTileAt(ctx, z, y, x, targetLocal)
|
targetLocal time.Time
|
||||||
if err != nil {
|
rec *radarTileRecord
|
||||||
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
|
||||||
Bw, Bs, Be, Bn, err := parseBounds(bounds)
|
Bw, Bs, Be, Bn, err := parseBounds(bounds)
|
||||||
if err != nil {
|
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")
|
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")
|
ymd := targetLocal.Format("20060102")
|
||||||
hh := targetLocal.Format("15")
|
hh := targetLocal.Format("15")
|
||||||
mm := targetLocal.Format("04")
|
mm := targetLocal.Format("04")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user