-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement per individual file and demo plotting script
This is useful for double checking household and workplace sizes
- Loading branch information
Showing
13 changed files
with
335 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "PerIndividualFile.h" | ||
|
||
#include <fmt/core.h> | ||
|
||
#include <vector> | ||
|
||
namespace exateppabm { | ||
namespace output { | ||
|
||
PerIndividualFile::PerIndividualFile(std::filesystem::path directory) : OutputFile(directory / PerIndividualFile::DEFAULT_FILENAME) { } | ||
|
||
PerIndividualFile::~PerIndividualFile() { } | ||
|
||
void PerIndividualFile::reset(const std::uint32_t n_total) { | ||
// Reset the observations vector | ||
this->_perPerson = std::vector<Person>(); | ||
this->_perPerson.reserve(n_total); | ||
} | ||
|
||
void PerIndividualFile::appendPerson(const Person person) { | ||
// @todo = ensure _perPerson has been initialised? | ||
this->_perPerson.push_back(person); | ||
} | ||
|
||
bool PerIndividualFile::write() { | ||
if (!this->_handle) { | ||
this->open(); | ||
} | ||
|
||
// Print to the file handle | ||
fmt::print(_handle, "ID,age_group,occupation_network,house_no,infection_count\n"); | ||
for (const auto& person : _perPerson) { | ||
fmt::print( | ||
_handle, | ||
"{},{},{},{},{}\n", | ||
person.id, | ||
person.age_group, | ||
person.occupation_network, | ||
person.house_no, | ||
person.infection_count); | ||
} | ||
|
||
fmt::print("Per individual data written to {}\n", std::filesystem::absolute(this->_filepath).c_str()); | ||
return true; | ||
} | ||
|
||
} // namespace output | ||
} // namespace exateppabm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#pragma once | ||
|
||
#include "OutputFile.h" | ||
|
||
#include <filesystem> | ||
#include <vector> | ||
|
||
#include "exateppabm/demographics.h" | ||
#include "exateppabm/person.h" | ||
|
||
namespace exateppabm { | ||
namespace output { | ||
|
||
/** | ||
* Class for representing the per individual file | ||
*/ | ||
class PerIndividualFile : public OutputFile { | ||
public: | ||
// Forward decl nested struct | ||
struct Person; | ||
|
||
/** | ||
* Constructor setting the path for file output. | ||
* @param directory parent directory for the file to be stored in (using the default filename) | ||
*/ | ||
explicit PerIndividualFile(std::filesystem::path directory); | ||
|
||
/** | ||
* Dtor | ||
*/ | ||
~PerIndividualFile(); | ||
|
||
/** | ||
* Reset the objects internal data structures, and pre-allocate memory for storing data for the current simulation | ||
* @param n_total number of people in total | ||
*/ | ||
void reset(std::uint32_t n_total); | ||
|
||
/** | ||
* Append a set of observations for a single time point to the internal data structure | ||
* | ||
* @param observations observations from a single time point | ||
*/ | ||
void appendPerson(Person observations); | ||
|
||
/** | ||
* Write the contents of the time series file to disk at the configured path | ||
* | ||
* @return bool indicating success | ||
*/ | ||
bool write(); | ||
|
||
/** | ||
* Structure for data observed at a single point in time within the time series | ||
*/ | ||
struct Person { | ||
/** | ||
* ID for the person | ||
*/ | ||
std::uint32_t id = 0; | ||
/** | ||
* Age group | ||
*/ | ||
exateppabm::demographics::AgeUnderlyingType age_group = 0; | ||
/** | ||
* Work network index | ||
*/ | ||
std::uint32_t occupation_network = 0; | ||
/** | ||
* Household index | ||
*/ | ||
std::uint32_t house_no = 0; | ||
/** | ||
* Cumulative number of times this individual was infected | ||
*/ | ||
std::uint32_t infection_count = 0; | ||
}; | ||
|
||
private: | ||
/** | ||
* Default filename for output | ||
* @todo - factor in the run index for ensembles? | ||
*/ | ||
constexpr static char DEFAULT_FILENAME[] = "individual_file.csv"; | ||
/** | ||
* Private member containing the observation data | ||
*/ | ||
std::vector<Person> _perPerson; | ||
}; | ||
|
||
} // namespace output | ||
} // namespace exateppabm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.