put analyse data in namedtuple list + add global data in html template + fix css
This commit is contained in:
parent
37712f892d
commit
3952c6cab2
30
drees.py
30
drees.py
@ -3,11 +3,12 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from collections import namedtuple
|
||||
from datetime import datetime as dt
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from multiprocessing import Pool
|
||||
from typing import Any, Dict, List, Optional, OrderedDict, Tuple
|
||||
from typing import Any, Dict, List, Optional, OrderedDict, Tuple, Union
|
||||
|
||||
import numpy as np
|
||||
import requests
|
||||
@ -33,7 +34,8 @@ OUTPUT_SUFFIX = f"{TMP_SUFFIX}{FORMAT_SUFFIX}"
|
||||
|
||||
TMP_FILE_REGEX = re.compile(r"^.*{}$".format(OUTPUT_SUFFIX.replace(".", "\.")))
|
||||
|
||||
MAIN_URL = "https://covid.thegux.fr/"
|
||||
# MAIN_URL = "https://covid.thegux.fr/"
|
||||
MAIN_URL = "/home/romain/code/covid-plotter/"
|
||||
|
||||
# cycler could be better, but for ages plots it's ok
|
||||
AGE_COLORS = {
|
||||
@ -79,6 +81,10 @@ class AgeGroup(DreesEnum):
|
||||
VERY_OLD = (4, "[80;+]")
|
||||
|
||||
|
||||
VaccineMean = namedtuple("VaccineMean", ["age", "field", "percent"])
|
||||
AgeMean = namedtuple("AgeMean", ["age", "field", "percent"])
|
||||
|
||||
|
||||
def get_data(
|
||||
file_path: Optional[str] = None,
|
||||
extension: Optional[str] = "json",
|
||||
@ -283,11 +289,12 @@ def save_and_close_fig(
|
||||
logging.info(f"{output_path} plotted")
|
||||
|
||||
|
||||
def analyse(np_data: np.ndarray, np_date: np.ndarray) -> None:
|
||||
def analyse(np_data: np.ndarray) -> List[Union[VaccineMean, AgeMean]]:
|
||||
"""
|
||||
analyse data
|
||||
"""
|
||||
logging.info("analysing data...")
|
||||
lst_analyse_data: List[Union[VaccineMean, AgeMean]] = list()
|
||||
np_percent_vac, _ = get_vaccine_percent(np_data)
|
||||
|
||||
logging.info("--- field by age vaccine mean percent ---")
|
||||
@ -297,6 +304,9 @@ def analyse(np_data: np.ndarray, np_date: np.ndarray) -> None:
|
||||
np.nanmean(np_percent_vac[:, age_group.value, field.value]) * 100, 2
|
||||
)
|
||||
print(f"{field.name} - {age_group.label} - vac : {mean_vac_percent}%")
|
||||
lst_analyse_data.append(
|
||||
VaccineMean(age_group.label, field.label, mean_vac_percent)
|
||||
)
|
||||
|
||||
logging.info("--- age by field and vac status mean percent ---")
|
||||
for field in Field:
|
||||
@ -310,6 +320,9 @@ def analyse(np_data: np.ndarray, np_date: np.ndarray) -> None:
|
||||
np.nanmean(np_percent_age[:, age_group.value]), 2
|
||||
)
|
||||
print(f"age: {age_group.label} - field: {field.name} = {percent_age_mean}%")
|
||||
lst_analyse_data.append(
|
||||
AgeMean(age_group.label, field.label, percent_age_mean)
|
||||
)
|
||||
|
||||
percent_age_vac_mean = np.round(
|
||||
np.nanmean(np_percent_age_vac[:, age_group.value]), 2
|
||||
@ -324,6 +337,7 @@ def analyse(np_data: np.ndarray, np_date: np.ndarray) -> None:
|
||||
print(
|
||||
f"age: {age_group.label} - status: unvac - field: {field.name} = {percent_age_unvac_mean}%"
|
||||
)
|
||||
return lst_analyse_data
|
||||
|
||||
|
||||
def plot_bar_age_percent_vac_status_by_field(
|
||||
@ -523,7 +537,9 @@ def move_tmp_plots() -> None:
|
||||
logging.info("files moved")
|
||||
|
||||
|
||||
def generate_html_page(np_date: np.ndarray) -> None:
|
||||
def generate_html_page(
|
||||
np_date: np.ndarray, lst_analyse_data: List[Union[VaccineMean, AgeMean]]
|
||||
) -> None:
|
||||
logging.info("generating html page with plots...")
|
||||
os.makedirs(BUILD_REPOSITORY, exist_ok=True)
|
||||
env = Environment(
|
||||
@ -540,6 +556,8 @@ def generate_html_page(np_date: np.ndarray) -> None:
|
||||
"static": os.path.join(MAIN_URL, STATIC_REPOSITORY),
|
||||
"src": DATA_URL,
|
||||
"period": f"{date_start} - {date_end}",
|
||||
"vaccine_mean": [x for x in lst_analyse_data if type(x) == VaccineMean],
|
||||
"age_mean": [x for x in lst_analyse_data if type(x) == AgeMean],
|
||||
}
|
||||
)
|
||||
with open(os.path.join(BUILD_REPOSITORY, "index.html"), "w") as f:
|
||||
@ -593,7 +611,7 @@ if __name__ == "__main__":
|
||||
dic_data_grouped: Dict[dt, Any] = group_by_age_date(dic_data)
|
||||
np_data, np_date = get_np_data(dic_data_grouped)
|
||||
|
||||
analyse(np_data, np_date)
|
||||
lst_analyse_data = analyse(np_data)
|
||||
|
||||
if not args.no_plot:
|
||||
os.makedirs(OUTPUT_REPOSITORY, exist_ok=True)
|
||||
@ -612,4 +630,4 @@ if __name__ == "__main__":
|
||||
move_tmp_plots()
|
||||
|
||||
if args.to_html:
|
||||
generate_html_page(np_date)
|
||||
generate_html_page(np_date, lst_analyse_data)
|
||||
|
||||
@ -18,14 +18,52 @@
|
||||
flex: 0 1 33%
|
||||
}
|
||||
|
||||
.table-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.table-item {
|
||||
flex: 0 1 33%
|
||||
}
|
||||
|
||||
.img-bars {
|
||||
width: 1500px;
|
||||
height: 500px;
|
||||
border: solid
|
||||
}
|
||||
|
||||
table, th, td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: auto;
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
hr {
|
||||
width: 100%;
|
||||
margin-top: 40px;
|
||||
border: 0;
|
||||
height: 1px;
|
||||
background: #333;
|
||||
background-image: -webkit-linear-gradient(left, #ccc, #333, #ccc);
|
||||
background-image: -moz-linear-gradient(left, #ccc, #333, #ccc);
|
||||
background-image: -ms-linear-gradient(left, #ccc, #333, #ccc);
|
||||
background-image: -o-linear-gradient(left, #ccc, #333, #ccc);
|
||||
}
|
||||
|
||||
h1, h3, h5 {
|
||||
text-decoration: underline;
|
||||
}
|
||||
@ -1,24 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Thegux covid-19</title>
|
||||
<title>Covid-19 DREES dataset</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="keywords" content="thegux, covid">
|
||||
<link rel="stylesheet" href="{{ static }}/css/index.css">
|
||||
<meta name="description" content="A simple page to share some useful data about covid 19">
|
||||
<meta name="description" content="A simple page to share some useful data about DREES covid 19 dataset">
|
||||
</head>
|
||||
<body>
|
||||
<div class="main-container">
|
||||
<h1>Thegux covid-19</h1>
|
||||
<h1>Covid-19 DREES dataset</h1>
|
||||
<div>source : <a href="{{ src }}">Data DRESS</a></div>
|
||||
<div>période temporelle : <b>{{ period }}</b></div>
|
||||
<div>pas de temps : <b>journalier</b></div>
|
||||
<h3>Hospitalisations/Soins critiques/Décés par status vaccinal groupés et tranches d'âges</h3>
|
||||
<div>contact: <b>admin@thegux.fr</b></div>
|
||||
<hr/>
|
||||
<h3>Données globales</h3>
|
||||
<h5>Répartition des tranches d'âges par catégorie (moyennée sur la période temporelle)</h5>
|
||||
<div class="table-container">
|
||||
{% for field in fields %}
|
||||
<div class="table-item">
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="2">{{ field.label }}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Age</th>
|
||||
<th>%</th>
|
||||
</tr>
|
||||
{% for mean in age_mean %}
|
||||
{% if field.label == mean.field %}
|
||||
<tr>
|
||||
<td>{{ mean.age }}</td>
|
||||
<td>{{ mean.percent }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<h5>Pourcentage de vaccinés par catégorie (moyenné sur la période temporelle)</h5>
|
||||
<div class="table-container">
|
||||
{% for field in fields %}
|
||||
<div class="table-item">
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="2">{{ field.label }}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Age</th>
|
||||
<th>%</th>
|
||||
</tr>
|
||||
{% for mean in vaccine_mean %}
|
||||
{% if field.label == mean.field %}
|
||||
<tr>
|
||||
<td>{{ mean.age }}</td>
|
||||
<td>{{ mean.percent }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<hr/>
|
||||
<h3>Hospitalisations/Soins critiques/Décés par status vaccinal et tranches d'âges groupées</h3>
|
||||
{% for field in fields %}
|
||||
<img src="{{ static }}/plots/age_percent_vac_{{ field.name.lower() }}.png"/>
|
||||
<img src="{{ static }}/plots/age_percent_unvac_{{ field.name.lower() }}.png"/>
|
||||
{% endfor %}
|
||||
<h3>Hospitalisations/Soins critiques/Décés par tranches d'âges groupés et status vaccinal</h3>
|
||||
<h3>Hospitalisations/Soins critiques/Décés par tranches d'âges et status vaccinal groupé</h3>
|
||||
{% for age in ages %}
|
||||
{% for field in fields %}
|
||||
<img src="{{ static }}/plots/vac_percent_{{ age.name.lower() }}_{{ field.name.lower() }}.png"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user