Merge branch 'master' of code.nerd2nerd.org:n0ob/rollerverbrauch
This commit is contained in:
commit
0a778295b6
20
main.py
20
main.py
|
@ -55,6 +55,26 @@ def getPitStops():
|
||||||
data = {'pitstops': preparePitStops(getAllPitStops())}
|
data = {'pitstops': preparePitStops(getAllPitStops())}
|
||||||
return render_template('pitstops.html', data=data)
|
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):
|
def preparePitStops(pitstops):
|
||||||
for index in range(1, len(pitstops)):
|
for index in range(1, len(pitstops)):
|
||||||
last = pitstops[index - 1]
|
last = pitstops[index - 1]
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
{% block navigation %}
|
{% block navigation %}
|
||||||
<li><a href='{{ url_for('getPitStops') }}'>Home</a></li>
|
<li><a href='{{ url_for('getPitStops') }}'>Home</a></li>
|
||||||
<li><a href='{{ url_for('createPitStopForm') }}' class="active">Create Pitstop</a></li>
|
<li><a href='{{ url_for('createPitStopForm') }}' class="active">Create Pitstop</a></li>
|
||||||
|
<li><a href='{{ url_for('getStatistics') }}'>Statistics</a></li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
{% block navigation %}
|
{% block navigation %}
|
||||||
<li><a href='{{ url_for('getPitStops') }}' class="active">Home</a></li>
|
<li><a href='{{ url_for('getPitStops') }}' class="active">Home</a></li>
|
||||||
<li><a href='{{ url_for('createPitStopForm') }}'>Create Pitstop</a></li>
|
<li><a href='{{ url_for('createPitStopForm') }}'>Create Pitstop</a></li>
|
||||||
|
<li><a href='{{ url_for('getStatistics') }}'>Statistics</a></li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
@ -49,5 +50,5 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -0,0 +1,36 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% block navigation %}
|
||||||
|
<li><a href='{{ url_for('getPitStops') }}'>Home</a></li>
|
||||||
|
<li><a href='{{ url_for('createPitStopForm') }}'>Create Pitstop</a></li>
|
||||||
|
<li><a href='{{ url_for('getStatistics') }}' class="active">Statistics</a></li>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Number of Pitstops:</th>
|
||||||
|
<td>{{ data.count }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Logged Distance:</th>
|
||||||
|
<td>{{ data.distance }} km</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Average Distance:</th>
|
||||||
|
<td>{{ data.averageDistance }} km</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Litres fuelled:</th>
|
||||||
|
<td>{{ data.litres }} l</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Average Litres fuelled:</th>
|
||||||
|
<td>{{ data.averageListresFuelled }} l</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Average Litres used:</th>
|
||||||
|
<td>{{ data.averageListresUsed }} l/100km</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue