diff --git a/src/utils.cpp b/src/utils.cpp index fa5a245..d6ce7e9 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -13,7 +13,7 @@ std::vector parseCsv(const std::string &csv) { string line; std::vector dates; - // Get rid of the first line + // Get rid of the first line (header) std::getline(stream, line); while (std::getline(stream, line)) { @@ -23,7 +23,6 @@ std::vector parseCsv(const std::string &csv) { uint tokenPos = 0; while ((pos = line.find(delimiter)) != std::string::npos) { token = line.substr(0, pos); - // std::cout << token << std::endl; if (token.length() > 0) { istringstream liness(token); @@ -38,37 +37,31 @@ std::vector parseCsv(const std::string &csv) { std::chrono::day{(uint)day}}; std::vector::iterator it; - WasteDate wd; + it = std::find_if(dates.begin(), dates.end(), [&date](const WasteDate &x) { return date == x.date; }); if (it == dates.end()) { + WasteDate wd; wd.date = date; dates.push_back(wd); - wd = dates.back(); - } else { - wd = *it; + it = std::prev(dates.end()); } switch (tokenPos) { case 0: - // printf("Gelber Sack: %s\n", token.c_str()); - wd.wasteTypes.push_back(Waste::GelberSack); + it->wasteTypes.push_back(Waste::GelberSack); break; case 1: - // printf("Papiertonne: %s\n", token.c_str()); - wd.wasteTypes.push_back(Waste::Papiertonne); + it->wasteTypes.push_back(Waste::Papiertonne); break; case 2: - // printf("Biotonne: %s\n", token.c_str()); - wd.wasteTypes.push_back(Waste::Biotonne); + it->wasteTypes.push_back(Waste::Biotonne); break; case 3: - // printf("Restmüll: %s\n", token.c_str()); - wd.wasteTypes.push_back(Waste::Restmuell); + it->wasteTypes.push_back(Waste::Restmuell); break; case 4: - // printf("Problemstoffmobil: %s\n", token.c_str()); - wd.wasteTypes.push_back(Waste::Problemstoffmobil); + it->wasteTypes.push_back(Waste::Problemstoffmobil); break; default: #ifdef DEBUG @@ -83,12 +76,6 @@ std::vector parseCsv(const std::string &csv) { } } - // for(const auto& ymd: dates) { - // std::cout << "Current Year: " << static_cast(ymd.date.year()) - // << ", Month: " << static_cast(ymd.date.month()) - // << ", Day: " << static_cast(ymd.date.day()) << '\n'; - // } - return dates; }