ordering dic_data by date (keys) + set to 0 'effectif' lower thant 0 + dotted line for graphs by fields and ages + black (#1)

This commit is contained in:
landrigun 2022-04-13 13:36:28 +00:00
parent 7ac6c5ff33
commit 5c499bebee

View File

@ -69,6 +69,7 @@ class VacStatus(DreesEnum):
"""
WARN: Be careful, after refreshing dataset, some VacStatus can changed
"""
NC = (0, "Non-vaccinés")
PDR = (1, "Primo dose récente")
PDE = (2, "Primo dose efficace")
@ -180,6 +181,8 @@ def structure_data(data: Dict[str, Any]) -> Dict[dt, Any]:
for quota in Quota:
quota_name = quota.name.lower()
dic_data[date][age][vac_status][quota_name] = row_fields[quota_name]
# order `dic_data` date keys in ascending order
dic_data = OrderedDict(sorted(dic_data.items(), key=lambda t: t[0]))
logging.info("data restructured")
return dic_data
@ -203,10 +206,12 @@ def get_np_data(dic_data: Dict[dt, Any]) -> Tuple[np.ndarray, np.ndarray]:
idx_field = get_enum_field(field)
np_data[idx_date, idx_age, idx_vac, idx_field] = value
logging.info("date and data generated")
np_date = np.array(sorted(np_date))
date_start = np_date[0]
date_end = np_date[len(np_date) - 1]
logging.info(f"range period : {date_start} - {date_end}")
# set 'effectif' equals to 0 if effectif < 1 (0.04 means nothing...)
quota_mask = np_data[:, :, :, 3] < 1
np_data[quota_mask] = 0
return np_data, np_date
@ -470,12 +475,13 @@ def plot_fields_by_age_vac(
fig, _ = get_plot_fig()
for field in Field:
plt.plot(
np_date,
np_result = (
10e6
* np_data[:, age_group.value, vac_status.value, field.value]
/ np_data[:, age_group.value, vac_status.value, Quota.EFFECTIF.value],
label=f"{field.label}",
/ np_data[:, age_group.value, vac_status.value, Quota.EFFECTIF.value]
)
plt.plot(
np_date, np_result, label=f"{field.label}", linestyle="dotted", linewidth=2
)
plt.xlabel("Date")
plt.ylabel("Cas par million de personnes")