LCOV - code coverage report
Current view: top level - models/ode_secirts - parameters_io.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 23 95.7 %
Date: 2025-01-17 12:16:22 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* 
       2             : * Copyright (C) 2020-2025 MEmilio
       3             : *
       4             : * Authors: Henrik Zunker, Wadim Koslow, Daniel Abele, Martin J. Kühn
       5             : *
       6             : * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
       7             : *
       8             : * Licensed under the Apache License, Version 2.0 (the "License");
       9             : * you may not use this file except in compliance with the License.
      10             : * You may obtain a copy of the License at
      11             : *
      12             : *     http://www.apache.org/licenses/LICENSE-2.0
      13             : *
      14             : * Unless required by applicable law or agreed to in writing, software
      15             : * distributed under the License is distributed on an "AS IS" BASIS,
      16             : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      17             : * See the License for the specific language governing permissions and
      18             : * limitations under the License.
      19             : */
      20             : 
      21             : #include "ode_secirts/parameters_io.h"
      22             : #include "memilio/geography/regions.h"
      23             : #include "memilio/io/io.h"
      24             : #include "ode_secirts/parameters.h"
      25             : 
      26             : #ifdef MEMILIO_HAS_JSONCPP
      27             : 
      28             : #include "memilio/io/epi_data.h"
      29             : #include "memilio/utils/memory.h"
      30             : #include "memilio/utils/uncertain_value.h"
      31             : #include "memilio/utils/stl_util.h"
      32             : #include "memilio/mobility/graph.h"
      33             : #include "memilio/mobility/metapopulation_mobility_instant.h"
      34             : #include "memilio/epidemiology/damping.h"
      35             : #include "memilio/epidemiology/populations.h"
      36             : #include "memilio/epidemiology/uncertain_matrix.h"
      37             : #include "memilio/utils/compiler_diagnostics.h"
      38             : #include "memilio/utils/date.h"
      39             : 
      40             : #include <boost/filesystem.hpp>
      41             : 
      42             : #include <numeric>
      43             : #include <vector>
      44             : #include <iostream>
      45             : #include <string>
      46             : #include <random>
      47             : #include <fstream>
      48             : 
      49             : namespace mio
      50             : {
      51             : namespace osecirts
      52             : {
      53             : namespace details
      54             : {
      55             : 
      56          45 : IOResult<std::vector<std::vector<double>>> read_population_data(const std::string& path,
      57             :                                                                 const std::vector<int>& vregion)
      58             : {
      59          45 :     BOOST_OUTCOME_TRY(auto&& population_data, mio::read_population_data(path));
      60          45 :     return read_population_data(population_data, vregion);
      61          45 : }
      62             : 
      63          45 : IOResult<std::vector<std::vector<double>>> read_population_data(const std::vector<PopulationDataEntry>& population_data,
      64             :                                                                 const std::vector<int>& vregion)
      65             : {
      66          45 :     std::vector<std::vector<double>> vnum_population(
      67         180 :         vregion.size(), std::vector<double>(ConfirmedCasesDataEntry::age_group_names.size(), 0.0));
      68             : 
      69       18090 :     for (auto&& county_entry : population_data) {
      70             :         //accumulate population of states or country from population of counties
      71       18045 :         if (!county_entry.county_id && !county_entry.district_id) {
      72           0 :             return failure(StatusCode::InvalidFileFormat, "File with county population expected.");
      73             :         }
      74             :         //find region that this county belongs to
      75             :         //all counties belong to the country (id = 0)
      76      119061 :         auto it = std::find_if(vregion.begin(), vregion.end(), [&county_entry](auto r) {
      77       10827 :             return r == 0 ||
      78       39699 :                    (county_entry.county_id &&
      79       46917 :                     regions::StateId(r) == regions::get_state_id(int(*county_entry.county_id))) ||
      80       93816 :                    (county_entry.county_id && regions::CountyId(r) == *county_entry.county_id) ||
      81       75735 :                    (county_entry.district_id && regions::DistrictId(r) == *county_entry.district_id);
      82             :         });
      83       18045 :         if (it != vregion.end()) {
      84        7245 :             auto region_idx      = size_t(it - vregion.begin());
      85        7245 :             auto& num_population = vnum_population[region_idx];
      86       50715 :             for (size_t age = 0; age < num_population.size(); age++) {
      87       43470 :                 num_population[age] += county_entry.population[AgeGroup(age)];
      88             :             }
      89             :         }
      90             :     }
      91             : 
      92          45 :     return success(vnum_population);
      93          45 : }
      94             : 
      95             : } // namespace details
      96             : } // namespace osecirts
      97             : } // namespace mio
      98             : 
      99             : #endif // MEMILIO_HAS_JSONCPP

Generated by: LCOV version 1.14