Use fallbacks counter to print a single warning message

This commit is contained in:
Michael Krasnyk 2017-04-11 13:06:22 +02:00 committed by Patrick Niklaus
parent 37794a5e8a
commit 6698b5e07e
2 changed files with 48 additions and 27 deletions

View File

@ -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 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-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}" 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,2"
And stderr should contain "Segment: 1,3" And stderr should contain "Segment: 1,3"
And I route I should get And I route I should get
| from | to | route | speed | | from | to | route | speed |
| a | b | ab,ab | 100 km/h | | a | b | ab,ab | 100 km/h |
| a | c | ac,ac | 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"

View File

@ -34,6 +34,7 @@
#include <tbb/parallel_invoke.h> #include <tbb/parallel_invoke.h>
#include <algorithm> #include <algorithm>
#include <atomic>
#include <bitset> #include <bitset>
#include <cstdint> #include <cstdint>
#include <fstream> #include <fstream>
@ -67,31 +68,6 @@ inline EdgeWeight convertToDuration(double speed_in_kmh, double distance_in_mete
return std::max(1, boost::numeric_cast<EdgeWeight>(std::round(duration * 10.))); return std::max(1, boost::numeric_cast<EdgeWeight>(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<EdgeWeight>(std::round(weight * weight_multiplier)));
}
#if !defined(NDEBUG) #if !defined(NDEBUG)
void checkWeightsConsistency( void checkWeightsConsistency(
const UpdaterConfig &config, const UpdaterConfig &config,
@ -168,6 +144,25 @@ updateSegmentData(const UpdaterConfig &config,
counters_type(num_counters, 0)); counters_type(num_counters, 0));
const constexpr auto LUA_SOURCE = 0; const constexpr auto LUA_SOURCE = 0;
// closure to convert SpeedSource value to weight and count fallbacks to durations
std::atomic<std::uint32_t> 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<EdgeWeight>(std::round(weight * weight_multiplier)));
};
// The check here is enabled by the `--edge-weight-updates-over-factor` flag it logs a // 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 // warning if the new duration exceeds a heuristic of what a reasonable duration update is
std::unique_ptr<extractor::SegmentDataContainer> segment_data_backup; std::unique_ptr<extractor::SegmentDataContainer> segment_data_backup;
@ -207,7 +202,7 @@ updateSegmentData(const UpdaterConfig &config,
{ {
auto segment_length = segment_lengths[segment_offset]; auto segment_length = segment_lengths[segment_offset];
auto new_duration = convertToDuration(value->speed, segment_length); 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_was_updated = true;
fwd_weights_range[segment_offset] = new_weight; fwd_weights_range[segment_offset] = new_weight;
@ -240,7 +235,7 @@ updateSegmentData(const UpdaterConfig &config,
{ {
auto segment_length = segment_lengths[segment_offset]; auto segment_length = segment_lengths[segment_offset];
auto new_duration = convertToDuration(value->speed, segment_length); 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_was_updated = true;
rev_weights_range[segment_offset] = new_weight; 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) if (config.log_edge_updates_factor > 0)
{ {
BOOST_ASSERT(segment_data_backup); BOOST_ASSERT(segment_data_backup);