adjust mypy conf + requirements.txt

This commit is contained in:
rmanach 2021-12-27 10:17:07 +01:00
parent 70ac7d1bb7
commit 4818d78cfe
3 changed files with 25 additions and 14 deletions

View File

@ -104,7 +104,7 @@ def get_enum_field(value):
return field.value
def group_by_age_date(data: Dict[str, Any], fields: List[str]) -> Dict[dt, Any]:
def group_by_age_date(data: Dict[str, Any]) -> Dict[dt, Any]:
"""
group the original dictionnary into a more readable one
'date': {
@ -131,8 +131,10 @@ def group_by_age_date(data: Dict[str, Any], fields: List[str]) -> Dict[dt, Any]:
dic_data_grouped[date][age] = OrderedDict()
if vac_status not in dic_data_grouped[date][age]:
dic_data_grouped[date][age][vac_status] = OrderedDict()
for field in fields:
dic_data_grouped[date][age][vac_status][field] = row_fields[field]
for field in Field:
dic_data_grouped[date][age][vac_status][field.label] = row_fields[
field.label
]
logging.info("data restructured")
return dic_data_grouped
@ -209,8 +211,8 @@ def plot_cumulative_field(
np_cumulate_unvac: np.ndarray = np.cumsum(
np_data_unvac[:, age_group.value, field.value], axis=0
)
plt.plot(np_date, np_cumulate_vac, label=f"{age_group.label} vaccinate")
plt.plot(np_date, np_cumulate_unvac, label=f"{age_group.label} unvaccinate")
plt.plot(np_date, np_cumulate_vac, label=f"{age_group.label} vax")
plt.plot(np_date, np_cumulate_unvac, label=f"{age_group.label} no vax")
plt.title(f"nombre de {field.label} cumulé par age")
plt.xlabel("date")
@ -266,6 +268,7 @@ def plot_bar_data_by_age_field(
a limit days period is set to have an readable plot
"""
np_percent_vac, np_percent_unvac = get_vaccine_percent(np_data)
# adjust the fig size to display correctly bars and labels
fig, ax = get_plot_fig(figsize=(22, 8))
for idx_date in range(len(np_date)):
@ -275,15 +278,15 @@ def plot_bar_data_by_age_field(
unvac_percent = np.round(
np_percent_unvac[idx_date, age_group.value, field.value] * 100
)
bar_vac = ax.bar(idx_date, vac_percent, color="b", label="vac")
bar_unvac = ax.bar(
idx_date, unvac_percent, bottom=vac_percent, color="r", label="novac"
)
bar_vac = ax.bar(idx_date, vac_percent, color="b", label="vax")
ax.bar(idx_date, unvac_percent, bottom=vac_percent, color="r", label="no vax")
ax.bar_label(bar_vac, label_type="edge", color="black", fontsize="8")
ax.set_ylim(top=105)
ax.set_ylim(top=105) # to display 100% label
ax.set_ylabel("%")
ax.set_title(f"{age_group.label} - {field.label}")
# avoid displaying all dates
ax.set(
xticks=range(len(np_date)),
xticklabels=[
@ -291,7 +294,7 @@ def plot_bar_data_by_age_field(
for idx, d in enumerate(np_date.astype(dt))
],
)
plt.legend(["vaccinate", "unvaccinate"], loc=0, frameon=True)
plt.legend(["vax", "no vax"], loc=0, frameon=True)
save_and_close_fig(
fig,
@ -351,9 +354,7 @@ if __name__ == "__main__":
dic_data: Dict[str, Any] = get_data(
file_path=os.path.join(DATA_REPOSITORY, "dress.json"), refresh=args.refresh
)
dic_data_grouped: Dict[dt, Any] = group_by_age_date(
dic_data, [x.label for x in Field]
)
dic_data_grouped: Dict[dt, Any] = group_by_age_date(dic_data)
np_data, np_date = get_np_data(dic_data_grouped)

4
mypy.ini Normal file
View File

@ -0,0 +1,4 @@
[mypy]
python_version = 3.8
ignore_missing_imports = True
disable_error_code = attr-defined

View File

@ -5,16 +5,22 @@ chardet==4.0.0
click==8.0.1
cycler==0.10.0
idna==2.10
isort==5.10.1
kiwisolver==1.3.1
matplotlib==3.4.2
mypy==0.920
mypy-extensions==0.4.3
numpy==1.20.3
pathspec==0.8.1
Pillow==8.2.0
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2021.3
regex==2021.4.4
requests==2.25.1
six==1.16.0
toml==0.10.2
tomli==2.0.0
types-requests==2.26.2
typing-extensions==4.0.1
urllib3==1.26.4