fix: 彩云API 的时间转化为右端点
This commit is contained in:
parent
19ea80614c
commit
65f95662ca
@ -65,7 +65,10 @@ func RunCaiyunFetch(ctx context.Context, token string) error {
|
|||||||
|
|
||||||
issuedAt := time.Now().In(loc)
|
issuedAt := time.Now().In(loc)
|
||||||
startHour := issuedAt.Truncate(time.Hour)
|
startHour := issuedAt.Truncate(time.Hour)
|
||||||
targets := []time.Time{startHour.Add(1 * time.Hour), startHour.Add(2 * time.Hour), startHour.Add(3 * time.Hour)}
|
// 彩云小时接口返回的是“左端点”时刻(例如 13:00 表示 13:00-14:00 区间)。
|
||||||
|
// 我们将左端点列表保留为 startHour, startHour+1h, startHour+2h,并在写库时统一 +1h
|
||||||
|
// 使得 forecast_time 表示区间右端,与实测聚合对齐。
|
||||||
|
leftEdges := []time.Time{startHour, startHour.Add(1 * time.Hour), startHour.Add(2 * time.Hour)}
|
||||||
|
|
||||||
for _, s := range stations {
|
for _, s := range stations {
|
||||||
if !s.lat.Valid || !s.lon.Valid {
|
if !s.lat.Valid || !s.lon.Valid {
|
||||||
@ -161,27 +164,30 @@ func RunCaiyunFetch(ctx context.Context, token string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("处理时间点: %v", targets)
|
log.Printf("处理时间点(彩云左端): %v", leftEdges)
|
||||||
for _, ft := range targets {
|
for _, left := range leftEdges {
|
||||||
if v, ok := table[ft]; ok {
|
v, ok := table[left]
|
||||||
log.Printf("写入预报点: station=%s time=%s rain=%.3f temp=%.2f rh=%.1f ws=%.3f wdir=%.1f prob=%.1f pres=%.2f",
|
if !ok {
|
||||||
s.id, ft.Format(time.RFC3339), v.rain, v.temp, v.rh, v.ws, v.wdir, v.prob, v.pres)
|
log.Printf("时间点无数据: %s", left.Format(time.RFC3339))
|
||||||
if err := upsertForecastCaiyun(ctx, db, s.id, issuedAt, ft,
|
continue
|
||||||
int64(v.rain*1000.0), // mm → x1000
|
}
|
||||||
int64(v.temp*100.0), // °C → x100
|
ft := left.Add(1 * time.Hour)
|
||||||
int64(v.rh), // %
|
log.Printf("写入预报点: station=%s forecast_time=%s (source=%s) rain=%.3f temp=%.2f rh=%.1f ws=%.3f wdir=%.1f prob=%.1f pres=%.2f",
|
||||||
int64(v.ws*1000.0), // m/s → x1000
|
s.id, ft.Format(time.RFC3339), left.Format(time.RFC3339), v.rain, v.temp, v.rh, v.ws, v.wdir, v.prob, v.pres)
|
||||||
int64(0), // gust: 彩云小时接口无阵风,置0
|
err := upsertForecastCaiyun(ctx, db, s.id, issuedAt, ft,
|
||||||
int64(v.wdir), // 度
|
int64(v.rain*1000.0), // mm → x1000
|
||||||
int64(v.prob), // %
|
int64(v.temp*100.0), // °C → x100
|
||||||
int64(v.pres*100.0), // hPa → x100
|
int64(v.rh), // %
|
||||||
); err != nil {
|
int64(v.ws*1000.0), // m/s → x1000
|
||||||
log.Printf("写入forecast失败(caiyun) station=%s time=%s err=%v", s.id, ft.Format(time.RFC3339), err)
|
int64(0), // gust: 彩云小时接口无阵风,置0
|
||||||
} else {
|
int64(v.wdir), // 度
|
||||||
log.Printf("写入forecast成功(caiyun) station=%s time=%s", s.id, ft.Format(time.RFC3339))
|
int64(v.prob), // %
|
||||||
}
|
int64(v.pres*100.0), // hPa → x100
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("写入forecast失败(caiyun) station=%s time=%s err=%v", s.id, ft.Format(time.RFC3339), err)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("时间点无数据: %s", ft.Format(time.RFC3339))
|
log.Printf("写入forecast成功(caiyun) station=%s time=%s", s.id, ft.Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user