Browse Source

Merge branch 'master' of github.com:aaronpk/Compass

pull/5/head
Aaron Parecki 4 years ago
parent
commit
e9c23a0ade
No known key found for this signature in database GPG Key ID: 276C2817346D6056
8 changed files with 22908 additions and 26 deletions
  1. +18
    -0
      README.md
  2. +15
    -9
      compass/app/Http/Controllers/Api.php
  3. +22853
    -0
      compass/app/Http/Controllers/LocalTime.php
  4. +1
    -0
      compass/app/Http/routes.php
  5. +8
    -5
      compass/app/Jobs/TripComplete.php
  6. +10
    -10
      compass/composer.lock
  7. +1
    -0
      compass/public/assets/map.js
  8. +2
    -2
      compass/resources/views/map.blade.php

+ 18
- 0
README.md View File

@ -28,6 +28,8 @@ The open source iOS [GPS Logger](https://github.com/esripdx/GPS-Logger-iOS) will
To read a database, make a GET request as follows:
#### Get all data for a calendar day
`GET /api/query`
* token - (required) the read token for the database
@ -37,12 +39,28 @@ To read a database, make a GET request as follows:
* linestring - combine all the returned results into a GeoJSON linestring
* date - specify a date to return all data on that day (YYYY-mm-dd format)
#### Get the last location before a given timestamp
`GET /api/last`
* token - (required) the read token for the database
* tz - (optional, default UTC) timezone string (e.g. America/Los_Angeles) which will be used to determine the absolute start/end times for the day
* before - (optional, default to now) specify a full timestamp to return a single record before this date (the point returned will be no more than 24 hours before the given date)
* geocode - (optional) if "true", then the location found will be reverse geocoded using [Atlas](https://atlas.p3k.io) to find the city and timezone at the location
#### Find the last location matching a clock time
`GET /api/find-from-localtime`
This API method can help you answer the question "Where was I when my watch read 9:30am on July 15th?".
Timestamps in Exif data do not include the timezone offset, and there is no standard mechanism for including the timezone offset in Exif. Some Canon cameras put the offset in a field, but not all of them do. You can use this method to find your location given an Exif date.
* token - (required) the read token for the database
* input - specify a clock time in the format `YYYY-mm-dd HH:MM:SS`
This will query the database and find the closest matching location for when your clock read that time.
## Credits

+ 15
- 9
compass/app/Http/Controllers/Api.php View File

@ -69,13 +69,18 @@ class Api extends BaseController
$events[] = $rec;
} else {
#$record->date->format('U.u');
$locations[] = $record->data;
$props = $record->data->properties;
$date = $record->date;
$date->setTimeZone(new DateTimeZone($tz));
$props->timestamp = $date->format('c');
$props->unixtime = (int)$date->format('U');
$properties[] = $props;
// Ignore super inaccurate locations
if(!property_exists($record->data->properties, 'horizontal_accuracy')
|| $record->data->properties->horizontal_accuracy <= 5000) {
$locations[] = $record->data;
$props = $record->data->properties;
$date = $record->date;
$date->setTimeZone(new DateTimeZone($tz));
$props->timestamp = $date->format('c');
$props->unixtime = (int)$date->format('U');
$properties[] = $props;
}
}
}
@ -184,7 +189,8 @@ class Api extends BaseController
$coords = $record->data->geometry->coordinates;
$params = [
'latitude' => $coords[1],
'longitude' => $coords[0]
'longitude' => $coords[0],
'date' => $record->data->properties->timestamp
];
$ch = curl_init(env('ATLAS_BASE').'api/geocode?'.http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -197,7 +203,7 @@ class Api extends BaseController
}
}
return response(json_encode($response));
return response(json_encode($response))->header('Content-Type', 'application/json');;
}
public function input(Request $request) {

+ 22853
- 0
compass/app/Http/Controllers/LocalTime.php
File diff suppressed because it is too large
View File


+ 1
- 0
compass/app/Http/routes.php View File

@ -14,6 +14,7 @@ $app->post('/database/create', 'Controller@createDatabase');
$app->get('/api/query', 'Api@query');
$app->get('/api/last', 'Api@last');
$app->get('/api/find-from-localtime', 'LocalTime@find');
$app->get('/api/input', 'Api@account');
$app->post('/api/input', 'Api@input');
$app->post('/api/trip-complete', 'Api@trip_complete');

+ 8
- 5
compass/app/Jobs/TripComplete.php View File

@ -46,11 +46,14 @@ class TripComplete extends Job implements SelfHandling, ShouldQueue
foreach($results as $id=>$record) {
// Don't include app action tracking data
if(!property_exists($record->data->properties, 'action')) {
$record->data->properties = array_filter((array)$record->data->properties, function($k){
// Remove some of the app-specific tracking keys from each record
return !in_array($k, ['locations_in_payload','desired_accuracy','significant_change','pauses','deferred']);
}, ARRAY_FILTER_USE_KEY);
$features[] = $record->data;
// Ignore locations with accuracy worse than 5000m
if(property_exists($record->data->properties, 'horizontal_accuracy') && $record->data->properties->horizontal_accuracy <= 5000) {
$record->data->properties = array_filter((array)$record->data->properties, function($k){
// Remove some of the app-specific tracking keys from each record
return !in_array($k, ['locations_in_payload','desired_accuracy','significant_change','pauses','deferred']);
}, ARRAY_FILTER_USE_KEY);
$features[] = $record->data;
}
}
}

+ 10
- 10
compass/composer.lock View File

@ -1964,16 +1964,16 @@
},
{
"name": "p3k/quartz-db",
"version": "0.1.0",
"version": "0.1.1",
"source": {
"type": "git",
"url": "https://github.com/aaronpk/QuartzDB.git",
"reference": "d060c23716fc5d0a4bdb77f32e8c813e29c923ed"
"reference": "d0273a08181cffd91343ba788ff234fbd9daffa6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aaronpk/QuartzDB/zipball/d060c23716fc5d0a4bdb77f32e8c813e29c923ed",
"reference": "d060c23716fc5d0a4bdb77f32e8c813e29c923ed",
"url": "https://api.github.com/repos/aaronpk/QuartzDB/zipball/d0273a08181cffd91343ba788ff234fbd9daffa6",
"reference": "d0273a08181cffd91343ba788ff234fbd9daffa6",
"shasum": ""
},
"type": "library",
@ -1992,20 +1992,20 @@
}
],
"description": "A flat-file database optimized to hold time-series data.",
"time": "2015-09-21 17:56:12"
"time": "2016-01-29 00:39:52"
},
{
"name": "paragonie/random_compat",
"version": "1.1.5",
"version": "1.1.6",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "dd8998b7c846f6909f4e7a5f67fabebfc412a4f7"
"reference": "e6f80ab77885151908d0ec743689ca700886e8b0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/dd8998b7c846f6909f4e7a5f67fabebfc412a4f7",
"reference": "dd8998b7c846f6909f4e7a5f67fabebfc412a4f7",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/e6f80ab77885151908d0ec743689ca700886e8b0",
"reference": "e6f80ab77885151908d0ec743689ca700886e8b0",
"shasum": ""
},
"require": {
@ -2040,7 +2040,7 @@
"pseudorandom",
"random"
],
"time": "2016-01-06 13:31:20"
"time": "2016-01-29 16:19:52"
},
{
"name": "predis/predis",

+ 1
- 0
compass/public/assets/map.js View File

@ -137,6 +137,7 @@ jQuery(function($){
var db_token = $("#database").data("token");
$.get("/api/query?format=linestring&start="+$('#range-from').val()+"&end="+$('#range-to').val()+"&tz="+$("#timezone").val()+"&token="+db_token, function(data){
$("#range-go").removeClass("loading");
$("#trip-create-form").removeClass("hidden");
displayLineOnMap(data, {pins: true});
});
return false;

+ 2
- 2
compass/resources/views/map.blade.php View File

@ -14,11 +14,11 @@
</div>
</div>
@if($database->micropub_endpoint)
<div class="ui form" style="margin-top: 4px;">
<div class="ui form hidden" style="margin-top: 4px;" id="trip-create-form">
<div class="fields">
<div style="display: flex; margin-right: 4px;">
<select id="trip-mode">
@foreach(['bicycle', 'car2go', 'drive', 'train', 'walk', 'run', 'plane', 'train', 'bus'] as $mode)
@foreach(['walk', 'run', 'bicycle', 'car2go', 'car', 'taxi', 'bus', 'train', 'plane'] as $mode)
<option value="{{ $mode }}">{{ $mode }}</option>
@endforeach
</select>

Loading…
Cancel
Save