Skip to content

Commit

Permalink
Merge pull request #8 from KG32/feat/multi_thread
Browse files Browse the repository at this point in the history
Feat/multi thread
  • Loading branch information
KG32 authored Nov 1, 2024
2 parents 96e0553 + d5e7e11 commit 42fbd22
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 94 deletions.
50 changes: 48 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ repository = "https://github.com/KG32/dive-reporter.git"

[dependencies]
colored = "2.1.0"
dive-deco = "2.0.0"
dive-deco = "4.3.4"
eframe = "0.27.2"
futures = "0.3.30"
quick-xml = {version = "0.31.0", features = ["serialize"] }
quick-xml = { version = "0.31.0", features = ["serialize"] }
rayon = "1.10.0"
rfd = "0.14.1"
serde = { version = "1.0", features = ["derive"] }
61 changes: 39 additions & 22 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use crate::{
dive,
stats::{Stats, StatsData, StatsOutput},
};
use eframe::egui::{self, InnerResponse, Ui};
use std::{future::Future, path::PathBuf};
use std::error::Error;
use rfd::FileDialog;
use crate::{dive, stats::{Stats, StatsOutput}};
use std::{error::Error, sync::Arc};
use std::{future::Future, path::PathBuf};

#[derive(Clone)]
pub struct App {
Expand All @@ -17,7 +20,7 @@ pub struct App {

#[derive(Clone)]
struct AppState {
error: Option<AppError>
error: Option<AppError>,
}

#[derive(Clone)]
Expand All @@ -39,11 +42,9 @@ impl Default for App {
stats_output: vec![],
config: AppConfig {
path: None,
gradient_factors: (30, 70)
gradient_factors: (30, 70),
},
state: AppState {
error: None,
}
state: AppState { error: None },
}
}
}
Expand All @@ -55,7 +56,11 @@ impl eframe::App for App {
ui.separator();

// config
self.render_pair(ui, "Path:", &self.config.path.clone().unwrap_or("-".to_string()));
self.render_pair(
ui,
"Path:",
&self.config.path.clone().unwrap_or("-".to_string()),
);
ui.separator();

// open file btn
Expand All @@ -66,12 +71,15 @@ impl eframe::App for App {
// stats container
match &self.state.error {
None => {
let stats = self.stats.clone();
// let stats = self.stats.clone();
let stats_arc = Arc::clone(&self.stats.stats_data);
let stats_guard = stats_arc.lock().unwrap();
let stats = stats_guard;
if stats.dives_no > 0 {
self.state.error = None;
self.render_stats(ui, &stats)
self.render_stats(ui, &*stats)
}
},
}
Some(err) => {
self.render_error(ui, &err);
}
Expand All @@ -91,9 +99,7 @@ impl App {
eframe::run_native(
"Dive reporter",
options,
Box::new(|_cc| {
Box::<App>::default()
}),
Box::new(|_cc| Box::<App>::default()),
)
}

Expand All @@ -118,30 +124,41 @@ impl App {
self.run_stats(&dir);
}
}

}
}

fn render_stats(&mut self, ui: &mut Ui, stats: &Stats) {
fn render_stats(&mut self, ui: &mut Ui, stats: &StatsData) {
let depth_max = stats.depth_max.to_string();
let gf_surf_max = stats.gf_surf_max.round().to_string();
let gf_99_max = stats.gf_99_max.round().to_string();
let gf_end_max = stats.gf_end_max.round().to_string();

ui.vertical(|ui| {
self.render_pair(ui, "Dives:", &stats.dives_no.to_string());
self.render_pair(ui, "Total time:", &Stats::seconds_to_readable(stats.total_time));
self.render_pair(
ui,
"Total time:",
&Stats::seconds_to_readable(stats.total_time),
);
self.render_pair(ui, "Max depth", &format!("{depth_max}m"));
self.render_pair(ui, "Deco dives:", &stats.deco_dives_no.to_string());
self.render_pair(ui, "Total time in deco:", &Stats::seconds_to_readable(stats.time_in_deco));
self.render_pair(
ui,
"Total time in deco:",
&Stats::seconds_to_readable(stats.time_in_deco),
);
self.render_pair(ui, "Max surface GF:", &format!("{gf_surf_max}%"));
self.render_pair(ui, "Max GF99:", &format!("{gf_99_max}%"));
self.render_pair(ui, "Max end GF:", &format!("{gf_end_max}%"));
self.render_pair(ui, "Time below:", "");
for record in stats.time_below.iter() {
let (depth, time) = record;
ui.indent("", |ui| {
self.render_pair(ui, &format!("-{depth}:"), &Stats::seconds_to_readable(*time));
self.render_pair(
ui,
&format!("-{depth}:"),
&Stats::seconds_to_readable(*time),
);
});
}
});
Expand Down Expand Up @@ -177,10 +194,10 @@ impl App {
self.state.error = None;
}
self.stats = stats
},
}
Err(err) => {
let app_err = AppError {
text: err.to_string()
text: err.to_string(),
};
self.state.error = Some(app_err);
}
Expand Down
28 changes: 15 additions & 13 deletions src/dive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use dive_deco::{BuehlmannConfig, BuehlmannModel, DecoModel, Gas, Pressure, Super
use crate::common::{GradientFactorsSetting, GF};
use crate::parser::WaypointElem;
use crate::stats::TimeBelowDepthData;
use crate::{common::{Depth, Seconds}, parser::DiveElem, stats::GasMixesData};
use crate::{
common::{Depth, Seconds},
parser::DiveElem,
stats::GasMixesData,
};

#[derive(Debug)]
pub struct DiveMeta {
Expand Down Expand Up @@ -52,17 +56,16 @@ impl Dive {

pub fn calc_dive_stats(&mut self, dive_data: &DiveElem, gas_mixes: &GasMixesData) {
let (gf_lo, gf_hi) = self.meta.gradient_factors;
let mut model = BuehlmannModel::new(BuehlmannConfig::new().gradient_factors(gf_lo, gf_hi));
let mut model = BuehlmannModel::new(
BuehlmannConfig::new()
.with_gradient_factors(gf_lo, gf_hi)
.with_ceiling_type(dive_deco::CeilingType::Adaptive),
);
// calc by data point
let mut last_waypoint_time: Seconds = 0;
let dive_data_points = &dive_data.samples.waypoints;
for data_point in dive_data_points {
self.process_data_point(
&mut model,
&data_point,
last_waypoint_time,
&gas_mixes,
);
self.process_data_point(&mut model, &data_point, last_waypoint_time, &gas_mixes);
// update last waypoint time
last_waypoint_time = data_point.dive_time;
}
Expand Down Expand Up @@ -91,13 +94,13 @@ impl Dive {
match gas {
Some(gas) => {
self.meta.current_mix = gas;
},
}
None => {
panic!("Gas not found");
}
}
},
None => ()
}
None => (),
}

// deco model step
Expand Down Expand Up @@ -160,7 +163,7 @@ impl Dive {
gas = Some(Gas::new(mix_definition.o2, mix_definition.he.unwrap_or(0.)));
}
}
},
}
None => {
panic!("No gas mixes, can't process switch");
}
Expand All @@ -175,5 +178,4 @@ impl Dive {
}
time_below
}

}
Loading

0 comments on commit 42fbd22

Please sign in to comment.