Skip to content

Commit

Permalink
Merge pull request #358 from helxplatform/order_program_list
Browse files Browse the repository at this point in the history
order_program_list
  • Loading branch information
YaphetKG authored May 31, 2024
2 parents 6648ef3 + 6109c58 commit 87231ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/dug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Config:
nboost_host: str = "nboost"
nboost_port: int = 8000

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

# Preprocessor config that will be passed to annotate.Preprocessor constructor
preprocessor: dict = field(
default_factory=lambda: {
Expand Down Expand Up @@ -137,6 +141,8 @@ 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"
}

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

from dug.config import Config

Expand Down Expand Up @@ -553,7 +553,15 @@ 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


Expand Down
4 changes: 2 additions & 2 deletions src/dug/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def search_program( program_name: Optional[str] = None):
@APP.get('/program_list')
async def get_program_list():
"""
Search for studies by unique_id (ID or name) and/or study_name.
Search for program by program name.
"""
result = await search.search_program_list()
return {
Expand All @@ -159,4 +159,4 @@ async def get_program_list():
"status": "success"
}
if __name__ == '__main__':
uvicorn.run(APP)
uvicorn.run(APP,port=8181)

0 comments on commit 87231ef

Please sign in to comment.