Skip to content

Commit

Permalink
run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jurriaan committed Jun 5, 2024
1 parent 53251dd commit 58def56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/util/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ pub fn plot_timeseries_svg(
.y_label_area_size(30)
.build_cartesian_2d(first_entry.0..last_entry.0, min_y..max_y)?;

let mut mesh = chart
.configure_mesh();
let mut mesh = chart.configure_mesh();

if last_entry.0 - first_entry.0 < Duration::hours(48) && Utc::now() - last_entry.0.to_utc() < Duration::hours(24) {
if last_entry.0 - first_entry.0 < Duration::hours(48)
&& Utc::now() - last_entry.0.to_utc() < Duration::hours(24)
{
mesh.x_label_formatter(&|x| format!("{:02}:{:02}", x.hour(), x.minute()))
} else {
&mut mesh
}
.y_labels(5)
.x_labels(4)
.disable_mesh()
.draw()?;
.y_labels(5)
.x_labels(4)
.disable_mesh()
.draw()?;

chart
.draw_series(LineSeries::new(entries, &RED))?
Expand Down
24 changes: 17 additions & 7 deletions src/web_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,25 +600,35 @@ async fn node_details(
.await
.map_err(DatabaseError)?;

let max_age_minutes : Option<i64> = headers.get("x-meshstellar-max-age").map(|x| x.to_str().unwrap_or("all")).and_then(|x| x.parse().ok());
let max_age_minutes: Option<i64> = headers
.get("x-meshstellar-max-age")
.map(|x| x.to_str().unwrap_or("all"))
.and_then(|x| x.parse().ok());

let min_time_nanos = if let Some(max_age) = max_age_minutes {
let cur_time = Utc::now().timestamp_nanos_opt().unwrap();
cur_time - (max_age as i64 * 60_000_000_000)
cur_time - (max_age * 60_000_000_000)
} else {
0
};

let offset_minutes : i32 = headers.get("x-meshstellar-tz-offset").map(|x| x.to_str().unwrap_or("0")).and_then(|x| x.parse().ok()).unwrap_or_default();
let offset = if offset_minutes.abs() < 24 * 60 {
FixedOffset::west_opt(offset_minutes * 60).unwrap_or_else(|| FixedOffset::west_opt(0).unwrap())
let offset_minutes: i32 = headers
.get("x-meshstellar-tz-offset")
.map(|x| x.to_str().unwrap_or("0"))
.and_then(|x| x.parse().ok())
.unwrap_or_default();
let offset = if offset_minutes.abs() < 24 * 60 {
FixedOffset::west_opt(offset_minutes * 60)
.unwrap_or_else(|| FixedOffset::west_opt(0).unwrap())
} else {
FixedOffset::west_opt(0).unwrap()
};

Ok(into_response(&NodeDetailsTemplate {
node,
plots: create_plots(pool, node_id, min_time_nanos, offset).await.unwrap_or_default(),
plots: create_plots(pool, node_id, min_time_nanos, offset)
.await
.unwrap_or_default(),
}))
}

Expand All @@ -642,7 +652,7 @@ async fn create_plots(
pool: State<SqlitePool>,
node_id: i64,
min_time: i64,
time_zone_offset: FixedOffset
time_zone_offset: FixedOffset,
) -> axum::response::Result<Vec<PlotData>> {
let mut entries_map : HashMap<String, Vec<(DateTime<FixedOffset>, f64)>>= sqlx::query!(
r#"
Expand Down

0 comments on commit 58def56

Please sign in to comment.