mvp table with alc predict and ready date
All checks were successful
Build and Push Image / Build and push image (push) Has been skipped

This commit is contained in:
Andrew Ridgway 2024-09-16 03:25:20 +00:00
parent 436836d4ac
commit dc7fa20e92
2 changed files with 16 additions and 8 deletions

View File

@ -9,6 +9,9 @@ class BeerCharts():
def __init__(self): def __init__(self):
self.db = db_conn() self.db = db_conn()
def bar_chart(self, items, data):
return 0
def line_chart(self, title, field, limit): def line_chart(self, title, field, limit):
data = self.db.beer_db data = self.db.beer_db

View File

@ -24,24 +24,29 @@ class TableBuilder():
df_dict["final_reading"].append(record["final_reading"]) df_dict["final_reading"].append(record["final_reading"])
df = pd.DataFrame(data=df_dict) df = pd.DataFrame(data=df_dict)
sql = f""" sql = f"""
SELECT x.beer_run_id as "Beer Run", SELECT x.beer_run_id as beer_run_id,
max(sg) as "Max", max(sg) as max,
min(sg) as "Min" min(sg) as min,
y.date as final_reading_date
FROM df x FROM df x
JOIN JOIN
( SELECT DISTINCT beer_run_id ( SELECT DISTINCT beer_run_id, date
FROM df FROM df
WHERE final_reading = 'True' WHERE final_reading = 'True'
) y ON x.beer_run_id = y.beer_run_id ) y ON x.beer_run_id = y.beer_run_id
GROUP BY x.beer_run_id GROUP BY x.beer_run_id, y.date
ORDER BY x.beer_run_id desc ORDER BY x.beer_run_id desc
LIMIT {limit} LIMIT {limit}
""" """
df_sum = duckdb.sql(sql).df() df_sum = duckdb.sql(sql).df()
sql = f""" sql = f"""
SELECT *, SELECT x.beer_run_id as "Beer Run",
ROUND(((CAST (max AS INTEGER) - CAST(min AS INTEGER)) / 7.36) + 0.5, 2) AS "Alcohol Prediction" x.max as "Max",
FROM df_sum x.min as "Min",
ROUND(((CAST (max AS INTEGER) - CAST(min AS INTEGER)) / 7.36) + 0.5, 2) AS "Alcohol Prediction",
cast(final_reading_date as DATE) + INTERVAL 14 DAY as "Ready Date"
FROM df_sum x
""" """
df_calc = duckdb.sql(sql).df() df_calc = duckdb.sql(sql).df()
return df_calc return df_calc