Skip to content

Commit

Permalink
HDX-10398 add extra fields in output for data completeness
Browse files Browse the repository at this point in the history
  • Loading branch information
danmihaila committed Dec 4, 2024
1 parent 3068b36 commit 771ba34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ckanext-hdx_org_group/ckanext/hdx_org_group/actions/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def hdx_datagrid_show(context, data_dict):
if id:
grp_dict = get_action('hdx_light_group_show')(context, {'id':id})
data_completeness = country_helper._get_data_completeness(grp_dict.get('name'))
replaced_data_completeness = country_helper.hdx_replace_datagrid_labels(data_completeness)
replaced_data_completeness = country_helper.hdx_replace_datagrid_labels(data_completeness, grp_dict)
return replaced_data_completeness
else:
raise NotFound('Group was not found.')
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ckan.plugins.toolkit as tk
import ckanext.hdx_org_group.helpers.caching as caching
# import ckanext.hdx_package.helpers.screenshot as screenshot

from datetime import datetime
from ckanext.hdx_org_group.controller_logic.group_search_logic import GroupSearchLogic
import ckan.lib.helpers as h
from ckanext.hdx_search.helpers.constants import DEFAULT_SORTING
Expand Down Expand Up @@ -309,7 +309,7 @@ def hdx_datagrid_org_get_display_text(dataseries_dict):
}


def transform_dict(data):
def transform_data_completeness(data):
if isinstance(data, dict):
new_dict = {}
for key, value in data.items():
Expand All @@ -321,19 +321,21 @@ def transform_dict(data):
value = DATA_COMPLETENESS_STATE_DICT.get(value, value)

# Recursively transform values
new_dict[new_key] = transform_dict(value)
new_dict[new_key] = transform_data_completeness(value)
return new_dict
elif isinstance(data, list):
return [transform_dict(item) for item in data]
return [transform_data_completeness(item) for item in data]
return data


# Assuming `your_dict` is the large dictionary you want to process



def hdx_replace_datagrid_labels(data_completeness):
def hdx_replace_datagrid_labels(data_completeness, grp_dict):
# Replace keys in the dictionary
# updated_data = replace_keys(data_completeness, DATA_COMPLETENESS_LABELS_DICT)
updated_data = transform_dict(data_completeness)
updated_data = transform_data_completeness(data_completeness)
updated_data.pop("inherits_from", None)
updated_data.pop("name", None)
updated_data.pop("title", None)
updated_data.pop("description", None)
updated_data['date'] = datetime.now()
updated_data['iso3'] = grp_dict.get('name')
updated_data['title'] = grp_dict.get('title') or grp_dict.get('display_name')
return updated_data

0 comments on commit 771ba34

Please sign in to comment.