Port the data repeository over to the new structure

This commit is contained in:
Starbeamrainbowlabs 2019-02-18 20:44:37 +00:00
parent 828e7ad999
commit 3c2605dcb9
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 10 additions and 10 deletions

View File

@ -63,7 +63,7 @@ class FetchData implements IAction {
// 2: Pull data from database // 2: Pull data from database
$data = $this->measurement_repo->get_readings_by_date( $data = $this->measurement_repo->get_readings_by_date(
new \DateTime($_GET["datetime"]), new \DateTime($_GET["datetime"]),
$_GET["reading_type"] $measurement_type_id
); );
// 2.5: Validate data from database // 2.5: Validate data from database

View File

@ -6,11 +6,11 @@ interface IMeasurementDataRepository {
/** /**
* Returns the specified reading type for all devices at the specified date * Returns the specified reading type for all devices at the specified date
* and time. * and time.
* @param DateTime $datetime The date and time to get the readings for. * @param DateTime $datetime The date and time to get the readings for.
* @param string $reading_type The reading type to fetch. * @param int $reading_type_id The reading type id to fetch.
* @return array The requested readings. * @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. * 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. * 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 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 $start The starting DateTime.
* @param DateTime $end The ending 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. * @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. * @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);
} }

View File

@ -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; $s = $this->get_static;
$o = $this->get_static_extra; $o = $this->get_static_extra;
return $this->database->query( return $this->database->query(
@ -88,7 +88,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
", [ ", [
// The database likes strings, not PHP DateTime() instances // The database likes strings, not PHP DateTime() instances
"datetime" => $datetime->format(\DateTime::ISO8601), "datetime" => $datetime->format(\DateTime::ISO8601),
"reading_type" => $reading_type, "reading_type" => $type_id,
"max_reading_timediff" => $this->settings->get("data.max_reading_timediff") "max_reading_timediff" => $this->settings->get("data.max_reading_timediff")
] ]
)->fetchAll(); )->fetchAll();
@ -113,7 +113,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
)->fetch(); )->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) if($average_seconds < 1)
throw new Exception("Error: average_seconds must be greater than 1, but '$average_seconds' was specified."); throw new Exception("Error: average_seconds must be greater than 1, but '$average_seconds' was specified.");
$s = $this->get_static; $s = $this->get_static;
@ -146,7 +146,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
{$s("table_name_metadata")}.{$s("column_metadata_storedon")} {$s("table_name_metadata")}.{$s("column_metadata_storedon")}
)) / :average_seconds);", [ )) / :average_seconds);", [
"device_id" => $device_id, "device_id" => $device_id,
"reading_type" => $reading_type, "reading_type" => $type_id,
"start_datetime" => $start->format(\DateTime::ISO8601), "start_datetime" => $start->format(\DateTime::ISO8601),
"end_datetime" => $end->format(\DateTime::ISO8601), "end_datetime" => $end->format(\DateTime::ISO8601),
"average_seconds" => $average_seconds "average_seconds" => $average_seconds