--- a/common.inc.php +++ b/common.inc.php @@ -1,14 +1,25 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die('Unable to connect to database server.'); +} +catch (Exception $e) { + die('Unknown error in ' . __FILE__ . '.'); +} +$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $basePath = ""; $DATA_DIR = "./data"; /** Returns the offset from the origin timezone to the remote timezone, in seconds. - * @param $remote_tz; - * @param $origin_tz; If null the servers current timezone is used as the origin. - * @return int; + * @param $remote_tz; + * @param $origin_tz; If null the servers current timezone is used as the origin. + * @return int; */ -function get_timezone_offset($remote_tz, $origin_tz = null) { +function get_timezone_offset($remote_tz, $origin_tz = null) +{ if ($origin_tz === null) { if (!is_string($origin_tz = date_default_timezone_get())) { return false; // A UTC timestamp was returned -- bail out! @@ -22,138 +33,71 @@ return $offset; } -function getSensorValuesByHour($sensorID, $timeFrom, $timeTo) { - $sql = 'select min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings - group by tgid, date_trunc(\'hour\', call_timestamp) order by time'; - $query = $this->db->query($sql, Array($sensorID, $timeFrom, $timeTo)); - return $query->result_array(); -} - -function getSensorValuesByDay($sensorID, $dayFrom, $dayTo) { - $sql = 'select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ? - group by sensor_id, date_trunc(\'day\', time) order by time'; - - $query = $this->db->query($sql, Array($sensorID)); - return $query->result_array(); -} - -function getSensorDataYears($sensorID, $timeFrom, $timeTo) { - $sql = "select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year"; - - $query = $this->db->query($sql, Array($sensorID)); - return $query->result_array(); -} - -function getSensorDataMonths($sensorID, $timeFrom, $timeTo) { - $sql = "select distinct extract('month' from time) as month, extract('year' from time) as year from sensor_values where sensor_id = ? order by year, month"; - - $query = $this->db->query($sql, Array($sensorID)); - return $query->result_array(); -} - -function getSensorDataDays($sensorID, $timeFrom, $timeTo) { - $sql = "select distinct extract('day' from time) as day, extract('month' from time) as month, extract('year' from time) as year from sensor_values where sensor_id = ? order by year,month,day"; - - $query = $this->db->query($sql, Array($sensorID)); - return $query->result_array(); -} - -function include_header($title) { +function include_header($title) +{ global $basePath; ?> + + + + + + + + + + - - - - - - - + - - + + + + + + + + + + + - <?php echo $title; ?> - Scannr + + - - - - +function include_footer() +{ + global $basePath; + ?> - - + + + + - - + - - - - -
- - -
- - - - - - - - - - - - - - - - - - -