From 58b98cf89f8c624923701669d04f138117c915cb Mon Sep 17 00:00:00 2001 From: kerrick-lyft Date: Tue, 20 Sep 2016 10:26:53 -0700 Subject: [PATCH] Smarter search radius formula for map matching --- include/engine/api/match_parameters.hpp | 19 +++++++++++++++- .../server/api/match_parameter_grammar.hpp | 22 ++++++++++++++++++- src/engine/plugins/match.cpp | 12 ++++------ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/include/engine/api/match_parameters.hpp b/include/engine/api/match_parameters.hpp index 87e67ebbbda..1460ba6037b 100644 --- a/include/engine/api/match_parameters.hpp +++ b/include/engine/api/match_parameters.hpp @@ -28,6 +28,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ENGINE_API_MATCH_PARAMETERS_HPP #define ENGINE_API_MATCH_PARAMETERS_HPP +#define SEARCH_RADIUS_BASE_DEFAULT 45 +#define SEARCH_RADIUS_BASE_LIMIT 100 +#define SEARCH_RADIUS_MULTIPLIER_DEFAULT 3.5 +#define SEARCH_RADIUS_MULTIPLIER_LIMIT 10 +#define SEARCH_RADIUS_MAX_DEFAULT 200 +#define SEARCH_RADIUS_MAX_LIMIT 500 + #include "engine/api/route_parameters.hpp" #include @@ -67,10 +74,20 @@ struct MatchParameters : public RouteParameters } std::vector timestamps; + + double search_radius_base = SEARCH_RADIUS_BASE_DEFAULT; + double search_radius_multiplier = SEARCH_RADIUS_MULTIPLIER_DEFAULT; + double search_radius_max = SEARCH_RADIUS_MAX_DEFAULT; + bool IsValid() const { return RouteParameters::IsValid() && - (timestamps.empty() || timestamps.size() == coordinates.size()); + (timestamps.empty() || timestamps.size() == coordinates.size()) && + search_radius_base >= 0 && search_radius_multiplier >= 0 && search_radius_max > 0 && + // limit the search_radius parameters to sane values to prevent overloading the server + search_radius_base <= SEARCH_RADIUS_BASE_LIMIT && + search_radius_multiplier <= SEARCH_RADIUS_MULTIPLIER_LIMIT && + search_radius_max <= SEARCH_RADIUS_MAX_LIMIT; } }; } diff --git a/include/server/api/match_parameter_grammar.hpp b/include/server/api/match_parameter_grammar.hpp index ac4c02c670e..bb3cfa7654b 100644 --- a/include/server/api/match_parameter_grammar.hpp +++ b/include/server/api/match_parameter_grammar.hpp @@ -33,13 +33,33 @@ struct MatchParametersGrammar final : public RouteParametersGrammar - -('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1)) % '&'); + -('?' > (timestamps_rule(qi::_r1) | + search_radius_base_rule(qi::_r1) | + search_radius_multiplier_rule(qi::_r1) | + search_radius_max_rule(qi::_r1) | + BaseGrammar::base_rule(qi::_r1)) + % '&'); } private: qi::rule root_rule; qi::rule timestamps_rule; + qi::rule search_radius_base_rule; + qi::rule search_radius_multiplier_rule; + qi::rule search_radius_max_rule; }; } } diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index c544cf3f056..1efb156669d 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -139,15 +139,11 @@ Status MatchPlugin::HandleRequest(const std::shared_ptr &maybe_radius) { - if (maybe_radius) - { - return *maybe_radius * RADIUS_MULTIPLIER; - } - else - { - return DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER; - } + double in_radius = maybe_radius ? *maybe_radius : DEFAULT_GPS_PRECISION; + return std::min( + in_radius * parameters.search_radius_multiplier + parameters.search_radius_base, + parameters.search_radius_max); }); }