Add graph into gymnast chrono listing

This commit is contained in:
Gregory Trullemans 2024-04-11 12:18:14 +02:00
parent 8612ea9087
commit 514807204a
4 changed files with 225 additions and 17 deletions

View File

@ -6,7 +6,9 @@
<div class="row">
<div class="col-8">
<h4 class="">
{% if gymnast %}<i><a href="{% url 'gymnast_details_tab' gymnast.id 'scores' %}">{{ gymnast }}</a></i>'s{% endif %} chronos listing
{% if gymnast %}
<i><a href="{% url 'gymnast_details_tab' gymnast.id 'scores' %}">{{ gymnast }}</a></i>'s
{% endif %} chronos listing
</h4>
</div>
<div class="col-1 ml-auto">
@ -23,15 +25,68 @@
</div>
<div class="card-body vh-100">
<div class="table-responsive">
{% if gymnast %}
<div class="row">
<div class="col-md-6">
<table class="table table-striped tablesorter" id="chrono_table">
<thead>
<tr>
<th style="width: 8%">&nbsp;</th>
<th style="width: 12%" class="header text-center">Date</th>
<th style="width: 20%" class="header text-center">Routine</th>
<th style="width: 15%" class="header text-center">Type</th>
<th style="width: 10%" class="header text-center">Score</th>
<th style="width: 10%" class="header text-center">TOF</th>
</tr>
</thead>
<tbody>
{% for chrono in chrono_list %}
<tr role="row" class="{% cycle 'odd' 'even' %}">
<td>
<a href="{% url 'chrono_update' chrono.id %}">
<span class="tim-icons icon-pencil text-warning"></span>
</a>
&nbsp;
<a href="{% url 'jump_chrono_values_create_or_update' chrono.id %}">
<span class="far fa-search-plus text-warning"></span>
</a>
</td>
<td class="text-center">
{% if chrono.details.all %}
<a href="{% url 'jump_chrono_details' chrono.id %}">
{% endif %}
{{ chrono.date | date:"j-n-Y" }}
{% if chrono.details.all %}
</a>
{% endif %}
</td>
<td class="text-center">
{% if chrono.routine %}
{{ chrono.routine.long_label }}
{% else %}
{{ chrono.get_chrono_type_display }}
{% endif %}
</td>
<td class="text-center">{{ chrono.get_score_type_display }}</td>
<td class="text-center">{{ chrono.score }}</td>
<td class="text-center">{{ chrono.tof }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-md-6">
<canvas id="chart_chrono" class="chartjs" width="400" height="200"></canvas>
</div>
</div>
{% else %}
{% if chrono_list %}
<table class="table table-striped tablesorter" id="chrono_table">
<thead>
<tr>
<th style="width: 6%">&nbsp;</th>
<th style="width: 12%" class="header">Date</th>
{% if not gymnast %}
<th style="width: 25%" class="header text-left">Gymnast</th>
{% endif %}
<th style="width: 25%" class="header text-left">Routine</th>
<th style="width: 15%" class="header">Type</th>
<th style="width: 10%" class="header text-center">Score</th>
@ -51,13 +106,11 @@
</a>
</td>
<td>{% if chrono.details.all %}<a href="{% url 'jump_chrono_details' chrono.id %}">{% endif %}{{ chrono.date | date:"j-n-Y" }}{% if chrono.details.all %}</a>{% endif %}</td>
{% if not gymnast %}
<td class="text-left">
{% if chrono.gymnast.id in request.session.available_gymnast or request.user.is_superuser %}<a href="{% url 'gymnast_details_tab' chrono.gymnast.id 'scores' %}">{% endif %}
{{ chrono.gymnast }}
</a>
</td>
{% endif %}
<td class="text-left">
{% if chrono.routine %}
{{ chrono.routine.long_label }}
@ -75,6 +128,7 @@
{% else %}
<p class="text-muted">There are no chronos corresponding to your criterias.</p>
{% endif %}
{% endif %}
</div>
</div>
</div>
@ -100,5 +154,150 @@
"bInfo": false,
});
});
{% if chrono_list %}
var timeFormat = 'DD-MM-YYYY';
var ctx = document.getElementById('chart_chrono').getContext('2d');
var gradient_stroke_1 = ctx.createLinearGradient(0, 230, 0, 50);
var gradient_stroke_2 = ctx.createLinearGradient(0, 230, 0, 50);
var gradient_stroke_3 = ctx.createLinearGradient(0, 230, 0, 50);
var gradient_stroke_4 = ctx.createLinearGradient(0, 230, 0, 50);
gradient_stroke_1.addColorStop(0.75, 'rgba(75, 192, 192, 0.3)');
gradient_stroke_1.addColorStop(0.5, 'rgba(75, 192, 192, 0.2)');
gradient_stroke_1.addColorStop(0.25, 'rgba(75, 192, 192, 0)');
gradient_stroke_2.addColorStop(1, 'rgba(255, 99, 132, 0.4)');
gradient_stroke_2.addColorStop(0.75, 'rgba(255, 99, 132, 0.3)');
gradient_stroke_2.addColorStop(0.5, 'rgba(255, 99, 132, 0.2)');
gradient_stroke_2.addColorStop(0.25, 'rgba(255, 99, 132, 0)');
gradient_stroke_3.addColorStop(1, 'rgba(255, 159, 64, 0.4)');
gradient_stroke_3.addColorStop(0.75, 'rgba(255, 159, 64, 0.3)');
gradient_stroke_3.addColorStop(0.5, 'rgba(255, 159, 64, 0.2)');
gradient_stroke_3.addColorStop(0.25, 'rgba(255, 159, 64, 0)');
gradient_stroke_4.addColorStop(1, 'rgba(54, 162, 235, 0.4)');
gradient_stroke_4.addColorStop(0.75, 'rgba(54, 162, 235, 0.3)');
gradient_stroke_4.addColorStop(0.5, 'rgba(54, 162, 235, 0.2)');
gradient_stroke_4.addColorStop(0.25, 'rgba(54, 162, 235, 0)');
var straightjump_values = [
{% for chrono in chrono_10c %}
{
x: '{{ chrono.date | date:"d-m-Y" }}',
y: '{{ chrono.score_avg | floatformat:3 }}'
},
{% endfor %}
];
var compulsory_routine_values = [
{% for chrono in chrono_r1 %}
{
x: '{{ chrono.date | date:"d-m-Y" }}',
y: '{{ chrono.score_avg | floatformat:3 }}'
},
{% endfor %}
];
var volontary_routine_values = [
{% for chrono in chrono_r2 %}
{
x: '{{ chrono.date | date:"d-m-Y" }}',
y: '{{ chrono.score_avg | floatformat:3 }}'
},
{% endfor %}
];
var final_routine_values = [
{% for chrono in chrono_rf %}
{
x: '{{ chrono.date | date:"d-m-Y" }}',
y: '{{ chrono.score_avg | floatformat:3 }}'
},
{% endfor %}
];
var chrono_values = {
datasets: [
{% if chrono_10c %}
{
label: '10 |',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_1,
borderColor: 'rgb(75, 192, 192)',
pointBackgroundColor: 'rgb(75, 192, 192)',
fill: true,
data: straightjump_values,
},
{% endif %}
{% if chrono_r1 %}
{
label: 'Q1R1',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_2,
borderColor: 'rgb(255, 99, 132)',
pointBackgroundColor: 'rgb(255, 99, 132)',
fill: true,
data: compulsory_routine_values,
},
{% endif %}
{% if chrono_r2 %}
{
label: 'Q1R2',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_3,
borderColor: 'rgb(255, 159, 64)',
pointBackgroundColor: 'rgb(255, 159, 64)',
fill: true,
data: volontary_routine_values,
},
{% endif %}
{% if chrono_rf %}
{
label: 'Q2R1',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_4,
borderColor: 'rgb(255, 205, 86)',
pointBackgroundColor: 'rgb(255, 205, 86)',
fill: true,
data: final_routine_values,
},
{% endif %}
]
}
new Chart(ctx, {
type: 'line',
data: chrono_values,
options: {
scales: {
x: {
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Date',
ticks: {
autoSkip: true,
source: 'data',
},
},
time: {
parser: timeFormat,
tooltipFormat: 'LL',
round: 'day',
},
},
},
plugins: {
legend: {
display: true,
position: 'bottom',
}
}
},
});
{% endif %}
</script>
{% endblock %}

