Skip to content

Commit f240ffa

Browse files
committed
feat(api): include global variables
feat(api): start creating the detailed report classes for the files feat(api): start splitting the catalog.db into catalogs for each dataset
1 parent 7b40d30 commit f240ffa

17 files changed

Lines changed: 487 additions & 364 deletions

File tree

pysus/api/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Roadmap
2+

pysus/api/_impl/databases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import pandas as pd
2727
from pysus.api.client import PySUS
28-
from pysus.api.types import State
28+
from pysus.api.types import Origin, State
2929
from tqdm import tqdm
3030

3131

@@ -519,7 +519,7 @@ def list_files(
519519
"CNES",
520520
"CIHA",
521521
],
522-
client: Literal["FTP", "DadosGov"] | None = None,
522+
client: Origin | None = None,
523523
group: str | None = None,
524524
state: str | None = None,
525525
year: int | list[int] | None = None,
@@ -536,7 +536,7 @@ def list_files(
536536
----------
537537
dataset : Literal
538538
Dataset name (e.g. ``"SINAN"``, ``"SINASC"``, etc.).
539-
client : Literal["FTP", "DadosGov"], optional
539+
client : Origin, optional
540540
Data source client to query.
541541
group : str, optional
542542
Group or disease code to filter by.

pysus/api/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from typing import TYPE_CHECKING, Literal
1212

1313
import anyio
14+
15+
from pysus.api.types import Origin
1416
import duckdb
1517
import pandas as pd
1618
from pysus import CACHEPATH
@@ -477,7 +479,7 @@ def get_completed_remote_paths(self) -> set[str]:
477479

478480
async def query(
479481
self,
480-
client: Literal["DadosGov", "FTP"] | None = None,
482+
client: Origin | None = None,
481483
dataset: str | None = None,
482484
group: str | None = None,
483485
state: str | None = None,

pysus/api/dadosgov/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PrivateAttr
1212
from pysus import __version__
1313
from pysus.api.models import BaseRemoteClient, BaseRemoteFile
14+
from pysus.api.types import DadosGov as DADOSGOV
1415

1516
if TYPE_CHECKING:
1617
from .models import Dataset
@@ -89,7 +90,7 @@ def name(self) -> str:
8990
str
9091
The abbreviated client name ``"DadosGov"``.
9192
"""
92-
return "DadosGov"
93+
return DADOSGOV
9394

9495
@property
9596
def long_name(self) -> str:

pysus/api/dadosgov/models.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ def _dedup_entries(
3030
if m:
3131
stem = filename[: m.start()]
3232
fmt = m.group(1).lower()
33-
grouped.setdefault(stem, []).append(
34-
(fmt, filename, recurso, metadata)
35-
)
33+
grouped.setdefault(stem, []).append((fmt, filename, recurso, metadata))
3634
else:
37-
grouped.setdefault(filename, []).append(
38-
("", filename, recurso, metadata)
39-
)
35+
grouped.setdefault(filename, []).append(("", filename, recurso, metadata))
4036

4137
result: list[tuple[str, Any, dict]] = []
4238
for _, items in grouped.items():
@@ -249,9 +245,7 @@ class Group(BaseRemoteGroup):
249245
"""A group of files within a dataset."""
250246

251247
record: ConjuntoDados
252-
_formatter: Callable[[str], dict[str, Any]] | None = PrivateAttr(
253-
default=None
254-
)
248+
_formatter: Callable[[str], dict[str, Any]] | None = PrivateAttr(default=None)
255249

256250
def __init__(
257251
self,
@@ -271,7 +265,8 @@ def __init__(
271265
A callable that extracts metadata from filenames.
272266
"""
273267
super().__init__(
274-
record=record, dataset=dataset # type: ignore[call-arg]
268+
record=record,
269+
dataset=dataset, # type: ignore[call-arg]
275270
)
276271
self._formatter = formatter
277272

@@ -318,9 +313,7 @@ async def _fetch_files(self) -> list[BaseRemoteFile]:
318313
"""Build File objects from the underlying resources."""
319314
entries: list[tuple[str, Any, dict]] = []
320315
for recurso in self.record.resources:
321-
filename = (
322-
recurso.file_name or recurso.url.split("/")[-1].split("?")[0]
323-
)
316+
filename = recurso.file_name or recurso.url.split("/")[-1].split("?")[0]
324317
if filename.lower().endswith(".pdf") or filename.startswith("get_"):
325318
continue
326319
metadata = {}
@@ -354,7 +347,7 @@ class Dataset(BaseRemoteDataset):
354347
"""
355348

356349
ids: list[str] = []
357-
client: "DadosGov"
350+
client: DadosGov
358351
group_aliases: dict[str, str] = {}
359352

360353
def __repr__(self):
@@ -369,7 +362,7 @@ def formatter(self, filename: str) -> dict[str, Any]:
369362
async def _fetch_content(self) -> list[Group]:
370363
"""Fetch all groups belonging to this dataset."""
371364
items: list[Group] = []
372-
client: "DadosGov" = self.client
365+
client: DadosGov = self.client
373366
if self.ids:
374367
for group_id in self.ids:
375368
record = await client.get_dataset(group_id)
File renamed without changes.

0 commit comments

Comments
 (0)