Browse Source

add exit pause region event, stub for receiving trips

pull/5/head
Aaron Parecki 9 years ago
parent
commit
6475d760dc
2 changed files with 43 additions and 24 deletions
  1. +30
    -17
      compass/app/Http/Controllers/Api.php
  2. +13
    -7
      compass/public/assets/events.js

+ 30
- 17
compass/app/Http/Controllers/Api.php View File

@ -115,29 +115,42 @@ class Api extends BaseController
$qz = new Quartz\DB(env('STORAGE_DIR').$db->name, 'w'); $qz = new Quartz\DB(env('STORAGE_DIR').$db->name, 'w');
$num = 0; $num = 0;
$trips = 0;
foreach($request->input('locations') as $loc) { 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');
} }
} }

+ 13
- 7
compass/public/assets/events.js View File

@ -7,19 +7,25 @@ function collectEventSeries(data) {
name: "Visit", name: "Visit",
type: 'scatter', type: 'scatter',
color: '#8f799e', color: '#8f799e',
y: 10,
y: 80,
data: [] data: []
}, },
"paused_location_updates": { "paused_location_updates": {
name: "Paused Location Updates", name: "Paused Location Updates",
color: '#a0876e', color: '#a0876e',
y: 20,
y: 70,
data: [] data: []
}, },
"resumed_location_updates": { "resumed_location_updates": {
name: "Resumed Location Updates", name: "Resumed Location Updates",
color: '#819e73', color: '#819e73',
y: 30,
y: 60,
data: []
},
"exited_pause_region": {
name: "Exited Pause Region",
color: '#819e73',
y: 50,
data: [] data: []
}, },
"did_finish_deferred_updates": { "did_finish_deferred_updates": {
@ -31,19 +37,19 @@ function collectEventSeries(data) {
"did_enter_background": { "did_enter_background": {
name: "Entered Background", name: "Entered Background",
color: '#799b9e', color: '#799b9e',
y: 50,
y: 30,
data: [] data: []
}, },
"will_resign_active": { "will_resign_active": {
name: "Will Resign Active", name: "Will Resign Active",
color: '#737f9e', color: '#737f9e',
y: 60,
y: 20,
data: [] data: []
}, },
"will_terminate": { "will_terminate": {
name: "Will Terminate", name: "Will Terminate",
color: '#9e7773', color: '#9e7773',
y: 70,
y: 10,
data: [] data: []
} }
}; };
@ -52,7 +58,7 @@ function collectEventSeries(data) {
series[events[i].properties.action].data.push({ series[events[i].properties.action].data.push({
x: new Date(events[i].properties.unixtime*1000), x: new Date(events[i].properties.unixtime*1000),
y: series[events[i].properties.action].y, y: series[events[i].properties.action].y,
location: events[i].geometry.coordinates
location: (events[i].geometry ? events[i].geometry.coordinates : null)
}); });
} }

Loading…
Cancel
Save