Update gymnast tob

This commit is contained in:
Gregory Trullemans 2024-02-04 18:55:02 +01:00
parent 5973a0e946
commit 89ae716643
3 changed files with 131 additions and 128 deletions

View File

@ -5,27 +5,26 @@
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h4>Scores</h4>
<h4>Intensity statistics</h4>
</div>
<div class="card-body pt-0 pb-0 pr-0 pl-0">
{% if score_list %}
<div><canvas id="chart_score_competition" class="chartjs" width="400" height="200"></canvas></div>
{% if intensity_list %}
<div><canvas id="chart_intensity" class="chartjs" width="400" height="200"></canvas></div>
{% else %}
<p class="pl-3 text-muted">No score recorded for this gymnast.</p>
<p class="pl-3 text-muted">No intensity recorded for this gymnast.</p>
{% endif %}
</div>
<div class="card-footer text-right text-muted pt-0">
{% if score_list %}
<a href="{% url 'score_list_for_gymnast' gymnast_id %}">
<button type="submit" value="add" class="btn btn-icon btn-warning mr-2">
<i class="fal fa-crosshairs"></i>
{% if intensity_list %}
<a href="{% url 'intensity_list_for_gymnast' gymnast_id %}">
<button type="submit" value="list" class="btn btn-icon btn-warning mr-2">
<i class="fal fa-analytics"></i> <!-- Routines -->
</button>
</a>
{% endif %}
{% if request.user|has_group:"trainer" or request.user|is_user_equal_to_gymnast:gymnast_id %}
<a href="{% url 'score_create_for_gymnast' gymnast_id %}">
<a href="{% url 'intensity_create_for_gymnast' gymnast_id %}">
<button type="submit" value="add" class="btn btn-icon btn-warning ">
<i class="fas fa-plus"></i>
</button>
@ -80,91 +79,75 @@
<script type="text/javascript">
var timeFormat = 'DD-MM-YYYY';
{% if score_list %}
var ctx = document.getElementById('chart_score_competition').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);
{% if intensity_list %}
var ctx = document.getElementById('chart_intensity').getContext('2d');
gradient_stroke_1.addColorStop(1, 'rgba(255, 99, 132, 0.4)');
gradient_stroke_1.addColorStop(0.75, 'rgba(255, 99, 132, 0.3)');
gradient_stroke_1.addColorStop(0.5, 'rgba(255, 99, 132, 0.2)');
gradient_stroke_1.addColorStop(0.25, 'rgba(255, 99, 132, 0)');
gradient_stroke_2.addColorStop(1, 'rgba(255, 159, 64, 0.4)');
gradient_stroke_2.addColorStop(0.75, 'rgba(255, 159, 64, 0.3)');
gradient_stroke_2.addColorStop(0.5, 'rgba(255, 159, 64, 0.2)');
gradient_stroke_2.addColorStop(0.25, 'rgba(255, 159, 64, 0)');
gradient_stroke_3.addColorStop(1, 'rgba(54, 162, 235, 0.4)');
gradient_stroke_3.addColorStop(0.75, 'rgba(54, 162, 235, 0.3)');
gradient_stroke_3.addColorStop(0.5, 'rgba(54, 162, 235, 0.2)');
gradient_stroke_3.addColorStop(0.25, 'rgba(54, 162, 235, 0)');
var compulsory_routine_scrore = [
{% for score in score_routine1_list %}
{
x: '{{ score.event.date_begin | date:"d-m-Y" }}',
y: '{{ score.total }}'
},
var mean_difficulty_by_passe = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_difficulty_by_passe_in_unit }}'
},
{% endfor %}
];
var voluntary_routine_scrore = [
{% for score in score_routine2_list %}
{
x: '{{ score.event.date_begin | date:"d-m-Y" }}',
y: '{{ score.total }}'
},
var mean_quantity_of_skill_by_time = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_quantity_of_skill_by_time }}'
},
{% endfor %}
];
var final_routine_scrore = [
{% for score in score_routine3_list %}
{
x: '{{ score.event.date_begin | date:"d-m-Y" }}',
y: '{{ score.total }}'
},
var mean_quantity_of_skill_by_passe = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_quantity_of_skill_by_passe }}'
},
{% endfor %}
];
var mean_difficulty_by_skill = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_difficulty_by_skill }}'
},
{% endfor %}
];
var score_values = {
datasets: [
{% if score_routine1_list %}
{
label: 'Q1R1',
label: 'diff/pass',
cubicInterpolationMode: 'monotone',
borderColor: 'rgb(75, 192, 192)',
pointBackgroundColor: 'rgb(75, 192, 192)',
data: mean_difficulty_by_passe
},
{
label: '# skills',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_1,
borderColor: 'rgb(255, 99, 132)',
pointBackgroundColor: 'rgb(255, 99, 132)',
fill: true,
data: compulsory_routine_scrore
data: mean_quantity_of_skill_by_time
},
{% endif %}
{% if score_routine2_list %}
{
label: 'Q1R2',
label: '# skill/pass',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_2,
borderColor: 'rgb(255, 159, 64)',
pointBackgroundColor: 'rgb(255, 159, 64)',
fill: true,
data: voluntary_routine_scrore
data: mean_quantity_of_skill_by_passe
},
{% endif %}
{% if score_routine3_list %}
{
label: 'Q2R1',
label: 'diff/skill',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_3,
borderColor: 'rgb(54, 162, 235)',
pointBackgroundColor: 'rgb(54, 162, 235)',
fill: true,
data: final_routine_scrore
data: mean_difficulty_by_skill
},
{% endif %}
],
}
@ -200,6 +183,7 @@
},
});
{% endif %}
/*
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',

View File

@ -5,26 +5,27 @@
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h4>Intensity statistics</h4>
<h4>Scores</h4>
</div>
<div class="card-body pt-0 pb-0 pr-0 pl-0">
{% if intensity_list %}
<div><canvas id="chart_intensity" class="chartjs" width="400" height="200"></canvas></div>
{% if score_list %}
<div><canvas id="chart_score_competition" class="chartjs" width="400" height="200"></canvas></div>
{% else %}
<p class="pl-3 text-muted">No intensity recorded for this gymnast.</p>
<p class="pl-3 text-muted">No score recorded for this gymnast.</p>
{% endif %}
</div>
<div class="card-footer text-right text-muted pt-0">
{% if intensity_list %}
<a href="{% url 'intensity_list_for_gymnast' gymnast_id %}">
<button type="submit" value="list" class="btn btn-icon btn-warning mr-2">
<i class="fal fa-analytics"></i> <!-- Routines -->
{% if score_list %}
<a href="{% url 'score_list_for_gymnast' gymnast_id %}">
<button type="submit" value="add" class="btn btn-icon btn-warning mr-2">
<i class="fal fa-crosshairs"></i>
</button>
</a>
{% endif %}
{% if request.user|has_group:"trainer" or request.user|is_user_equal_to_gymnast:gymnast_id %}
<a href="{% url 'intensity_create_for_gymnast' gymnast_id %}">
<a href="{% url 'score_create_for_gymnast' gymnast_id %}">
<button type="submit" value="add" class="btn btn-icon btn-warning ">
<i class="fas fa-plus"></i>
</button>
@ -215,75 +216,91 @@
var timeFormat = 'DD-MM-YYYY';
{% if intensity_list %}
var ctx = document.getElementById('chart_intensity').getContext('2d');
{% if score_list %}
var ctx = document.getElementById('chart_score_competition').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 mean_difficulty_by_passe = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_difficulty_by_passe_in_unit }}'
},
gradient_stroke_1.addColorStop(1, 'rgba(255, 99, 132, 0.4)');
gradient_stroke_1.addColorStop(0.75, 'rgba(255, 99, 132, 0.3)');
gradient_stroke_1.addColorStop(0.5, 'rgba(255, 99, 132, 0.2)');
gradient_stroke_1.addColorStop(0.25, 'rgba(255, 99, 132, 0)');
gradient_stroke_2.addColorStop(1, 'rgba(255, 159, 64, 0.4)');
gradient_stroke_2.addColorStop(0.75, 'rgba(255, 159, 64, 0.3)');
gradient_stroke_2.addColorStop(0.5, 'rgba(255, 159, 64, 0.2)');
gradient_stroke_2.addColorStop(0.25, 'rgba(255, 159, 64, 0)');
gradient_stroke_3.addColorStop(1, 'rgba(54, 162, 235, 0.4)');
gradient_stroke_3.addColorStop(0.75, 'rgba(54, 162, 235, 0.3)');
gradient_stroke_3.addColorStop(0.5, 'rgba(54, 162, 235, 0.2)');
gradient_stroke_3.addColorStop(0.25, 'rgba(54, 162, 235, 0)');
var compulsory_routine_scrore = [
{% for score in score_routine1_list %}
{
x: '{{ score.event.date_begin | date:"d-m-Y" }}',
y: '{{ score.total }}'
},
{% endfor %}
];
var mean_quantity_of_skill_by_time = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_quantity_of_skill_by_time }}'
},
var voluntary_routine_scrore = [
{% for score in score_routine2_list %}
{
x: '{{ score.event.date_begin | date:"d-m-Y" }}',
y: '{{ score.total }}'
},
{% endfor %}
];
var mean_quantity_of_skill_by_passe = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_quantity_of_skill_by_passe }}'
},
{% endfor %}
];
var mean_difficulty_by_skill = [
{% for score in intensity_list %}
{
x: '{{ score.date | date:"d-m-Y" }}',
y: '{{ score.mean_difficulty_by_skill }}'
},
var final_routine_scrore = [
{% for score in score_routine3_list %}
{
x: '{{ score.event.date_begin | date:"d-m-Y" }}',
y: '{{ score.total }}'
},
{% endfor %}
];
var score_values = {
datasets: [
{% if score_routine1_list %}
{
label: 'diff/pass',
cubicInterpolationMode: 'monotone',
borderColor: 'rgb(75, 192, 192)',
pointBackgroundColor: 'rgb(75, 192, 192)',
data: mean_difficulty_by_passe
},
{
label: '# skills',
label: 'Q1R1',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_1,
borderColor: 'rgb(255, 99, 132)',
pointBackgroundColor: 'rgb(255, 99, 132)',
data: mean_quantity_of_skill_by_time
fill: true,
data: compulsory_routine_scrore
},
{% endif %}
{% if score_routine2_list %}
{
label: '# skill/pass',
label: 'Q1R2',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_2,
borderColor: 'rgb(255, 159, 64)',
pointBackgroundColor: 'rgb(255, 159, 64)',
data: mean_quantity_of_skill_by_passe
fill: true,
data: voluntary_routine_scrore
},
{% endif %}
{% if score_routine3_list %}
{
label: 'diff/skill',
label: 'Q2R1',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_3,
borderColor: 'rgb(54, 162, 235)',
pointBackgroundColor: 'rgb(54, 162, 235)',
data: mean_difficulty_by_skill
fill: true,
data: final_routine_scrore
},
{% endif %}
],
}

View File

@ -301,19 +301,18 @@ def gymnast_display_scores_chrono(request, gymnast_id):
Args:
gymnast_id (int) identifiant du gymnast
TODO: limiter les intensités aux X derniers records/semaines/mois ?
"""
start_date = pendulum.now().date().subtract(months=6)
score_list = Point.objects.filter(gymnast=gymnast_id).order_by("-event__date_begin")
intensity_list = Intensity.objects.filter(gymnast=gymnast_id).order_by("date")
chrono_list = Chrono.objects.filter(
gymnast=gymnast_id, date__gte=start_date
).order_by("date")
base_queryset = chrono_list.values("date").annotate(score_avg=Avg("tof"))
context = {
"score_list": score_list,
"score_routine1_list": score_list.filter(routine_type=1),
"score_routine2_list": score_list.filter(routine_type=2),
"score_routine3_list": score_list.filter(routine_type=3),
"intensity_list": intensity_list,
"chrono_list": chrono_list,
"chrono_10c": base_queryset.filter(chrono_type=0),
"chrono_r1": base_queryset.filter(chrono_type=1),
@ -321,7 +320,7 @@ def gymnast_display_scores_chrono(request, gymnast_id):
"chrono_rf": base_queryset.filter(chrono_type=3),
"gymnast_id": gymnast_id,
}
return render(request, "gymnasts/tabs/tab_scores_and_chronos.html", context)
return render(request, "gymnasts/tabs/tab_intensity_and_chronos.html", context)
# @login_required
@ -368,7 +367,7 @@ def gymnast_display_routine_statistics(request, gymnast_id):
routine_two_done_list = NumberOfRoutineDone.objects.filter(
gymnast=gymnast_id, routine_type=2
).order_by("date")
intensity_list = Intensity.objects.filter(gymnast=gymnast_id).order_by("date")
score_list = Point.objects.filter(gymnast=gymnast_id).order_by("-event__date_begin")
context = {
"ghr_list": ghr_list,
@ -379,10 +378,13 @@ def gymnast_display_routine_statistics(request, gymnast_id):
"has_routine_5": has_routine_5,
"routine_one_done_list": routine_one_done_list,
"routine_two_done_list": routine_two_done_list,
"intensity_list": intensity_list,
"score_list": score_list,
"score_routine1_list": score_list.filter(routine_type=1),
"score_routine2_list": score_list.filter(routine_type=2),
"score_routine3_list": score_list.filter(routine_type=3),
"gymnast_id": gymnast_id,
}
return render(request, "gymnasts/tabs/tab_routines_and_routine_stats.html", context)
return render(request, "gymnasts/tabs/tab_routines_and_scores.html", context)
@login_required