Skip to content

Commit

Permalink
Rename settings object from Data to Settings
Browse files Browse the repository at this point in the history
Renaming Data to Settings, which is more intuitive
  • Loading branch information
Markus Herberg Hovd committed Dec 30, 2023
1 parent 016d6ae commit 52f5bbc
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/algorithms.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::{self, settings::run::Data};
use crate::prelude::{self, settings::run::Settings};

use output::NPResult;
use prelude::{datafile::Scenario, *};
Expand All @@ -22,7 +22,7 @@ pub trait Algorithm {

pub fn initialize_algorithm<S>(
engine: Engine<S>,
settings: Data,
settings: Settings,
scenarios: Vec<Scenario>,
tx: mpsc::UnboundedSender<Comm>,
) -> Box<dyn Algorithm>
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/npag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
output::NPResult,
output::{CycleLog, NPCycle},
prob, qr,
settings::run::Data,
settings::run::Settings,
simulation::predict::Engine,
simulation::predict::{sim_obs, Predict},
},
Expand Down Expand Up @@ -49,7 +49,7 @@ where
scenarios: Vec<Scenario>,
c: (f64, f64, f64, f64),
tx: UnboundedSender<Comm>,
settings: Data,
settings: Settings,
}

impl<S> Algorithm for NPAG<S>
Expand Down Expand Up @@ -99,7 +99,7 @@ where
scenarios: Vec<Scenario>,
c: (f64, f64, f64, f64),
tx: UnboundedSender<Comm>,
settings: Data,
settings: Settings,
) -> Self
where
S: Predict<'static> + std::marker::Sync,
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/npod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
output::NPResult,
output::{CycleLog, NPCycle},
prob, qr,
settings::run::Data,
settings::run::Settings,
simulation::predict::Engine,
simulation::predict::{sim_obs, Predict},
},
Expand Down Expand Up @@ -45,7 +45,7 @@ where
scenarios: Vec<Scenario>,
c: (f64, f64, f64, f64),
tx: UnboundedSender<Comm>,
settings: Data,
settings: Settings,
}

impl<S> Algorithm for NPOD<S>
Expand Down Expand Up @@ -95,7 +95,7 @@ where
scenarios: Vec<Scenario>,
c: (f64, f64, f64, f64),
tx: UnboundedSender<Comm>,
settings: Data,
settings: Settings,
) -> Self
where
S: Predict<'static> + std::marker::Sync,
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/postprob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
ipm,
output::NPResult,
prob,
settings::run::Data,
settings::run::Settings,
simulation::predict::Engine,
simulation::predict::{sim_obs, Predict},
},
Expand Down Expand Up @@ -35,7 +35,7 @@ where
c: (f64, f64, f64, f64),
#[allow(dead_code)]
tx: UnboundedSender<Comm>,
settings: Data,
settings: Settings,
}

impl<S> Algorithm for POSTPROB<S>
Expand Down Expand Up @@ -69,7 +69,7 @@ where
scenarios: Vec<Scenario>,
c: (f64, f64, f64, f64),
tx: UnboundedSender<Comm>,
settings: Data,
settings: Settings,
) -> Self
where
S: Predict<'static> + std::marker::Sync,
Expand Down
4 changes: 2 additions & 2 deletions src/entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::prelude::{
*,
};
use crate::routines::datafile::Scenario;
use crate::routines::settings::run::Data;
use crate::routines::settings::run::Settings;

use csv::{ReaderBuilder, WriterBuilder};
use eyre::Result;
Expand Down Expand Up @@ -150,7 +150,7 @@ where
/// Returns an NPresult object
pub fn start_internal<S>(
engine: Engine<S>,
settings: Data,
settings: Settings,
scenarios: Vec<Scenario>,
) -> Result<NPResult>
where
Expand Down
4 changes: 2 additions & 2 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::routines::settings::run::Data;
use crate::routines::settings::run::Settings;
use crate::tui::ui::Comm;
use std::io::{self, Write};
use tokio::sync::mpsc::UnboundedSender;
Expand All @@ -9,7 +9,7 @@ use tracing_subscriber::registry::Registry;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

