From 0e58cb1142fa17bcbfccfdccb9e59355ad3bd19a Mon Sep 17 00:00:00 2001 From: Benjamin Sigonneau Date: Sun, 21 Aug 2022 23:42:25 +0200 Subject: [PATCH] Show current prices on webapp (table + graph) --- views/search_results.tpl | 38 +++++++++++++++++++++++++++++++++++++- webapp.py | 9 ++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/views/search_results.tpl b/views/search_results.tpl index 58c20ff..71e2b24 100644 --- a/views/search_results.tpl +++ b/views/search_results.tpl @@ -14,6 +14,11 @@ 1000-1499 L 500-999 L + + Actuellement + {{current_1000}} + {{current_500}} + % for x in results: {{x.date.strftime('%A')}} @@ -32,13 +37,44 @@ y: {{ [d.price for d in results] }}, type: 'scatter', name: '1000-1499 L', + marker: { + color: '#1f77b4', + }, }, { x: {{ [str(d.date) for d in results if d.price500 is not None] }}, y: {{ [d.price500 for d in results if d.price500 is not None] }}, type: 'scatter', name: '500-999 L', - }]; + marker: { + color: '#ff7f0e', + }, + }, + { + x: [new Date().toJSON().slice(0, 10)], + y: [{{ current_1000 }}], + type: 'scatter', + name: 'today', + showlegend: false, + mode: 'markers', + marker: { + symbol: 'cross', + color: '#1f77b4', + }, + }, + { + x: [new Date().toJSON().slice(0, 10)], + y: [{{ current_500 }}], + type: 'scatter', + name: 'today', + showlegend: false, + mode: 'markers', + marker: { + symbol: 'cross', + color: '#ff7f0e', + }, + }, + ]; var plotLayout = { margin: { t: 0 } }; diff --git a/webapp.py b/webapp.py index e548b9c..d15ca46 100644 --- a/webapp.py +++ b/webapp.py @@ -4,6 +4,7 @@ import os from bottle import hook, request, route, run, static_file, view import models +from fioul import get_today_prices_from_internet from models import Price # ---------------------------------------------------------------------- @@ -14,6 +15,7 @@ from models import Price @view("search_results", template_settings={"noescape": True}) def results_page(): results = Price.select().order_by(Price.date.desc()) + current_500, current_1000 = get_today_prices_from_internet() day_classes = { 0: "monday", 1: "tuesday", @@ -23,7 +25,12 @@ def results_page(): 5: "saturday", 6: "sunday", } - return dict(results=results, day_classes=day_classes) + return dict( + results=results, + day_classes=day_classes, + current_500=current_500, + current_1000=current_1000, + ) @route("/static/")