Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jul 2, 2024
1 parent ace4ab2 commit 9e22ab3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <map>
#include <sstream>
#include <string>
#include <vector>

namespace Antares
{
Expand All @@ -46,7 +47,8 @@ class HydroErrorsCollector
void CheckForErrors() const;

private:
std::multimap<std::string, std::string> areasErrorMap_;
std::map<std::string, std::vector<std::string>> areasErrorMap_;
std::string& CurrentMessage(const std::string& name);
};

template<class T>
Expand Down
38 changes: 9 additions & 29 deletions src/solver/hydro/management/HydroErrorsCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,21 @@ void HydroErrorsCollector::CheckForErrors() const
{
if (!areasErrorMap_.empty())
{
std::set<std::string> uniqueKeys;
std::transform(areasErrorMap_.begin(),
areasErrorMap_.end(),
std::inserter(uniqueKeys, uniqueKeys.begin()),
[](const auto& pair) { return pair.first; });

for (const auto& key: uniqueKeys)
for (const auto& [key, values]: areasErrorMap_)
{
for (const auto& value:
areasErrorMap_
| std::views::filter([&key](const auto& p) { return p.first == key; })
| std::views::take(10))
for (const auto& value: values | std::views::take(10))
{
logs.error() << "In Area " << value.first << ": " << value.second << " ";
logs.error() << "In Area " << key << ": " << value << " ";
}
}

// for (auto value = areasErrorMap_.begin(); value != areasErrorMap_.end();)
// {
// const auto& key = value->first;
// const auto& rangeEnd = areasErrorMap_.upper_bound(key);

// const auto& limit = std::min(value + 10, rangeEnd);

// for (; value != limit; ++value)
// {
// logs.error() << "In Area " << value.first << ": " << value.second << " ";
// }

// // Move iterator to the next key
// value = rangeEnd;
// }

throw FatalError("Hydro validation has failed !");
}
}

HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector,
const std::string& name):
areaSingleErrorMessage_(collector->areasErrorMap_.insert({name, ""})->second)
areaSingleErrorMessage_(collector->CurrentMessage(name))
{
}

Expand All @@ -62,4 +37,9 @@ HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std::
return AreaReference(this, name);
}

std::string& HydroErrorsCollector::CurrentMessage(const std::string& name)
{
auto& msgs = areasErrorMap_[name];
return *msgs.insert(msgs.end(), "");
}
} // namespace Antares

0 comments on commit 9e22ab3

Please sign in to comment.