pub fn setup_log(settings: &Data, ui_tx: UnboundedSender<Comm>) {
pub fn setup_log(settings: &Settings, ui_tx: UnboundedSender<Comm>) {
// Use the log level defined in configuration file, or default to info
let log_level = settings
.parsed
Expand Down
4 changes: 2 additions & 2 deletions src/routines/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::fs::File;

use ndarray::Array2;

use crate::prelude::settings::run::Data;
use crate::prelude::settings::run::Settings;

pub mod sobol;

pub fn sample_space(settings: &Data, ranges: &Vec<(f64, f64)>) -> Array2<f64> {
pub fn sample_space(settings: &Settings, ranges: &Vec<(f64, f64)>) -> Array2<f64> {
match &settings.parsed.paths.prior_dist {
Some(prior_path) => {
let file = File::open(prior_path).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/routines/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use datafile::Scenario;
use ndarray::parallel::prelude::*;
use ndarray::{Array, Array1, Array2, Axis};
use predict::{post_predictions, sim_obs, Engine, Predict};
use settings::run::Data;
use settings::run::Settings;
use std::fs::File;

/// Defines the result objects from an NPAG run
Expand All @@ -19,7 +19,7 @@ pub struct NPResult {
pub cycles: usize,
pub converged: bool,
pub par_names: Vec<String>,
pub settings: Data,
pub settings: Settings,
}

impl NPResult {
Expand All @@ -32,7 +32,7 @@ impl NPResult {
objf: f64,
cycles: usize,
converged: bool,
settings: Data,
settings: Settings,
) -> Self {
// TODO: Add support for fixed and constant parameters

Expand Down
6 changes: 3 additions & 3 deletions src/routines/settings/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use toml::value::Array;
use toml::{self, Table};

#[derive(Deserialize, Clone, Debug)]
pub struct Data {
pub struct Settings {
pub computed: Computed,
pub parsed: Parsed,
}
Expand Down Expand Up @@ -68,7 +68,7 @@ pub struct Config {
pub log_level: Option<String>,
}

pub fn read(filename: String) -> Data {
pub fn read(filename: String) -> Settings {
let contents = match fs::read_to_string(&filename) {
Ok(c) => c,
Err(e) => {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn read(filename: String) -> Data {
}
}

Data {
Settings {
computed: Computed {
random: Range {
names: pn,
Expand Down
8 changes: 4 additions & 4 deletions src/routines/settings/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process::exit;
use toml;

#[derive(Deserialize, Clone, Debug)]
pub struct Data {
pub struct Settings {
pub paths: Paths,
pub config: Config,
}
Expand All @@ -21,7 +21,7 @@ pub struct Config {
pub tad: Option<f64>,
}

pub fn read(filename: String) -> Data {
pub fn read(filename: String) -> Settings {
let contents = match fs::read_to_string(&filename) {
Ok(c) => c,
Err(e) => {
Expand All @@ -30,15 +30,15 @@ pub fn read(filename: String) -> Data {
exit(1);
}
};
let parse: Data = match toml::from_str(&contents) {
let parse: Settings = match toml::from_str(&contents) {
Ok(d) => d,
Err(e) => {
eprintln!("{}", e);
eprintln!("ERROR: Unable to load data from {}", &filename);
exit(1);
}
};
Data {
Settings {
paths: Paths {
data: parse.paths.data,
theta: parse.paths.theta,
Expand Down
8 changes: 4 additions & 4 deletions src/tui/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ratatui::{

use super::App;

use crate::prelude::settings::run::Data;
use crate::prelude::settings::run::Settings;

pub fn draw_title<'a>() -> Paragraph<'a> {
Paragraph::new("NPcore Execution")
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn draw_status<'a>(app: &App, elapsed_time: Duration) -> Table<'a> {
.column_spacing(1)
}

pub fn draw_options<'a>(settings: &Data) -> Table<'a> {
pub fn draw_options<'a>(settings: &Settings) -> Table<'a> {
// Define the table data

let cycles = settings.parsed.config.cycles.to_string();
Expand Down Expand Up @@ -255,7 +255,7 @@ pub fn draw_tabs<'a>(app: &App) -> Tabs<'a> {
tabs
}

fn get_computed_settings(settings: &Data) -> Vec<Row> {
fn get_computed_settings(settings: &Settings) -> Vec<Row> {
let computed = settings.computed.clone();
let mut rows = Vec::new();
let key_style = Style::default().fg(Color::LightCyan);
Expand Down Expand Up @@ -299,7 +299,7 @@ fn get_computed_settings(settings: &Data) -> Vec<Row> {
rows
}

pub fn draw_parameter_bounds(settings: &Data) -> Table {
pub fn draw_parameter_bounds(settings: &Settings) -> Table {
let rows = get_computed_settings(&settings);
Table::default()
.rows(rows)
Expand Down
6 changes: 3 additions & 3 deletions src/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub enum Comm {
LogMessage(String),
}

use crate::prelude::{output::NPCycle, settings::run::Data};
use crate::prelude::{output::NPCycle, settings::run::Settings};
use crate::tui::components::*;

pub fn start_ui(mut rx: UnboundedReceiver<Comm>, settings: Data) -> Result<()> {
pub fn start_ui(mut rx: UnboundedReceiver<Comm>, settings: Settings) -> Result<()> {
let stdout = stdout();
crossterm::terminal::enable_raw_mode()?;
let backend = CrosstermBackend::new(stdout);
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn draw(
app: &App,
cycle_history: &CycleHistory,
elapsed_time: Duration,
settings: &Data,
settings: &Settings,
log_history: &Vec<String>,
) {
let size = rect.size();
Expand Down

0 comments on commit 52f5bbc

Please sign in to comment.