davidr70 commited on
Commit
0d42969
·
1 Parent(s): 26c3df6

add in run_ids

Browse files
Files changed (1) hide show
  1. app.py +33 -66
app.py CHANGED
@@ -10,6 +10,7 @@ source_finders = []
10
  questions_dict = {}
11
  source_finders_dict = {}
12
  question_options = []
 
13
  finder_options = []
14
  finder_labels = {"All": "All Source Finders"}
15
 
@@ -29,17 +30,10 @@ async def get_source_finders():
29
 
30
 
31
  # Get distinct run IDs for a question
32
- async def get_run_ids(question_id: int, source_finder_id: Optional[int] = None):
33
  async with get_async_connection() as conn:
34
- query = "SELECT DISTINCT run_id FROM source_runs WHERE question_id = $1"
35
  params = [question_id]
36
-
37
- if source_finder_id != "All" and source_finder_id is not None:
38
- query += " AND source_finder_id = $2"
39
- params.append(source_finder_id)
40
-
41
- query += " ORDER BY run_id"
42
-
43
  run_ids = await conn.fetch(query, *params)
44
  return [r["run_id"] for r in run_ids]
45
 
@@ -53,22 +47,12 @@ async def get_source_runs(question_id: int, source_finder_id: Optional[int] = No
53
  SELECT sr.*, sf.source_finder_type as finder_name
54
  FROM source_runs sr
55
  JOIN source_finders sf ON sr.source_finder_id = sf.id
56
- WHERE sr.question_id = $1 and sr.run_id = 1
 
57
  """
58
- params = [question_id]
59
- param_counter = 2
60
-
61
- if source_finder_id:
62
- query += f" AND sr.source_finder_id = ${param_counter}"
63
- params.append(source_finder_id)
64
- param_counter += 1
65
 
66
- # if run_id:
67
- # query += f" AND sr.run_id = ${param_counter}"
68
- # params.append(run_id)
69
- # param_counter += 1
70
-
71
- query += " ORDER BY sr.run_id, sr.rank DESC"
72
 
73
  sources = await conn.fetch(query, *params)
74
  return [dict(s) for s in sources]
@@ -92,7 +76,7 @@ async def initialize_data():
92
 
93
 
94
  # Main function to handle UI interactions
95
- def update_source_runs(question_option, source_finder_id):
96
  if not question_option:
97
  return None, [], "No question selected", None
98
 
@@ -100,22 +84,22 @@ def update_source_runs(question_option, source_finder_id):
100
  question_id = int(question_option.split(":")[0])
101
 
102
  # Get run_ids for filtering - use asyncio.run for each independent operation
103
- # available_run_ids = asyncio.run(get_run_ids(question_id, source_finder_id))
104
- # run_id_options = [str(r_id) for r_id in available_run_ids]
105
 
106
  # If the selected run_id is not in available options, reset it
107
  # if run_id not in run_id_options:
108
  # run_id = None
109
  #
110
  # # Convert run_id to int if not "All"
111
- # run_id_int = None if len(run_id) == 0 else int(run_id)
112
  finder_id_int = None if len(source_finder_id) == 0 else int(source_finder_id)
113
 
114
  # Get source runs data
115
- source_runs = asyncio.run(get_source_runs(question_id, finder_id_int))
116
 
117
  if not source_runs:
118
- return None, None, "No results found for the selected filters"
119
 
120
  # Create DataFrame for display
121
  df = pd.DataFrame(source_runs)
@@ -129,25 +113,7 @@ def update_source_runs(question_option, source_finder_id):
129
 
130
  result_message = f"Found {len(source_runs)} results"
131
 
132
- return df_display, result_message
133
-
134
-
135
- # Function to update run_id dropdown when question or source_finder changes
136
- def update_run_ids(question_option, source_finder_id):
137
- if not question_option:
138
- return [], None, "No question selected", None
139
-
140
- # Extract question ID
141
- question_id = int(question_option.split(":")[0])
142
-
143
- # Convert source_finder_id if not "All"
144
- finder_id_int = None if source_finder_id == "All" else int(source_finder_id)
145
-
146
- # Get available run IDs
147
- available_run_ids = asyncio.run(get_run_ids(question_id, finder_id_int))
148
- run_id_options = ["All"] + [str(run_id) for run_id in available_run_ids]
149
-
150
- return run_id_options, None, "", None
151
 
152
 
153
 
@@ -170,6 +136,14 @@ async def main():
170
  interactive=True
171
  )
172
 
 
 
 
 
 
 
 
 
173
  with gr.Row():
174
  source_finder_dropdown = gr.Dropdown(
175
  choices=finder_options,
@@ -177,13 +151,6 @@ async def main():
177
  interactive=True
178
  )
179
 
180
- # run_id_dropdown = gr.Dropdown(
181
- # choices=[],
182
- # value="",
183
- # label="Run ID",
184
- # interactive=True
185
- # )
186
-
187
  result_text = gr.Markdown("Select a question to view source runs")
188
 
189
  results_table = gr.DataFrame(
@@ -214,29 +181,29 @@ async def main():
214
  # Set up event handlers
215
  question_dropdown.change(
216
  update_source_runs,
217
- inputs=[question_dropdown, source_finder_dropdown],
218
  # outputs=[run_id_dropdown, results_table, result_text, download_button]
219
- outputs=[results_table, result_text]
220
  )
221
 
222
  source_finder_dropdown.change(
223
  update_source_runs,
224
- inputs=[question_dropdown, source_finder_dropdown],
225
  # outputs=[run_id_dropdown, results_table, result_text, download_button]
226
- outputs=[results_table, result_text]
227
  )
228
 
229
- # run_id_dropdown.change(
230
- # update_source_runs,
231
- # inputs=[question_dropdown, source_finder_dropdown, run_id_dropdown],
232
- # outputs=[results_table, run_id_dropdown, result_text, download_button]
233
- # )
234
 
235
  # Initial load of data when question is selected
236
  question_dropdown.change(
237
  update_source_runs,
238
- inputs=[question_dropdown, source_finder_dropdown],
239
- outputs=[results_table, result_text]
240
  )
241
 
242
  app.queue()
 
10
  questions_dict = {}
11
  source_finders_dict = {}
12
  question_options = []
13
+ run_ids = []
14
  finder_options = []
15
  finder_labels = {"All": "All Source Finders"}
16
 
 
30
 
31
 
32
  # Get distinct run IDs for a question
33
+ async def get_run_ids(question_id: int):
34
  async with get_async_connection() as conn:
35
+ query = "SELECT DISTINCT run_id FROM source_runs WHERE question_id = $1 order by run_id desc"
36
  params = [question_id]
 
 
 
 
 
 
 
37
  run_ids = await conn.fetch(query, *params)
38
  return [r["run_id"] for r in run_ids]
39
 
 
47
  SELECT sr.*, sf.source_finder_type as finder_name
48
  FROM source_runs sr
49
  JOIN source_finders sf ON sr.source_finder_id = sf.id
50
+ WHERE sr.question_id = $1 and sr.run_id = $2
51
+ AND sr.source_finder_id = $3
52
  """
53
+ params = [question_id, run_id, source_finder_id]
 
 
 
 
 
 
54
 
55
+ query += " ORDER BY sr.rank DESC"
 
 
 
 
 
56
 
57
  sources = await conn.fetch(query, *params)
58
  return [dict(s) for s in sources]
 
76
 
77
 
78
  # Main function to handle UI interactions
79
+ def update_source_runs(question_option, source_finder_id, run_id):
80
  if not question_option:
81
  return None, [], "No question selected", None
82
 
 
84
  question_id = int(question_option.split(":")[0])
85
 
86
  # Get run_ids for filtering - use asyncio.run for each independent operation
87
+ available_run_ids = asyncio.run(get_run_ids(question_id))
88
+ run_id_options = [str(r_id) for r_id in available_run_ids]
89
 
90
  # If the selected run_id is not in available options, reset it
91
  # if run_id not in run_id_options:
92
  # run_id = None
93
  #
94
  # # Convert run_id to int if not "All"
95
+ run_id_int = available_run_ids[0]
96
  finder_id_int = None if len(source_finder_id) == 0 else int(source_finder_id)
97
 
98
  # Get source runs data
99
+ source_runs = asyncio.run(get_source_runs(question_id, finder_id_int, run_id_int))
100
 
101
  if not source_runs:
102
+ return None, run_id_options, "No results found for the selected filters"
103
 
104
  # Create DataFrame for display
105
  df = pd.DataFrame(source_runs)
 
113
 
114
  result_message = f"Found {len(source_runs)} results"
115
 
116
+ return df_display, run_id_options, result_message,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
 
119
 
 
136
  interactive=True
137
  )
