Skip to content

Commit

Permalink
Include disease and CID10 on result
Browse files Browse the repository at this point in the history
  • Loading branch information
luabida committed Dec 22, 2023
1 parent d3251f2 commit 5563b98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .utils import (
CACHEPATH,
CID10,
STATES,
comp_duration,
get_municipality_name,
Expand Down Expand Up @@ -215,8 +216,10 @@ def _save_results(self, geocode, results, curve):

def _parse_results(self) -> pd.DataFrame:
data = {
"geocode": [],
"disease": [],
"CID10": [],
"year": [],
"geocode": [],
"muni_name": [],
"peak_week": [],
"beta": [],
Expand All @@ -232,6 +235,8 @@ def _parse_results(self) -> pd.DataFrame:

for gc, curve in self.curves.items():
for c in curve:
data["disease"].append(self.disease)
data["CID10"].append(CID10[self.disease])
data["geocode"].append(gc)
data["muni_name"].append(get_municipality_name(gc))
data["year"].append(c["year"])
Expand Down Expand Up @@ -309,7 +314,7 @@ def _to_duckdb(self, output_dir: str):
try:
rows = con.execute(
f"SELECT COUNT(*) FROM '{table_name}'"
f" WHERE year = {self.year}"
f" WHERE year = {self.year} AND disease = '{self.disease}'"
).fetchone()[0]

if rows > 0:
Expand All @@ -318,6 +323,7 @@ def _to_duckdb(self, output_dir: str):
con.execute(
f"DELETE FROM '{table_name}'"
f" WHERE year = {self.year}"
f" AND disease = '{self.disease}'"
)
con.execute(f"INSERT INTO '{table_name}' SELECT * FROM df")
except duckdb.duckdb.CatalogException:
Expand Down
7 changes: 7 additions & 0 deletions src/scanner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
}


CID10 = {
"dengue": "A90",
"zika": "A92.8",
"chik": "A92.0",
}


def get_municipality_name(geocode: Union[str, int]) -> str:
"""
returns municipality name by geocode, according to IBGE's geocode format
Expand Down

0 comments on commit 5563b98

Please sign in to comment.