From 64549ae42de84958cf4cd30014cf676410bc4754 Mon Sep 17 00:00:00 2001 From: ua1zbe Date: Fri, 24 Mar 2023 15:43:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20'h?= =?UTF-8?q?tdocs/includes/repositories/packetrepository.class.php'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/packetrepository.class.php | 213 ------------------ 1 file changed, 213 deletions(-) delete mode 100644 htdocs/includes/repositories/packetrepository.class.php diff --git a/htdocs/includes/repositories/packetrepository.class.php b/htdocs/includes/repositories/packetrepository.class.php deleted file mode 100644 index 9cbf810..0000000 --- a/htdocs/includes/repositories/packetrepository.class.php +++ /dev/null @@ -1,213 +0,0 @@ -getObjectFromSql('select * from packet where id = ? and timestamp = ?', [$id, $timestamp]); - } - - /** - * Get object list with raw by station id for the latest 24 hours - * - * @param int $stationId - * @param int $limit - * @param int $offset - * @return array - */ - public function getObjectListWithRawByStationId($stationId, $limit, $offset) - { - if (!isInt($stationId) || !isInt($limit) || !isInt($offset)) { - return []; - } - $sql = 'select packet.* from packet packet where station_id = ? and timestamp > ? and raw is not null order by timestamp desc, id desc limit ? offset ?'; - $parameters = [$stationId, time() - (24*60*60), $limit, $offset]; - return $this->getObjectListFromSql($sql, $parameters); - } - - /** - * Get number of packets with raw by station id for the latest 24 hours - * - * @param int $stationId - * @return int - */ - public function getNumberOfPacketsWithRawByStationId($stationId) - { - if (!isInt($stationId)) { - return 0; - } - $sql = 'select count(*) c from packet where station_id = ? and timestamp > ? and raw is not null'; - $parameters = [$stationId, time() - (24*60*60)]; - - $pdo = PDOConnection::getInstance(); - $stmt = $pdo->prepareAndExec($sql, $parameters); - $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); - - $sum = 0; - foreach($rows as $row) { - $sum += $row['c']; - } - - return $sum; - } - - /** - * Get object list with raw by sender station id for the latest 24 hours - * - * @param int $stationId - * @param int $limit - * @param int $offset - * @return array - */ - public function getObjectListWithRawBySenderStationId($stationId, $limit, $offset) - { - if (!isInt($stationId) || !isInt($limit) || !isInt($offset)) { - return []; - } - $sql = 'select packet.* from packet where sender_id in (select latest_sender_id from station where id = ?) and timestamp > ? and raw is not null order by timestamp desc, id desc limit ? offset ?'; - $parameters = [$stationId, time() - (24*60*60), $limit, $offset]; - return $this->getObjectListFromSql($sql, $parameters); - } - - /** - * Get number of packets with raw by sender station id for the latest 24 hours - * - * @param int $stationId - * @return int - */ - public function getNumberOfPacketsWithRawBySenderStationId($stationId) - { - if (!isInt($stationId)) { - return 0; - } - $sql = 'select count(*) c from packet where sender_id in (select latest_sender_id from station where id = ?) and timestamp > ? and raw is not null'; - $parameters = [$stationId, time() - (24*60*60)]; - - $pdo = PDOConnection::getInstance(); - $stmt = $pdo->prepareAndExec($sql, $parameters); - $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); - - $sum = 0; - foreach($rows as $row) { - $sum += $row['c']; - } - return $sum; - } - - /** - * Get latest confirmed position packet object by station id - * - * @param int $stationId - * @return Packet - */ - public function getLatestConfirmedObjectByStationId($stationId) - { - if (!isInt($stationId)) { - return new Packet(0); - } - $station = StationRepository::getInstance()->getObjectById($stationId); - if ($station->isExistingObject()) { - return $this->getObjectById($station->latestConfirmedPacketId, $station->latestConfirmedPacketTimestamp); - } - return new Packet(null); - } - - /** - * Get latest packet data list by station id (useful for creating a chart) - * - * @param int $stationId - * @param int $numberOfHours - * @param array $columns - * @return Array - */ - public function getLatestDataListByStationId($stationId, $numberOfHours, $columns) - { - $result = Array(); - if (!isInt($stationId) || !isInt($numberOfHours)) { - return $result; - } - - if (!in_array('timestamp', $columns)) { - // Just to be sure - $columns[] = 'timestamp'; - } - - $startTimestamp = time() - $numberOfHours*60*60; - $sql = 'select ' . implode(',', $columns) . ', position_timestamp from packet - where station_id = ? - and timestamp >= ? - and (speed is not null or altitude is not null) - and map_id in (1,12,5,7,9) - order by timestamp'; - $arg = [$stationId, $startTimestamp]; - - $pdo = PDOConnection::getInstance(); - $stmt = $pdo->prepareAndExec($sql, $arg); - $records = $stmt->fetchAll(PDO::FETCH_ASSOC); - foreach ($records as $record) { - - // Add value for position start if position start is within interval - if ($record['position_timestamp'] != null && $record['position_timestamp'] < $record['timestamp'] && $record['position_timestamp'] >= $startTimestamp) { - $posRecord = $record; - $posRecord['timestamp'] = $posRecord['position_timestamp']; - unset($posRecord['position_timestamp']); - $result[] = $posRecord; - } - - // Add value from found packet - unset($record['position_timestamp']); - $result[] = $record; - } - - return $result; - } - - /** - * Get object list (only confirmed) - * @param array $stationIdList - * @param int $startTimestamp - * @param int $endTimestamp - * @return array - */ - public function getConfirmedObjectListByStationIdList($stationIdList, $startTimestamp, $endTimestamp) { - if (!isInt($startTimestamp) || !isInt($endTimestamp)) { - return $result; - } - - $sql = 'select * from packet where station_id in (' . implode(',', $stationIdList) . ') and timestamp > ? and timestamp < ? and map_id = 1 order by timestamp'; - $parameters = [$startTimestamp, $endTimestamp]; - return $this->getObjectListFromSql($sql, $parameters); - } -}