View File

@ -383,8 +383,17 @@ def chrono_listing(request, gymnast_id=None):
and gymnast_id in request.session["available_gymnast"]
)
):
chrono_list = Chrono.objects.filter(gymnast=gymnast_id)
gymnast = Gymnast.objects.get(pk=gymnast_id)
chrono_list = Chrono.objects.filter(gymnast=gymnast_id).order_by("date")
base_queryset = chrono_list.values("date").annotate(score_avg=Avg("tof"))
context = {
"chrono_10c": base_queryset.filter(chrono_type=0),
"chrono_r1": base_queryset.filter(chrono_type=1),
"chrono_r2": base_queryset.filter(chrono_type=2),
"chrono_rf": base_queryset.filter(chrono_type=3),
}
else:
if request.user.is_superuser:
chrono_list = Chrono.objects.all()
@ -393,7 +402,8 @@ def chrono_listing(request, gymnast_id=None):
gymnast__in=request.session["available_gymnast"]
)
context = {"chrono_list": chrono_list, "gymnast": gymnast}
context["chrono_list"] = chrono_list
context["gymnast"] = gymnast
return render(request, "chronos/list.html", context)

View File

@ -95,9 +95,8 @@
</div>
<script type="text/javascript">
var timeFormat = 'DD-MM-YYYY';
{% if intensity_list %}
var timeFormat = 'DD-MM-YYYY';
var ctx = document.getElementById('chart_intensity').getContext('2d');
var average_difficulty_by_passe = [

View File

@ -68,7 +68,7 @@
0: { sorter: false },
},
dateFormat: "uk",
sortList: [[2, 1]]
sortList: [[1, 1]]
});
$('#score_table').DataTable({