diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php index 6036795..3812ec4 100644 --- a/compass/app/Http/Controllers/Api.php +++ b/compass/app/Http/Controllers/Api.php @@ -72,9 +72,9 @@ class Api extends BaseController } else { #$record->date->format('U.u'); // Ignore super inaccurate locations - if(!property_exists($record->data->properties, 'horizontal_accuracy') + if(!property_exists($record->data->properties, 'horizontal_accuracy') || $record->data->properties->horizontal_accuracy <= 5000) { - + $locations[] = $record->data; $props = $record->data->properties; $date = $record->date; @@ -264,11 +264,23 @@ class Api extends BaseController $date = new DateTime($loc['properties']['timestamp']); if($date) { - $cacheKey = 'compass::'.$db->name.'::'.$date->format('U'); + + $shouldAdd = true; // Skip adding if the timestamp is already in the cache. // Helps prevent writing duplicate data when the HTTP request is interrupted. - if(!env('CACHE_DRIVER') || !Cache::has($cacheKey)) { + $cacheKey = 'compass::'.$db->name.'::'.$date->format('U'); + if(env('CACHE_DRIVER') && Cache::has($cacheKey)) + $shouldAdd = false; + + // Ignore points at 0,0 + // Around November 2019, Overland on iOS started reporting 0,0 points pretty frequently, several + // times per day, and sometimes for a whole hour in a row. Not sure whether the + // real data from iOS was null,null or actually 0,0 but we'll ignore it here anyway + if($loc['geometry']['coordinates'][0] == 0 && $loc['geometry']['coordinates'][1] == 0) + $shouldAdd = false; + + if($shouldAdd) { $num++; $qz->add($date, $loc); if(env('CACHE_DRIVER')) @@ -303,8 +315,8 @@ class Api extends BaseController } $response = [ - 'result' => 'ok', - 'saved' => $num, + 'result' => 'ok', + 'saved' => $num, 'trips' => $trips ];