Stride Reference Manual  - generated for commit 9643b11
SummaryFile.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2017, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "SummaryFile.h"
22 
23 #include "util/FileSys.h"
24 
25 #include <boost/property_tree/ptree.hpp>
26 
27 namespace stride {
28 namespace output {
29 
30 using namespace std;
31 using namespace stride::util;
32 
33 // FIXME Some of the parameters written to this file have become optional over time.
34 // Seeding rate + immmunity rate
35 
36 SummaryFile::SummaryFile(const string& output_prefix) : m_fstream() { Initialize(output_prefix); }
37 
39 
40 void SummaryFile::Initialize(const string& output_prefix)
41 {
42  const auto p = FileSys::BuildPath(output_prefix, "summary.csv");
43  m_fstream.open(p.c_str());
44 
45  // add header
46  m_fstream << "population_file,num_days,population_size,seeding_rate,r0,transmission_probability,"
47  "immunity_rate,num_threads,rng_seed,"
48  "run_time,total_time,num_cases,AR,output_prefix,start_date,age_"
49  "contact_matrix_file,num_"
50  "participants_survey,disease_config_file"
51  << endl;
52 }
53 
54 void SummaryFile::Print(const boost::property_tree::ptree& config_pt, unsigned int population_size,
55  unsigned int num_cases, double transmission_probability, unsigned int run_time,
56  unsigned int total_time)
57 {
58  m_fstream << config_pt.get<string>("run.population_file") << "," << config_pt.get<unsigned int>("run.num_days")
59  << "," << population_size << "," << config_pt.get<double>("run.seeding_rate") << ","
60  << config_pt.get<double>("run.r0") << "," << transmission_probability << ","
61  << config_pt.get<double>("run.immunity_rate") << "," << config_pt.get<unsigned int>("run.num_threads")
62  << "," << config_pt.get<unsigned int>("run.rng_seed") << "," << run_time << "," << total_time << ","
63  << num_cases << "," << static_cast<double>(num_cases) / population_size << ","
64  << config_pt.get<string>("run.output_prefix") << "," << config_pt.get<string>("run.start_date") << ","
65  << config_pt.get<string>("run.age_contact_matrix_file") << ","
66  << config_pt.get<unsigned int>("run.num_participants_survey") << ","
67  << config_pt.get<string>("run.disease_config_file") << endl;
68 }
69 
70 } // namespace output
71 } // namespace stride
Utilities for the project.
void Initialize(const std::string &output_dir)
Generate file name and open the file stream.
Definition: SummaryFile.cpp:40
Header for the SummaryFile class.
~SummaryFile()
Destructor: close the file stream.
Definition: SummaryFile.cpp:38
SummaryFile(const std::string &output_prefix="output")
Constructor: initialize.
Definition: SummaryFile.cpp:36
STL namespace.
static filesys::path BuildPath(const std::string &output_prefix, const std::string &filename)
Interpret prefix (directory or filename prefix) and return appropriate path.
Definition: FileSys.cpp:52
Interface for install directory queries.
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
std::ofstream m_fstream
The file stream.
Definition: SummaryFile.h:51
void Print(const boost::property_tree::ptree &config_pt, unsigned int population_size, unsigned int num_cases, double transmission_probability, unsigned int run_time, unsigned int total_time)
Print the given output with corresponding tag.
Definition: SummaryFile.cpp:54