Fix
This commit is contained in:
parent
ae9065a1e0
commit
f2296ec82d
7 changed files with 196 additions and 25 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use crate::core::models::{UnifiedData, UnifiedMonitorData};
|
||||
use crate::data::heartbeat::model::HeartbeatEntry;
|
||||
use crate::i18n::t;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
@ -17,6 +18,7 @@ pub struct MonitorViewState {
|
|||
pub response_time: String,
|
||||
pub uptime_24h: String,
|
||||
pub last_check: String,
|
||||
pub status_history: Vec<MonitorStatus>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -45,6 +47,8 @@ impl DashboardViewState {
|
|||
let mut monitors = Vec::new();
|
||||
|
||||
for monitor in data.monitors {
|
||||
let status_history = get_status_history(&monitor.heartbeats);
|
||||
|
||||
let status = match monitor.heartbeats.last().map(|h| h.status) {
|
||||
Some(1) => MonitorStatus::Up,
|
||||
Some(0) => MonitorStatus::Down,
|
||||
|
|
@ -77,6 +81,7 @@ impl DashboardViewState {
|
|||
response_time,
|
||||
uptime_24h,
|
||||
last_check,
|
||||
status_history,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -96,3 +101,23 @@ impl DashboardViewState {
|
|||
self.monitors.get(self.selected_index)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_status_history(heartbeats: &[HeartbeatEntry]) -> Vec<MonitorStatus> {
|
||||
let mut history = heartbeats
|
||||
.iter()
|
||||
.rev()
|
||||
.take(100)
|
||||
.map(|h| match h.status {
|
||||
0 => MonitorStatus::Down,
|
||||
1 => MonitorStatus::Up,
|
||||
_ => MonitorStatus::Unknown,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
while history.len() < 100 {
|
||||
history.push(MonitorStatus::Unknown);
|
||||
}
|
||||
|
||||
history.reverse();
|
||||
history
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue