| 
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -21,8 +21,8 @@ class Api extends BaseController | 
															
														
														
													
														
															
																 | 
																 | 
																    $db = DB::table('databases')->where('write_token','=',$token)->first(); | 
																 | 
																 | 
																    $db = DB::table('databases')->where('write_token','=',$token)->first(); | 
															
														
														
													
														
															
																 | 
																 | 
																    if(!$db) | 
																 | 
																 | 
																    if(!$db) | 
															
														
														
													
														
															
																 | 
																 | 
																      return response(json_encode(['error' => 'invalid token']))->header('Content-Type', 'application/json'); | 
																 | 
																 | 
																      return response(json_encode(['error' => 'invalid token']))->header('Content-Type', 'application/json'); | 
															
														
														
													
														
															
																 | 
																 | 
																     | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    return response(json_encode(['name' => $db->name]))->header('Content-Type', 'application/json');     | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    return response(json_encode(['name' => $db->name]))->header('Content-Type', 'application/json'); | 
															
														
														
													
														
															
																 | 
																 | 
																  } | 
																 | 
																 | 
																  } | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																  public function query(Request $request) { | 
																 | 
																 | 
																  public function query(Request $request) { | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -86,7 +86,7 @@ class Api extends BaseController | 
															
														
														
													
														
															
																 | 
																 | 
																        else | 
																 | 
																 | 
																        else | 
															
														
														
													
														
															
																 | 
																 | 
																          $linestring['coordinates'][] = null; | 
																 | 
																 | 
																          $linestring['coordinates'][] = null; | 
															
														
														
													
														
															
																 | 
																 | 
																      } | 
																 | 
																 | 
																      } | 
															
														
														
													
														
															
																 | 
																 | 
																       | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																      $response = array( | 
																 | 
																 | 
																      $response = array( | 
															
														
														
													
														
															
																 | 
																 | 
																        'linestring' => $linestring, | 
																 | 
																 | 
																        'linestring' => $linestring, | 
															
														
														
													
														
															
																 | 
																 | 
																        'events' => $events | 
																 | 
																 | 
																        'events' => $events | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -98,7 +98,7 @@ class Api extends BaseController | 
															
														
														
													
														
															
																 | 
																 | 
																      ]; | 
																 | 
																 | 
																      ]; | 
															
														
														
													
														
															
																 | 
																 | 
																    } | 
																 | 
																 | 
																    } | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																    return response(json_encode($response))->header('Content-Type', 'application/json');     | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    return response(json_encode($response))->header('Content-Type', 'application/json'); | 
															
														
														
													
														
															
																 | 
																 | 
																  } | 
																 | 
																 | 
																  } | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																  public function input(Request $request) { | 
																 | 
																 | 
																  public function input(Request $request) { | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -119,17 +119,7 @@ class Api extends BaseController | 
															
														
														
													
														
															
																 | 
																 | 
																    $trips = 0; | 
																 | 
																 | 
																    $trips = 0; | 
															
														
														
													
														
															
																 | 
																 | 
																    foreach($request->input('locations') as $loc) { | 
																 | 
																 | 
																    foreach($request->input('locations') as $loc) { | 
															
														
														
													
														
															
																 | 
																 | 
																      if(array_key_exists('properties', $loc)) { | 
																 | 
																 | 
																      if(array_key_exists('properties', $loc)) { | 
															
														
														
													
														
															
																 | 
																 | 
																        if(array_key_exists('type', $loc['properties']) && $loc['properties']['type'] == 'trip') { | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																          try { | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																             | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																            $this->dispatch(new TripComplete($db->id, $loc)); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																            $trips++; | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																             | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																          } catch(Exception $e) { | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																            Log::warning('Received invalid trip'); | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																          }          | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																        } elseif(array_key_exists('timestamp', $loc['properties'])) { | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        if(array_key_exists('timestamp', $loc['properties'])) { | 
															
														
														
													
														
															
																 | 
																 | 
																          try { | 
																 | 
																 | 
																          try { | 
															
														
														
													
														
															
																 | 
																 | 
																            if(preg_match('/^\d+\.\d+$/', $loc['properties']['timestamp'])) | 
																 | 
																 | 
																            if(preg_match('/^\d+\.\d+$/', $loc['properties']['timestamp'])) | 
															
														
														
													
														
															
																 | 
																 | 
																              $date = DateTime::createFromFormat('U.u', $loc['properties']['timestamp']); | 
																 | 
																 | 
																              $date = DateTime::createFromFormat('U.u', $loc['properties']['timestamp']); | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -137,10 +127,21 @@ class Api extends BaseController | 
															
														
														
													
														
															
																 | 
																 | 
																              $date = DateTime::createFromFormat('U', $loc['properties']['timestamp']); | 
																 | 
																 | 
																              $date = DateTime::createFromFormat('U', $loc['properties']['timestamp']); | 
															
														
														
													
														
															
																 | 
																 | 
																            else | 
																 | 
																 | 
																            else | 
															
														
														
													
														
															
																 | 
																 | 
																              $date = new DateTime($loc['properties']['timestamp']); | 
																 | 
																 | 
																              $date = new DateTime($loc['properties']['timestamp']); | 
															
														
														
													
														
															
																 | 
																 | 
																   | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																            if($date) { | 
																 | 
																 | 
																            if($date) { | 
															
														
														
													
														
															
																 | 
																 | 
																              $num++; | 
																 | 
																 | 
																              $num++; | 
															
														
														
													
														
															
																 | 
																 | 
																              $qz->add($date, $loc); | 
																 | 
																 | 
																              $qz->add($date, $loc); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																              if(array_key_exists('type', $loc['properties']) && $loc['properties']['type'] == 'trip') { | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                try { | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                  $job = (new TripComplete($db->id, $loc))->onQueue('compass'); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                  $this->dispatch($job); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                  $trips++; | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                } catch(Exception $e) { | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                  Log::warning('Received invalid trip'); | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																                } | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																              } | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																            } else { | 
																 | 
																 | 
																            } else { | 
															
														
														
													
														
															
																 | 
																 | 
																              Log::warning('Received invalid date: ' . $loc['properties']['timestamp']); | 
																 | 
																 | 
																              Log::warning('Received invalid date: ' . $loc['properties']['timestamp']); | 
															
														
														
													
														
															
																 | 
																 | 
																            } | 
																 | 
																 | 
																            } | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																	
																 | 
																
 |