Stride Reference Manual  1.0
PersonFile.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, Willem L, Kuylen E, Stijven S & Broeckhove J
14  */
15 
21 #include "PersonFile.h"
22 
23 
24 namespace stride {
25 namespace output {
26 
27 using namespace std;
28 
29 PersonFile::PersonFile(const std::string& file) {
30  initialize(file);
31 }
32 
34  m_fstream.close();
35 }
36 
37 void PersonFile::initialize(const std::string& file) {
38  m_fstream.open((file + "_person.csv").c_str());
39 
40  // add header
41  m_fstream << "id,is_recovered,is_immune,start_infectiousness,"
42  << "end_infectiousness,start_symptomatic,end_symptomatic" << endl;
43 }
44 
45 void PersonFile::print(const std::shared_ptr<const Population> population) {
46  for (const auto& p : *population) {
47  const auto& h = p.getHealth();
48  if (!h.isSusceptible()) {
49  m_fstream << p.getId() << "," << h.isRecovered() << "," << h.isImmune() << ","
50  << h.getStartInfectiousness() << "," << h.getEndInfectiousness() << ","
51  << h.getStartSymptomatic() << "," << h.getEndSymptomatic() << endl;
52  }
53  }
54 }
55 
56 }
57 }
void initialize(const std::string &file)
Generate file name and open the file stream.
Definition: PersonFile.cpp:37
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
PersonFile(const std::string &file="stride_person")
Constructor: initialize.
Definition: PersonFile.cpp:29
STL namespace.
void print(const std::shared_ptr< const Population > population)
Print the given cases with corresponding tag.
Definition: PersonFile.cpp:45
Header for the PersonFile class.
~PersonFile()
Destructor: close the file stream.
Definition: PersonFile.cpp:33