Skip to content

Commit

Permalink
Merge pull request #3 from presentient/feature/search_profile_by_key
Browse files Browse the repository at this point in the history
Feature/search profile by key
  • Loading branch information
russell-phe committed Sep 2, 2021
2 parents fa78c7c + 11308b2 commit 713b0b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 18 additions & 3 deletions fingertips_py/metadata.py
Expand Up @@ -5,7 +5,6 @@
metadata.
"""


import pandas as pd
from urllib.error import HTTPError, URLError
from .api_calls import get_data_in_tuple, base_url, make_request, get_json, get_json_return_df, deal_with_url_error
Expand Down Expand Up @@ -274,8 +273,8 @@ def get_area_types_for_profile(profile_id, is_test=False):
:return: A list of dictionaries of area types with relevant information
"""
if is_test:
return get_json(base_url + 'area_types?profile_ids=' + str(profile_id)), base_url + 'area_types?profile_ids=' +\
str(profile_id)
return get_json(base_url + 'area_types?profile_ids=' + str(profile_id)), base_url + 'area_types?profile_ids=' + \
str(profile_id)
return get_json(base_url + 'area_types?profile_ids=' + str(profile_id))


Expand Down Expand Up @@ -311,6 +310,22 @@ def get_profile_by_name(profile_name):
return profile_obj


def get_profile_by_key(profile_key):
"""
Returns a profile object given a key (as the stub following 'profile' in the website URL). For example,
give, a URL of the form `https://fingertips.phe.org.uk/profile/general-practice/data#page/3/gid/2000...`,
the key is 'general-practice'.
:param profile_key: The exact key for the profile.
:return: A dictionary of the profile metadata including domain information or an error message
"""
all_profiles = get_all_profiles()
for profile in all_profiles:
if profile['Key'] == profile_key:
return profile
return 'Profile could not be found'


def get_metadata_for_indicator_as_dataframe(indicator_ids, is_test=False):
"""
Returns a dataframe of metadata for a given indicator ID or list of indicator IDs.
Expand Down
10 changes: 8 additions & 2 deletions fingertips_py/unit_tests/tests.py
Expand Up @@ -4,11 +4,11 @@
from ..retrieve_data import get_all_data_for_profile, get_all_data_for_indicators, get_data_by_indicator_ids, \
get_all_areas_for_all_indicators, get_data_for_indicator_at_all_available_geographies
from ..metadata import get_metadata_for_profile_as_dataframe, get_metadata, get_metadata_for_indicator_as_dataframe, \
get_metadata_for_domain_as_dataframe, get_all_value_notes, get_profile_by_name, get_area_types_for_profile,\
get_metadata_for_domain_as_dataframe, get_all_value_notes, get_profile_by_name, get_area_types_for_profile, \
get_domains_in_profile, get_all_profiles, get_area_types_as_dict, get_age_from_id, get_area_type_ids_for_profile, \
get_profile_by_id, get_age_id, get_all_ages, get_all_sexes, get_areas_for_area_type, get_metadata_for_indicator, \
get_multiplier_and_calculation_for_indicator, get_sex_from_id, get_sex_id, get_value_note_id, \
get_metadata_for_all_indicators, get_metadata_for_all_indicators_from_csv, get_all_areas
get_metadata_for_all_indicators, get_metadata_for_all_indicators_from_csv, get_all_areas, get_profile_by_key
from ..area_data import deprivation_decile


Expand Down Expand Up @@ -133,6 +133,12 @@ def test_get_profile_by_name():
assert data['Id'] == 84


def test_get_profile_by_key():
data = get_profile_by_key("general-practice")
assert isinstance(data, dict) is True
assert data['Id'] == 20


def test_get_area_types_for_profile():
data = get_area_types_for_profile(84)
assert isinstance(data, list) is True
Expand Down

0 comments on commit 713b0b0

Please sign in to comment.