Skip to content

Commit

Permalink
Hack to write risk factors for all individuals to files per year.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturner246 committed Nov 27, 2023
1 parent 23df436 commit be8f71b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/HealthGPS/healthgps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <memory>
#include <stdexcept>

// HACK: write individuals' risk factors to files.
#include <fmt/format.h>
#include <fstream>

namespace { // anonymous namespace

/// @brief Defines the net immigration synchronisation message
Expand Down Expand Up @@ -150,6 +154,29 @@ void HealthGPS::initialise_population() {
analysis_->initialise_population(context_);

print_initial_population_statistics();

// HACK: write individuals' risk factors to files.
std::vector<core::Identifier> keys = {
"Age", "Gender", "Sector", "Income", "Carbohydrate", "Fat",
"Protein", "Sodium", "PhysicalActivity", "EnergyIntake", "Height", "Weight"};
std::ofstream file(fmt::format("initialise_{}.csv", context_.time_now()));

for (const auto &key : keys) {
file << key.to_string() << ",";
}
file << "\n";

for (const auto &person : context_.population()) {
if (!person.is_active()) {
continue;
}

for (const auto &key : keys) {
file << person.get_risk_factor_value(key) << ",";
}
file << "\n";
}
file.close();
}

void HealthGPS::update_population() {
Expand All @@ -172,6 +199,29 @@ void HealthGPS::update_population() {

// Publish results to data logger
analysis_->update_population(context_);

// HACK: write individuals' risk factors to files.
std::vector<core::Identifier> keys = {
"Age", "Gender", "Sector", "Income", "Carbohydrate", "Fat",
"Protein", "Sodium", "PhysicalActivity", "EnergyIntake", "Height", "Weight"};
std::ofstream file(fmt::format("update_{}.csv", context_.time_now()));

for (const auto &key : keys) {
file << key.to_string() << ",";
}
file << "\n";

for (const auto &person : context_.population()) {
if (!person.is_active()) {
continue;
}

for (const auto &key : keys) {
file << person.get_risk_factor_value(key) << ",";
}
file << "\n";
}
file.close();
}

void HealthGPS::update_net_immigration() {
Expand Down

0 comments on commit be8f71b

Please sign in to comment.