[generator] Fixed camera parsing.

This commit is contained in:
Maksim Andrianov 2019-10-01 17:40:50 +03:00 committed by gmoryes
parent 39eeb42b7f
commit 50442b529d
2 changed files with 12 additions and 12 deletions

View file

@ -35,13 +35,13 @@ namespace routing
{
size_t const CameraProcessor::kMaxSpeedSpeedStringLength = 32;
std::string ValidateMaxSpeedString(std::string const & maxSpeedString)
boost::optional<double> GetMaxSpeed(std::string const & maxSpeedString)
{
routing::SpeedInUnits speed;
if (!generator::ParseMaxspeedTag(maxSpeedString, speed) || !speed.IsNumeric())
return std::string();
return {};
return strings::to_string(measurement_utils::ToSpeedKmPH(speed.GetSpeed(), speed.GetUnits()));
return measurement_utils::ToSpeedKmPH(speed.GetSpeed(), speed.GetUnits());
}
CameraProcessor::CameraInfo::CameraInfo(OsmElement const & element)
@ -50,15 +50,13 @@ CameraProcessor::CameraInfo::CameraInfo(OsmElement const & element)
, m_lat(element.m_lat)
{
auto const maxspeed = element.GetTag("maxspeed");
if (maxspeed.empty())
if (maxspeed.empty() || maxspeed.size() > kMaxSpeedSpeedStringLength)
return;
auto const validatedMaxspeed = ValidateMaxSpeedString(maxspeed);
if (validatedMaxspeed.size() > kMaxSpeedSpeedStringLength ||
!strings::to_int(validatedMaxspeed.c_str(), m_speed))
{
if (auto const validatedMaxspeed = GetMaxSpeed(maxspeed))
m_speed = static_cast<uint32_t>(*validatedMaxspeed);
else
LOG(LWARNING, ("Bad speed format of camera:", maxspeed, ", osmId:", element.m_id));
}
}
CameraProcessor::CameraProcessor(std::string const & filename)

View file

@ -12,6 +12,8 @@
#include <unordered_map>
#include <vector>
#include <boost/optional.hpp>
namespace generator_tests
{
class TestCameraCollector;
@ -34,14 +36,14 @@ class FeatureBuilder;
// TODO (@gmoryes) move members of m_routingTagsProcessor to generator
namespace routing
{
/// \brief Gets text with speed, returns formatted speed string in km per hour.
/// \brief Returns formatted speed in km per hour.
/// \param maxSpeedString - text with speed. Possible format:
/// "130" - means 130 km per hour.
/// "130 mph" - means 130 miles per hour.
/// "130 kmh" - means 130 km per hour.
/// See https://wiki.openstreetmap.org/wiki/Key:maxspeed
/// for more details about input string.
std::string ValidateMaxSpeedString(std::string const & maxSpeedString);
boost::optional<double> GetMaxSpeed(std::string const & maxSpeedString);
class CameraProcessor
{
@ -58,7 +60,7 @@ public:
uint64_t m_id = 0;
double m_lon = 0.0;
double m_lat = 0.0;
int32_t m_speed = 0;
uint32_t m_speed = 0;
std::vector<uint64_t> m_ways;
};