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 %}
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 | +