Add post-answer review and per-question loading
This commit is contained in:
@@ -246,7 +246,13 @@ func advance_core_question() -> bool:
|
||||
if question.is_empty():
|
||||
core_status_message = "All available questions cleared."
|
||||
return false
|
||||
active_questions.append(question)
|
||||
return append_core_question(question)
|
||||
|
||||
|
||||
func append_core_question(question: Dictionary) -> bool:
|
||||
if question.is_empty():
|
||||
return false
|
||||
active_questions.append(_prepare_question_choices(question.duplicate(true)))
|
||||
answers.append(null)
|
||||
current_index = active_questions.size() - 1
|
||||
current_question_started_at = Time.get_ticks_msec() / 1000.0
|
||||
@@ -257,6 +263,15 @@ func advance_core_question() -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func get_core_excluded_question_ids() -> Array:
|
||||
var excluded: Array = ProfileService.get_profile().get("correct_question_ids", []).duplicate()
|
||||
for question in active_questions:
|
||||
var question_id := str(question.get("id", ""))
|
||||
if question_id != "" and not excluded.has(question_id):
|
||||
excluded.append(question_id)
|
||||
return excluded
|
||||
|
||||
|
||||
func get_current_elapsed_seconds() -> float:
|
||||
if current_question_started_at <= 0.0:
|
||||
return 0.0
|
||||
|
||||
@@ -43,6 +43,7 @@ var pending_report_question_id := ""
|
||||
var attempt_queue: Array = []
|
||||
var active_attempt_index := -1
|
||||
var attempt_request_active := false
|
||||
var pending_excluded_question_ids: Array = []
|
||||
|
||||
func _ready() -> void:
|
||||
questions_api_url = EndpointConfig.resolve(
|
||||
@@ -92,30 +93,34 @@ func _ready() -> void:
|
||||
_process_attempt_queue()
|
||||
|
||||
|
||||
func load_questions_from_api(reset_retry: bool = true) -> void:
|
||||
func load_questions_from_api(reset_retry: bool = true, excluded_question_ids: Array = []) -> void:
|
||||
if AuthState.access_token.is_empty():
|
||||
_set_load_error("Login required before loading questions.", false)
|
||||
return
|
||||
|
||||
if reset_retry:
|
||||
pending_excluded_question_ids = excluded_question_ids.duplicate()
|
||||
retry_attempt = 0
|
||||
next_retry_seconds = 0
|
||||
retry_timer.stop()
|
||||
|
||||
var should_load_ratings := load_state == "idle"
|
||||
is_loading = true
|
||||
load_state = "retrying" if retry_attempt > 0 else "loading"
|
||||
last_error = ""
|
||||
questions.clear()
|
||||
questions_changed.emit()
|
||||
load_ratings_from_api()
|
||||
if should_load_ratings:
|
||||
load_ratings_from_api()
|
||||
|
||||
var headers := PackedStringArray([
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer %s" % AuthState.access_token
|
||||
])
|
||||
var payload := {
|
||||
"limit": 80,
|
||||
"supportsChoicePools": true
|
||||
"limit": 1,
|
||||
"supportsChoicePools": true,
|
||||
"excludeExternalIds": pending_excluded_question_ids
|
||||
}
|
||||
var err := request.request(questions_api_url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
||||
if err != OK:
|
||||
@@ -156,7 +161,11 @@ func retry_now() -> void:
|
||||
retry_attempt = 0
|
||||
next_retry_seconds = 0
|
||||
retry_timer.stop()
|
||||
load_questions_from_api(false)
|
||||
load_questions_from_api(false, pending_excluded_question_ids)
|
||||
|
||||
|
||||
func load_next_random_question(excluded_question_ids: Array) -> void:
|
||||
load_questions_from_api(true, excluded_question_ids)
|
||||
|
||||
|
||||
func clear_questions() -> void:
|
||||
@@ -185,6 +194,7 @@ func clear_questions() -> void:
|
||||
category_elos = {}
|
||||
last_rating_change = {}
|
||||
pending_report_question_id = ""
|
||||
pending_excluded_question_ids.clear()
|
||||
questions_changed.emit()
|
||||
ratings_changed.emit()
|
||||
|
||||
@@ -592,6 +602,24 @@ func _normalize_api_question(item: Variant) -> Dictionary:
|
||||
"labs": item.get("labs", []),
|
||||
"media": item.get("media", []),
|
||||
"tags": item.get("tags", []),
|
||||
"references": item.get("references", [])
|
||||
"references": _normalize_references(item.get("references", []))
|
||||
}
|
||||
return normalized
|
||||
|
||||
|
||||
func _normalize_references(raw_references: Variant) -> Array:
|
||||
var normalized: Array = []
|
||||
if typeof(raw_references) != TYPE_ARRAY:
|
||||
return normalized
|
||||
for raw_reference in raw_references:
|
||||
if typeof(raw_reference) != TYPE_DICTIONARY:
|
||||
continue
|
||||
normalized.append({
|
||||
"title": str(raw_reference.get("title", raw_reference.get("Title", ""))).strip_edges(),
|
||||
"publisher": str(raw_reference.get("publisher", raw_reference.get("Publisher", ""))).strip_edges(),
|
||||
"url": str(raw_reference.get("url", raw_reference.get("Url", ""))).strip_edges(),
|
||||
"supports": str(raw_reference.get("supports", raw_reference.get("Supports", ""))).strip_edges(),
|
||||
"accessed_on": str(raw_reference.get("accessedOn", raw_reference.get("accessed_on", raw_reference.get("AccessedOn", "")))).strip_edges(),
|
||||
"reviewer": str(raw_reference.get("reviewer", raw_reference.get("Reviewer", ""))).strip_edges()
|
||||
})
|
||||
return normalized
|
||||
|
||||
Reference in New Issue
Block a user