-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement get_available_years for all online_data databases
- Loading branch information
Showing
12 changed files
with
170 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
""" | ||
Download data from the national immunization program | ||
""" | ||
from typing import Union | ||
from typing import Union, Literal | ||
|
||
from pysus.online_data import FTP_Downloader, FTP_Inspect | ||
from pysus.ftp.databases.pni import PNI | ||
from pysus.ftp import CACHEPATH | ||
|
||
|
||
pni = PNI().load() | ||
|
||
|
||
def get_available_years(group, states): | ||
""" | ||
Fetch available years for `group` and/or `months`. | ||
:param group: PNI group, options are "CPNI" or "DPNI" | ||
:param state: UF code, can be a list. E.g: "SP" or ["SP", "RJ"] | ||
:return: list of available years | ||
""" | ||
files = pni.get_files(group=group, uf=states) | ||
return sorted(list(set(pni.describe(f)["year"] for f in files))) | ||
|
||
|
||
def download( | ||
group: Union[list, Literal["CNPI", "DPNI"]], | ||
states: Union[str, list], | ||
years: Union[str, list, int], | ||
data_dir: str = CACHEPATH, | ||
) -> list: | ||
""" | ||
Download imunization records for a given States and years. | ||
:param state: uf two letter code, can be a list | ||
:param year: year in 4 digits, can be a list | ||
:param group: PNI group, options are "CPNI" or "DPNI" | ||
:param state: uf two letter code, can be a list. E.g: "SP" or ["SP", "RJ"] | ||
:param year: year in 4 digits, can be a list. E.g: 1 or [1, 2, 3] | ||
:param data_dir: directory where data will be downloaded | ||
:return: list of downloaded parquet paths | ||
:return: list of downloaded ParquetData | ||
""" | ||
return FTP_Downloader('PNI').download( | ||
PNI_group='CPNI', UFs=states, years=years, local_dir=data_dir | ||
) | ||
|
||
|
||
def get_available_years(state): | ||
""" | ||
Fetch available years (dbf names) for the `state`. | ||
:param state: uf code | ||
:return: list of strings (filenames) | ||
""" | ||
return FTP_Inspect('PNI').list_available_years(UF=state, PNI_group='CPNI') | ||
|
||
|
||
def available_docs(): | ||
return FTP_Inspect('PNI').list_all(PNI_group='CPNI') | ||
files = pni.get_files(group, uf=states, year=years) | ||
return pni.download(files, local_dir=data_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters