Skip to content

Commit

Permalink
added program description and sorted the program names alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
yskale committed Jul 17, 2024
1 parent 70ae8f7 commit 9a85295
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/dug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Config:
nboost_port: int = 8000

program_sort_list: str = ""
program_name_mappings: dict=field(
program_description: dict=field(
default_factory=lambda:{})

# Preprocessor config that will be passed to annotate.Preprocessor constructor
Expand Down Expand Up @@ -141,8 +141,7 @@ def from_env(cls):
"redis_host": "REDIS_HOST",
"redis_port": "REDIS_PORT",
"redis_password": "REDIS_PASSWORD",
"program_sort_list": "PROGRAM_SORT_LIST",
"program_name_mappings" : "PROGRAM_NAME_MAPPINGS"
"program_description": "PROGRAM_DESCRIPTION",
}

kwargs = {}
Expand Down
26 changes: 14 additions & 12 deletions src/dug/core/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import logging
from elasticsearch import AsyncElasticsearch
from elasticsearch.helpers import async_scan
import ssl,os,json

import ssl,json
from dug.config import Config


logger = logging.getLogger('dug')


Expand Down Expand Up @@ -528,7 +528,6 @@ async def search_program(self, program_name=None, offset=0, size=None):


async def search_program_list(self):

query_body = {
"size": 0, # We don't need the documents themselves, so set the size to 0
"aggs": {
Expand All @@ -554,15 +553,18 @@ async def search_program_list(self):
# The unique data_types and their counts of unique collection_ids will be in the 'aggregations' field of the response
unique_data_types = search_results['aggregations']['unique_program_names']['buckets']
data=unique_data_types
program_keys =self._cfg.program_sort_list.split(',')
#key_mapping = self._cfg.program_name_mappings
#key_mapping = json.loads(key_mapping)
key_index_map = {key: index for index, key in enumerate(program_keys)}
unique_data_types = sorted(data, key=lambda x: key_index_map.get(x['key'], len(program_keys)))
#for item in unique_data_types:
# if item['key'] in key_mapping:
# item['key'] = key_mapping[item['key']]
return unique_data_types
print(data)
# Sorting the data alphabetically based on 'key'
sorted_data = sorted(data, key=lambda x: x['key'])

#Add description as another field in exisiting data based on the program name
descriptions_json = self._cfg.program_description
descriptions = json.loads(descriptions_json)
description_dict = {item['key']: item['description'] for item in descriptions}
for item in sorted_data:
item['description'] = description_dict.get(item['key'], '')

return sorted_data


def _get_var_query(self, concept, fuzziness, prefix_length, query):
Expand Down

0 comments on commit 9a85295

Please sign in to comment.