mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-22 06:23:01 +00:00
Revert "Don't use the new datetime computed column until the issues are worked out"
This reverts commit 97e234b920
.
This commit is contained in:
parent
99e0aba81d
commit
030d0cb9be
1 changed files with 12 additions and 17 deletions
|
@ -30,8 +30,6 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
public static $column_metadata_lat = "reading_latitude";
|
public static $column_metadata_lat = "reading_latitude";
|
||||||
public static $column_metadata_long = "reading_longitude";
|
public static $column_metadata_long = "reading_longitude";
|
||||||
|
|
||||||
public static $column_metadata_datetime_poly;
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
/** @var TomlConfig */
|
/** @var TomlConfig */
|
||||||
|
@ -64,9 +62,6 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
$this->database = $in_database;
|
$this->database = $in_database;
|
||||||
$this->settings = $in_settings;
|
$this->settings = $in_settings;
|
||||||
|
|
||||||
self::$column_metadata_datetime_poly = "COALESCE(".self::$table_name_metadata.".".self::$column_metadata_recordedon.",".self::$table_name_metadata.".".self::$column_metadata_storedon.")";
|
|
||||||
|
|
||||||
|
|
||||||
$this->get_static = function($name) { return self::$$name; };
|
$this->get_static = function($name) { return self::$$name; };
|
||||||
$this->get_static_extra = function($class_name, $name) {
|
$this->get_static_extra = function($class_name, $name) {
|
||||||
return $class_name::$$name;
|
return $class_name::$$name;
|
||||||
|
@ -89,17 +84,17 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
{$s("table_name_values")}.{$s("column_values_reading_id")},
|
{$s("table_name_values")}.{$s("column_values_reading_id")},
|
||||||
|
|
||||||
{$s("table_name_metadata")}.{$s("column_metadata_device_id")},
|
{$s("table_name_metadata")}.{$s("column_metadata_device_id")},
|
||||||
{$s("column_metadata_datetime_poly")} AS datetime,
|
{$s("table_name_metadata")}.{$s("column_metadata_datetime")} AS datetime,
|
||||||
COUNT({$s("table_name_metadata")}.{$s("column_metadata_device_id")}) AS record_count
|
COUNT({$s("table_name_metadata")}.{$s("column_metadata_device_id")}) AS record_count
|
||||||
FROM {$s("table_name_values")}
|
FROM {$s("table_name_values")}
|
||||||
JOIN {$s("table_name_metadata")} ON {$s("table_name_values")}.{$s("column_values_reading_id")} = {$s("table_name_metadata")}.id
|
JOIN {$s("table_name_metadata")} ON {$s("table_name_values")}.{$s("column_values_reading_id")} = {$s("table_name_metadata")}.id
|
||||||
WHERE
|
WHERE
|
||||||
{$s("column_metadata_datetime_poly")} >= :start_datetime AND
|
{$s("table_name_metadata")}.{$s("column_metadata_datetime")} >= :start_datetime AND
|
||||||
{$s("column_metadata_datetime_poly")} <= :end_datetime
|
{$s("table_name_metadata")}.{$s("column_metadata_datetime")} <= :end_datetime
|
||||||
AND
|
AND
|
||||||
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type
|
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type
|
||||||
GROUP BY {$s("table_name_metadata")}.{$s("column_metadata_device_id")}
|
GROUP BY {$s("table_name_metadata")}.{$s("column_metadata_device_id")}
|
||||||
ORDER BY {$s("column_metadata_datetime_poly")}
|
ORDER BY {$s("table_name_metadata")}.{$s("column_metadata_datetime")}
|
||||||
", [
|
", [
|
||||||
"reading_type" => $type_id,
|
"reading_type" => $type_id,
|
||||||
// The database likes strings, not PHP DateTime() instances
|
// The database likes strings, not PHP DateTime() instances
|
||||||
|
@ -113,8 +108,8 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
$s = $this->get_static;
|
$s = $this->get_static;
|
||||||
return $this->database->query(
|
return $this->database->query(
|
||||||
"SELECT
|
"SELECT
|
||||||
MIN({$s("column_metadata_datetime_poly")}) AS start,
|
MIN({$s("table_name_metadata")}.{$s("column_metadata_datetime")}) AS start,
|
||||||
MAX({$s("column_metadata_datetime_poly")}) AS end
|
MAX({$s("table_name_metadata")}.{$s("column_metadata_datetime")}) AS end
|
||||||
FROM {$s("table_name_metadata")}
|
FROM {$s("table_name_metadata")}
|
||||||
WHERE {$s("table_name_metadata")}.{$s("column_metadata_device_id")} = :device_id;", [
|
WHERE {$s("table_name_metadata")}.{$s("column_metadata_device_id")} = :device_id;", [
|
||||||
"device_id" => $device_id
|
"device_id" => $device_id
|
||||||
|
@ -131,7 +126,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
AVG({$s("table_name_values")}.{$s("column_values_value")}) AS {$s("column_values_value")},
|
AVG({$s("table_name_values")}.{$s("column_values_value")}) AS {$s("column_values_value")},
|
||||||
MIN({$s("table_name_values")}.{$s("column_values_reading_id")}) AS {$s("column_values_reading_id")},
|
MIN({$s("table_name_values")}.{$s("column_values_reading_id")}) AS {$s("column_values_reading_id")},
|
||||||
|
|
||||||
MIN({$s("column_metadata_datetime_poly")}) AS datetime
|
MIN({$s("table_name_metadata")}.{$s("column_metadata_datetime")}) AS datetime
|
||||||
FROM {$s("table_name_values")}
|
FROM {$s("table_name_values")}
|
||||||
JOIN {$s("table_name_metadata")} ON
|
JOIN {$s("table_name_metadata")} ON
|
||||||
{$s("table_name_metadata")}.{$s("column_metadata_id")} = {$s("table_name_values")}.{$s("column_values_reading_id")}
|
{$s("table_name_metadata")}.{$s("column_metadata_id")} = {$s("table_name_values")}.{$s("column_values_reading_id")}
|
||||||
|
@ -139,9 +134,9 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
{$s("table_name_metadata")}.{$s("column_metadata_device_id")} = :device_id AND
|
{$s("table_name_metadata")}.{$s("column_metadata_device_id")} = :device_id AND
|
||||||
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type AND
|
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type AND
|
||||||
|
|
||||||
{$s("column_metadata_datetime_poly")} >= :start_datetime AND
|
{$s("table_name_metadata")}.{$s("column_metadata_datetime")} >= :start_datetime AND
|
||||||
{$s("column_metadata_datetime_poly")} <= :end_datetime
|
{$s("table_name_metadata")}.{$s("column_metadata_datetime")} <= :end_datetime
|
||||||
GROUP BY CEIL(UNIX_TIMESTAMP({$s("column_metadata_datetime_poly")}) / :average_seconds);", [
|
GROUP BY CEIL(UNIX_TIMESTAMP({$s("table_name_metadata")}.{$s("column_metadata_datetime")}) / :average_seconds);", [
|
||||||
"device_id" => $device_id,
|
"device_id" => $device_id,
|
||||||
"reading_type" => $type_id,
|
"reading_type" => $type_id,
|
||||||
"start_datetime" => $start->format(Constants::DATETIME_FORMAT_SQL),
|
"start_datetime" => $start->format(Constants::DATETIME_FORMAT_SQL),
|
||||||
|
@ -160,14 +155,14 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
||||||
{$s("table_name_values")}.{$s("column_values_value")} AS {$s("column_values_value")},
|
{$s("table_name_values")}.{$s("column_values_value")} AS {$s("column_values_value")},
|
||||||
{$s("table_name_values")}.{$s("column_values_reading_id")} AS {$s("column_values_reading_id")},
|
{$s("table_name_values")}.{$s("column_values_reading_id")} AS {$s("column_values_reading_id")},
|
||||||
|
|
||||||
{$s("column_metadata_datetime_poly")} AS datetime
|
{$s("table_name_metadata")}.{$s("column_metadata_datetime")} AS datetime
|
||||||
FROM {$s("table_name_values")}
|
FROM {$s("table_name_values")}
|
||||||
JOIN {$s("table_name_metadata")} ON
|
JOIN {$s("table_name_metadata")} ON
|
||||||
{$s("table_name_metadata")}.{$s("column_metadata_id")} = {$s("table_name_values")}.{$s("column_values_reading_id")}
|
{$s("table_name_metadata")}.{$s("column_metadata_id")} = {$s("table_name_values")}.{$s("column_values_reading_id")}
|
||||||
WHERE
|
WHERE
|
||||||
{$s("table_name_metadata")}.{$s("column_metadata_device_id")} = :device_id AND
|
{$s("table_name_metadata")}.{$s("column_metadata_device_id")} = :device_id AND
|
||||||
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type
|
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type
|
||||||
ORDER BY {$s("column_metadata_datetime_poly")} DESC
|
ORDER BY {$s("table_name_metadata")}.{$s("column_metadata_datetime")} DESC
|
||||||
LIMIT :count;", [
|
LIMIT :count;", [
|
||||||
"device_id" => $device_id,
|
"device_id" => $device_id,
|
||||||
"reading_type" => $type_id,
|
"reading_type" => $type_id,
|
||||||
|
|
Loading…
Reference in a new issue