--- /dev/null
+attach :hrldb as hrl;
+create table if not exists hrl.data (
+ dt int,
+ addr text,
+ count int,
+ batt float,
+ mint float,
+ temp float,
+ maxt float,
+ minh float,
+ humid float,
+ maxh float,
+ primary key(dt, addr)
+) without rowid;
+
+attach :rawdb as raw;
+insert or ignore into hrl.data (dt, addr, count, batt, mint, temp, maxt, minh, humid, maxh)
+select strftime("%s", strftime("%Y-%m-%d %H:00:00", dt, "unixepoch")) hour,
+ addr,
+ count(*) count,
+ avg(batt) batt,
+ min(temp) mint,
+ avg(temp) temp,
+ max(temp) maxt,
+ min(humid) minh,
+ avg(humid) humid,
+ max(humid) maxh
+from raw.data where dt < strftime("%s", strftime("%Y-%m-%d %H:00:00", unixepoch(), "unixepoch"))
+group by strftime("%Y-%m-%d %H", dt, "unixepoch"), addr;
+
+delete from raw.data where dt < strftime("%s", datetime(strftime("%Y-%m-%d %H:00:00"), "-1 hour"));
+tbcncollector (1.00) experimental; urgency=low
+
+ * Hourly aggregation
+
+ -- Eugene Crosser <crosser@average.org> Fri, 26 Jul 2024 22:47:09 +0200
+
tbcncollector (0.01) experimental; urgency=low
* Initial version
Section: python
Depends: adduser,
python3-bleak,
+ sqlite3,
${misc:Depends},
${python3:Depends}
Description: Daemon to collect data from ThermoBeacons
# Environment for tbcncollector
-OPTIONS=""
+RAW_DB="/var/lib/tbcncollector/raw.db"
+HOURLY_DB="/var/lib/tbcncollector/hourly.db"
README.md var/lib/tbcncollector
+aggregate.sql usr/share/tbcncollector/
%:
dh $@ --with python3 --buildsystem pybuild
+
+override_dh_installsystemd:
+ dh_installsystemd --name=tbcncollector
+ dh_installsystemd --name=tbcncollector-hourly
+
--- /dev/null
+[Unit]
+Description=Aggregate tbncollector data on hourly basis
+Wants=tbcncollector-hourly.timer
+
+[Service]
+Type=oneshot
+EnvironmentFile=-/etc/default/tbcncollector
+ExecStart=/usr/bin/sqlite3 "" ".param set :rawdb "${RAW_DB} \
+ ".param set :hrldb "${HOURLY_DB} \
+ ".read /usr/share/tbcncollector/aggregate.sql"
+StandardOutput=journal
+StandardError=inherit
+User=tbcncollector
+Group=tbcncollector
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+[Unit]
+Description=Aggregate tbncollector data on hourly basis
+Requires=tbcncollector-hourly.service
+
+[Timer]
+Unit=tbcncollector-hourly.service
+OnCalendar=*-*-* *:05:00
+
+[Install]
+WantedBy=timers.target
[Service]
Type=simple
EnvironmentFile=-/etc/default/tbcncollector
-ExecStart=python3 -m tbcncollector $OPTIONS
+ExecStart=python3 -m tbcncollector $RAW_DB
KillSignal=INT
Restart=on-failure
StandardOutput=journal