diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php index a03e2a4..918ba83 100644 --- a/compass/app/Http/Controllers/Api.php +++ b/compass/app/Http/Controllers/Api.php @@ -115,29 +115,42 @@ class Api extends BaseController $qz = new Quartz\DB(env('STORAGE_DIR').$db->name, 'w'); $num = 0; + $trips = 0; foreach($request->input('locations') as $loc) { - if(array_key_exists('properties', $loc) && array_key_exists('timestamp', $loc['properties'])) { - try { - if(preg_match('/^\d+\.\d+$/', $loc['properties']['timestamp'])) - $date = DateTime::createFromFormat('U.u', $loc['properties']['timestamp']); - elseif(preg_match('/^\d+$/', $loc['properties']['timestamp'])) - $date = DateTime::createFromFormat('U', $loc['properties']['timestamp']); - else - $date = new DateTime($loc['properties']['timestamp']); - - if($date) { - $num++; - $qz->add($date, $loc); - } else { - Log::warning('Received invalid date: ' . $loc['properties']['timestamp']); + if(array_key_exists('properties', $loc)) { + if(array_key_exists('type', $loc['properties']) && $loc['properties']['type'] == 'trip') { + try { + + + + $trips++; + + } catch(Exception $e) { + Log::warning('Received invalid trip'); + } + } elseif(array_key_exists('timestamp', $loc['properties'])) { + try { + if(preg_match('/^\d+\.\d+$/', $loc['properties']['timestamp'])) + $date = DateTime::createFromFormat('U.u', $loc['properties']['timestamp']); + elseif(preg_match('/^\d+$/', $loc['properties']['timestamp'])) + $date = DateTime::createFromFormat('U', $loc['properties']['timestamp']); + else + $date = new DateTime($loc['properties']['timestamp']); + + if($date) { + $num++; + $qz->add($date, $loc); + } else { + Log::warning('Received invalid date: ' . $loc['properties']['timestamp']); + } + } catch(Exception $e) { + Log::warning('Received invalid date: ' . $loc['properties']['timestamp']); } - } catch(Exception $e) { - Log::warning('Received invalid date: ' . $loc['properties']['timestamp']); } } } - return response(json_encode(['result' => 'ok', 'saved' => $num]))->header('Content-Type', 'application/json'); + return response(json_encode(['result' => 'ok', 'saved' => $num, 'trips' => $trips]))->header('Content-Type', 'application/json'); } } diff --git a/compass/public/assets/events.js b/compass/public/assets/events.js index eacc732..02277d5 100644 --- a/compass/public/assets/events.js +++ b/compass/public/assets/events.js @@ -7,19 +7,25 @@ function collectEventSeries(data) { name: "Visit", type: 'scatter', color: '#8f799e', - y: 10, + y: 80, data: [] }, "paused_location_updates": { name: "Paused Location Updates", color: '#a0876e', - y: 20, + y: 70, data: [] }, "resumed_location_updates": { name: "Resumed Location Updates", color: '#819e73', - y: 30, + y: 60, + data: [] + }, + "exited_pause_region": { + name: "Exited Pause Region", + color: '#819e73', + y: 50, data: [] }, "did_finish_deferred_updates": { @@ -31,19 +37,19 @@ function collectEventSeries(data) { "did_enter_background": { name: "Entered Background", color: '#799b9e', - y: 50, + y: 30, data: [] }, "will_resign_active": { name: "Will Resign Active", color: '#737f9e', - y: 60, + y: 20, data: [] }, "will_terminate": { name: "Will Terminate", color: '#9e7773', - y: 70, + y: 10, data: [] } }; @@ -52,7 +58,7 @@ function collectEventSeries(data) { series[events[i].properties.action].data.push({ x: new Date(events[i].properties.unixtime*1000), y: series[events[i].properties.action].y, - location: events[i].geometry.coordinates + location: (events[i].geometry ? events[i].geometry.coordinates : null) }); }