v0.5.0
This commit is contained in:
@@ -233,6 +233,12 @@ ORDER BY MIN(timestamp) ASC
|
||||
LIMIT ?3
|
||||
"#;
|
||||
|
||||
pub const LIST_DEVICE_HISTORY_BEFORE: &str = r#"
|
||||
SELECT id,device_id,timestamp,indoor_temperature,outdoor_temperature,target_temperature,power,source
|
||||
FROM readings WHERE timestamp < ?1 ORDER BY timestamp ASC LIMIT ?2
|
||||
"#;
|
||||
pub const DELETE_READING_BY_ID: &str = "DELETE FROM readings WHERE id=?1";
|
||||
|
||||
pub const PRUNE_READINGS: &str = "DELETE FROM readings WHERE timestamp < ?1";
|
||||
|
||||
pub const INSERT_ZONE_READING_IF_DUE: &str = r#"
|
||||
@@ -276,6 +282,13 @@ LIMIT ?3
|
||||
|
||||
pub const DELETE_ZONE_READINGS_BY_ZONE_ID: &str = "DELETE FROM zone_readings WHERE zone_id=?1";
|
||||
pub const DELETE_ZONE_READINGS_BY_DEVICE_ID: &str = "DELETE FROM zone_readings WHERE device_id=?1";
|
||||
pub const LIST_ZONE_HISTORY_BEFORE: &str = r#"
|
||||
SELECT id,zone_id,device_id,timestamp,gree_temperature,external_temperature,control_temperature,
|
||||
target_temperature,device_setpoint,outdoor_temperature,power,mode,fan_speed,demand,control_source,active_preset
|
||||
FROM zone_readings WHERE timestamp < ?1 ORDER BY timestamp ASC LIMIT ?2
|
||||
"#;
|
||||
pub const DELETE_ZONE_READING_BY_ID: &str = "DELETE FROM zone_readings WHERE id=?1";
|
||||
|
||||
pub const PRUNE_ZONE_READINGS: &str = "DELETE FROM zone_readings WHERE timestamp < ?1";
|
||||
|
||||
pub const INSERT_HA_READING_IF_DUE: &str = r#"
|
||||
@@ -306,8 +319,58 @@ ORDER BY MIN(timestamp) ASC
|
||||
LIMIT ?3
|
||||
"#;
|
||||
|
||||
pub const LIST_HA_HISTORY_BEFORE: &str = r#"
|
||||
SELECT id,entity_id,zone_id,kind,timestamp,temperature
|
||||
FROM ha_readings WHERE timestamp < ?1 ORDER BY timestamp ASC LIMIT ?2
|
||||
"#;
|
||||
pub const DELETE_HA_READING_BY_ID: &str = "DELETE FROM ha_readings WHERE id=?1";
|
||||
|
||||
pub const PRUNE_HA_READINGS: &str = "DELETE FROM ha_readings WHERE timestamp < ?1";
|
||||
|
||||
|
||||
// Tiered history compaction keeps only the resolution the charts can actually display.
|
||||
pub const COMPACT_DEVICE_HISTORY: &str = r#"
|
||||
DELETE FROM readings WHERE id IN (
|
||||
SELECT id FROM (
|
||||
SELECT id, ROW_NUMBER() OVER (
|
||||
PARTITION BY device_id, CAST(unixepoch(timestamp)/?1 AS INTEGER)
|
||||
ORDER BY timestamp DESC, id DESC
|
||||
) AS rn
|
||||
FROM readings WHERE timestamp < ?2 AND timestamp >= ?3
|
||||
) WHERE rn > 1
|
||||
)
|
||||
"#;
|
||||
|
||||
pub const COMPACT_ZONE_HISTORY: &str = r#"
|
||||
DELETE FROM zone_readings WHERE id IN (
|
||||
SELECT id FROM (
|
||||
SELECT id, ROW_NUMBER() OVER (
|
||||
PARTITION BY zone_id, CAST(unixepoch(timestamp)/?1 AS INTEGER)
|
||||
ORDER BY timestamp DESC, id DESC
|
||||
) AS rn
|
||||
FROM zone_readings WHERE timestamp < ?2 AND timestamp >= ?3
|
||||
) WHERE rn > 1
|
||||
)
|
||||
"#;
|
||||
|
||||
pub const COMPACT_HA_HISTORY: &str = r#"
|
||||
DELETE FROM ha_readings WHERE id IN (
|
||||
SELECT id FROM (
|
||||
SELECT id, ROW_NUMBER() OVER (
|
||||
PARTITION BY entity_id, COALESCE(zone_id,''), kind, CAST(unixepoch(timestamp)/?1 AS INTEGER)
|
||||
ORDER BY timestamp DESC, id DESC
|
||||
) AS rn
|
||||
FROM ha_readings WHERE timestamp < ?2 AND timestamp >= ?3
|
||||
) WHERE rn > 1
|
||||
)
|
||||
"#;
|
||||
|
||||
pub const CLEAR_CONFIGURATION: &str = r#"
|
||||
DELETE FROM schedules;
|
||||
DELETE FROM automations;
|
||||
DELETE FROM zones;
|
||||
DELETE FROM devices;
|
||||
"#;
|
||||
pub const HISTORY_COUNTS: &str = r#"
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM readings),
|
||||
|
||||
Reference in New Issue
Block a user