diff --git a/htdocs/public/data/coverage.php b/htdocs/public/data/coverage.php new file mode 100644 index 0000000..bb662aa --- /dev/null +++ b/htdocs/public/data/coverage.php @@ -0,0 +1,31 @@ +getObjectById($_GET['id'] ?? null); +if ($station->isExistingObject()) { + $response['station_id'] = $station->id; + $response['coverage'] = []; + + $numberOfHours = 10*24; // latest 10 days should be enough + $limit = 5000; // Limit number of packets to reduce load on server (and browser) + + if (getWebsiteConfig('coverage_only_moving_senders')) { + $packetPaths = PacketPathRepository::getInstance()->getLatestMovingDataListByReceivingStationId($_GET['id'] ?? null, $numberOfHours, $limit); + } else { + $packetPaths = PacketPathRepository::getInstance()->getLatestDataListByReceivingStationId($_GET['id'] ?? null, $numberOfHours, $limit); + } + + + foreach ($packetPaths as $path) { + $row = []; + $row['latitude'] = $path['sending_latitude']; + $row['longitude'] = $path['sending_longitude']; + $row['distance'] = $path['distance']; + $response['coverage'][] = $row; + } +} + +header('Content-type: application/json'); +echo json_encode($response); diff --git a/htdocs/public/data/kml.php b/htdocs/public/data/kml.php new file mode 100644 index 0000000..79321f5 --- /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); +} diff --git a/htdocs/public/data/trail.php b/htdocs/public/data/trail.php new file mode 100644 index 0000000..ccca7cc --- /dev/null +++ b/htdocs/public/data/trail.php @@ -0,0 +1,55 @@ +getObjectById($_GET['id'] ?? null); +if ($station->isExistingObject()) { + $numberOfHours = $_GET['hours'] ?? 1; + + $columns = ['timestamp']; + $type = 'speed'; + if ($_GET['type'] == 'speed') { + $type = 'speed'; + if ($_GET['imperialUnits'] ?? '0' == '1') { + $response[] = array('Время', 'Скорость (миль/ч)'); + } else { + $response[] = array('Время', 'Скорость (км/ч)'); + } + } else { + $type = 'altitude'; + if ($_GET['imperialUnits'] ?? '0' == '1') { + $response[] = array('Время', 'Высота (фут)'); + } else { + $response[] = array('Время', 'Высота (м)'); + } + } + $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 < ($packet['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);