diff --git a/app/rollerverbrauch/templates/layout.html b/app/rollerverbrauch/templates/layout.html
index 60e5ebe..8920020 100644
--- a/app/rollerverbrauch/templates/layout.html
+++ b/app/rollerverbrauch/templates/layout.html
@@ -85,30 +85,6 @@
{% endmacro %}
-{% macro chartScript(divId, data, unit)%}
- {% set hash = divId | md5 %}
-
- data_{{ hash }} = [{% for stop in data %}{
- "date": "{{stop.date}}",
- "value": {{stop.value}}
- }{% if not loop.last %},{%endif%}
- {% endfor%}
- ]
- var chart_{{ hash }} = createChart('{{divId}}', data_{{ hash }}, '{{unit}}');
-
- function zoom_chart_{{ hash }}() {
- chart_{{ hash }}.zoomToIndexes(
- chart_{{ hash }}.dataProvider.length - 40,
- chart_{{ hash }}.dataProvider.length - 1
- );
- }
-
- chart_{{ hash }}.addListener("rendered", zoom_chart_{{ hash }});
-
- zoom_chart_{{ hash }}()
-
-{% endmacro %}
-
diff --git a/app/rollerverbrauch/templates/statistics.html b/app/rollerverbrauch/templates/statistics.html
index b6a3aaf..0b3ceb4 100644
--- a/app/rollerverbrauch/templates/statistics.html
+++ b/app/rollerverbrauch/templates/statistics.html
@@ -1,5 +1,44 @@
{% extends "layout.html" %}
+{% macro chartScript(divId, data, unit)%}
+ {% set hash = divId | md5 %}
+
+ data_{{ hash }} = [{% for stop in data %}{
+ "date": "{{stop.date}}",
+ "value": {{stop.value}}
+ }{% if not loop.last %},{%endif%}
+ {% endfor%}
+ ]
+ var chart_{{ hash }} = createChart('{{divId}}', data_{{ hash }}, '{{unit}}');
+
+ function zoom_chart_{{ hash }}() {
+ chart_{{ hash }}.zoomToIndexes(
+ chart_{{ hash }}.dataProvider.length - 40,
+ chart_{{ hash }}.dataProvider.length - 1
+ );
+ }
+
+ chart_{{ hash }}.addListener("rendered", zoom_chart_{{ hash }});
+
+ zoom_chart_{{ hash }}()
+{% endmacro %}
+
+{% macro chart(data, baseId, unit, link, active)%}
+ {% set chartID = 'chart_' + baseId %}
+
@@ -47,7 +86,7 @@
Amount fuelled: |
- {{ consumable.amount | round(2) }} {{ consumable.unit }} |
+ {{ consumable.overall_amount | round(2) }} {{ consumable.unit }} |
Average Amount fuelled: |
@@ -58,52 +97,56 @@
{{ consumable.average_amount_used | round(2) }} {{ consumable.unit }}/100km |
+
+{% set ID = vehicle.id|string + '_c' + consumable.id|string %}
+{% set odometerID = ID + '_odometer' %}
+{% set consumptionID = ID + '_consumption' %}
+{% set amountID = ID + '_amount' %}
+
+
+ {% set baseId = 'v' + odometerID %}
+ {% set link = url_for('select_consumable_for_new_pitstop', vid=vehicle.id) %}
+ {{ chart(vehicle.odometers, baseId, 'km', link, true) }}
+
+
+ {% set baseId = 'v' + consumptionID %}
+ {% set link = url_for('create_pit_stop_form', vid=vehicle.id, cid=consumable.id) %}
+ {{ chart(consumable.average_amount, baseId, consumable.unit + '/100km', link, false) }}
+
+
+ {% set baseId = 'v' + amountID %}
+ {% set link = url_for('create_pit_stop_form', vid=vehicle.id, cid=consumable.id) %}
+ {{ chart(consumable.amounts, baseId, consumable.unit, link, false) }}
+
+
+
{% endfor %}
-
-
- {% if vehicle.odometers|length > 0 %}
-
-
- {% else %}
-
- {% endif %}
-
- {% for consumable in vehicle.consumables %}
-
- {% if consumable.average_amount|length > 0 %}
-
-
- {% else %}
-
- {% endif %}
-
- {% endfor %}
-
{% endfor %}
diff --git a/app/rollerverbrauch/tools.py b/app/rollerverbrauch/tools.py
index 3cbaa9a..aef46d5 100644
--- a/app/rollerverbrauch/tools.py
+++ b/app/rollerverbrauch/tools.py
@@ -11,24 +11,26 @@ class ConsumableStats:
self.name = consumable.name
self.id = consumable.id
self.unit = consumable.unit
- self.amount = 0
+ self.overall_amount = 0
self.average_distance = 0
self.average_amount_fuelled = 0
self.average_amount_used = 0
self.average_amount = []
+ self.amounts = []
pitstops = [stop for stop in vehicle.pitstops if stop.consumable_id == consumable.id]
pitstop_count = len(pitstops)
if pitstop_count > 0:
for pitstop in pitstops:
- self.amount += pitstop.amount
- self.average_amount_fuelled = self.amount / pitstop_count
-
+ self.overall_amount += pitstop.amount
+ self.amounts.append(StatsEvent(pitstop.date, pitstop.amount))
+ self.average_amount_fuelled = self.overall_amount / pitstop_count
+ print(self.amounts)
if pitstop_count > 1:
overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
self.average_distance = overall_distance / (pitstop_count - 1)
- self.average_amount_used = 100 * (self.amount - pitstops[0].amount) / overall_distance
+ self.average_amount_used = 100 * (self.overall_amount - pitstops[0].amount) / overall_distance
for index in range(1, pitstop_count):
last_ps = pitstops[index - 1]
current_ps = pitstops[index]
@@ -37,6 +39,7 @@ class ConsumableStats:
current_ps.date,
round(100 * current_ps.amount/(current_ps.odometer - last_ps.odometer), 2)))
+
class VehicleStats:
def __init__(self, vehicle):
self.name = vehicle.name
@@ -49,41 +52,15 @@ class VehicleStats:
for consumable in vehicle.consumables:
self.consumables.append(ConsumableStats(vehicle, consumable))
-# self.overall_litres = 0
-#
-# self.litres = []
-# self.average_litres = []
-# self.costsPerLitre = []
-# self.costs = []
-# self.average_costs_per_litre = 0
- # cost_count = 0;
-
pitstop_count = len(vehicle.pitstops)
if pitstop_count > 0:
for pitstop in vehicle.pitstops:
- # self.overall_litres += pitstop.amount
- # self.litres.append(StatsEvent(pitstop.date, pitstop.amount))
self.odometers.append(StatsEvent(pitstop.date, pitstop.odometer))
- # self.costsPerLitre.append(StatsEvent(pitstop.date, pitstop.costs / pitstop.amount))
- # self.costs.append(StatsEvent(pitstop.date, pitstop.costs))
self.overall_costs += pitstop.costs
- # self.average_costs_per_litre += (pitstop.costs / pitstop.amount)
- # if pitstop.costs > 0:
- # cost_count += 1
- # if cost_count > 0:
- # self.average_costs_per_litre = self.average_costs_per_litre / cost_count
- # else:
- # self.average_costs_per_litre = 0
if pitstop_count > 1:
self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
- # 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)))
class StatsEvent:
@@ -178,13 +155,13 @@ def compute_lower_limits_for_new_pitstop(latest_pitstop, last_pitstop_consumable
# if last_pitstop_consumable is not None and last_pitstop_consumable != latest_pitstop:
# if latest_pitstop.id > last_pitstop_consumable.id:
# return Pitstop(latest_pitstop.odometer,
- # last_pitstop_consumable.amount,
+ # last_pitstop_consumable.overall_amount,
# latest_pitstop.date,
# last_pitstop_consumable.costs,
# consumable_id)
# else:
# return Pitstop(last_pitstop_consumable.odometer,
- # last_pitstop_consumable.amount,
+ # last_pitstop_consumable.overall_amount,
# last_pitstop_consumable.date,
# last_pitstop_consumable.costs,
# consumable_id)
@@ -193,7 +170,7 @@ def compute_lower_limits_for_new_pitstop(latest_pitstop, last_pitstop_consumable
# litres = 0
# costs = 0
# if latest_pitstop.consumable_id == last_pitstop_consumable.consumable_id:
- # litres = latest_pitstop.amount
+ # litres = latest_pitstop.overall_amount
# costs = latest_pitstop.costs
# return Pitstop(latest_pitstop.odometer, litres, latest_pitstop.date, costs, consumable_id)
# else: