Skip to content

Commit

Permalink
move parsing of the systems hit JSON path to the config
Browse files Browse the repository at this point in the history
  • Loading branch information
jueri committed Nov 11, 2024
1 parent 2cc97f9 commit f8bdf62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 3 additions & 7 deletions web/app/services/ranking_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from app.models import Result, System, db
from app.services.interleave_service import interleave_rankings
from flask import current_app
from jsonpath_ng import parse
from pytz import timezone

client = docker.DockerClient(base_url="unix://var/run/docker.sock")
Expand Down Expand Up @@ -106,8 +105,7 @@ def query_system(container_name, query, rpp, page, session_id, type="EXP"):
if hits_path is None:
hits = result["itemlist"]
else:
jsonpath_expr = parse(hits_path)
hits = jsonpath_expr.find(result)[0].value
hits = hits_path.find(result)[0].value

if isinstance(hits[0], dict):
item_dict = {
Expand Down Expand Up @@ -160,8 +158,7 @@ def build_id_map(container_name, ranking, result):
"docid", "docid"
)
if hits_path:
jsonpath_expr = parse(hits_path)
matches = jsonpath_expr.find(result)
matches = hits_path.find(result)
assert len(matches) == 1

id_map = {hit[docid_name]: hit for hit in matches[0].value}
Expand Down Expand Up @@ -205,8 +202,7 @@ def build_simple_response(ranking_obj):
"hits_path"
)
if base_path:
jsonpath_expr = parse(base_path)
matches = jsonpath_expr.find(result_base)
matches = base_path.find(result_base)
assert len(matches) == 1
matches[0].value = hits
return result_base
Expand Down
7 changes: 6 additions & 1 deletion web/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
from datetime import datetime
from jsonpath_ng import parse

basedir = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -16,7 +17,6 @@ def load_as_list(env_var):
if os.environ.get(env_var):
for list_item in os.environ.get(env_var).split(" "):
variable_list.append(list_item)

return variable_list


Expand Down Expand Up @@ -78,6 +78,11 @@ class Config:
if SYSTEMS_CONFIG[system].get("base"):
RANKING_BASELINE_CONTAINER = system

# JSON Path
if SYSTEMS_CONFIG[system].get("hits_path"):
hits_path = parse(SYSTEMS_CONFIG[system]["hits_path"])
SYSTEMS_CONFIG[system]["hits_path"] = hits_path

else:
# Ranking
RANKING_CONTAINER_NAMES = load_as_list("RANKSYS_LIST") # container_list
Expand Down

0 comments on commit f8bdf62

Please sign in to comment.