From 3c2605dcb9ef2feb03aa56cd310cf54958f0d9aa Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 18 Feb 2019 20:44:37 +0000 Subject: [PATCH] Port the data repeository over to the new structure --- logic/Actions/FetchData.php | 2 +- logic/Repositories/IMeasurementDataRepository.php | 10 +++++----- .../Repositories/MariaDBMeasurementDataRepository.php | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/logic/Actions/FetchData.php b/logic/Actions/FetchData.php index 241a70d..6c5418e 100644 --- a/logic/Actions/FetchData.php +++ b/logic/Actions/FetchData.php @@ -63,7 +63,7 @@ class FetchData implements IAction { // 2: Pull data from database $data = $this->measurement_repo->get_readings_by_date( new \DateTime($_GET["datetime"]), - $_GET["reading_type"] + $measurement_type_id ); // 2.5: Validate data from database diff --git a/logic/Repositories/IMeasurementDataRepository.php b/logic/Repositories/IMeasurementDataRepository.php index 27bdf77..7220fb3 100644 --- a/logic/Repositories/IMeasurementDataRepository.php +++ b/logic/Repositories/IMeasurementDataRepository.php @@ -6,11 +6,11 @@ interface IMeasurementDataRepository { /** * Returns the specified reading type for all devices at the specified date * and time. - * @param DateTime $datetime The date and time to get the readings for. - * @param string $reading_type The reading type to fetch. + * @param DateTime $datetime The date and time to get the readings for. + * @param int $reading_type_id The reading type id to fetch. * @return array The requested readings. */ - public function get_readings_by_date(\DateTime $datetime, string $reading_type); + public function get_readings_by_date(\DateTime $datetime, int $reading_type_id); /** * Gets the first and last DateTimes of the readings for a specified device. @@ -21,12 +21,12 @@ interface IMeasurementDataRepository { /** * Gets the readings of a specified type for a specific device between the 2 given dates and times. * @param int $device_id The id of the device to fetch data for. - * @param string $reading_type The reading type to fetch. + * @param string $type_id The reading type to fetch. * @param DateTime $start The starting DateTime. * @param DateTime $end The ending DateTime. * @param int $average_seconds The number of seconds to averageg the data over. For example a value of 3600 (1 hour) will return 1 data point per hour, with the value of each point an average of all the readings for that hour. * @return array The requested data. */ - public function get_readings_by_device(int $device_id, string $reading_type, \DateTime $start, \DateTime $end, int $average_seconds = 1); + public function get_readings_by_device(int $device_id, int $type_id, \DateTime $start, \DateTime $end, int $average_seconds = 1); } diff --git a/logic/Repositories/MariaDBMeasurementDataRepository.php b/logic/Repositories/MariaDBMeasurementDataRepository.php index c3d3ef9..d1e53d8 100644 --- a/logic/Repositories/MariaDBMeasurementDataRepository.php +++ b/logic/Repositories/MariaDBMeasurementDataRepository.php @@ -49,7 +49,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { }; } - public function get_readings_by_date(\DateTime $datetime, string $reading_type) { + public function get_readings_by_date(\DateTime $datetime, int $type_id) { $s = $this->get_static; $o = $this->get_static_extra; return $this->database->query( @@ -88,7 +88,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { ", [ // The database likes strings, not PHP DateTime() instances "datetime" => $datetime->format(\DateTime::ISO8601), - "reading_type" => $reading_type, + "reading_type" => $type_id, "max_reading_timediff" => $this->settings->get("data.max_reading_timediff") ] )->fetchAll(); @@ -113,7 +113,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { )->fetch(); } - public function get_readings_by_device(int $device_id, string $reading_type, \DateTime $start, \DateTime $end, int $average_seconds = 1) { + public function get_readings_by_device(int $device_id, int $type_id, \DateTime $start, \DateTime $end, int $average_seconds = 1) { if($average_seconds < 1) throw new Exception("Error: average_seconds must be greater than 1, but '$average_seconds' was specified."); $s = $this->get_static; @@ -146,7 +146,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { {$s("table_name_metadata")}.{$s("column_metadata_storedon")} )) / :average_seconds);", [ "device_id" => $device_id, - "reading_type" => $reading_type, + "reading_type" => $type_id, "start_datetime" => $start->format(\DateTime::ISO8601), "end_datetime" => $end->format(\DateTime::ISO8601), "average_seconds" => $average_seconds