areas.cpp
/*
  This function imports CSV files that contain a single measure. The should
  CSV file consists of columns containing the authority code and years.
  Each row contains an authority code and values for each year (or no value
  if the data doesn't exist).

  Note that these files should not include the names for areas

  The datasets that will be parsed by this function are
   - complete-popu1009-area.csv
   - complete-popu1009-pop.csv
   - complete-popu1009-opden.csv

  @param is
    The input stream from InputSource

  @param cols
    A map of the enum BethyYw::SourceColumnMapping (see datasets.h) to strings
    that give the column header in the CSV file

  @param areasFilter
    An umodifiable pointer to set of umodifiable strings for areas to import,
    or an empty set if all areas should be imported

  @param measuresFilter
    An umodifiable pointer to set of strings for measures to import, or an empty 
    set if all measures should be imported

  @param yearsFilter
    An umodifiable pointer to an umodifiable tuple of two unsigned integers,
    where if both values are 0, then all years should be imported, otherwise
    they should be treated as a the range of years to be imported

  @return
    void

  @see
    See datasets.h for details of how the variable cols is organised

  @see
    See bethyw.cpp for details of how the variable areasFilter is created

  @example
    InputFile input("data/complete-popu1009-pop.csv");
    auto is = input.open();

    auto cols = InputFiles::DATASETS["complete-pop"].COLS;

    auto areasFilter = BethYw::parseAreasArg();
    auto yearsFilter = BethYw::parseYearsArg();

    Areas data = Areas();
    areas.populateFromAuthorityCodeCSV(is, cols, &areasFilter, &yearsFilter);

  @throws 
    std::runtime_error if a parsing error occurs (e.g. due to a malformed file)
    std::out_of_range if there are not enough columns in cols
*/
This function imports CSV files that contain a single measure. The should
CSV file consists of columns containing the authority code and years.
Each row contains an authority code and values for each year (or no value
if the data doesn't exist).

Note that these files should not include the names for areas


This function imports CSV files that contain a single measure . The should CSV file consists of columns containing the authority code and years . Each row contains an authority code and values for each year ( or no value if the data doesn ' t exist ) . Note that these files should not include the names for areas
void Areas::populateFromAuthorityByYearCSV(std::istream &is,
                                       const BethYw::SourceColumnMapping &cols,
                                       const StringFilterSet * const areasFilter,
                                       const StringFilterSet * const measuresFilter,
                                       const YearFilterTuple * const yearsFilter){
    auto dataCode = cols.at(BethYw::SourceColumn::SINGLE_MEASURE_CODE);
    auto dataName = cols.at(BethYw::SourceColumn::SINGLE_MEASURE_NAME);
    if(is.good() && (isFilterEmpty(measuresFilter) || filterContains(measuresFilter, dataCode))){
        unsigned int yearStart = std::get<0>(*yearsFilter);
        unsigned int yearEnd = std::get<1>(*yearsFilter);
        bool allYears = yearsFilter == nullptr ||(yearStart == 0 && yearEnd == 0);
        std::string line;
        std::getline(is,line);
        getVariableCSV(line);
        std::vector<unsigned int> years;
        while(!(line.empty()))
            years.push_back(std::stol(getVariableCSV(line)));
        while(std::getline(is, line)){
            std::string localAuthCode = getVariableCSV(line);
            if(isFilterEmpty(areasFilter) || filterContains(areasFilter, localAuthCode)){
                Measure measure(dataCode,dataName);
                for(auto const& year : years){
                    if(allYears || (year >= yearStart && year <= yearEnd)){
                        measure.setValue(year,std::stod(getVariableCSV(line)));
                    }else{
                        getVariableCSV(line);
                    }
                    Area tempArea(localAuthCode);
                    tempArea.setMeasure(dataCode, measure);
                    setArea(localAuthCode, tempArea);
                }
            }
        }
    }
}
void Areas :: populateFromAuthorityByYearCSV ( std :: istream & is , const BethYw :: SourceColumnMapping & cols , const StringFilterSet * const areasFilter , const StringFilterSet * const measuresFilter , const YearFilterTuple * const yearsFilter ) { auto dataCode = cols . at ( BethYw :: SourceColumn :: SINGLE_MEASURE_CODE ) ; auto dataName = cols . at ( BethYw :: SourceColumn :: SINGLE_MEASURE_NAME ) ; if ( is . good ( ) && ( isFilterEmpty ( measuresFilter ) || filterContains ( measuresFilter , dataCode ) ) ) { unsigned int yearStart = std :: get < 0 > ( * yearsFilter ) ; unsigned int yearEnd = std :: get < 1 > ( * yearsFilter ) ; bool allYears = yearsFilter == nullptr || ( yearStart == 0 && yearEnd == 0 ) ; std :: string line ; std :: getline ( is , line ) ; getVariableCSV ( line ) ; std :: vector < unsigned int > years ; while ( ! ( line . empty ( ) ) ) years . push_back ( std :: stol ( getVariableCSV ( line ) ) ) ; while ( std :: getline ( is , line ) ) { std :: string localAuthCode = getVariableCSV ( line ) ; if ( isFilterEmpty ( areasFilter ) || filterContains ( areasFilter , localAuthCode ) ) { Measure measure ( dataCode , dataName ) ; for ( auto const & year : years ) { if ( allYears || ( year >= yearStart && year <= yearEnd ) ) { measure . setValue ( year , std :: stod ( getVariableCSV ( line ) ) ) ; } else { getVariableCSV ( line ) ; } Area tempArea ( localAuthCode ) ; tempArea . setMeasure ( dataCode , measure ) ; setArea ( localAuthCode , tempArea ) ; } } } } }
This function imports CSV files that contain a single measure.
This function imports CSV files that contain a single measure .
//get years for readability //reading first variable which is just AuthorityCode //gets all the years at the top