fix: 雷达区域数据导出修改为本小时的45分
This commit is contained in:
parent
2ee30db410
commit
7bc2337549
@ -20,7 +20,7 @@ import (
|
|||||||
"weatherstation/internal/database"
|
"weatherstation/internal/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service that, at each hour, processes previous hour's :30 radar tile for z/y/x,
|
// Service that, at hh:45 each hour, processes current hour's :30 radar tile for z/y/x,
|
||||||
// splits a user region into 0.1° grid, averages dBZ (linear domain), fetches Open‑Meteo
|
// splits a user region into 0.1° grid, averages dBZ (linear domain), fetches Open‑Meteo
|
||||||
// hourly variables at grid centers, and writes a CSV.
|
// hourly variables at grid centers, and writes a CSV.
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ func fetchMeteo(ctx context.Context, client *http.Client, lon, lat float64, utcH
|
|||||||
return &mv, nil
|
return &mv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// job executes the split+augment for a specific local time (CST) and fixed minute=30 of previous hour.
|
// job executes the split+augment for a specific local time (CST) and fixed minute=30 of the same hour.
|
||||||
func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir string, runAt time.Time) error {
|
func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir string, runAt time.Time) error {
|
||||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
@ -185,8 +185,8 @@ func job(ctx context.Context, z, y, x int, bounds string, tzOffset int, outDir s
|
|||||||
}
|
}
|
||||||
runAt = runAt.In(loc)
|
runAt = runAt.In(loc)
|
||||||
|
|
||||||
// Previous hour's :30
|
// Current hour's :30
|
||||||
targetLocal := runAt.Truncate(time.Hour).Add(-1 * time.Hour).Add(30 * time.Minute)
|
targetLocal := runAt.Truncate(time.Hour).Add(30 * time.Minute)
|
||||||
|
|
||||||
// Fetch tile
|
// Fetch tile
|
||||||
rec, err := getRadarTileAt(ctx, z, y, x, targetLocal)
|
rec, err := getRadarTileAt(ctx, z, y, x, targetLocal)
|
||||||
@ -398,14 +398,17 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hourly scheduler: run at each hour boundary for previous hour :30
|
// Scheduler: run hourly at hh:45 for current hour's :30 radar tile
|
||||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
loc = time.FixedZone("CST", 8*3600)
|
loc = time.FixedZone("CST", 8*3600)
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
now := time.Now().In(loc)
|
now := time.Now().In(loc)
|
||||||
runAt := now.Truncate(time.Hour).Add(time.Hour) // next hour
|
runAt := now.Truncate(time.Hour).Add(45 * time.Minute)
|
||||||
|
if now.After(runAt) {
|
||||||
|
runAt = runAt.Add(time.Hour)
|
||||||
|
}
|
||||||
time.Sleep(time.Until(runAt))
|
time.Sleep(time.Until(runAt))
|
||||||
// execute
|
// execute
|
||||||
if err := job(ctx, *z, *y, *x, *b, *tzOffset, *outDir, runAt); err != nil {
|
if err := job(ctx, *z, *y, *x, *b, *tzOffset, *outDir, runAt); err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user