statistics 3rd

This commit is contained in:
Joachim Lusiardi 2016-07-11 22:15:23 +02:00
parent ca5bd9bb02
commit aa9fda93c0
1 changed files with 134 additions and 140 deletions

View File

@ -23,159 +23,153 @@
zoom_chart_{{ hash }}() zoom_chart_{{ hash }}()
{% endmacro %} {% endmacro %}
{% macro chart(data, baseId, unit, link, active)%} {% macro nav_tab(id, text, active) %}
{% set chartID = 'chart_' + baseId %} {#
<div class="tab-pane {% if active %}active{% endif %}" id="{{ baseId }}">
{% if data|length > 0 %} #}
<div id="{{ chartID }}" style="width:100%; height:500px;"></div> <li class="{% if active %}active{% endif %}">
<script type="text/javascript"> <a href="#ref_{{id}}" id="id_{{id}}" data-toggle="tab" >
{{ chartScript(chartID, data, unit) }} {{ text }}
</script> </a>
{% else %} </li>
<div class="alert alert-warning" role="alert"> {% endmacro %}
not enough data: <a href="{{ link }}">log a pitstop</a>?
</div> {% macro tab_pane(id, content, active) %}
{% endif %} <div class="tab-pane {% if active %}active{% endif %}" id="ref_{{ id }}">
{{ content }}
</div>
{% endmacro %}
{% macro chart(data, baseId, unit, link) %}
{% if data|length > 0 %}
{% set chartID = 'chart_' + baseId %}
<div id="{{ chartID }}" style="width:100%; height:500px;"></div>
<script type="text/javascript">
{{ chartScript(chartID, data, unit) }}
</script>
{% else %}
<div class="alert alert-warning" role="alert">
not enough data: <a href="{{ link }}">log a pitstop</a>?
</div>
{% endif %}
{% endmacro %}
{% macro print_consumable_table(consumable) %}
<table class="table table-striped table-bordered table-condensed">
<tr>
<th>Average Distance:</th>
<td>{{ consumable.average_distance | round(2) }} km</td>
</tr>
<tr>
<th>Amount fuelled:</th>
<td>{{ consumable.overall_amount | round(2) }} {{ consumable.unit }}</td>
</tr>
<tr>
<th>Average Amount fuelled:</th>
<td>{{ consumable.average_amount_fuelled | round(2) }} {{ consumable.unit }}</td>
</tr>
<tr>
<th>Average Amount used:</th>
<td>{{ consumable.average_amount_used | round(2) }} {{ consumable.unit }}/100km</td>
</tr>
</table>
{% endmacro %}
{% macro print_vehicle_table(vehicle) %}
<h3>{{vehicle.name}}</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed">
<tr>
<th>Logged Distance:</th>
<td>{{ vehicle.overall_distance | round(2) }} km</td>
</tr>
<tr>
<th>Logged Costs:</th>
<td>{{ vehicle.overall_costs | round(2) }} €</td>
</tr>
</table>
</div> </div>
{% endmacro %} {% endmacro %}
{% macro tab_script(id) %}
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#{{id}}').tab();
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
}
});
</script>
{% endmacro %}
{% block body %} {% block body %}
<div id="content"> <div id="content">
<ul id="vehicle_tabs" class="nav nav-tabs" data-tabs="tabs"> <ul id="vehicle_tabs" class="nav nav-tabs" data-tabs="tabs">
{% for vehicle in data %} {% for vehicle in data %}
<li {% if loop.first %}class="active" {%endif %}> {{ nav_tab(vehicle.id, vehicle.name, loop.first) }}
<a href="#v{{vehicle.id}}" id="i{{vehicle.id}}" data-toggle="tab">
{{ vehicle.name }}
</a>
</li>
{% endfor %} {% endfor %}
</ul> </ul>
<div id="vehicle_content" class="tab-content "> <div id="vehicle_content" class="tab-content ">
{% for vehicle in data %} {% for vehicle in data %}
<div class="tab-pane {% if loop.first %}active{% endif %}" id="v{{vehicle.id}}"> <div class="tab-pane {% if loop.first %}active{% endif %}" id="ref_{{vehicle.id}}">
<h3>{{vehicle.name}}</h3> {{ print_vehicle_table(vehicle) }}
<div class="table-responsive"> <ul id="vehicle_{{vehicle.id}}_tabs" class="nav nav-tabs" data-tabs="tabs">
<table class="table table-striped table-bordered table-condensed"> {{ nav_tab(vehicle.id|string + '_odometer', 'Odometer', true) }}
<tr> {% for consumable in vehicle.consumables %}
<th>Logged Distance:</th> {{ nav_tab(vehicle.id|string + '_' + consumable.id|string, consumable.name, false) }}
<td>{{ vehicle.overall_distance | round(2) }} km</td> {% endfor %}
</tr> </ul>
<tr> <div id="vehicle_{{vehicle.id}}_content" class="tab-content ">
<th>Logged Costs:</th> {{ tab_pane(
<td>{{ vehicle.overall_costs | round(2) }} €</td> vehicle.id|string + '_odometer',
</tr> chart(
</table> vehicle.odometers,
</div> 'ref_' + vehicle.id|string + '_odometer',
'km',
<ul id="consumable_tabs" class="nav nav-tabs" data-tabs="tabs"> url_for('select_consumable_for_new_pitstop', vid=vehicle.id)
{% for consumable in vehicle.consumables %} ),
<li class="{% if loop.first %}active{% endif %}"> true
<a href="#v{{vehicle.id}}_c{{consumable.id}}" id="i{{vehicle.id}}_c{{consumable.id}}" data-toggle="tab" > )
{{ consumable.name }} }}
</a> {% for consumable in vehicle.consumables %}
</li> <div class="tab-pane" id="ref_{{vehicle.id}}_{{consumable.id}}">
{% endfor %} {{ print_consumable_table(consumable) }}
</ul> <ul id="consumable_{{vehicle.id}}_{{consumable.id}}_tabs" class="nav nav-tabs" data-tabs="tabs">
<div id="consumable_tabs-content" class="tab-content"> {{ nav_tab(vehicle.id|string + '_' + consumable.id|string + '_consumption', 'Consumption', true) }}
{% for consumable in vehicle.consumables %} {{ nav_tab(vehicle.id|string + '_' + consumable.id|string + '_amount', 'Amount', false) }}
<div class="tab-pane {% if loop.first %}active{% endif %}" id="v{{vehicle.id}}_c{{consumable.id}}"> </ul>
<table class="table table-striped table-bordered table-condensed"> <div id="consumable_{{vehicle.id}}_{{consumable.id}}_content" class="tab-content ">
<tr> {{ tab_pane(
<th>Average Distance:</th> vehicle.id|string + '_' + consumable.id|string + '_consumption',
<td>{{ consumable.average_distance | round(2) }} km</td> chart(
</tr> consumable.average_amount,
<tr> 'ref_' + vehicle.id|string + '_' + consumable.id|string + '_consumption',
<th>Amount fuelled:</th> consumable.unit + '/100km',
<td>{{ consumable.overall_amount | round(2) }} {{ consumable.unit }}</td> url_for('create_pit_stop_form', vid=vehicle.id, cid=consumable.id)
</tr> ),
<tr> true
<th>Average Amount fuelled:</th> )
<td>{{ consumable.average_amount_fuelled | round(2) }} {{ consumable.unit }}</td> }}
</tr> {{ tab_pane(
<tr> vehicle.id|string + '_' + consumable.id|string + '_amount',
<th>Average Amount used:</th> chart(
<td>{{ consumable.average_amount_used | round(2) }} {{ consumable.unit }}/100km</td> consumable.amounts,
</tr> 'ref_' + vehicle.id|string + '_' + consumable.id|string + '_amount',
</table> consumable.unit,
url_for('create_pit_stop_form', vid=vehicle.id, cid=consumable.id)
{% set ID = vehicle.id|string + '_c' + consumable.id|string %} ),
{% set odometerID = ID + '_odometer' %} false
{% set consumptionID = ID + '_consumption' %} )
{% set amountID = ID + '_amount' %} }}
<ul id="charts_{{ID}}_tabs" class="nav nav-tabs" data-tabs="tabs"> </div>
<li class="active"> {{ tab_script('vehicle_' + vehicle.id + '_' + consumable.id + '_tabs') }}
<a href="#v{{odometerID}}" id="i{{odometerID}}" data-toggle="tab" > </div>
Odometer {% endfor %}
</a> </div>
</li> {{ tab_script('vehicle_' + vehicle.id + '_tabs') }}
<li>
<a href="#v{{consumptionID}}" id="i{{consumptionID}}" data-toggle="tab" >
Consumption
</a>
</li>
<li>
<a href="#v{{amountID}}" id="i{{amountID}}" data-toggle="tab" >
Amount
</a>
</li>
</ul>
<div id="charts_{{ID}}_tabs-content" class="tab-content">
{% 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) }}
</div>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#charts_{{ID}}_tabs').tab();
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
}
});
</script>
</div>
{% endfor %}
</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{{ tab_script('vehicle_tabs') }}
</div> </div>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#vehicle_tabs').tab();
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
}
});
jQuery(document).ready(function ($) {
$('#consumable_tabs').tab();
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
}
});
jQuery(document).ready(function ($) {
$('#charts_tabs').tab();
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
}
});
</script>
{% endblock %} {% endblock %}