v0.4.2
This commit is contained in:
@@ -63,6 +63,29 @@ CREATE TABLE IF NOT EXISTS readings (
|
||||
CREATE INDEX IF NOT EXISTS readings_device_time_idx
|
||||
ON readings(device_id, timestamp DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS zone_readings (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
zone_id TEXT NOT NULL,
|
||||
device_id TEXT NOT NULL,
|
||||
timestamp TEXT NOT NULL,
|
||||
gree_temperature REAL,
|
||||
external_temperature REAL,
|
||||
control_temperature REAL,
|
||||
target_temperature REAL,
|
||||
device_setpoint REAL,
|
||||
outdoor_temperature REAL,
|
||||
power INTEGER NOT NULL,
|
||||
mode TEXT NOT NULL,
|
||||
fan_speed INTEGER NOT NULL,
|
||||
demand INTEGER NOT NULL,
|
||||
control_source TEXT NOT NULL,
|
||||
active_preset TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS zone_readings_zone_time_idx
|
||||
ON zone_readings(zone_id, timestamp DESC);
|
||||
CREATE INDEX IF NOT EXISTS zone_readings_time_idx
|
||||
ON zone_readings(timestamp DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS event_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp TEXT NOT NULL,
|
||||
@@ -85,6 +108,8 @@ INSERT OR IGNORE INTO schema_migrations(version, applied_at)
|
||||
VALUES (1, strftime('%Y-%m-%dT%H:%M:%fZ','now'));
|
||||
INSERT OR IGNORE INTO schema_migrations(version, applied_at)
|
||||
VALUES (2, strftime('%Y-%m-%dT%H:%M:%fZ','now'));
|
||||
INSERT OR IGNORE INTO schema_migrations(version, applied_at)
|
||||
VALUES (3, strftime('%Y-%m-%dT%H:%M:%fZ','now'));
|
||||
"#;
|
||||
|
||||
pub const COUNT_DEVICES: &str = "SELECT COUNT(*) FROM devices";
|
||||
@@ -175,6 +200,68 @@ LIMIT ?2
|
||||
|
||||
pub const PRUNE_READINGS: &str = "DELETE FROM readings WHERE timestamp < ?1";
|
||||
|
||||
pub const INSERT_ZONE_READING_IF_DUE: &str = r#"
|
||||
INSERT INTO zone_readings(
|
||||
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
|
||||
)
|
||||
SELECT ?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM zone_readings WHERE zone_id=?1 AND timestamp>=?16 LIMIT 1
|
||||
)
|
||||
"#;
|
||||
|
||||
pub const LIST_ZONE_READINGS_BY_ZONE: &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 zone_id=?1 AND timestamp>=?2
|
||||
ORDER BY timestamp ASC
|
||||
LIMIT ?3
|
||||
"#;
|
||||
|
||||
pub const LIST_ZONE_READINGS_ALL: &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 LIST_ZONE_HISTORY_BY_ZONE_BUCKETED: &str = r#"
|
||||
SELECT MIN(id),zone_id,MAX(device_id),MIN(timestamp),
|
||||
AVG(gree_temperature),AVG(external_temperature),AVG(control_temperature),
|
||||
AVG(target_temperature),AVG(device_setpoint),AVG(outdoor_temperature),
|
||||
MAX(power),MAX(mode),CAST(ROUND(AVG(fan_speed)) AS INTEGER),MAX(demand),
|
||||
MAX(control_source),MAX(active_preset)
|
||||
FROM zone_readings
|
||||
WHERE zone_id=?1 AND timestamp>=?2
|
||||
GROUP BY zone_id, CAST(unixepoch(timestamp)/?3 AS INTEGER)
|
||||
ORDER BY MIN(timestamp) ASC
|
||||
LIMIT ?4
|
||||
"#;
|
||||
|
||||
pub const LIST_ZONE_HISTORY_ALL_BUCKETED: &str = r#"
|
||||
SELECT MIN(id),zone_id,MAX(device_id),MIN(timestamp),
|
||||
AVG(gree_temperature),AVG(external_temperature),AVG(control_temperature),
|
||||
AVG(target_temperature),AVG(device_setpoint),AVG(outdoor_temperature),
|
||||
MAX(power),MAX(mode),CAST(ROUND(AVG(fan_speed)) AS INTEGER),MAX(demand),
|
||||
MAX(control_source),MAX(active_preset)
|
||||
FROM zone_readings
|
||||
WHERE timestamp>=?1
|
||||
GROUP BY zone_id, CAST(unixepoch(timestamp)/?2 AS INTEGER)
|
||||
ORDER BY MIN(timestamp) ASC
|
||||
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 PRUNE_ZONE_READINGS: &str = "DELETE FROM zone_readings WHERE timestamp < ?1";
|
||||
|
||||
pub const INSERT_EVENT: &str =
|
||||
"INSERT INTO event_log(timestamp,level,kind,message,metadata) VALUES(?1,?2,?3,?4,?5)";
|
||||
pub const LIST_EVENTS: &str =
|
||||
|
||||
Reference in New Issue
Block a user