Browse Source

[server/fetch-data] Dedupe records & add property to indicate the # of records

pull/26/head
Starbeamrainbowlabs 4 years ago
parent
commit
3a62ef08d9
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 8
      logic/Repositories/MariaDBMeasurementDataRepository.php
  2. 2
      settings.default.toml

8
logic/Repositories/MariaDBMeasurementDataRepository.php

@ -55,7 +55,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { @@ -55,7 +55,7 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
return $this->database->query(
"SELECT
{$s("table_name_values")}.*,
{$s("table_name_metadata")}.device_id,
{$s("table_name_metadata")}.{$s("column_metadata_device_id")},
COALESCE(
{$s("table_name_metadata")}.{$s("column_metadata_recordedon")},
{$s("table_name_metadata")}.{$s("column_metadata_storedon")}
@ -67,7 +67,8 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { @@ -67,7 +67,8 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
COALESCE(
{$s("table_name_metadata")}.{$s("column_metadata_long")},
{$o(MariaDBDeviceRepository::class, "table_name")}.{$o(MariaDBDeviceRepository::class, "column_long")}
) AS longitude
) AS longitude,
COUNT({$s("table_name_metadata")}.{$s("column_metadata_device_id")}) AS record_count
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 {$o(MariaDBDeviceRepository::class, "table_name")} ON {$s("table_name_metadata")}.{$s("column_metadata_device_id")} = {$o(MariaDBDeviceRepository::class, "table_name")}.{$o(MariaDBDeviceRepository::class, "column_device_id")}
@ -80,7 +81,8 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository { @@ -80,7 +81,8 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
))) < :max_reading_timediff
AND
{$s("table_name_values")}.{$s("column_values_reading_type")} = :reading_type
GROUP BY {$s("table_name_metadata")}.{$s("column_metadata_device_id")}
ORDER BY {$s("table_name_metadata")}.{$s("column_metadata_recordedon")}
", [
// The database likes strings, not PHP DateTime() instances
"datetime" => $datetime->format(\DateTime::ISO8601),

2
settings.default.toml

@ -44,4 +44,4 @@ max-age = 2592000 # 30 days @@ -44,4 +44,4 @@ max-age = 2592000 # 30 days
# need to be a bit 'fuzzy' about which readings we consider to be part of which
# time-step. Ideally, this value should be half of the actual data recording
# interval.
max_reading_timediff = 15
max_reading_timediff = 180

Loading…
Cancel
Save