From 4588cf20f1b38464fba8eddf65b7037b538e38b6 Mon Sep 17 00:00:00 2001 From: joachim lusiardi Date: Thu, 5 Mar 2015 21:14:21 +0100 Subject: [PATCH] added statistics page --- main.py | 20 +++++++++++++++++++ templates/newPitStopForm.html | 1 + templates/pitstops.html | 3 ++- templates/statistics.html | 36 +++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 templates/statistics.html diff --git a/main.py b/main.py index 423aae7..9b93524 100644 --- a/main.py +++ b/main.py @@ -55,6 +55,26 @@ def getPitStops(): data = {'pitstops': preparePitStops(getAllPitStops())} return render_template('pitstops.html', data=data) +@app.route('/statistics', methods=['GET']) +def getStatistics(): + pitstops = getAllPitStops() + distance = pitstops[-1]['odometer'] - pitstops[0]['odometer'] + count = len(pitstops) + averageDistance = round(distance/count, 2) + sumLitres = 0 + for pitstop in pitstops: + sumLitres += pitstop['litres'] + averageLitresFuelled = round(sumLitres/count, 2) + averageLitresUsed = round(100 * sumLitres/distance, 2) + data = { + 'distance':distance, + 'count': count, + 'litres': round(sumLitres, 2), + 'averageDistance': averageDistance, + 'averageListresFuelled': averageLitresFuelled, + 'averageListresUsed': averageLitresUsed} + return render_template('statistics.html', data=data) + def preparePitStops(pitstops): for index in range(1, len(pitstops)): last = pitstops[index - 1] diff --git a/templates/newPitStopForm.html b/templates/newPitStopForm.html index 466d4d8..c81e58a 100644 --- a/templates/newPitStopForm.html +++ b/templates/newPitStopForm.html @@ -3,6 +3,7 @@ {% block navigation %}
  • Home
  • Create Pitstop
  • +
  • Statistics
  • {% endblock %} {% block body %} diff --git a/templates/pitstops.html b/templates/pitstops.html index c725c15..3458792 100644 --- a/templates/pitstops.html +++ b/templates/pitstops.html @@ -3,6 +3,7 @@ {% block navigation %}
  • Home
  • Create Pitstop
  • +
  • Statistics
  • {% endblock %} {% block body %} @@ -49,5 +50,5 @@ {% endfor %} - {% endblock %} \ No newline at end of file diff --git a/templates/statistics.html b/templates/statistics.html new file mode 100644 index 0000000..d930826 --- /dev/null +++ b/templates/statistics.html @@ -0,0 +1,36 @@ +{% extends "layout.html" %} + +{% block navigation %} +
  • Home
  • +
  • Create Pitstop
  • +
  • Statistics
  • +{% endblock %} + +{% block body %} + + + + + + + + + + + + + + + + + + + + + + + + + +
    Number of Pitstops:{{ data.count }}
    Logged Distance:{{ data.distance }} km
    Average Distance:{{ data.averageDistance }} km
    Litres fuelled:{{ data.litres }} l
    Average Litres fuelled:{{ data.averageListresFuelled }} l
    Average Litres used:{{ data.averageListresUsed }} l/100km
    +{% endblock %} \ No newline at end of file