-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
public_data/infra/consommation/progression/table/ConsoByDeterminantTableMapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.template.loader import render_to_string | ||
|
||
from public_data.domain.consommation.entity import ConsommationCollection | ||
|
||
|
||
class ConsoByDeterminantTableMapper: | ||
@staticmethod | ||
def map(consommation_progression: list[ConsommationCollection]): | ||
category_to_attr = { | ||
"Habitat": "habitat", | ||
"Activité": "activite", | ||
"Mixte": "mixte", | ||
"Route": "route", | ||
"Ferré": "ferre", | ||
"Inconnu": "non_reseigne", | ||
"Total": "total", | ||
} | ||
|
||
headers = ["Destination"] + [str(conso.year) for conso in consommation_progression] + ["Total"] | ||
|
||
data = [] | ||
for category in category_to_attr: | ||
category_values = [getattr(conso, category_to_attr[category]) for conso in consommation_progression] | ||
category_total = sum(category_values) | ||
# On arrondit ensuite pour ne pas fausser le total | ||
category_values_rounded = [round(value, 2) for value in category_values] | ||
category_total_rounded = round(category_total, 2) | ||
data.append([category] + category_values_rounded + [category_total_rounded]) | ||
|
||
return render_to_string( | ||
"public_data/partials/conso_by_determinant_table.html", | ||
{ | ||
"headers": headers, | ||
"data": data, | ||
}, | ||
) | ||
|
||
return render_to_string( | ||
"public_data/partials/conso_by_determinant_table.html", | ||
{ | ||
"headers": headers, | ||
"data": data, | ||
}, | ||
) |
33 changes: 33 additions & 0 deletions
33
public_data/templates/public_data/partials/conso_by_determinant_table.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div class="fr-table fr-table--bordered"> | ||
<div class="fr-table__wrapper"> | ||
<div class="fr-table__container"> | ||
<div class="fr-table__content"> | ||
<table> | ||
<caption> | ||
Consommation d'espaces NAF sur le territoire par an et par destination (en ha) | ||
</caption> | ||
<thead> | ||
<tr> | ||
{% for header in headers %} | ||
<th scope="col" class="{% if forloop.first %}fr-text--bold fr-cell--fixed{% else %}fr-cell--right{% endif %} {% if forloop.last %}fr-text--bold{% endif %}"> | ||
{{ header }} | ||
</th> | ||
{% endfor %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for row in data %} | ||
<tr class="{% if forloop.last %}fr-text--bold{% endif %}"> | ||
{% for cell in row %} | ||
<td class="{% if forloop.first %}fr-text--bold fr-cell--fixed{% else %}fr-cell--right{% endif %} {% if forloop.last %}fr-text--bold{% endif %}"> | ||
{{ cell }} | ||
</td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |