fix: 修正回填逻辑
This commit is contained in:
parent
77d85816bd
commit
f969c2fe0f
@ -214,17 +214,18 @@ func RunBackfill10Min(ctx context.Context, opts BackfillOptions) error {
|
||||
$7, $8, $9,
|
||||
$10, $11, $12, $13
|
||||
) ON CONFLICT (station_id, bucket_start) DO UPDATE SET
|
||||
temp_c_x100 = EXCLUDED.temp_c_x100,
|
||||
humidity_pct = EXCLUDED.humidity_pct,
|
||||
wind_speed_ms_x1000 = EXCLUDED.wind_speed_ms_x1000,
|
||||
wind_gust_ms_x1000 = EXCLUDED.wind_gust_ms_x1000,
|
||||
wind_dir_deg = EXCLUDED.wind_dir_deg,
|
||||
rain_10m_mm_x1000 = EXCLUDED.rain_10m_mm_x1000,
|
||||
rain_total_mm_x1000 = EXCLUDED.rain_total_mm_x1000,
|
||||
solar_wm2_x100 = EXCLUDED.solar_wm2_x100,
|
||||
uv_index = EXCLUDED.uv_index,
|
||||
pressure_hpa_x100 = EXCLUDED.pressure_hpa_x100,
|
||||
sample_count = EXCLUDED.sample_count`
|
||||
-- 仅当新聚合样本数不小于已有样本数时才用新值覆盖均值类字段,避免回退
|
||||
temp_c_x100 = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.temp_c_x100 ELSE rs485_weather_10min.temp_c_x100 END,
|
||||
humidity_pct = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.humidity_pct ELSE rs485_weather_10min.humidity_pct END,
|
||||
wind_speed_ms_x1000 = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.wind_speed_ms_x1000 ELSE rs485_weather_10min.wind_speed_ms_x1000 END,
|
||||
wind_gust_ms_x1000 = GREATEST(rs485_weather_10min.wind_gust_ms_x1000, EXCLUDED.wind_gust_ms_x1000),
|
||||
wind_dir_deg = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.wind_dir_deg ELSE rs485_weather_10min.wind_dir_deg END,
|
||||
rain_10m_mm_x1000 = GREATEST(rs485_weather_10min.rain_10m_mm_x1000, EXCLUDED.rain_10m_mm_x1000),
|
||||
rain_total_mm_x1000 = GREATEST(rs485_weather_10min.rain_total_mm_x1000, EXCLUDED.rain_total_mm_x1000),
|
||||
solar_wm2_x100 = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.solar_wm2_x100 ELSE rs485_weather_10min.solar_wm2_x100 END,
|
||||
uv_index = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.uv_index ELSE rs485_weather_10min.uv_index END,
|
||||
pressure_hpa_x100 = CASE WHEN EXCLUDED.sample_count >= rs485_weather_10min.sample_count THEN EXCLUDED.pressure_hpa_x100 ELSE rs485_weather_10min.pressure_hpa_x100 END,
|
||||
sample_count = GREATEST(rs485_weather_10min.sample_count, EXCLUDED.sample_count)`
|
||||
|
||||
for stationID, m := range buckets {
|
||||
for bucketStart, ag := range m {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user