From b1fcb71174f4f8f3dabe8dbbd8fd754c6a5f8418 Mon Sep 17 00:00:00 2001 From: Per Qvarforth Date: Sun, 30 Jan 2022 13:13:57 +0100 Subject: [PATCH 01/10] added trail chart --- htdocs/public/data/kml.php | 60 ++++++++ htdocs/public/data/trail.php | 55 +++++++ htdocs/public/station/overview.php | 3 +- htdocs/public/station/raw.php | 1 + htdocs/public/station/statistics.php | 1 + htdocs/public/station/telemetry.php | 1 + htdocs/public/station/trail.php | 210 +++++++++++++++++++++++++++ htdocs/public/station/weather.php | 1 + 8 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 htdocs/public/data/kml.php create mode 100644 htdocs/public/data/trail.php create mode 100644 htdocs/public/station/trail.php diff --git a/htdocs/public/data/kml.php b/htdocs/public/data/kml.php new file mode 100644 index 0000000..7038a33 --- /dev/null +++ b/htdocs/public/data/kml.php @@ -0,0 +1,60 @@ +getObjectById($_GET['id']); +} else { + $station = new Station(null); +} + +$color = null; +if (isset($_GET['color'])) { + $color = $_GET['color']; +} + +$startTimestamp = time() - (60*60*24); // Default to 24h +if (isset($_GET['startts'])) { + $startTimestamp = $_GET['startts']; +} +if ($startTimestamp < (time() - (60*60*24*3))) { + $startTimestamp = time() - (60*60*24*3); // Not older than 3 days allowed +} + +$endTimestamp = time(); +if (isset($_GET['endts']) && isInt($_GET['endts'])) { + $endTimestamp = $_GET['endts']; +} + +$startTimestampString = strftime('%Y%m%d%H%M', $startTimestamp); +$endTimestampString = strftime('%Y%m%d%H%M', $endTimestamp); + +if ($station->isExistingObject()) { + $stationIds = []; + if ($station->stationTypeId == 2) { + $currentStations = StationRepository::getInstance()->getObjectListByName($station->name, 2, $station->sourceId); + foreach ($currentStations as $currentStation) { + $stationIds[] = $currentStation->getId(); + } + } else { + $stationIds[] = $station->getId(); + } + + $lateststation = null; + foreach ($stationIds as $stationId) { + $s = StationRepository::getInstance()->getObjectById($stationId); + if ($lateststation === null) { + $lateststation = $s; + } else if ($lateststation->latestConfirmedPacketTimestamp < $s->latestConfirmedPacketTimestamp) { + $lateststation = $s; + } + } + + $packets = PacketRepository::getInstance()->getConfirmedObjectListByStationIdList($stationIds, $startTimestamp, $endTimestamp); + $dom = Kml::getInstance()->getKmlDomDocument($lateststation, $packets, $startTimestamp, $endTimestamp, $color); + $kmlOutput = $dom->saveXML(); + + header('Content-type: application/vnd.google-earth.kml+xml'); + header('Content-Disposition: attachment; filename="' . htmlspecialchars($lateststation->name) . '-' . $startTimestampString . '-' . $endTimestampString . '.kml"'); + echo Kml::getInstance()->formatKmlContent($kmlOutput, " ", 4); +} \ No newline at end of file diff --git a/htdocs/public/data/trail.php b/htdocs/public/data/trail.php new file mode 100644 index 0000000..1229b1e --- /dev/null +++ b/htdocs/public/data/trail.php @@ -0,0 +1,55 @@ +getObjectById($_GET['id'] ?? null); +if ($station->isExistingObject()) { + $numberOfHours = $_GET['hours'] ?? 1; +error_log($numberOfHours); + $columns = ['timestamp']; + $type = 'speed'; + if ($_GET['type'] == 'speed') { + $type = 'speed'; + if ($_GET['imperialUnits'] ?? '0' == '1') { + $response[] = array('Time', 'Speed (mph)'); + } else { + $response[] = array('Time', 'Speed (kmh)'); + } + } else { + $type = 'altitude'; + if ($_GET['imperialUnits'] ?? '0' == '1') { + $response[] = array('Time', 'Altitude (ft)'); + } else { + $response[] = array('Time', 'Altitude (m)'); + } + } + $columns[] = $type; + + $packets = PacketRepository::getInstance()->getLatestDataListByStationId($_GET['id'] ?? null, $numberOfHours, $columns); + foreach($packets as $packet) { + $value = floatval($packet[$type]); + if ($_GET['imperialUnits'] ?? '0' == '1') { + if ($type == 'speed') { + $value = convertKilometerToMile($value); + } else if ($type == 'altitude') { + $value = convertMeterToFeet($value); + } + } + + if ($type == 'speed' && count($response) > 1) { + if (isset($response[count($response) - 1])) { + $prevTimestamp = $response[count($response) - 1][0]; + if ($prevTimestamp < ($timestamp - 60*60)) { + // Previous value is old, make sure we have a break in graph + $response[] = array($prevTimestamp + 1, null); + } + } + } + + $response[] = [$packet['timestamp'], $value]; + } +} + +header('Content-type: application/json'); +echo json_encode($response); diff --git a/htdocs/public/station/overview.php b/htdocs/public/station/overview.php index bd47579..e05c0c5 100644 --- a/htdocs/public/station/overview.php +++ b/htdocs/public/station/overview.php @@ -52,6 +52,7 @@
diff --git a/htdocs/public/station/raw.php b/htdocs/public/station/raw.php index 9bf2892..3879c9e 100644 --- a/htdocs/public/station/raw.php +++ b/htdocs/public/station/raw.php @@ -84,6 +84,7 @@ diff --git a/htdocs/public/js/main.js b/htdocs/public/js/main.js index 7967c9a..37b9e0f 100755 --- a/htdocs/public/js/main.js +++ b/htdocs/public/js/main.js @@ -19,6 +19,11 @@ if (!inIframe()) { $("#tdTopnav").hide(); } +// Set correct time length option to active +jQuery(document).ready(function ($) { + $("#tdTopnavTimelengthDefault").addClass("dropdown-content-checkbox-active"); +}); + // Open station dialog if user clicked on station name jQuery(document).ready(function ($) { trackdirect.addListener("station-name-clicked", function (data) { @@ -86,9 +91,10 @@ jQuery(document).ready(function ($) { // Time travel is stopped when filtering is stopped $("#right-container-timetravel").hide(); - // Tail length is reset to 60 minutes when filtering is stopped - $("#tdTopnavTimelength>a").removeClass("active"); - $("#tdTopnavTimelength60").addClass("active"); + // Reset tail length to default when filtering is stopped + $("#tdTopnavTimelength>a").removeClass("dropdown-content-checkbox-active"); + $("#tdTopnavTimelengthDefault").addClass("dropdown-content-checkbox-active"); + $(".dropdown-content-checkbox-only-filtering").addClass("dropdown-content-checkbox-hidden"); } else { var counts = {}; for (var i = 0; i < packets.length; i++) { @@ -102,6 +108,7 @@ jQuery(document).ready(function ($) { "Filtering on " + Object.keys(counts).length + " station(s)" ); $("#right-container-filtered").show(); + $(".dropdown-content-checkbox-only-filtering").removeClass("dropdown-content-checkbox-hidden"); } }); }); From bf7146f27e356c9034fd8e5cb44fff0c93ef9e6c Mon Sep 17 00:00:00 2001 From: Per Qvarforth Date: Sun, 30 Jan 2022 23:43:21 +0100 Subject: [PATCH 10/10] changed geoip service --- htdocs/public/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/public/index.php b/htdocs/public/index.php index 5abb463..202f748 100755 --- a/htdocs/public/index.php +++ b/htdocs/public/index.php @@ -90,8 +90,8 @@ options['defaultLatitude'] = '59.30928'; options['defaultLongitude'] = '18.08830'; - // Tip: request position from some ip->location service (here using freegeoip as an example) - $.getJSON('https://freegeoip.app/json/', function(data) { + // Tip: request position from some ip->location service (https://freegeoip.app/json and https://ipapi.co/json is two examples) + $.getJSON('https://ipapi.co/json', function(data) { if (data.latitude && data.longitude) { options['defaultLatitude'] = data.latitude; options['defaultLongitude'] = data.longitude;