From 198e7c16762332c2c438cf06bce73f6bddddfc6b Mon Sep 17 00:00:00 2001 From: Ryan J Field Date: Wed, 19 Jan 2022 16:26:20 +0000 Subject: [PATCH] Clean command line parameters --- README.md | 23 +++++++-------- data/seirs_config.yaml | 2 +- data/seirs_config_windows.yaml | 2 +- include/simpleModel.hxx | 2 +- src/simpleModel.cxx | 52 ++++++++++++++++------------------ 5 files changed, 38 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index dcdbff2..72ad7cd 100644 --- a/README.md +++ b/README.md @@ -69,20 +69,9 @@ $ cmake --build build --config=Release ## Usage The executable is located in the `build/bin[/release]` directory -The executable is designed to be run independently using the `--local` flag and taking one parameter: -### on Unix -``` -build/bin/cppSimpleModel --local data/static_params_SEIRS.csv -``` -### or on windows: -``` -build/bin/release/cppSimpleModel.exe --local data\static_params_SEIRS.csv" -``` - -### or conjuction with the [fair cli](#Fair-CLI): +The executable is designed to be run in conjuction with the [fair cli](#Fair-CLI): (From a virtual environment within the repo directory) - #### Fair CLI The [FAIR commandline interface]("https://github.com/FAIRDataPipeline/FAIR-CLI") is available to install using pip: ``` @@ -101,3 +90,13 @@ fair init --ci fair pull data/seirs_config_windows.yaml fair run data/seirs_config_windows.yaml ``` + +The executable can run standalone and run the SEIRS model taking in a csv with initial parameters: +### on Unix +``` +build/bin/cppSimpleModel data/static_params_SEIRS.csv +``` +### or on windows: +``` +build/bin/release/cppSimpleModel.exe data\static_params_SEIRS.csv" +``` \ No newline at end of file diff --git a/data/seirs_config.yaml b/data/seirs_config.yaml index 5e889d8..6dce187 100644 --- a/data/seirs_config.yaml +++ b/data/seirs_config.yaml @@ -1,7 +1,7 @@ run_metadata: default_input_namespace: rfield description: SEIRS Model cpp - script: ./build/bin/cppSimpleModel --ci + script: ./build/bin/cppSimpleModel remote_repo: https://github.com/FAIRDataPipeline/cppSimpleModel.git register: diff --git a/data/seirs_config_windows.yaml b/data/seirs_config_windows.yaml index 088636b..7c97620 100644 --- a/data/seirs_config_windows.yaml +++ b/data/seirs_config_windows.yaml @@ -1,7 +1,7 @@ run_metadata: default_input_namespace: rfield description: SEIRS Model cpp - script: "build\\bin\\release\\cppSimpleModel.exe --ci" + script: "build\\bin\\release\\cppSimpleModel.exe" remote_repo: https://github.com/FAIRDataPipeline/cppSimpleModel.git register: diff --git a/include/simpleModel.hxx b/include/simpleModel.hxx index f884170..d5608a8 100644 --- a/include/simpleModel.hxx +++ b/include/simpleModel.hxx @@ -49,6 +49,6 @@ void run_local(std::string inital_parameters_path, std::string csv_output_path, std::string figure_output_path); -void run_ci(); +void run_cli(); std::string getEnvVar( std::string const & key ); \ No newline at end of file diff --git a/src/simpleModel.cxx b/src/simpleModel.cxx index c9a984a..54d280d 100644 --- a/src/simpleModel.cxx +++ b/src/simpleModel.cxx @@ -2,38 +2,34 @@ int main(int argc, char** argv) { try{ - - if(argc > 1) + if(argc == 1){ + run_cli(); + } + else if(argc > 1) { - if (std::string(argv[1]).front() != '-') { - std::cout << "Please specify a switch see -h"; - return 1; - } - else if (std::string(argv[1]).find("h") != std::string::npos) { - std::cout << "Usage:\ - \n --ci\ - \n --local initial_parameters_path"; - return 1; - } - else if (std::string(argv[1]).find("-ci") != std::string::npos) { - run_ci(); - } - else if (std::string(argv[1]).find("-local") != std::string::npos) { - if(argc == 3){ - ghc::filesystem::create_directories(ghc::filesystem::path("data_store")); - run_local(std::string(argv[2]), "data_store/cpp_model_output.csv", "data_store/cpp_figure_output.png"); - } - else if (argc != 5){ - std::cout << "Incorrect Number of parameters supplied"; + if (std::string(argv[1]).substr(0,2) == "--") { + if (std::string(argv[1]).find("--h") != std::string::npos) { + std::cout << "Usage:\ + \n cppSimpleModel : Run the model using the CLI\ + \n cppSimpleModel initial_parameters_path : Run the model with the given initial parameters"; return 1; } - else { - run_local(std::string(argv[2]), std::string(argv[3]), std::string(argv[4])); + else{ + std::cout << "Unknown switch supplied see cppSimpleModel --h"; + return 1; } + } + else if(argc != 2){ + std::cout << "Incorrect Number of parameters supplied see --h"; + return 1; + } + else { + ghc::filesystem::create_directories(ghc::filesystem::path("data_store")); + run_local(std::string(argv[1]), "data_store/cpp_model_output.csv", "data_store/cpp_figure_output.png"); } } else { - std::cout << "Please specify a switch see -h"; + std::cout << "Incorrect usage see --h"; return 1; } } @@ -44,6 +40,7 @@ int main(int argc, char** argv) { } catch (const char* msg) { std::cerr << msg << std::endl; + return 1; } catch(...) { @@ -57,6 +54,7 @@ int main(int argc, char** argv) { void run_local(std::string initial_parameters_path, std::string csv_output_path, std::string figure_output_path){ + FDP::APILogger->info("Running SIERS model"); seirsModel sm = seirsModel(initial_parameters_path, 1000, 5, 0.999, 0.001, 0, 0); @@ -65,7 +63,7 @@ void run_local(std::string initial_parameters_path, sm.plot_model(figure_output_path, true); } -void run_ci(){ +void run_cli(){ FDP::APILogger->info("Reading token"); std::string token = getEnvVar("FDP_LOCAL_TOKEN"); ghc::filesystem::path fdp_path = getEnvVar("FDP_CONFIG_DIR"); @@ -122,8 +120,6 @@ void seirsModel::validate_initial_parameters(std::map &init std::string required_keys = "alpha,beta,inv_gamma,inv_omega,inv_mu,inv_sigma"; for( std::map::iterator it = initial_state.begin(); it!= initial_state.end(); it++){ keys += it->first; - //std::cout << "\nValidating key:" + it->first; - //std::cout << "\nfound: " + std::to_string(it->second); } std::istringstream iss(required_keys); std::string current_parameter;