Merge pull request 'add in current runs table' (#3) from dev into master
All checks were successful
Build and Push Image / Build and push image (push) Successful in 15m47s
All checks were successful
Build and Push Image / Build and push image (push) Successful in 15m47s
Reviewed-on: #3
This commit is contained in:
commit
fb65ba4ee0
@ -30,6 +30,12 @@ def create_graphs():
|
|||||||
sg = chart.line_chart("SG", "sg", 30)
|
sg = chart.line_chart("SG", "sg", 30)
|
||||||
show(column(sg))
|
show(column(sg))
|
||||||
|
|
||||||
|
def data_frame_to_table(df) -> str:
|
||||||
|
|
||||||
|
tr_replace_string = '<tr align="center" style="border-bottom:1pt solid black;">'
|
||||||
|
return_html = df.to_html(col_space='75px', index=False,
|
||||||
|
justify='center', border=3).replace('<tr>', tr_replace_string)
|
||||||
|
return return_html
|
||||||
|
|
||||||
class userForm(FlaskForm):
|
class userForm(FlaskForm):
|
||||||
username = StringField("User Name?", validators=[DataRequired()])
|
username = StringField("User Name?", validators=[DataRequired()])
|
||||||
@ -64,10 +70,13 @@ def index():
|
|||||||
def updater():
|
def updater():
|
||||||
if 'logged_in' not in session:
|
if 'logged_in' not in session:
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
predicted_alc_table = table_builder.TableBuilder().table_build()
|
table_Data = table_builder.TableBuilder()
|
||||||
tr_replace_string = '<tr align="center" style="border-bottom:1pt solid black;">'
|
predicted_alc_table = table_Data.done_runs_build()
|
||||||
beer_html = predicted_alc_table.to_html(col_space='75px', index=False,
|
current_runs_table = table_Data.current_runs_build()
|
||||||
justify='center', border=3).replace('<tr>', tr_replace_string)
|
|
||||||
|
beer_html = data_frame_to_table(predicted_alc_table)
|
||||||
|
current_html = data_frame_to_table(current_runs_table)
|
||||||
|
|
||||||
query_db = beer_database_query.pool_query()
|
query_db = beer_database_query.pool_query()
|
||||||
query = query_db.get_top(10, "sg")
|
query = query_db.get_top(10, "sg")
|
||||||
form = dataForm()
|
form = dataForm()
|
||||||
@ -98,10 +107,10 @@ def updater():
|
|||||||
database.create_re_record(new_record["beer_run_id"], new_record["beer_type"], new_record["sg"],
|
database.create_re_record(new_record["beer_run_id"], new_record["beer_type"], new_record["sg"],
|
||||||
new_record["date"], final_run_value, new_record["comment"])
|
new_record["date"], final_run_value, new_record["comment"])
|
||||||
|
|
||||||
return render_template("updater.html", beer_data = beer_html
|
return render_template("updater.html", beer_data = beer_html, current_data = current_html
|
||||||
, list=query, form=form, success=True, updater_name = "Saucy Beer Maker")
|
, list=query, form=form, success=True, updater_name = "Saucy Beer Maker")
|
||||||
else:
|
else:
|
||||||
return render_template("updater.html", beer_data = beer_html
|
return render_template("updater.html", beer_data = beer_html, current_data = current_html
|
||||||
, list=query, form=form, sucess=False)
|
, list=query, form=form, sucess=False)
|
||||||
|
|
||||||
# @app.route("/update_db", methods=["POST"])
|
# @app.route("/update_db", methods=["POST"])
|
||||||
|
@ -7,8 +7,6 @@ import duckdb
|
|||||||
class TableBuilder():
|
class TableBuilder():
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.db = db_conn()
|
self.db = db_conn()
|
||||||
|
|
||||||
def table_build(self, limit=10) -> pd.DataFrame:
|
|
||||||
data = self.db.beer_db
|
data = self.db.beer_db
|
||||||
data = data.find({}).sort("date", -1)
|
data = data.find({}).sort("date", -1)
|
||||||
df_dict = {}
|
df_dict = {}
|
||||||
@ -21,8 +19,14 @@ class TableBuilder():
|
|||||||
df_dict["beer_run_id"].append(record["beer_run_id"])
|
df_dict["beer_run_id"].append(record["beer_run_id"])
|
||||||
df_dict["sg"].append(record["sg"])
|
df_dict["sg"].append(record["sg"])
|
||||||
df_dict["date"].append(record["date"])
|
df_dict["date"].append(record["date"])
|
||||||
df_dict["final_reading"].append(record["final_reading"])
|
df_dict["final_reading"].append(record["final_reading"])
|
||||||
df = pd.DataFrame(data=df_dict)
|
|
||||||
|
self.df_dict = df_dict
|
||||||
|
self.df = pd.DataFrame(data=self.df_dict)
|
||||||
|
|
||||||
|
def done_runs_build(self, limit=10) -> pd.DataFrame:
|
||||||
|
|
||||||
|
df = self.df
|
||||||
sql = f"""
|
sql = f"""
|
||||||
SELECT x.beer_run_id as beer_run_id,
|
SELECT x.beer_run_id as beer_run_id,
|
||||||
max(sg) as max,
|
max(sg) as max,
|
||||||
@ -43,7 +47,7 @@ class TableBuilder():
|
|||||||
SELECT x.beer_run_id as "Beer Run",
|
SELECT x.beer_run_id as "Beer Run",
|
||||||
x.max as "Max",
|
x.max as "Max",
|
||||||
x.min as "Min",
|
x.min as "Min",
|
||||||
ROUND(((CAST (max AS INTEGER) - CAST(min AS INTEGER)) / 7.36) + 0.5, 2) AS "Alcohol Prediction",
|
ROUND(((CAST (max AS INTEGER) - CAST(min AS INTEGER)) / 7.36) + 0.5, 2) AS "Alcohol Prediction +/- 0.5",
|
||||||
cast(final_reading_date as DATE) + INTERVAL 14 DAY as "Ready Date"
|
cast(final_reading_date as DATE) + INTERVAL 14 DAY as "Ready Date"
|
||||||
|
|
||||||
FROM df_sum x
|
FROM df_sum x
|
||||||
@ -51,4 +55,36 @@ class TableBuilder():
|
|||||||
df_calc = duckdb.sql(sql).df()
|
df_calc = duckdb.sql(sql).df()
|
||||||
return df_calc
|
return df_calc
|
||||||
|
|
||||||
|
def current_runs_build(self, limit=10) -> pd.DataFrame:
|
||||||
|
df = self.df
|
||||||
|
sql = f"""
|
||||||
|
SELECT x.beer_run_id as beer_run_id,
|
||||||
|
max(sg) as max,
|
||||||
|
min(sg) as min,
|
||||||
|
min(cast(x.date as DATE)) as first_reading_date
|
||||||
|
FROM df x
|
||||||
|
LEFT JOIN
|
||||||
|
( SELECT DISTINCT beer_run_id
|
||||||
|
FROM df
|
||||||
|
WHERE final_reading = 'True'
|
||||||
|
) y ON x.beer_run_id = y.beer_run_id
|
||||||
|
WHERE y.beer_run_id is null
|
||||||
|
GROUP BY x.beer_run_id
|
||||||
|
ORDER BY x.beer_run_id desc
|
||||||
|
LIMIT {limit}
|
||||||
|
"""
|
||||||
|
df_sum = duckdb.sql(sql).df()
|
||||||
|
sql = f"""
|
||||||
|
SELECT x.beer_run_id as "Beer Run",
|
||||||
|
x.max as "Max",
|
||||||
|
x.min as "Min",
|
||||||
|
ROUND(((CAST (max AS INTEGER) - 1012) / 7.36) + 0.5, 2) AS "Alcohol Prediction (1012) +/- 0.5",
|
||||||
|
first_reading_date + INTERVAL 7 DAY as "Earliest Bottling/Kegging Date"
|
||||||
|
|
||||||
|
FROM df_sum x
|
||||||
|
"""
|
||||||
|
df_calc = duckdb.sql(sql).df()
|
||||||
|
return df_calc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,8 +52,13 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
|
|
||||||
|
<h3>Current Runs</h3>
|
||||||
|
{{ current_data | safe }}
|
||||||
|
|
||||||
|
<h3>Previous Runs</h3>
|
||||||
{{ beer_data | safe }}
|
{{ beer_data | safe }}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user