--- a/common.inc.php +++ b/common.inc.php @@ -1,5 +1,15 @@ 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__ . '.'); +} $basePath = ""; $DATA_DIR = "./data"; @@ -22,96 +32,42 @@ 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) { global $basePath; ?> - + + + + + + + + + + + - - - - - - - + - - + + + + + + + + + + + - <?php echo $title; ?> - Scannr - - - - - - - - - - - - - - - - - - - -
+ -
- - - - - - - - - - - - - - - - + + + +