update enum variant value and add exception if not found + sort dates (#1)

This commit is contained in:
landrigun 2022-04-13 11:52:40 +00:00
parent fc7b84da28
commit 7ac6c5ff33

View File

@ -66,15 +66,18 @@ class Quota(DreesEnum):
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")
CM3MSR = (3, "Complet de moins de 3 mois - sans rappel")
CM3MAR = (4, "Complet de moins de 3 mois - avec rappel")
CM3MAR = (4, "Complet - avec rappel de moins de 3 mois")
CM36MSR = (5, "Complet entre 3 mois et 6 mois - sans rappel")
CM36MAR = (6, "Complet entre 3 mois et 6 mois - avec rappel")
C6MAR = (7, "Complet de 6 mois et plus - avec rappel")
C6MSR = (8, "Complet de 6 mois et plus - sans rappel")
CM36MAR = (6, "Complet - avec rappel entre 3 mois et 6 mois")
C6MAR = (7, "Complet - avec rappel de 6 mois ou plus")
C6MSR = (8, "Complet de 6 mois ou plus - sans rappel")
class AgeGroup(DreesEnum):
@ -124,12 +127,14 @@ def get_enum_vac_status(value):
for vac_status in VacStatus:
if vac_status.label == value:
return vac_status.value
raise Exception(f"vac status : {value} does not exit in enum 'VacStatus'")
def get_enum_age(value):
for age_group in AgeGroup:
if age_group.label == value:
return age_group.value
raise Exception(f"age : {value} does not exit in enum 'AgeGroup'")
def get_enum_field(value):
@ -139,6 +144,7 @@ def get_enum_field(value):
for quota in Quota:
if quota.name.lower() == value:
return quota.value
raise Exception(f"field : {value} does not exit in enum 'Field'")
def structure_data(data: Dict[str, Any]) -> Dict[dt, Any]:
@ -197,6 +203,7 @@ 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}")