138
 
139
+ run_id_dropdown = gr.Dropdown(
140
+ choices=run_ids,
141
+ value="1",
142
+ allow_custom_value=True,
143
+ label="Run ids for Question",
144
+ interactive=True
145
+ )
146
+
147
  with gr.Row():
148
  source_finder_dropdown = gr.Dropdown(
149
  choices=finder_options,
 
151
  interactive=True
152
  )
153
 
 
 
 
 
 
 
 
154
  result_text = gr.Markdown("Select a question to view source runs")
155
 
156
  results_table = gr.DataFrame(
 
181
  # Set up event handlers
182
  question_dropdown.change(
183
  update_source_runs,
184
+ inputs=[question_dropdown, source_finder_dropdown, run_id_dropdown],
185
  # outputs=[run_id_dropdown, results_table, result_text, download_button]
186
+ outputs=[results_table, run_id_dropdown, result_text]
187
  )
188
 
189
  source_finder_dropdown.change(
190
  update_source_runs,
191
+ inputs=[question_dropdown, source_finder_dropdown, run_id_dropdown],
192
  # outputs=[run_id_dropdown, results_table, result_text, download_button]
193
+ outputs=[results_table, run_id_dropdown, result_text]
194
  )
195
 
196
+ run_id_dropdown.change(
197
+ update_source_runs,
198
+ inputs=[question_dropdown, source_finder_dropdown, run_id_dropdown],
199
+ outputs=[results_table, run_id_dropdown, result_text]
200
+ )
201
 
202
  # Initial load of data when question is selected
203
  question_dropdown.change(
204
  update_source_runs,
205
+ inputs=[question_dropdown, source_finder_dropdown, run_id_dropdown],
206
+ outputs=[results_table, run_id_dropdown, result_text]
207
  )
208
 
209
  app.queue()