From 22598acfc9a6486a02379e13d147b1fc47014ba9 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 12 Aug 2018 21:58:43 +0200 Subject: [PATCH] Cleanup. --- lib/Database/AbstractDatabase.php | 27 ---------------- tools/import_google_history.php | 54 +++++++------------------------ 2 files changed, 12 insertions(+), 69 deletions(-) diff --git a/lib/Database/AbstractDatabase.php b/lib/Database/AbstractDatabase.php index 284c9f4..2daf28b 100644 --- a/lib/Database/AbstractDatabase.php +++ b/lib/Database/AbstractDatabase.php @@ -56,33 +56,6 @@ class AbstractDatabase return $result; } - public function addLocation( - int $accuracy = null, - int $altitude = null, - int $battery_level = null, - int $heading = null, - string $description = null, - string $event = null, - float $latitude, - float $longitude, - int $radius = null, - string $trig = null, - string $tracker_id = null, - int $epoch, - int $vertical_accuracy = null, - int $velocity = null, - float $pressure = null, - string $connection = null, - string $topic = null, - int $place_id = null, - int $osm_id = null - ): bool { - $sql = 'INSERT INTO ' . $this->prefix . 'locations (accuracy, altitude, battery_level, heading, description, event, latitude, longitude, radius, trig, tracker_id, epoch, vertical_accuracy, velocity, pressure, connection, topic, place_id, osm_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - $params = array($accuracy, $altitude, $battery_level, $heading, $description, $event, $latitude, $longitude, $radius, $trig, $tracker_id, $epoch, $vertical_accuracy, $velocity, $pressure, $connection, $topic, $place_id, $osm_id); - $result = $this->execute($sql, $params); - return $result; - } - public function getMarkers(int $time_from, int $time_to, int $min_accuracy = 1000): array { $sql = 'SELECT * FROM ' . $this->prefix . 'locations WHERE epoch >= ? AND epoch <= ? AND accuracy < ? AND altitude >=0 ORDER BY tracker_id, epoch ASC'; diff --git a/tools/import_google_history.php b/tools/import_google_history.php index 78c499c..4eb350e 100755 --- a/tools/import_google_history.php +++ b/tools/import_google_history.php @@ -11,6 +11,7 @@ use \pcrov\JsonReader\JsonReader; use \pcrov\JsonReader\InputStream\Stream; use \OwntracksRecorder\Database\MySql; use \OwntracksRecorder\Database\SQLite; +use \OwntracksRecorder\RecordType\Location; $fs = filesize($INPUT_FILE); $fp = fopen($INPUT_FILE, 'rb'); @@ -49,50 +50,19 @@ do { #print_r($data); - $accuracy = null; - $altitude = null; - $battery_level = null; - $heading = null; - $description = null; - $event = null; - $latitude = null; - $longitude = null; - $radius = null; - $trig = null; - $tracker_id = null; - $epoch = null; - $vertical_accuracy = null; - $velocity = null; - $pressure = null; - $connection = 'i'; // i = imported + $loc = new Location(); + $loc->connection = 'i'; // i = imported - if (array_key_exists('accuracy', $data)) $accuracy = intval($data['accuracy']); - if (array_key_exists('altitude', $data)) $altitude = intval($data['altitude']); - if (array_key_exists('heading', $data)) $heading = intval($data['heading']); - $latitude = floatval($data['latitudeE7']) / 1e7; - $longitude = floatval($data['longitudeE7']) / 1e7; - $epoch = (int)floor(intval($data['timestampMs']) / 1000); - if (array_key_exists('verticalAccuracy', $data)) $vertical_accuracy = intval($data['verticalAccuracy']); - if (array_key_exists('velocity', $data)) $velocity = intval(floatval($data['velocity'])*3.6); // metres per second to km/h + if (array_key_exists('accuracy', $data)) $loc->accuracy = intval($data['accuracy']); + if (array_key_exists('altitude', $data)) $loc->altitude = intval($data['altitude']); + if (array_key_exists('heading', $data)) $loc->heading = intval($data['heading']); + $loc->latitude = floatval($data['latitudeE7']) / 1e7; + $loc->longitude = floatval($data['longitudeE7']) / 1e7; + $loc->epoch = (int)floor(intval($data['timestampMs']) / 1000); + if (array_key_exists('verticalAccuracy', $data)) $loc->vertical_accuracy = intval($data['verticalAccuracy']); + if (array_key_exists('velocity', $data)) $loc->velocity = intval(floatval($data['velocity'])*3.6); // metres per second to km/h - $sql->addLocation( - $accuracy, - $altitude, - $battery_level, - $heading, - $description, - $event, - $latitude, - $longitude, - $radius, - $trig, - $TRACKER_ID, - $epoch, - $vertical_accuracy, - $velocity, - $pressure, - $connection - ); + $sql->addRecord($loc); $i++; if ($i%2000 == 0) {