Skip to content

Commit

Permalink
Clean command line parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanJField committed Jan 19, 2022
1 parent 3e93ba0 commit 198e7c1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 43 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand All @@ -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"
```
2 changes: 1 addition & 1 deletion data/seirs_config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion data/seirs_config_windows.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion include/simpleModel.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
52 changes: 24 additions & 28 deletions src/simpleModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -44,6 +40,7 @@ int main(int argc, char** argv) {
}
catch (const char* msg) {
std::cerr << msg << std::endl;
return 1;
}
catch(...)
{
Expand All @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -122,8 +120,6 @@ void seirsModel::validate_initial_parameters(std::map<std::string, double> &init
std::string required_keys = "alpha,beta,inv_gamma,inv_omega,inv_mu,inv_sigma";
for( std::map<std::string, double>::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;
Expand Down

0 comments on commit 198e7c1

Please sign in to comment.