Print statistics only for allowed turns

This commit is contained in:
Michael Krasnyk 2017-11-27 15:19:42 +01:00
parent 4d54456f66
commit e805f85407

View File

@ -10,8 +10,8 @@
#include <algorithm> #include <algorithm>
#include <iomanip> #include <iomanip>
#include <iterator> #include <iterator>
#include <map>
#include <mutex> #include <mutex>
#include <unordered_map>
#include <cstdint> #include <cstdint>
@ -55,7 +55,7 @@ class StatisticsHandler final : public IntersectionHandler
for (const auto &kv : type_hist) for (const auto &kv : type_hist)
if (kv.second > 0) if (kv.second > 0)
util::Log() << std::fixed << std::setprecision(2) util::Log() << " " << std::fixed << std::setprecision(2)
<< internalInstructionTypeToString(kv.first) << ": " << kv.second << internalInstructionTypeToString(kv.first) << ": " << kv.second
<< " (" << (kv.second / static_cast<float>(num_types) * 100.) << "%)"; << " (" << (kv.second / static_cast<float>(num_types) * 100.) << "%)";
@ -63,7 +63,7 @@ class StatisticsHandler final : public IntersectionHandler
for (const auto &kv : modifier_hist) for (const auto &kv : modifier_hist)
if (kv.second > 0) if (kv.second > 0)
util::Log() << std::fixed << std::setprecision(2) util::Log() << " " << std::fixed << std::setprecision(2)
<< instructionModifierToString(kv.first) << ": " << kv.second << " (" << instructionModifierToString(kv.first) << ": " << kv.second << " ("
<< (kv.second / static_cast<float>(num_modifiers) * 100.) << "%)"; << (kv.second / static_cast<float>(num_modifiers) * 100.) << "%)";
} }
@ -84,21 +84,23 @@ class StatisticsHandler final : public IntersectionHandler
// numbers closer to the handlers and see how often handlers ran. // numbers closer to the handlers and see how often handlers ran.
for (const auto &road : intersection) for (const auto &road : intersection)
{ {
if (road.entry_allowed)
{
const auto type = road.instruction.type; const auto type = road.instruction.type;
const auto modifier = road.instruction.direction_modifier; const auto modifier = road.instruction.direction_modifier;
type_hist[type] += 1; type_hist[type] += 1;
modifier_hist[modifier] += 1; modifier_hist[modifier] += 1;
} }
}
return intersection; return intersection;
} }
private: private:
mutable std::mutex lock; mutable std::mutex lock;
mutable std::unordered_map<TurnType::Enum, std::uint64_t> type_hist; mutable std::map<TurnType::Enum, std::uint64_t> type_hist;
mutable std::unordered_map<DirectionModifier::Enum, std::uint64_t> modifier_hist; mutable std::map<DirectionModifier::Enum, std::uint64_t> modifier_hist;
}; };
} // namespace guidance } // namespace guidance