--- a/common.inc.php +++ b/common.inc.php @@ -1,6 +1,18 @@ 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; @@ -21,97 +33,42 @@ return $offset; } -function getSensorValuesByHour($sensorID, $timeFrom, $timeTo) { - $sql = 'select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ? - and extract(epoch from time) > ? and extract(epoch from time) < ? - group by sensor_id, date_trunc(\'hour\', time) 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 time) as year from sensor_values where sensor_id = ? 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 - - - - - - - - - - - - - - - - - - - -
+ -
- - - - - - - - - - - - - - - - + + + +