Exemple #1
0
    $locationField = 'point';
    $mainSearchParams['body']['aggs']['events']['geohash_grid']['field'] = 'point';
} else {
    array_push($filters, array('term' => ['eventType' => $type]));
    $mainSearchParams['index'] = 'vehicleevents';
    $mainSearchParams['type'] = 'event';
    $mainSearchParams['body']['aggs']['events']['geohash_grid']['field'] = 'location';
}
array_push($filters, array('geo_bounding_box' => [$locationField => ['top_left' => ['lat' => 37.850636, 'lon' => -122.551841], 'bottom_right' => ['lat' => 37.665367, 'lon' => -122.276801]]]));
if ($route) {
    array_push($filters, array('term' => ['routeTag' => $route]));
}
$mainSearchParams['body']['query']['bool']['must'] = $filters;
$mainSearchParams['body']['aggs']['events']['geohash_grid']['precision'] = 8;
$mainSearchParams['body']['aggs']['events']['geohash_grid']['size'] = 1000;
$mainHits = $client->search($mainSearchParams);
$maxCount = -1;
$mainResults = array();
$geotools = new \League\Geotools\Geotools();
foreach ($mainHits['aggregations']['events']['buckets'] as $mainHitId => $mainHitValue) {
    $geoKey = $mainHitValue['key'];
    $docs = $mainHitValue['doc_count'];
    if ($maxCount == -1) {
        $maxCount = $docs;
    }
    $decodedGeo = $geotools->geohash()->decode($geoKey);
    $lat = $decodedGeo->getCoordinate()->getLatitude();
    $lon = $decodedGeo->getCoordinate()->getLongitude();
    $mainResults[] = array('lat' => $lat, 'lon' => $lon, 'score' => 3 * sprintf("%.5f", $docs / $maxCount));
}
echo json_encode($mainResults);
Exemple #2
0
 * Check version
 */
$columns = $PDO->query('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "' . $database . '" AND TABLE_NAME ="' . PREFIX . 'training"')->fetchAll(PDO::FETCH_COLUMN, 0);
if (!in_array('is_night', $columns)) {
    echo 'Update your installation from v2.3 to v2.4 via update.php.' . NL;
    exit;
}
/**
 * Overview for data
 */
$Routes = $PDO->query('SELECT tr.id, tr.time, tr.s, r.startpoint from ' . PREFIX . 'training tr LEFT JOIN ' . PREFIX . 'route r ON tr.routeid = r.id  WHERE tr.routeid IS NOT NULL AND r.startpoint IS NOT NULL AND startpoint != "7zzzzzzzzz"');
$InsertIsNight = $PDO->prepare('UPDATE ' . PREFIX . 'training SET `is_night` = :val WHERE `id` = :id');
$geotools = new \League\Geotools\Geotools();
$detector = new \Runalyze\Calculation\NightDetector();
while ($Route = $Routes->fetch()) {
    $coord = $geotools->geohash()->decode($Route['startpoint'])->getCoordinate();
    $timepoint = $Route['time'] + 0.5 * $Route['s'];
    $detector->setFrom($Route['time'] + 0.5 * $Route['s'], $geotools->geohash()->decode($Route['startpoint'])->getCoordinate());
    if ($detector->isKnown()) {
        $InsertIsNight->execute(array(':val' => $detector->value() ? 1 : 0, ':id' => $Route['id']));
    }
    echo ".";
}
if (CLI) {
    echo NL . NL;
}
echo 'done;' . NL;
echo NL;
echo 'Time: ' . (microtime(true) - $starttime) . 's' . NL;
echo 'Memory peak: ' . memory_get_peak_usage() . 'B' . NL;
echo NL;
Exemple #3
0
 /**
  * Add marker
  * @param float $Lat
  * @param float $Lng
  * @param string $Icon JS-icon
  * @param string $Tooltip [optional]
  */
 public final function addMarkerGeohash($Geohash, $Icon, $Tooltip = '')
 {
     $geotools = new \League\Geotools\Geotools();
     $decoded = $geotools->geohash()->decode($Geohash);
     $this->Marker[] = 'L.marker([' . $decoded->getCoordinate()->getLatitude() . ',' . $decoded->getCoordinate()->getLongitude() . '], {icon: ' . $Icon . ', tooltip: "' . $Tooltip . '"})';
 }