Bevy+Ratutui powered Monitoring of Pico-Strike devices
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rework monitoring layout page

+37 -70
+37 -70
src/views/monitoring.rs
··· 19 19 use ratatui::{ 20 20 layout::{Constraint, HorizontalAlignment, Layout}, 21 21 style::{Color, Stylize}, 22 - text::{Line, Span}, 22 + text::{Line, Span, Text, ToSpan}, 23 23 widgets::{Axis, Block, Chart, Dataset, Padding, Paragraph}, 24 24 }; 25 25 use striker_proto::{Response, StrikerRequest, StrikerResponse, Update}; ··· 184 184 q_signals: Query<(&Timestamp, &StormSignal, &SignalPeaks)>, 185 185 ) -> Result { 186 186 context.draw(|frame| { 187 - let [top, mid, bottom] = Layout::vertical([ 188 - Constraint::Length(3), 189 - Constraint::Fill(1), 190 - Constraint::Length(3), 191 - ]) 192 - .areas(frame.area()); 187 + let [mid, bottom] = 188 + Layout::vertical([Constraint::Fill(1), Constraint::Length(3)]).areas(frame.area()); 193 189 194 - let [top_left, top_mid_left, top_mid_right, top_right] = Layout::horizontal([ 195 - Constraint::Fill(1), 196 - Constraint::Fill(1), 197 - Constraint::Fill(1), 198 - Constraint::Fill(1), 199 - ]) 200 - .areas(top); 190 + let [chart_block, side_block] = 191 + Layout::horizontal([Constraint::Fill(3), Constraint::Fill(1)]).areas(mid); 201 192 202 - let [chart_block, detector_block] = 203 - Layout::vertical([Constraint::Fill(1), Constraint::Length(3)]).areas(mid); 193 + let [device_block, detector_block] = 194 + Layout::vertical([Constraint::Fill(1), Constraint::Fill(1)]).areas(side_block); 204 195 205 196 let (device, detector, levels, signals) = q_devices.get(connected.device).unwrap(); 206 197 ··· 213 204 .and_then(|s| s.last().copied()) 214 205 .and_then(|entity| q_signals.get(entity).ok()); 215 206 216 - let name = Paragraph::new(device.as_str()) 217 - .block( 218 - Block::bordered() 219 - .padding(Padding::horizontal(2)) 220 - .title("Device") 221 - .title_alignment(HorizontalAlignment::Center) 222 - .border_style(Color::LightGreen), 223 - ) 224 - .white(); 225 - 226 207 let timestamp = latest_signal.map(|(t, _, _)| t); 227 208 228 - let timestamp = Paragraph::new(Line::from_iter( 229 - timestamp.map(|t| Span::from(format!("{}", t.0))), 230 - )) 231 - .white() 232 - .block( 233 - Block::bordered() 234 - .padding(Padding::horizontal(2)) 235 - .title("Timestamp") 236 - .title_alignment(HorizontalAlignment::Center) 237 - .border_style(Color::LightGreen), 209 + let lines = [ 210 + Line::from(device.to_span()), 211 + Line::from_iter([Span::raw("Status: "), connected.connection_state.to_span()]), 212 + ] 213 + .into_iter() 214 + .chain(timestamp.map(|t| Line::from(t.0.to_span()))) 215 + .chain( 216 + latest_level.map(|level| Line::from_iter([Span::raw("Level: "), level.0.to_span()])), 238 217 ); 239 218 240 - let warn_level = Paragraph::new(Line::from_iter( 241 - Some(Span::raw("Level: ")) 242 - .into_iter() 243 - .chain(latest_level.map(|s| Span::from(format!("{}", s.0)))), 244 - )) 245 - .white() 246 - .block( 247 - Block::bordered() 248 - .padding(Padding::horizontal(2)) 249 - .title("Storm Warning") 250 - .title_alignment(HorizontalAlignment::Center) 251 - .border_style(Color::LightGreen), 252 - ); 253 - 254 - let connection = Paragraph::new(connected.connection_state.to_string()) 255 - .white() 219 + let info = Paragraph::new(Text::from_iter(lines)) 256 220 .block( 257 221 Block::bordered() 258 222 .padding(Padding::horizontal(2)) 259 - .title("State") 223 + .title("Device") 260 224 .title_alignment(HorizontalAlignment::Center) 261 225 .border_style(Color::LightGreen), 262 - ); 226 + ) 227 + .white(); 263 228 264 229 let (data, detected) = latest_signal 265 230 .map(|(_, samples, signals)| { ··· 271 236 .collect(), 272 237 signals.iter().fold(None, |acc, el| { 273 238 Some(acc.map_or_else( 274 - || (el.0, el.0 + 16), 275 - |prev: (usize, usize)| (prev.0, prev.1.max(el.0 + 16)), 239 + || (el.0, el.0 + 32), 240 + |prev: (usize, usize)| (prev.0, prev.1.max(el.0 + 32)), 276 241 )) 277 242 }), 278 243 ) ··· 343 308 344 309 let detector = detector.copied().unwrap_or_default(); 345 310 346 - let detector_info = Paragraph::new(format!( 347 - "Threshold: {}, Blip Size: {}, Max Duty {}, Current Duty: {}", 348 - detector.blip_threshold, detector.blip_size, detector.max_duty, detector.duty 349 - )) 350 - .block( 351 - Block::bordered() 352 - .padding(Padding::horizontal(2)) 353 - .border_style(Color::LightGreen), 354 - ) 355 - .white(); 311 + let detector_lines = [ 312 + Line::from_iter([Span::raw("Threshold: "), detector.blip_threshold.to_span()]), 313 + Line::from_iter([Span::raw("Blip Size: "), detector.blip_size.to_span()]), 314 + Line::from_iter([Span::raw("Max Duty: "), detector.max_duty.to_span()]), 315 + Line::from_iter([Span::raw("Current Duty: "), detector.duty.to_span()]), 316 + ]; 356 317 357 - frame.render_widget(name, top_left); 358 - frame.render_widget(timestamp, top_mid_left); 359 - frame.render_widget(warn_level, top_mid_right); 360 - frame.render_widget(connection, top_right); 318 + let detector_info = Paragraph::new(Text::from_iter(detector_lines)) 319 + .block( 320 + Block::bordered() 321 + .title("Settings") 322 + .padding(Padding::horizontal(2)) 323 + .border_style(Color::LightGreen), 324 + ) 325 + .white(); 326 + 327 + frame.render_widget(info, device_block); 361 328 frame.render_widget(chart2, chart_block); 362 329 frame.render_widget(chart, chart_block); 363 330 frame.render_widget(detector_info, detector_block);