Skip to content

Commit

Permalink
Implement domain feature getter in MST
Browse files Browse the repository at this point in the history
  • Loading branch information
daffidwilde committed Nov 14, 2023
1 parent 14387f0 commit 61cca25
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/centhesus/mst.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,27 @@ def __init__(
self.api = CensusAPI()
self.domain = self.get_domain()

def _get_domain_of_feature(self, feature):
"""Retrieve the domain for items in a feature of the API."""

if feature == "area-types" and self.area_type is None:
return {}
elif feature == "area-types":
items = [self.area_type]
elif feature == "dimensions":
items = self.dimensions
else:
raise ValueError(
"Feature must be one of 'area-types' or 'dimensions', "
f"not '{feature}'"
)

metadata = self.api.query_feature(
self.population_type, feature, *items
)
domain = dict(metadata[["id", "total_count"]].to_dict("split")["data"])

return domain

def get_domain(self):
"""Retrieve domain metadata from the API."""
"""Retrieve domain metadata from the API."""

0 comments on commit 61cca25

Please sign in to comment.