store raw data

This commit is contained in:
grove5_admin committed 2026-04-30 18:53:42 -07:00
1 parent 3332df2f9c
commit 797af1562d
2 files changed
+33 -1

No files matched your search

+23
View File
@@ -58,6 +58,11 @@ CREATE TABLE IF NOT EXISTS payloads (
pressure_hpa REAL, pressure_hpa REAL,
ambient_valid INTEGER, -- bool ambient_valid INTEGER, -- bool
-- Raw ADC values (for time-series storage and future reprocessing)
adc_temp INTEGER, -- raw 20-bit temperature ADC
adc_hum INTEGER, -- raw 16-bit humidity ADC
adc_pres INTEGER, -- raw 20-bit pressure ADC
-- CO2 (SCD43, fruiting only) -- CO2 (SCD43, fruiting only)
co2_ppm INTEGER, co2_ppm INTEGER,
co2_valid INTEGER, -- bool co2_valid INTEGER, -- bool
@@ -110,6 +115,10 @@ CREATE TABLE IF NOT EXISTS sweep_points (
resistance_corr REAL, -- humidity corrected (null until processed) resistance_corr REAL, -- humidity corrected (null until processed)
resistance_norm REAL, -- baseline normalized (null until baseline) resistance_norm REAL, -- baseline normalized (null until baseline)
-- Raw gas ADC values (for time-series and future modelling)
adc_gas_res INTEGER, -- raw 10-bit gas ADC
gas_range INTEGER, -- gas range 0-15
-- Validity flags -- Validity flags
heater_stable INTEGER, -- bool heater_stable INTEGER, -- bool
valid INTEGER -- bool valid INTEGER -- bool
@@ -247,3 +256,17 @@ CREATE TABLE IF NOT EXISTS schema_version (
INSERT OR IGNORE INTO schema_version (version, description) INSERT OR IGNORE INTO schema_version (version, description)
VALUES (1, 'Initial schema — runs, payloads, sweep_points, baselines, anomalies, co2e_calibration'); VALUES (1, 'Initial schema — runs, payloads, sweep_points, baselines, anomalies, co2e_calibration');
-- ── Migration: v2 — raw ADC columns ──────────────────────────────────────
-- Add raw ADC columns for time-series storage and future reprocessing.
-- These are idempotent — safe to re-run on existing databases.
ALTER TABLE payloads ADD COLUMN adc_temp INTEGER;
ALTER TABLE payloads ADD COLUMN adc_hum INTEGER;
ALTER TABLE payloads ADD COLUMN adc_pres INTEGER;
ALTER TABLE sweep_points ADD COLUMN adc_gas_res INTEGER;
ALTER TABLE sweep_points ADD COLUMN gas_range INTEGER;
INSERT OR IGNORE INTO schema_version (version, description)
VALUES (2, 'Add raw ADC columns: adc_temp, adc_hum, adc_pres, adc_gas_res, gas_range');
+10 -1
View File
@@ -164,6 +164,7 @@ async def insert_payload(
INSERT INTO payloads ( INSERT INTO payloads (
run_id, chamber_id, collected_at, received_at, raw_json, run_id, chamber_id, collected_at, received_at, raw_json,
temp_c, humidity_pct, pressure_hpa, ambient_valid, temp_c, humidity_pct, pressure_hpa, ambient_valid,
adc_temp, adc_hum, adc_pres,
co2_ppm, co2_valid, co2_ppm, co2_valid,
co2e_ppm, co2e_confidence, voc_ppb, co2e_ppm, co2e_confidence, voc_ppb,
z1_score, z2_score, z3_score, z1_score, z2_score, z3_score,
@@ -172,6 +173,7 @@ async def insert_payload(
) VALUES ( ) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?,
@@ -191,6 +193,10 @@ async def insert_payload(
raw.ambient.pressure_hpa, raw.ambient.pressure_hpa,
int(raw.ambient.valid), int(raw.ambient.valid),
raw.ambient.adc_temp,
raw.ambient.adc_hum,
raw.ambient.adc_pres,
raw.co2.ppm if raw.co2 else None, raw.co2.ppm if raw.co2 else None,
int(raw.co2.valid) if raw.co2 else None, int(raw.co2.valid) if raw.co2 else None,
@@ -240,6 +246,8 @@ async def insert_sweep_points(
p.resistance_raw, p.resistance_raw,
p.resistance_corr, p.resistance_corr,
p.resistance_norm, p.resistance_norm,
p.adc_gas_res,
p.gas_range,
int(p.heater_stable), int(p.heater_stable),
int(p.valid), int(p.valid),
) )
@@ -252,8 +260,9 @@ async def insert_sweep_points(
payload_id, chamber_id, collected_at, payload_id, chamber_id, collected_at,
heater_temp_c, heater_dur_ms, zone, heater_temp_c, heater_dur_ms, zone,
resistance_raw, resistance_corr, resistance_norm, resistance_raw, resistance_corr, resistance_norm,
adc_gas_res, gas_range,
heater_stable, valid heater_stable, valid
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", """,
rows, rows,
) )