void Partition_YearCrossAgeMatrix::DoPrepare() { unsigned lowest = 9999; unsigned highest = 0; niwa::partition::accessors::All all_view(model_); for (auto iterator = all_view.Begin(); iterator != all_view.End(); ++iterator) { if (lowest > (*iterator)->min_age_) lowest = (*iterator)->min_age_; if (highest < (*iterator)->max_age_) highest = (*iterator)->max_age_; } // Print the header cache_ << "*" << type_ << "[" << label_ << "]" << "\n"; cache_ << "time_step: " << time_step_ << "\n"; //cache_ << all_view.Begin().name_ << endl; // Print the age-groups const char separator = ' '; //const int nameWidth = 6; const int numWidth = 13; cache_ << "values "<< REPORT_R_DATAFRAME << "\n"; cache_ << std::left << std::setw(numWidth) << std::setfill(separator) << "year"; // leave an empty space in the years's column for (unsigned i = lowest; i <= highest; ++i) cache_ << std::left << std::setw(numWidth) << std::setfill(separator) << "AG" + std::to_string(i); cache_ << "\n"; }
void Partition_YearCrossAgeMatrix::DoExecute() { //cerr << "execute " << label_ << "\n"; // First, figure out the lowest and highest ages/length unsigned lowest = 9999; unsigned highest = 0; unsigned longest_length = 0; niwa::partition::accessors::All all_view(model_); for (auto iterator = all_view.Begin(); iterator != all_view.End(); ++iterator) { if (lowest > (*iterator)->min_age_) lowest = (*iterator)->min_age_; if (highest < (*iterator)->max_age_) highest = (*iterator)->max_age_; if (longest_length < (*iterator)->name_.length()) longest_length = (*iterator)->name_.length(); } const char separator = ' '; //const int nameWidth = 6; const int numWidth = 13; //cache_ << std::setprecision(5); for (auto iterator = all_view.Begin(); iterator != all_view.End(); ++iterator) { //cache_ << (*iterator)->name_; cache_ << std::left << std::setw(numWidth) << std::setfill(separator) << std::setprecision(1) << std::fixed << model_->current_year(); unsigned age = (*iterator)->min_age_; //unsigned year = (*iterator)->year_; //cout << "The year at this stage is " << year << endl; for (auto values = (*iterator)->data_.begin(); values != (*iterator)->data_.end(); ++values, age++) { if (age >= lowest && age <= highest) { Double value = *values; //cache_ << "\t" << std::fixed << AS_DOUBLE(value); cache_ << std::left << std::setw(numWidth) << std::setfill(separator) << std::setprecision(0) << std::fixed << AS_DOUBLE(value); } else cache_ << " " << "null"; } cache_ << "\n"; } // ready_for_writing_ = true; ready_for_writing_ = false; }
void Partition::DoExecute() { //cerr << "execute " << label_ << "\n"; // First, figure out the lowest and highest ages/length unsigned lowest = 9999; unsigned highest = 0; unsigned longest_length = 0; niwa::partition::accessors::All all_view(model_); for (auto iterator = all_view.Begin(); iterator != all_view.End(); ++iterator) { if (lowest > (*iterator)->min_age_) lowest = (*iterator)->min_age_; if (highest < (*iterator)->max_age_) highest = (*iterator)->max_age_; if (longest_length < (*iterator)->name_.length()) longest_length = (*iterator)->name_.length(); } // Print the header cache_ << "*"<< type_ << "[" << label_ << "]" << "\n"; cache_ << "year: " << model_->current_year() << "\n"; cache_ << "time_step: " << time_step_ << "\n"; cache_ << "values "<< REPORT_R_DATAFRAME<<"\n"; cache_ << "category"; for (unsigned i = lowest; i <= highest; ++i) cache_ << " " << i; cache_ << "\n"; for (auto iterator = all_view.Begin(); iterator != all_view.End(); ++iterator) { cache_ << (*iterator)->name_; unsigned age = (*iterator)->min_age_; for (auto values = (*iterator)->data_.begin(); values != (*iterator)->data_.end(); ++values, age++) { if (age >= lowest && age <= highest) { Double value = *values; cache_ << " " << std::fixed << AS_DOUBLE(value); } else cache_ << " " << "null"; } cache_ << "\n"; } ready_for_writing_ = true; }
/** * Execute method */ void PartitionMeanWeight::DoExecute() { // auto categories = Categories::Instance(); niwa::partition::accessors::All all_view(model_); unsigned year = model_->current_year(); cache_ << "*" << label_ << " " << "("<< type_ << ")"<<"\n"; cache_ << "year: " << year << "\n"; for (auto iterator = all_view.Begin(); iterator != all_view.End(); ++iterator) { (*iterator)->UpdateMeanWeightData(); (*iterator)->UpdateMeanLengthData(); string category = (*iterator)->name_; cache_ << category << " " << REPORT_R_LIST << "\n"; cache_ << "mean_weights " << REPORT_R_LIST << "\n"; cache_ << "values: "; for (unsigned age = (*iterator)->min_age_; age <= (*iterator)->max_age_; ++age) cache_ << (*iterator)->mean_weight_per_[age] << " "; cache_<<"\n"; cache_ << REPORT_R_LIST_END <<"\n"; cache_ << "age_lengths " << REPORT_R_LIST << "\n"; cache_ << "values: "; for (unsigned age = (*iterator)->min_age_; age <= (*iterator)->max_age_; ++age) cache_ << (*iterator)->mean_length_per_[age] << " "; cache_<<"\n"; cache_ << REPORT_R_LIST_END <<"\n"; cache_ << REPORT_R_LIST_END <<"\n"; } ready_for_writing_ = true; }