Browse Source

drop incoming data with 0,0 location

pull/34/head
Aaron Parecki 5 years ago
parent
commit
e0d10c0fb5
No known key found for this signature in database GPG Key ID: 276C2817346D6056
1 changed files with 18 additions and 6 deletions
  1. +18
    -6
      compass/app/Http/Controllers/Api.php

+ 18
- 6
compass/app/Http/Controllers/Api.php View File

@ -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
];

Loading…
Cancel
Save