Läuft erst mal , speichern in SQLite-DB
This commit is contained in:
42
db.js
42
db.js
@@ -18,19 +18,16 @@ CREATE TABLE IF NOT EXISTS readings (
|
||||
ts INTEGER NOT NULL, -- Unix-Zeit in Sekunden (UTC)
|
||||
source TEXT NOT NULL, -- 'archive' | 'loop'
|
||||
temp_out REAL, -- °C
|
||||
temp_out_high REAL, -- °C (nur Archiv)
|
||||
temp_out_low REAL, -- °C (nur Archiv)
|
||||
temp_in REAL, -- °C
|
||||
hum_out INTEGER, -- %
|
||||
hum_in INTEGER, -- %
|
||||
wind_avg REAL, -- km/h
|
||||
wind_high REAL, -- km/h (nur Archiv)
|
||||
wind_dir TEXT, -- Himmelsrichtung
|
||||
wind_high_dir TEXT, -- Himmelsrichtung (nur Archiv)
|
||||
pressure REAL, -- hPa
|
||||
rain REAL, -- mm (Archiv: Intervall; Loop: Tagessumme)
|
||||
rain_rate REAL, -- mm/h
|
||||
solar_rad INTEGER, -- W/m²
|
||||
forecast INTEGER, -- Forecast Icons Byte (nur Loop)
|
||||
UNIQUE(ts, source)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_readings_ts ON readings(ts);
|
||||
@@ -67,33 +64,30 @@ export function getLatestTs(db) {
|
||||
|
||||
const INSERT_SQL = `
|
||||
INSERT OR IGNORE INTO readings
|
||||
(ts, source, temp_out, temp_out_high, temp_out_low, temp_in,
|
||||
hum_out, hum_in, wind_avg, wind_high, wind_dir, wind_high_dir,
|
||||
pressure, rain, rain_rate, solar_rad)
|
||||
(ts, source, temp_out, temp_in,
|
||||
hum_out, hum_in, wind_avg, wind_high, wind_dir,
|
||||
pressure, rain, rain_rate, forecast)
|
||||
VALUES
|
||||
(@ts, @source, @temp_out, @temp_out_high, @temp_out_low, @temp_in,
|
||||
@hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir, @wind_high_dir,
|
||||
@pressure, @rain, @rain_rate, @solar_rad)
|
||||
(@ts, @source, @temp_out, @temp_in,
|
||||
@hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir,
|
||||
@pressure, @rain, @rain_rate, @forecast)
|
||||
`;
|
||||
|
||||
function toRow(record, source) {
|
||||
return {
|
||||
ts: Math.floor(record.time.getTime() / 1000),
|
||||
source,
|
||||
temp_out: record.tempOut ?? null,
|
||||
temp_out_high: record.tempOutHigh ?? null,
|
||||
temp_out_low: record.tempOutLow ?? null,
|
||||
temp_in: record.tempIn ?? null,
|
||||
hum_out: record.humOut ?? null,
|
||||
hum_in: record.humIn ?? null,
|
||||
wind_avg: record.windAvg ?? null,
|
||||
wind_high: record.windHigh ?? null,
|
||||
wind_dir: record.windDir ?? null,
|
||||
wind_high_dir: record.windHighDir ?? null,
|
||||
pressure: record.pressure ?? null,
|
||||
rain: record.rain ?? null,
|
||||
rain_rate: record.rainRate ?? null,
|
||||
solar_rad: record.solarRad ?? null,
|
||||
temp_out: record.tempOut ?? null,
|
||||
temp_in: record.tempIn ?? null,
|
||||
hum_out: record.humOut ?? null,
|
||||
hum_in: record.humIn ?? null,
|
||||
wind_avg: record.windAvg ?? null,
|
||||
wind_high: record.windGust ?? null,
|
||||
wind_dir: record.windDir ?? null,
|
||||
pressure: record.pressure ?? null,
|
||||
rain: record.rain ?? null,
|
||||
rain_rate: record.rainRate ?? null,
|
||||
forecast: record.forecast ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user