Stride Reference Manual  - generated for commit 9643b11
PersonsFile.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 "PersonsFile.h"
22 
23 #include "pop/Population.h"
24 #include "util/FileSys.h"
25 
26 namespace stride {
27 namespace output {
28 
29 using namespace std;
30 using namespace stride::util;
31 
32 PersonsFile::PersonsFile(const string& output_prefix) : m_fstream() { Initialize(output_prefix); }
33 
35 
36 void PersonsFile::Initialize(const string& output_prefix)
37 {
38  const auto p = FileSys::BuildPath(output_prefix, "persons.csv");
39  m_fstream.open(p.c_str());
40  // add header
41  m_fstream << "id,age,is_recovered,is_immune,start_infectiousness,"
42  << "end_infectiousness,start_symptomatic,end_symptomatic" << endl;
43 }
44 
45 void PersonsFile::Print(std::shared_ptr<const Population> population)
46 {
47  for (const auto& p : *population) {
48  const auto& h = p.GetHealth();
49  m_fstream << p.GetId() << "," << p.GetAge() << "," << h.IsRecovered() << "," << h.IsImmune() << ","
50  << h.GetStartInfectiousness() << "," << h.GetEndInfectiousness() << ","
51  << h.GetStartSymptomatic() << "," << h.GetEndSymptomatic() << std::endl;
52  }
53 }
54 
55 } // namespace output
56 } // namespace stride
void Initialize(const std::string &output_dir)
Generate file name and open the file stream.
Definition: PersonsFile.cpp:36
Utilities for the project.
Header for the PersonFile class.
STL namespace.
void Print(std::shared_ptr< const Population > population)
Print the given cases with corresponding tag.
Definition: PersonsFile.cpp:45
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
PersonsFile(const std::string &output_dir="output")
Constructor: initialize.
Definition: PersonsFile.cpp:32
~PersonsFile()
Destructor: close the file stream.
Definition: PersonsFile.cpp:34
Header file for the core Population class.
Interface for install directory queries.
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28