From 6698b5e07e7f65dc04bf4861f4f374bec601e82d Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 11 Apr 2017 13:06:22 +0200 Subject: [PATCH] Use fallbacks counter to print a single warning message --- .../edge-weight-updates-over-factor.feature | 19 +++++++ src/updater/updater.cpp | 56 ++++++++++--------- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/features/options/contract/edge-weight-updates-over-factor.feature b/features/options/contract/edge-weight-updates-over-factor.feature index 6d7c313bc..e503527bf 100644 --- a/features/options/contract/edge-weight-updates-over-factor.feature +++ b/features/options/contract/edge-weight-updates-over-factor.feature @@ -22,9 +22,28 @@ Feature: osrm-contract command line option: edge-weight-updates-over-factor Scenario: Logging weight with updates over factor of 2, long segment When I run "osrm-extract --profile {profile_file} {osm_file} --generate-edge-lookup" When I run "osrm-contract --edge-weight-updates-over-factor 2 --segment-speed-file {speeds_file} {processed_file}" + Then stderr should not contain "Speed values were used to update 2 segment(s)" And stderr should contain "Segment: 1,2" And stderr should contain "Segment: 1,3" And I route I should get | from | to | route | speed | | a | b | ab,ab | 100 km/h | | a | c | ac,ac | 100 km/h | + + + Scenario: Logging using weigts as durations for non-duration profile + Given the profile file "testbot" extended with + """ + properties.weight_name = 'steps' + function way_function(way, result) + result.forward_mode = mode.driving + result.backward_mode = mode.driving + result.weight = 1 + result.duration = 1 + end + """ + And the data has been saved to disk + + When I run "osrm-extract --profile {profile_file} {osm_file} --generate-edge-lookup" + When I run "osrm-contract --edge-weight-updates-over-factor 2 --segment-speed-file {speeds_file} {processed_file}" + Then stderr should contain "Speed values were used to update 2 segments for 'steps' profile" diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index ecdb7fbfa..a5f6f911b 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -67,31 +68,6 @@ inline EdgeWeight convertToDuration(double speed_in_kmh, double distance_in_mete return std::max(1, boost::numeric_cast(std::round(duration * 10.))); } -inline EdgeWeight convertToWeight(const SpeedSource &value, - double distance_in_meters, - const extractor::ProfileProperties &profile_properties) -{ - double rate = value.rate; - if (!std::isfinite(rate)) - { - if (!profile_properties.fallback_to_duration) - { - util::Log(logWARNING) << "rate is not specified for '" - << profile_properties.GetWeightName() - << "', falling back to speed"; - } - - rate = value.speed / 3.6; - } - - if (rate <= 0.) - return INVALID_EDGE_WEIGHT; - - const auto weight_multiplier = profile_properties.GetWeightMultiplier(); - const auto weight = distance_in_meters / rate; - return std::max(1, boost::numeric_cast(std::round(weight * weight_multiplier))); -} - #if !defined(NDEBUG) void checkWeightsConsistency( const UpdaterConfig &config, @@ -168,6 +144,25 @@ updateSegmentData(const UpdaterConfig &config, counters_type(num_counters, 0)); const constexpr auto LUA_SOURCE = 0; + // closure to convert SpeedSource value to weight and count fallbacks to durations + std::atomic fallbacks_to_duration{0}; + auto convertToWeight = [&profile_properties, &fallbacks_to_duration]( + const SpeedSource &value, double distance_in_meters) { + double rate = value.rate; + if (!std::isfinite(rate)) + { // use speed value in meters per second as the rate + ++fallbacks_to_duration; + rate = value.speed / 3.6; + } + + if (rate <= 0.) + return INVALID_EDGE_WEIGHT; + + const auto weight_multiplier = profile_properties.GetWeightMultiplier(); + const auto weight = distance_in_meters / rate; + return std::max(1, boost::numeric_cast(std::round(weight * weight_multiplier))); + }; + // The check here is enabled by the `--edge-weight-updates-over-factor` flag it logs a // warning if the new duration exceeds a heuristic of what a reasonable duration update is std::unique_ptr segment_data_backup; @@ -207,7 +202,7 @@ updateSegmentData(const UpdaterConfig &config, { auto segment_length = segment_lengths[segment_offset]; auto new_duration = convertToDuration(value->speed, segment_length); - auto new_weight = convertToWeight(*value, segment_length, profile_properties); + auto new_weight = convertToWeight(*value, segment_length); fwd_was_updated = true; fwd_weights_range[segment_offset] = new_weight; @@ -240,7 +235,7 @@ updateSegmentData(const UpdaterConfig &config, { auto segment_length = segment_lengths[segment_offset]; auto new_duration = convertToDuration(value->speed, segment_length); - auto new_weight = convertToWeight(*value, segment_length, profile_properties); + auto new_weight = convertToWeight(*value, segment_length); rev_was_updated = true; rev_weights_range[segment_offset] = new_weight; @@ -283,6 +278,13 @@ updateSegmentData(const UpdaterConfig &config, } } + if (!profile_properties.fallback_to_duration && fallbacks_to_duration > 0) + { + util::Log(logWARNING) << "Speed values were used to update " << fallbacks_to_duration + << " segments for '" << profile_properties.GetWeightName() + << "' profile"; + } + if (config.log_edge_updates_factor > 0) { BOOST_ASSERT(segment_data_backup);