New height/weight list for gymnast

This commit is contained in:
Gregory Trullemans 2024-04-10 12:15:20 +02:00
parent 9f889f27be
commit c3cde290e9
4 changed files with 208 additions and 32 deletions

View File

@ -374,6 +374,7 @@ class HeightWeight(Seasonisable):
verbose_name = "Height & weight"
verbose_name_plural = "Heights & weights"
unique_together = ("gymnast", "date")
ordering = ["date",]
gymnast = models.ForeignKey(
Gymnast,

View File

@ -1,5 +1,6 @@
{% extends "listing.html" %}
{% load has_group %}
{% load static %}
{% block datacontent %}
<div class="row justify-content-center">
@ -12,7 +13,7 @@
<div class="col-2 ml-auto pl-0">
<div class="text-right">
{% if request.user|has_group:"trainer" %}
<a href="{% if gymnast %}{% url 'heightweight_create_for_gymnast' gymnast.id %}{% else %}{% url 'heightweight_create' %}{% endif %}">
<a href="{% if gymnast %}{% url 'heightweight_create_for_gymnast' gymnast.id %}{% else %}{% url 'height_weight_create' %}{% endif %}">
<button type="submit" value="add" class="btn btn-icon btn-warning ">
<i class="fas fa-plus"></i>
</button>
@ -22,8 +23,75 @@
</div>
</div>
<div class="card-body pt-1">
{% if heightweight_list %}
<table class="table tablesorter table-striped mb-0" data-sort="table" id="heightweight_table">
{% if gymnast %}
<div class="row">
<div class="col-md-6">
<table class="table tablesorter table-striped mb-0" data-sort="table" id="height_weight_table">
<thead>
<tr>
<th></th>
<th class="header text-left">Date</th>
<th class="header text-center">Height</th>
<th class="header text-center">Hips height</th>
<th class="header text-center">Weight</th>
<th class="header text-center">BMI</th>
</tr>
</thead>
<tbody>
{% for height_weight in height_weight_list %}
<tr>
<td>
<a href="{% url 'heightweight_update' height_weight.id %}">
<span class="tim-icons icon-pencil text-warning"></span>
</a>
</td>
<td class="text-left">{{ height_weight.date | date:"j-n-Y" }}</td>
<td class="text-center">{{ height_weight.height }}</td>
<td class="text-center">{% if height_weight.hips_height == None %}-{% else %}{{ height_weight.hips_height }}{% endif %}</td>
<td class="text-center">{{ height_weight.weight }}</td>
<td class="text-center">
{% if gymnast %}
{% if gymnast.gender == 0 %}
{% if height_weight.bmi < 19 %}
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 21 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 23 %}
<span class="text-success"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 25 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% else %}
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% endif %}
{% else %}
{% if height_weight.bmi < 21 %}
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 23 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 25 %}
<span class="text-success"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 27 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% else %}
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% endif %}
{% endif %}
{% else %}
<b>{{ height_weight.bmi | floatformat:2 }}</b>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-md-6">
<canvas id="chart_height_weight" class="chartjs" width="400" height="200"></canvas>
</div>
</div>
{% else %}
{% if height_weight_list %}
<table class="table tablesorter table-striped mb-0" data-sort="table" id="height_weight_table">
<thead>
<tr>
<th></th>
@ -38,49 +106,49 @@
</tr>
</thead>
<tbody>
{% for heightweight in heightweight_list %}
{% for height_weight in height_weight_list %}
<tr>
<td>
<a href="{% url 'heightweight_update' heightweight.id %}">
<a href="{% url 'height_weight_update' height_weight.id %}">
<span class="tim-icons icon-pencil text-warning"></span>
</a>
</td>
<td class="text-left">{{ heightweight.date | date:"j-n-Y" }}</td>
<td class="text-left">{{ height_weight.date | date:"j-n-Y" }}</td>
{% if not gymnast %}
<td class="text-left">{% if gymnast.id in request.session.available_gymnast or request.user.is_superuser %}<a href="{% url 'gymnast_details' heightweight.gymnast.id %}">{% endif %}{{ heightweight.gymnast }}</a></td>
<td class="text-left">{% if gymnast.id in request.session.available_gymnast or request.user.is_superuser %}<a href="{% url 'gymnast_details' height_weight.gymnast.id %}">{% endif %}{{ height_weight.gymnast }}</a></td>
{% endif %}
<td class="text-center">{{ heightweight.height }}</td>
<td class="text-center">{% if heightweight.hips_height == None %}-{% else %}{{ heightweight.hips_height }}{% endif %}</td>
<td class="text-center">{{ heightweight.weight }}</td>
<td class="text-center">{{ height_weight.height }}</td>
<td class="text-center">{% if height_weight.hips_height == None %}-{% else %}{{ height_weight.hips_height }}{% endif %}</td>
<td class="text-center">{{ height_weight.weight }}</td>
<td class="text-center">
{% if gymnast %}
{% if gymnast.gender == 0 %}
{% if heightweight.bmi < 19 %}
<span class="text-danger"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% elif heightweight.bmi < 21 %}
<span class="text-warning"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% elif heightweight.bmi < 23 %}
<span class="text-success"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% elif heightweight.bmi < 25 %}
<span class="text-warning"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% if height_weight.bmi < 19 %}
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 21 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 23 %}
<span class="text-success"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 25 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% else %}
<span class="text-danger"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% endif %}
{% else %}
{% if heightweight.bmi < 21 %}
<span class="text-danger"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% elif heightweight.bmi < 23 %}
<span class="text-warning"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% elif heightweight.bmi < 25 %}
<span class="text-success"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% elif heightweight.bmi < 27 %}
<span class="text-warning"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
{% if height_weight.bmi < 21 %}
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 23 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 25 %}
<span class="text-success"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% elif height_weight.bmi < 27 %}
<span class="text-warning"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% else %}
<span class="text-danger"><b>{{ heightweight.bmi | floatformat:2 }}</b></span>
<span class="text-danger"><b>{{ height_weight.bmi | floatformat:2 }}</b></span>
{% endif %}
{% endif %}
{% else %}
<b>{{ heightweight.bmi | floatformat:2 }}</b>
<b>{{ height_weight.bmi | floatformat:2 }}</b>
{% endif %}
</td>
</tr>
@ -90,6 +158,7 @@
{% else %}
<p class="text-muted">There are no scores corresponding to your criterias</p>
{% endif %}
{% endif %}
</div>
</div>
</div>
@ -97,6 +166,7 @@
{% endblock %}
{% block footerscript %}
<script src="{% static "js/template_users/chart_gradient_color.js" %}"></script>
<script type="text/javascript">
$(document).ready(function () {
$('[data-sort="table"]').tablesorter({
@ -107,7 +177,7 @@
sortList: [[1, 1]]
});
$('#heightweight_table').DataTable({
$('#height_weight_table').DataTable({
scrollY: '50vh',
scrollCollapse: true,
paging: false,
@ -116,5 +186,107 @@
"bInfo" : false,
});
});
var timeFormat = 'DD-M-YYYY';
$('#injury_table').tablesorter({
headers: {
0: { sorter: false },
},
dateFormat: "uk",
sortList: [[1, 1]]
});
{% if height_weight_list %}
var ctx = document.getElementById("chart_height_weight").getContext("2d");
var border_color_pink = 'rgb(255, 99, 132)';
var gradient_stroke_pink = ctx.createLinearGradient(0, 230, 0, 50);
gradient_stroke_pink.addColorStop(1, 'rgba(255, 99, 132, 0.4)');
gradient_stroke_pink.addColorStop(0.75, 'rgba(255, 99, 132, 0.3)');
gradient_stroke_pink.addColorStop(0.5, 'rgba(255, 99, 132, 0.2)');
gradient_stroke_pink.addColorStop(0.25, 'rgba(255, 99, 132, 0)');
var border_color_orange = 'rgb(255, 159, 64)';
var gradient_stroke_orange = ctx.createLinearGradient(0, 230, 0, 50);
gradient_stroke_orange.addColorStop(1, 'rgba(255, 159, 64, 0.4)');
gradient_stroke_orange.addColorStop(0.75, 'rgba(255, 159, 64, 0.3)');
gradient_stroke_orange.addColorStop(0.5, 'rgba(255, 159, 64, 0.2)');
gradient_stroke_orange.addColorStop(0.25, 'rgba(255, 159, 64, 0)');
var height_values = [
{% for height_weight in height_weight_list %}
{
x: '{{ height_weight.date | date:"d-m-Y" }}',
y: '{{ height_weight.weight }}'
},
{% endfor %}
]
var weight_values = [
{% for height_weight in height_weight_list %}
{
x: '{{ height_weight.date | date:"d-m-Y" }}',
y: '{{ height_weight.height | add:"-100" }}'
},
{% endfor %}
]
var height_weight_data = {
datasets: [
{
label: 'Weight',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_pink,
borderColor: border_color_pink,
pointBackgroundColor: border_color_pink,
fill: true,
data: height_values,
},
{
label: 'Height',
cubicInterpolationMode: 'monotone',
backgroundColor: gradient_stroke_orange,
borderColor: border_color_orange,
pointBackgroundColor: border_color_orange,
fill: true,
data: weight_values
},
],
};
new Chart(ctx, {
responsive: true,
type: 'line',
data: height_weight_data,
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

@ -350,7 +350,7 @@ def heightweight_listing(request, gymnast_id=None):
gymnast__in=request.session["available_gymnast"]
)
context = {"heightweight_list": heightweight_list, "gymnast": gymnast}
context = {"height_weight_list": heightweight_list, "gymnast": gymnast}
return render(request, "heightweight/list.html", context)

View File

@ -237,7 +237,10 @@ def gymnast_display_physiological(request, gymnast_id):
).order_by("date")
height_weight_list = HeightWeight.objects.filter(
gymnast=gymnast_id, date__gte=start_date
).order_by("date")
)
if height_weight_list.count() <= 3:
height_weight_list = HeightWeight.objects.filter(gymnast=gymnast_id).order_by("-date")[:5][::-1]
context = {
"injury_list": injury_list,