Prevents the Matching getting confused when users are time-travelling.

This commit is contained in:
Daniel J. Hofmann
2016-10-21 18:19:23 -07:00
parent ba5871cfa1
commit a933b5d949
2 changed files with 13 additions and 1 deletions
+12
View File
@@ -12,6 +12,8 @@
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <iterator>
#include <memory>
#include <string>
#include <vector>
@@ -123,6 +125,16 @@ Status MatchPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFaca
return Error("InvalidValue", "Invalid coordinate value.", json_result);
}
// Check for same or increasing timestamps. Impl. note: Incontrast to `sort(first,
// last, less_equal)` checking `greater` in reverse meets irreflexive requirements.
const auto time_increases_monotonically = std::is_sorted(
parameters.timestamps.rbegin(), parameters.timestamps.rend(), std::greater<>{});
if (!time_increases_monotonically)
{
return Error("InvalidValue", "Timestamps need to be monotonically increasing.", json_result);
}
// assuming radius is the standard deviation of a normal distribution
// that models GPS noise (in this model), x3 should give us the correct
// search radius with > 99% confidence