From 6b861903afa0e2688892707d09752fe2710b8dd7 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Mon, 2 May 2016 07:59:31 +0200 Subject: [PATCH] add consumption chart --- app/rollerverbrauch/templates/statistics.html | 15 +++++++++++++++ app/rollerverbrauch/tools.py | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/app/rollerverbrauch/templates/statistics.html b/app/rollerverbrauch/templates/statistics.html index 24fa010..acbb91e 100644 --- a/app/rollerverbrauch/templates/statistics.html +++ b/app/rollerverbrauch/templates/statistics.html @@ -54,6 +54,11 @@ Odometer +
  • + + Consumption + +
  • @@ -76,6 +81,16 @@ not enough data. {% endif %}
    +
    + {% if vehicle.pitstop_count > 0 %} +
    + + {% else %} + not enough data. + {% endif %} +
    {% endfor %} diff --git a/app/rollerverbrauch/tools.py b/app/rollerverbrauch/tools.py index fca48c8..d33c255 100644 --- a/app/rollerverbrauch/tools.py +++ b/app/rollerverbrauch/tools.py @@ -12,6 +12,7 @@ class VehicleStats: self.average_litres_fuelled = 0 self.average_litres_used = 0 self.litres = [] + self.average_litres = [] self.odometers = [] if self.pitstop_count > 0: @@ -24,6 +25,11 @@ class VehicleStats: self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer self.average_distance = self.overall_distance / (self.pitstop_count - 1) self.average_litres_used = 100 * (self.overall_litres - vehicle.pitstops[0].litres) / self.overall_distance + for index in range(1, self.pitstop_count): + last_ps = vehicle.pitstops[index - 1] + current_ps = vehicle.pitstops[index] + self.average_litres.append(StatsEvent(current_ps.date, round(100 * current_ps.litres/(current_ps.odometer - last_ps.odometer),2))) + print(index) class StatsEvent: