group plotted data by fields
This commit is contained in:
parent
08cfc98dec
commit
ad9df230a5
51
drees.py
51
drees.py
@ -179,6 +179,22 @@ def get_values_by_age_vac_field(
|
|||||||
return dates, fields
|
return dates, fields
|
||||||
|
|
||||||
|
|
||||||
|
def get_values_by_age_vac(
|
||||||
|
dic_data_grouped: Dict[dt, Any], age: AgeGroup, vac_status: VacStatus
|
||||||
|
) -> Tuple[List[dt], List[Dict[str, Any]]]:
|
||||||
|
"""
|
||||||
|
get deep fields data by age and vaccine status
|
||||||
|
"""
|
||||||
|
dates: List[dt] = list()
|
||||||
|
fields: List[Dict[str, Any]] = list()
|
||||||
|
for date, dic_age_grouped in dic_data_grouped.items():
|
||||||
|
if (dic_vac_status := dic_age_grouped.get(age.value)) is not None:
|
||||||
|
if (dic_field := dic_vac_status.get(vac_status.value)) is not None:
|
||||||
|
fields.append(dic_field)
|
||||||
|
dates.append(date)
|
||||||
|
return dates, fields
|
||||||
|
|
||||||
|
|
||||||
def plot_cumulative_field(dic_data_grouped: Dict[dt, Any], field: Field) -> None:
|
def plot_cumulative_field(dic_data_grouped: Dict[dt, Any], field: Field) -> None:
|
||||||
fig = get_plot_fig()
|
fig = get_plot_fig()
|
||||||
|
|
||||||
@ -197,37 +213,44 @@ def plot_cumulative_field(dic_data_grouped: Dict[dt, Any], field: Field) -> None
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def plot_data(
|
def extract_field_values(fields: List[Dict[str, Any]], field: Field) -> np.ndarray:
|
||||||
dic_data_grouped: Dict[dt, Any], age: AgeGroup, vac_status: VacStatus, field: Field
|
field_values: List[float] = list()
|
||||||
|
for item in fields:
|
||||||
|
if (value := item.get(field)) is not None:
|
||||||
|
field_values.append(value)
|
||||||
|
return np.asarray(field_values)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_data_by_field(
|
||||||
|
dic_data_grouped: Dict[dt, Any], age: AgeGroup, vac_status: VacStatus
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Plot data by vaccine status, age and field
|
Plot data by vaccine status, age and field
|
||||||
"""
|
"""
|
||||||
fig = get_plot_fig()
|
fig = get_plot_fig()
|
||||||
|
|
||||||
dates, fields = get_values_by_age_vac_field(
|
dates, fields = get_values_by_age_vac(dic_data_grouped, age, vac_status)
|
||||||
dic_data_grouped, age, vac_status, field
|
|
||||||
)
|
|
||||||
|
|
||||||
plt.plot(dates, fields, label=f"{field.value}")
|
for field in Field:
|
||||||
plt.xlabel("date")
|
field_values = extract_field_values(fields, field)
|
||||||
plt.ylabel("nombre")
|
plt.plot(dates, field_values, label=f"{field.value}")
|
||||||
plt.title(f"{age}ans - {vac_status}")
|
plt.xlabel("date")
|
||||||
|
plt.ylabel("nombre")
|
||||||
|
plt.title(f"{age}ans - {vac_status}")
|
||||||
|
|
||||||
save_and_close_fig(
|
save_and_close_fig(
|
||||||
fig, os.path.join(OUTPUT_REPOSITORY, f"{age}_{vac_status}_{field}.pdf")
|
fig, os.path.join(OUTPUT_REPOSITORY, f"{age}_{vac_status}_{field}.pdf")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def build_data_pool_args() -> List[Tuple[AgeGroup, VacStatus, Field]]:
|
def build_data_pool_args() -> List[Tuple[AgeGroup, VacStatus]]:
|
||||||
"""
|
"""
|
||||||
build tuple arguments to plot all data on multiprocess
|
build tuple arguments to plot all data on multiprocess
|
||||||
"""
|
"""
|
||||||
pool_args: List[Tuple[AgeGroup, VacStatus, Field]] = list()
|
pool_args: List[Tuple[AgeGroup, VacStatus]] = list()
|
||||||
for age_group in AgeGroup:
|
for age_group in AgeGroup:
|
||||||
for vac_status in VacStatus:
|
for vac_status in VacStatus:
|
||||||
for field in Field:
|
pool_args.append((age_group, vac_status))
|
||||||
pool_args.append((age_group, vac_status, field))
|
|
||||||
return pool_args
|
return pool_args
|
||||||
|
|
||||||
|
|
||||||
@ -264,7 +287,7 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
|
|
||||||
plot_data_pool_args = build_data_pool_args()
|
plot_data_pool_args = build_data_pool_args()
|
||||||
f = partial(plot_data, dic_data_grouped)
|
f = partial(plot_data_by_field, dic_data_grouped)
|
||||||
with Pool() as pool:
|
with Pool() as pool:
|
||||||
pool.starmap(f, plot_data_pool_args)
|
pool.starmap(f, plot_data_pool_args)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user