Skip to content

Commit

Permalink
Finish v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
daniprec committed May 12, 2021
2 parents 14e26c6 + fb8dd28 commit 6e73c14
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions covidnpi/web/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ def return_ambits_by_province(
try:
y = dict_provincia[ambit]
except KeyError:
raise KeyError(f"Ambito '{ambit}' no existe")
print(f"[ERROR] Ambito '{ambit}' no existe para '{code}'")
y = [0] * len(x)
except TypeError:
raise KeyError(f"Provincia '{code}' no encontrada")
print(f"[ERROR] Provincia '{code}' no encontrada")
y = [0] * len(x)
dict_ambit = {
"x": x,
"y": y,
"y_max": 1,
"y_min": 0,
"x_max": x[-1],
"X_min": DATE_MIN,
"x_min": DATE_MIN,
}
dict_plot.update({ambit: dict_ambit})

Expand Down Expand Up @@ -75,22 +77,27 @@ def return_provinces_by_ambit(

dict_plot = {}

# Initialize x
x = [DATE_MIN]

for code in codes:
dict_provincia = col.find_one({"code": code})
try:
x = dict_provincia["fechas"]
y = dict_provincia[ambit]
except KeyError:
raise KeyError(f"Ambito '{ambit}' no existe")
print(f"[ERROR] Ambito '{ambit}' no existe para '{code}'")
y = [0] * len(x)
except TypeError:
raise KeyError(f"Provincia '{code}' no encontrada")
print(f"[ERROR] Provincia '{code}' no encontrada")
y = [0] * len(x)
dict_code = {
"x": x,
"y": y,
"y_max": 1,
"y_min": 0,
"x_max": x[-1],
"X_min": DATE_MIN,
"x_min": DATE_MIN,
}
dict_plot.update({code: dict_code})

Expand All @@ -117,13 +124,19 @@ def return_incidence_of_province(code: str, path_config: str = "covidnpi/config.
col = mongo.get_col("casos")

x = col.find_one({"code": code})
try:
x_max = x["fechas"][-1]
except KeyError:
print(f"[ERROR] El codigo '{code}' de 'casos' no tiene 'x'")
x_max = DATE_MIN

dict_plot = {
"x": x["fechas"],
"y": x["casos"],
"y_max": 800,
"y_min": 0,
"x_max": x[-1],
"X_min": DATE_MIN,
"x_max": x_max,
"x_min": DATE_MIN,
}
return dict_plot

Expand All @@ -148,12 +161,17 @@ def return_growth_of_province(code: str, path_config: str = "covidnpi/config.tom
col = mongo.get_col("casos")

x = col.find_one({"code": code})
try:
x_max = x["fechas"][-1]
except KeyError:
print(f"[ERROR] El codigo '{code}' de 'casos' no tiene 'x'")
x_max = DATE_MIN
dict_plot = {
"x": x["fechas"],
"y": x["crecimiento"],
"y_max": 200,
"y_min": -100,
"x_max": x[-1],
"X_min": DATE_MIN,
"x_max": x_max,
"x_min": DATE_MIN,
}
return dict_plot

0 comments on commit 6e73c14

Please sign in to comment.