Plot prices using plotly

This commit is contained in:
2022-08-06 22:38:08 +02:00
parent 0f35f0ff91
commit 907bb882a4
3 changed files with 91 additions and 4 deletions

65
static/plotly-2.12.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,7 @@
<link rel="stylesheet" href="/static/classless.css">
<link rel="stylesheet" href="/static/fioul.css">
<link rel="icon" type="image/png" href="/static/favicon.png" />
<script src="/static/plotly-2.12.1.min.js"></script>
</head>
<body>
<h1>Prix du m³ de fioul pour Languidic</h1>
@@ -16,5 +17,27 @@
</tr>
% end
</table>
<div id="price-plot"></div>
<script>
var plotDiv = document.getElementById('price-plot');
var plotData = [{
x: {{ [str(d.date) for d in results] }},
y: {{ [d.price for d in results] }},
type: 'scatter',
}];
var plotLayout = {
margin: { t: 0 }
};
var plotConfig = {
responsive: true,
displaylogo: false,
};
Plotly.newPlot(
plotDiv,
plotData,
plotLayout,
plotConfig,
);
</script>
</body>
</html>

View File

@@ -6,15 +6,14 @@ from bottle import hook, request, route, run, static_file, view
import models
from models import Price
# ----------------------------------------------------------------------
# Web application
@route("/")
@view("search_results")
@view("search_results", template_settings={'noescape':True})
def results_page():
query = Price.select().order_by(Price.date.desc())
results = list(query)
results = Price.select().order_by(Price.date.desc())
day_classes = {
0: "monday",
1: "tuesday",