Port the data repeository over to the new structure

pull/26/head
Starbeamrainbowlabs 4 years ago
parent 828e7ad999
commit 3c2605dcb9
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 2
      logic/Actions/FetchData.php
  2. 10
      logic/Repositories/IMeasurementDataRepository.php
  3. 8
      logic/Repositories/MariaDBMeasurementDataRepository.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

@ -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);
}

@ -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

Loading…
Cancel
Save