55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""HTTP entry points for the product's chart-choice pause."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
RECT_EVENT_SCORING_ENABLED = False
|
|
RECTIFICATION_PAUSED_RESPONSE = {
|
|
"error": "答题和选边暂已停用。现在可以保存填写的时间或范围中点。",
|
|
"code": "questionnaire_paused",
|
|
}
|
|
|
|
_PAUSED_ENDPOINTS = frozenset({
|
|
"/api/active_rectification_questions",
|
|
"/api/active_rectification_score",
|
|
"/api/active_rectification_events",
|
|
"/api/chart_choice/astrologer",
|
|
})
|
|
_PACKET = "/api/chart_choice/packet"
|
|
_DECIDE = "/api/chart_choice/decide"
|
|
_QUESTIONNAIRE_FIELDS = frozenset({
|
|
"questionnaire", "chart_answers", "answers", "overrideSide", "readBothAll", "resumeRecordId",
|
|
"event_answers", "appearance", "birthmarks", "events", "resume", "resume_v2",
|
|
"override_side", "read_both_all",
|
|
})
|
|
|
|
|
|
def rectification_request_paused(path: str, body: dict[str, Any]) -> bool:
|
|
if RECT_EVENT_SCORING_ENABLED:
|
|
return False
|
|
if path == "/api/technique_example":
|
|
endpoint = body.get("endpoint")
|
|
return isinstance(endpoint, str) and endpoint.strip() in _PAUSED_ENDPOINTS
|
|
if path in _PAUSED_ENDPOINTS:
|
|
return True
|
|
if path not in (_PACKET, _DECIDE):
|
|
return False
|
|
if _QUESTIONNAIRE_FIELDS.intersection(body) or body.get("resolved"):
|
|
return True
|
|
# Existing declaration saves use this answer-free stop mode to restore the full range.
|
|
if path == _DECIDE and body.get("adaptive") is True and body.get("stop") is True and "resolved" not in body:
|
|
return False
|
|
return "adaptive" in body or "stop" in body
|
|
|
|
|
|
def dispatch_chart_choice(path: str, body: dict[str, Any]) -> dict[str, Any]:
|
|
if path == _PACKET:
|
|
from .service import build_packet
|
|
return build_packet(body)
|
|
if path == _DECIDE:
|
|
from .service import decide_packet
|
|
return decide_packet(body)
|
|
|
|
from .astrologer import evaluate
|
|
return evaluate(body)
|