监控页面增强:温度变化闪绿光、观测N分钟前、更新戳可见

- 每张卡片加"观测 X 分钟前"时间感知
- 温度值变化时卡片边框闪绿光(HTMX afterSwap 事件)
- 更新时间戳移入 HTMX 局部刷新区,30s 刷新可见
- CSS 加 obs-age 样式
This commit is contained in:
2569718930@qq.com
2026-05-13 19:58:19 +08:00
parent 538cc7db2d
commit 239c9c446d
5 changed files with 55 additions and 2 deletions
+3 -1
View File
@@ -5,6 +5,7 @@ pub struct ObsRow {
pub temp_c: Option<f64>,
#[allow(dead_code)]
pub obs_time: Option<String>,
pub created_at: Option<String>,
}
/// Get recent temperature observations for an ICAO station.
@@ -14,7 +15,7 @@ pub fn get_recent_obs(db_path: &str, icao: &str, minutes: i32, limit: usize) ->
Err(_) => return vec![],
};
let sql = format!(
"SELECT temp_c, obs_time FROM airport_obs_log \
"SELECT temp_c, obs_time, created_at FROM airport_obs_log \
WHERE icao = ?1 AND created_at > datetime('now', '{} minutes') \
ORDER BY created_at DESC LIMIT ?2",
-minutes
@@ -28,6 +29,7 @@ pub fn get_recent_obs(db_path: &str, icao: &str, minutes: i32, limit: usize) ->
Ok(ObsRow {
temp_c: row.get(0)?,
obs_time: row.get(1)?,
created_at: row.get(2)?,
})
})
.ok()
+13
View File
@@ -59,6 +59,18 @@ fn load_city_snapshot(db_path: &str, (key, display, icao, airport, tz, thresh):
let temps: Vec<f64> = obs.iter().filter_map(|o| o.temp_c).collect();
let current_temp = temps.first().copied();
// Age of most recent observation
let obs_age_min = obs.first().and_then(|o| {
o.created_at.as_ref().and_then(|ts| {
chrono::NaiveDateTime::parse_from_str(ts, "%Y-%m-%d %H:%M:%S")
.ok()
.map(|dt| {
let obs_utc = dt.and_utc();
(now_utc - obs_utc).num_minutes().max(0)
})
})
});
// Trend from last 6 points
let trend_data: Vec<f64> = temps.iter().take(6).copied().collect();
let trend = trend::calc_trend(&trend_data);
@@ -94,6 +106,7 @@ fn load_city_snapshot(db_path: &str, (key, display, icao, airport, tz, thresh):
temp_ok: false,
trend_ok: false,
in_window: false,
obs_age_min,
}
}
+1
View File
@@ -19,6 +19,7 @@ pub struct CitySnapshot {
pub temp_ok: bool,
pub trend_ok: bool,
pub in_window: bool,
pub obs_age_min: Option<i64>,
}
#[derive(Debug, Clone, Copy, Serialize)]