Rewrite electricity-logger to use an sqlite3 database

This commit is contained in:
2022-06-25 22:17:46 +02:00
parent 458d824dc8
commit 5b09b06bcf
62 changed files with 5937 additions and 3 deletions

32
script/electricity/createdb.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: $0 [/path/to/db/database].db";
exit 1;
fi
echo "Creating database file $1...";
touch "$1";
if ! [ -f "$1" ]; then
echo "Cannot open or create database file $1, aborting.";
exit 1;
fi
TABLE_NAME="ElectricityLog";
echo "Creating table $TABLE_NAME...";
sqlite3 $1 "CREATE TABLE IF NOT EXISTS $TABLE_NAME (\
Date TEXT NOT NULL,\
TimeUtc TEXT NOT NULL,\
CurrentPowerUsage REAL NOT NULL,\
TotalPowerConsumptionDay REAL NOT NULL,\
TotalPowerConsumptionNight REAL NOT NULL,\
CurrentPowerReturn REAL NOT NULL,\
TotalPowerReturnDay REAL NOT NULL,\
TotalPowerReturnNight REAL NOT NULL,\
DayTarifEnabled INTEGER NOT NULL,\
GasConsumptionInCubicMeters REAL NOT NULL);";
echo "Creating indexes on table $TABLE_NAME...";
sqlite3 $1 "CREATE INDEX IF NOT EXISTS idx_Date ON $TABLE_NAME (Date);"
sqlite3 $1 "CREATE INDEX IF NOT EXISTS idx_TimeUtc ON $TABLE_NAME (TimeUtc);"