Spaces:
Sleeping
Sleeping
Debugging no button state change and bad session ID
Browse files
main.py
CHANGED
@@ -104,6 +104,7 @@ else:
|
|
104 |
app, rt = fast_app(debug=False, live=False, hdrs=hdrs)
|
105 |
REFRESH_TIME = 1
|
106 |
|
|
|
107 |
|
108 |
def untyped_save_to_storage(dc, filename):
|
109 |
if scheduler is None: return
|
@@ -119,21 +120,23 @@ def save_to_storage(nav_event:storage.NavigationEvent):
|
|
119 |
|
120 |
|
121 |
|
122 |
-
def
|
123 |
-
if 'session_id' not in session:
|
|
|
|
|
124 |
session_id = session["session_id"]
|
125 |
state_rows = session_state_table(limit=1, where=f"session_id == '{session_id}'", order_by="id DESC")
|
126 |
if len(state_rows) <= 0:
|
127 |
-
print("
|
128 |
return False, None
|
129 |
answer_id = state_rows[0].current_qeval
|
130 |
qa_obj_row = question_evaluation_table(limit=1, where=f"id == {answer_id}")
|
131 |
if len(qa_obj_row) <= 0:
|
132 |
-
print("There is no answer recorded")
|
133 |
return False, None
|
134 |
qe_obj = qa_obj_row[0]
|
135 |
if qe_id != qe_obj.id:
|
136 |
-
print(
|
137 |
return False, None
|
138 |
return True, qe_obj
|
139 |
|
@@ -183,19 +186,27 @@ def put(session, qe_id:int, ans_id:int, which:int):
|
|
183 |
print(qe_id, ans_id, which)
|
184 |
if which not in {-1, 1}:
|
185 |
return None
|
186 |
-
|
187 |
-
session_id
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
if
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
# save_to_storage(
|
201 |
# storage.NavigationEvent(event_type="/", event_session_id=session_id, event_params={"qe_id":qe_id})
|
@@ -230,13 +241,14 @@ def html_get_textual_feedback_form(qe_obj, thank=False):
|
|
230 |
@rt("/submit_feedback/{qe_id}")
|
231 |
def post(session, qe_id:int, freeform_feedback:str):
|
232 |
# Update the object
|
233 |
-
session_id = session.get("session_id", "Not set")
|
234 |
-
save_to_storage(
|
235 |
-
|
236 |
-
|
237 |
-
)
|
238 |
-
is_ok, qe_obj =
|
239 |
if not is_ok:
|
|
|
240 |
return "Error"
|
241 |
|
242 |
answer_eval_js = json.loads(qe_obj.answer_eval_text)
|
@@ -392,10 +404,10 @@ def render_clear_area(session_id, html_id):
|
|
392 |
# return html_render_clear_area_button(html_id)
|
393 |
eval_request_status, _ = get_latest_eval_request_status(session_id)
|
394 |
if eval_request_status != EVAL_STATE_NEW:
|
395 |
-
print("clear button: render button")
|
396 |
return html_render_clear_area_button(html_id)
|
397 |
else:
|
398 |
-
print("clear button: render empty")
|
399 |
return Div(P(""), _id=html_id, hx_swap_oob='true')
|
400 |
|
401 |
|
@@ -450,7 +462,7 @@ def get(session):
|
|
450 |
|
451 |
@rt("/render_answer")
|
452 |
def get(session):
|
453 |
-
if 'session_id' not in session: return "No session ID"
|
454 |
session_id = session["session_id"]
|
455 |
answer_area = html_render_answer_from_db(session_id, HTML_RESULTS_AREA)
|
456 |
return answer_area
|
@@ -458,7 +470,7 @@ def get(session):
|
|
458 |
|
459 |
@rt("/submit_to_eval", methods="post")
|
460 |
def post(ccodetoeval:str, session):
|
461 |
-
if 'session_id' not in session: return P("Bad call. No session ID")
|
462 |
session_id = session["session_id"]
|
463 |
session_obj = Session_State_cls(
|
464 |
session_id=session_id,
|
@@ -479,7 +491,7 @@ def post(ccodetoeval:str, session):
|
|
479 |
|
480 |
@rt("/clear_area", methods="get")
|
481 |
def get(session):
|
482 |
-
if 'session_id' not in session: return P("Bad call. No session ID")
|
483 |
session_id = session["session_id"]
|
484 |
save_to_storage(
|
485 |
storage.NavigationEvent(event_type="/clear_area", event_session_id=session_id)
|
|
|
104 |
app, rt = fast_app(debug=False, live=False, hdrs=hdrs)
|
105 |
REFRESH_TIME = 1
|
106 |
|
107 |
+
################# STORAGE
|
108 |
|
109 |
def untyped_save_to_storage(dc, filename):
|
110 |
if scheduler is None: return
|
|
|
120 |
|
121 |
|
122 |
|
123 |
+
def validate_and_get_question_evaluation_objectid(session, qe_id:int):
|
124 |
+
if 'session_id' not in session:
|
125 |
+
print("validate_and_get_question_evaluation_objectid bad session data")
|
126 |
+
return None
|
127 |
session_id = session["session_id"]
|
128 |
state_rows = session_state_table(limit=1, where=f"session_id == '{session_id}'", order_by="id DESC")
|
129 |
if len(state_rows) <= 0:
|
130 |
+
print("validate_and_get_question_evaluation_objectid there is no state")
|
131 |
return False, None
|
132 |
answer_id = state_rows[0].current_qeval
|
133 |
qa_obj_row = question_evaluation_table(limit=1, where=f"id == {answer_id}")
|
134 |
if len(qa_obj_row) <= 0:
|
135 |
+
print("validate_and_get_question_evaluation_objectid There is no answer recorded")
|
136 |
return False, None
|
137 |
qe_obj = qa_obj_row[0]
|
138 |
if qe_id != qe_obj.id:
|
139 |
+
print("validate_and_get_question_evaluation_objectid QE {qe_id} does not belong to {qe_obj.id}")
|
140 |
return False, None
|
141 |
return True, qe_obj
|
142 |
|
|
|
186 |
print(qe_id, ans_id, which)
|
187 |
if which not in {-1, 1}:
|
188 |
return None
|
189 |
+
|
190 |
+
# if 'session_id' not in session:
|
191 |
+
# print("toggle_up_down bad session data")
|
192 |
+
# return None
|
193 |
+
# session_id = session["session_id"]
|
194 |
+
# state_rows = session_state_table(limit=1, where=f"session_id == '{session_id}'", order_by="id DESC")
|
195 |
+
# if len(state_rows) <= 0:
|
196 |
+
# return None
|
197 |
+
# answer_id = state_rows[0].current_qeval
|
198 |
+
# qa_obj_row = question_evaluation_table(limit=1, where=f"id == {answer_id}")
|
199 |
+
# if len(qa_obj_row) <= 0:
|
200 |
+
# return None
|
201 |
+
# qe_obj = qa_obj_row[0]
|
202 |
+
# if qe_id != qe_obj.id:
|
203 |
+
# print(f"QE {qe_id} does not belong to {qe_obj.id}")
|
204 |
+
# return None
|
205 |
+
|
206 |
+
is_ok, qe_obj = validate_and_get_question_evaluation_objectid(session, qe_id)
|
207 |
+
if not is_ok:
|
208 |
+
print("toggle_up_down made session/object error")
|
209 |
+
return "Error"
|
210 |
|
211 |
# save_to_storage(
|
212 |
# storage.NavigationEvent(event_type="/", event_session_id=session_id, event_params={"qe_id":qe_id})
|
|
|
241 |
@rt("/submit_feedback/{qe_id}")
|
242 |
def post(session, qe_id:int, freeform_feedback:str):
|
243 |
# Update the object
|
244 |
+
# session_id = session.get("session_id", "Not set")
|
245 |
+
# save_to_storage(
|
246 |
+
# storage.NavigationEvent(event_type="/submit_feedback", event_session_id=session_id,
|
247 |
+
# event_params={"qe_id":qe_id})
|
248 |
+
# )
|
249 |
+
is_ok, qe_obj = validate_and_get_question_evaluation_objectid(session, qe_id)
|
250 |
if not is_ok:
|
251 |
+
print("submit_feedback made session/object error")
|
252 |
return "Error"
|
253 |
|
254 |
answer_eval_js = json.loads(qe_obj.answer_eval_text)
|
|
|
404 |
# return html_render_clear_area_button(html_id)
|
405 |
eval_request_status, _ = get_latest_eval_request_status(session_id)
|
406 |
if eval_request_status != EVAL_STATE_NEW:
|
407 |
+
# print("clear button: render button")
|
408 |
return html_render_clear_area_button(html_id)
|
409 |
else:
|
410 |
+
# print("clear button: render empty")
|
411 |
return Div(P(""), _id=html_id, hx_swap_oob='true')
|
412 |
|
413 |
|
|
|
462 |
|
463 |
@rt("/render_answer")
|
464 |
def get(session):
|
465 |
+
if 'session_id' not in session: return "render_answer No session ID"
|
466 |
session_id = session["session_id"]
|
467 |
answer_area = html_render_answer_from_db(session_id, HTML_RESULTS_AREA)
|
468 |
return answer_area
|
|
|
470 |
|
471 |
@rt("/submit_to_eval", methods="post")
|
472 |
def post(ccodetoeval:str, session):
|
473 |
+
if 'session_id' not in session: return P("submit_to_eval. Bad call. No session ID")
|
474 |
session_id = session["session_id"]
|
475 |
session_obj = Session_State_cls(
|
476 |
session_id=session_id,
|
|
|
491 |
|
492 |
@rt("/clear_area", methods="get")
|
493 |
def get(session):
|
494 |
+
if 'session_id' not in session: return P("clear_area. Bad call. No session ID")
|
495 |
session_id = session["session_id"]
|
496 |
save_to_storage(
|
497 |
storage.NavigationEvent(event_type="/clear_area", event_session_id=session_id)
|