davidr70 commited on
Commit
8799a8e
·
1 Parent(s): e519933

only show source finders with runs

Browse files
Files changed (1) hide show
  1. data_access.py +19 -3
data_access.py CHANGED
@@ -51,7 +51,17 @@ async def get_metadata(conn: asyncpg.Connection, question_id: int, source_finder
51
 
52
  # Get distinct source finders
53
  async def get_source_finders(conn: asyncpg.Connection):
54
- finders = await conn.fetch("SELECT id, source_finder_type as name FROM source_finders ORDER BY id")
 
 
 
 
 
 
 
 
 
 
55
  return [{"id": f["id"], "name": f["name"]} for f in finders]
56
 
57
 
@@ -79,10 +89,16 @@ async def get_run_ids(conn: asyncpg.Connection, source_finder_id: int, question_
79
 
80
  async def get_baseline_rankers(conn: asyncpg.Connection):
81
  query = """
82
- select sfr.id, sf.source_finder_type, sfr.description from talmudexplore.source_finder_runs sfr
83
  join source_finders sf on sf.id = sfr.source_finder_id
84
- order by sf.id
 
 
 
 
 
85
  """
 
86
  rankers = await conn.fetch(query)
87
  return [{"id": r["id"], "name": f"{r['source_finder_type']} : {r['description']}"} for r in rankers]
88
 
 
51
 
52
  # Get distinct source finders
53
  async def get_source_finders(conn: asyncpg.Connection):
54
+ finders = await conn.fetch("""
55
+ SELECT distinct sf.id, sf.source_finder_type as name from talmudexplore.source_finder_runs sfr
56
+ join talmudexplore.source_finders sf on sf.id = sfr.source_finder_id
57
+ WHERE EXISTS (
58
+ SELECT 1
59
+ FROM talmudexplore.source_run_results srr
60
+ WHERE srr.source_finder_run_id = sfr.id
61
+ )
62
+ ORDER BY sf.id
63
+ """
64
+ )
65
  return [{"id": f["id"], "name": f["name"]} for f in finders]
66
 
67
 
 
89
 
90
  async def get_baseline_rankers(conn: asyncpg.Connection):
91
  query = """
92
+ SELECT sfr.id, sf.source_finder_type, sfr.description from source_finder_runs sfr
93
  join source_finders sf on sf.id = sfr.source_finder_id
94
+ WHERE EXISTS (
95
+ SELECT 1
96
+ FROM source_run_results srr
97
+ WHERE srr.source_finder_run_id = sfr.id
98
+ )
99
+ ORDER BY sf.id
100
  """
101
+
102
  rankers = await conn.fetch(query)
103
  return [{"id": r["id"], "name": f"{r['source_finder_type']} : {r['description']}"} for r in rankers]
104