Skip to content

Commit

Permalink
Fix saturation curve submission (#2)
Browse files Browse the repository at this point in the history
* fix keyword for unit

* add checkbox to fit saturation curve

* fmt and lint
  • Loading branch information
trappitsch authored May 1, 2024
1 parent 03dbdce commit a13cfc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct TemplateApp {
#[serde(skip)]
sat_tmp_unit: SaturationCurveUnit,
#[serde(skip)]
sat_tmp_fit: bool,
#[serde(skip)]
sat_tmp_xdat: String,
#[serde(skip)]
sat_tmp_xdat_unc: String,
Expand Down Expand Up @@ -80,6 +82,7 @@ impl Default for TemplateApp {
sat_tmp_title: String::new(),
sat_tmp_notes: String::new(),
sat_tmp_unit: SaturationCurveUnit::WCM2,
sat_tmp_fit: true,
sat_tmp_xdat: String::new(),
sat_tmp_xdat_unc: String::new(),
sat_tmp_ydat: String::new(),
Expand Down Expand Up @@ -325,6 +328,7 @@ impl eframe::App for TemplateApp {
ui.separator();
ui.add_space(VERTICAL_SPACE);

// SATURATION CURVES
ui.heading(RichText::new("Saturation curves").strong());
ui.add_space(VERTICAL_SPACE);

Expand Down Expand Up @@ -354,6 +358,9 @@ impl eframe::App for TemplateApp {
});
ui.add_space(VERTICAL_SPACE);

ui.checkbox(&mut self.sat_tmp_fit, "Fit saturation curve");
ui.add_space(VERTICAL_SPACE);

ui.horizontal(|ui| {
ui.label("Notes:");
ui.text_edit_multiline(&mut self.sat_tmp_notes);
Expand Down Expand Up @@ -409,6 +416,7 @@ impl eframe::App for TemplateApp {
&self.sat_tmp_title,
&self.sat_tmp_notes,
&self.sat_tmp_unit,
self.sat_tmp_fit,
&self.sat_tmp_xdat,
&self.sat_tmp_xdat_unc,
&self.sat_tmp_ydat,
Expand All @@ -418,6 +426,7 @@ impl eframe::App for TemplateApp {
self.saturation_curves.push(sc);
self.sat_tmp_title.clear();
self.sat_tmp_notes.clear();
self.sat_tmp_fit = true;
self.sat_tmp_xdat.clear();
self.sat_tmp_xdat_unc.clear();
self.sat_tmp_ydat.clear();
Expand Down
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ pub struct SaturationCurve {
pub title: String,
pub notes: String,
pub units: SaturationCurveUnit,
pub fit: bool,
pub xdat: Vec<f64>,
pub xdat_unc: Option<Vec<f64>>,
pub ydat: Vec<f64>,
Expand All @@ -437,10 +438,12 @@ pub struct SaturationCurve {

impl SaturationCurve {
/// Create a new instance of Saturation curve or return an error if not successful.
#[allow(clippy::too_many_arguments)]
pub fn new_from_parts(
title: &str,
notes: &str,
units: &SaturationCurveUnit,
fit: bool,
xdat: &str,
xunc: &str,
ydat: &str,
Expand Down Expand Up @@ -481,6 +484,7 @@ impl SaturationCurve {
title: title.to_owned(),
notes: notes.to_owned(),
units: units.clone(),
fit,
xdat,
xdat_unc,
ydat,
Expand Down Expand Up @@ -618,7 +622,8 @@ fn create_json_output(app_entries: &TemplateApp) -> Result<String, String> {

json_out["saturation_curves"][&val.title] = json!({
"notes": val.notes,
"units": sat_unit_json,
"unit": sat_unit_json,
"fit": val.fit,
"data": {
"x": val.xdat,
"y": val.ydat,
Expand Down Expand Up @@ -763,10 +768,11 @@ fn load_config_file(app_entries: &mut TemplateApp) -> Result<(), String> {
let sat_json_all = &config_json["saturation_curves"];
for (title, value) in sat_json_all.as_object().unwrap() {
let notes = value["notes"].as_str().unwrap_or("").to_owned();
let units = match value["units"].as_str() {
let units = match value["unit"].as_str() {
Some("W") => SaturationCurveUnit::W,
_ => SaturationCurveUnit::WCM2,
};
let fit = value["fit"].as_bool().unwrap_or(true);
let xdat = match value["data"]["x"].as_array() {
Some(x) => json_array_to_f64(x)?,
None => {
Expand Down Expand Up @@ -797,6 +803,7 @@ fn load_config_file(app_entries: &mut TemplateApp) -> Result<(), String> {
title: title.to_owned(),
notes,
units,
fit,
xdat,
xdat_unc: xunc,
ydat,
Expand Down

0 comments on commit a13cfc2

Please sign in to comment.