Skip to content

Commit 0ed3f94

Browse files
committed
Replicate existing channels pattern for storing which stats to calc
1 parent 257fe6c commit 0ed3f94

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/HealthGPS/analysis_module.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,9 @@ void AnalysisModule::initialise_vector(RuntimeContext &context) {
6363
// `factors` vector.
6464
size_t num_stats_to_calc = context.mapping().entries().size() - factors_to_calculate_.size();
6565

66-
// But we calculate the mean and standard deviation of each factor, so we need to multiply by 2
67-
num_stats_to_calc *= 2;
68-
69-
// We also want to calculate the prevalence and incidence of each disease
70-
num_stats_to_calc += 2 * context.diseases().size();
71-
72-
// We also want to keep the count, deaths, and emigrations
73-
num_stats_to_calc += 3;
74-
75-
// We also want to calculate the normal, overweight, obese, and above weight prevalence
76-
num_stats_to_calc += 4;
77-
78-
// Finally, we want to calculate the mean and standard deviation of YLL, YLD, and DALY
79-
num_stats_to_calc += 6;
66+
// And for each factor, we calculate the stats described in `stats_to_calculate_`, so we
67+
// multiply the number of stats to calculate by the number of factors to calculate stats for.
68+
num_stats_to_calc *= stats_to_calculate_.size();
8069

8170
// The product of the number of bins for each factor can be used to calculate the size of the
8271
// `calculated_stats_` in the next step
@@ -573,6 +562,37 @@ void AnalysisModule::initialise_output_channels(RuntimeContext &context) {
573562
channels_.emplace_back("std_daly");
574563
}
575564

565+
void AnalysisModule::initialise_stats_to_calc(RuntimeContext &context) {
566+
if (!stats_to_calculate_.empty()) {
567+
return;
568+
}
569+
570+
stats_to_calculate_.push_back("count");
571+
stats_to_calculate_.push_back("deaths");
572+
stats_to_calculate_.push_back("emigrations");
573+
574+
for (const auto &factor : context.mapping().entries()) {
575+
stats_to_calculate_.push_back("mean_" + factor.key().to_string());
576+
stats_to_calculate_.push_back("std_" + factor.key().to_string());
577+
}
578+
579+
for (const auto &disease : context.diseases()) {
580+
stats_to_calculate_.push_back("prevalence_" + disease.code.to_string());
581+
stats_to_calculate_.push_back("incidence_" + disease.code.to_string());
582+
}
583+
584+
stats_to_calculate_.push_back("normal_weight");
585+
stats_to_calculate_.push_back("over_weight");
586+
stats_to_calculate_.push_back("obese_weight");
587+
stats_to_calculate_.push_back("above_weight");
588+
stats_to_calculate_.push_back("mean_yll");
589+
stats_to_calculate_.push_back("std_yll");
590+
stats_to_calculate_.push_back("mean_yld");
591+
stats_to_calculate_.push_back("std_yld");
592+
stats_to_calculate_.push_back("mean_daly");
593+
stats_to_calculate_.push_back("std_daly");
594+
}
595+
576596
std::unique_ptr<AnalysisModule> build_analysis_module(Repository &repository,
577597
const ModelInput &config) {
578598
auto analysis_entity = repository.manager().get_disease_analysis(config.settings().country());

src/HealthGPS/analysis_module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class AnalysisModule final : public UpdatableModule {
4646
WeightModel weight_classifier_;
4747
DoubleAgeGenderTable residual_disability_weight_;
4848
std::vector<std::string> channels_;
49+
std::vector<std::string> stats_to_calculate_;
4950
unsigned int comorbidities_;
5051
std::string name_{"Analysis"};
5152
std::vector<core::Identifier> factors_to_calculate_ = {"Gender"_id, "Age"_id};

0 commit comments

Comments
 (0)