In this recipe, we'll learn how to create an interactive Streamlit app to analyse energy usage with chdb.
Generate usage data
poetry run python datagen.pyThis writes data into data.csv
curl https://clickhouse.com/ | shLaunch ClickHouse Local
./clickhouse local -m --path energy.chdb## Ingest data
CREATE DATABASE energy;CREATE TABLE IF NOT EXISTS energy.tariffs
ENGINE = MergeTree
ORDER BY day
AS
SELECT arrayJoin(arrayMap(
x -> addDays(startDate, x),
range(dateDiff('days', startDate, endDate) + 1)
)) AS day, *
FROM file(`data/tariffs.csv`)
SETTINGS schema_inference_make_columns_nullable=0;CREATE TABLE energy.usage
ENGINE = MergeTree
ORDER BY epochTimestamp AS
SELECT *
FROM `data/data.csv`
SETTINGS schema_inference_make_columns_nullable=0;Make sure you exit ClickHouse Local first (type exit;)
poetry run streamlit run app.py --server.headless true