Spaces:
Sleeping
fix(upload-extract): use _catalogue_scorecard primary path for status
Browse filesPrevious fix mirrored only the fallback path of /api/policies/{id}/scorecard
(build_scorecard(extracted, insurer_reviews)). The endpoint's PRIMARY path
is _catalogue_scorecard(policy_id, profile), which builds off the
marketplace catalogue (heuristic record.json + curated overlay + dedup +
insurer reviews) β that's what produces the 52.2%/grade-C the user sees.
The bare build_scorecard path reads 17.4% because it doesn't see the
heuristic merge.
Same resolution order as the live scorecard endpoint:
1. _catalogue_scorecard(pid, None) β primary
2. build_scorecard(extracted, insurer_reviews) β fallback
This makes status.completeness_pct + status.overall_grade equal to the
scorecard endpoint's response BY CONSTRUCTION for every upload that
becomes a marketplace card (which is every successful upload).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- backend/uploaded_docs.py +30 -18
|
@@ -1147,27 +1147,39 @@ async def extract_one_for_upload(
|
|
| 1147 |
|
| 1148 |
# Resolve the freshly-graded card so the status can report the
|
| 1149 |
# actual completeness + grade the CHAT CARD will show. Mirror
|
| 1150 |
-
# the /api/policies/{id}/scorecard endpoint's resolution
|
| 1151 |
-
# byte-for-byte:
|
| 1152 |
-
#
|
| 1153 |
-
#
|
| 1154 |
-
#
|
| 1155 |
-
#
|
| 1156 |
-
#
|
|
|
|
| 1157 |
_final_completeness = None
|
| 1158 |
_final_grade = None
|
| 1159 |
try:
|
| 1160 |
-
|
| 1161 |
-
|
| 1162 |
-
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1171 |
if _sc is not None:
|
| 1172 |
_final_completeness = float(_sc.data_completeness_pct)
|
| 1173 |
_final_grade = _sc.overall_grade
|
|
|
|
| 1147 |
|
| 1148 |
# Resolve the freshly-graded card so the status can report the
|
| 1149 |
# actual completeness + grade the CHAT CARD will show. Mirror
|
| 1150 |
+
# the /api/policies/{id}/scorecard endpoint's resolution order
|
| 1151 |
+
# byte-for-byte: PRIMARY path is the marketplace catalogue
|
| 1152 |
+
# scorecard (_catalogue_scorecard) which folds in the heuristic
|
| 1153 |
+
# record.json + curated overlay + insurer reviews + product
|
| 1154 |
+
# dedup β that's what produces the 52.2%/grade-C the user sees
|
| 1155 |
+
# on the inline card. The fallback path (build_scorecard on the
|
| 1156 |
+
# bare extracted JSON) reads 17.4% because it doesn't see the
|
| 1157 |
+
# heuristic merge or reviews-driven sub-scores.
|
| 1158 |
_final_completeness = None
|
| 1159 |
_final_grade = None
|
| 1160 |
try:
|
| 1161 |
+
# PRIMARY β same call /api/policies/{id}/scorecard makes first.
|
| 1162 |
+
# Bust the marketplace grade cache first (we invalidated _MG_CACHE
|
| 1163 |
+
# above, but _catalogue_indices builds off the latest record.json
|
| 1164 |
+
# + extracted JSON on each call so this becomes a fresh build).
|
| 1165 |
+
import backend.main as _bm2
|
| 1166 |
+
_sc = _bm2._catalogue_scorecard(policy_id, None)
|
| 1167 |
+
if _sc is None:
|
| 1168 |
+
# FALLBACK β same path the endpoint falls through to for
|
| 1169 |
+
# non-catalogued ids. For user uploads this is just defensive;
|
| 1170 |
+
# the upload IS a marketplace card by design (record.json is
|
| 1171 |
+
# persisted under UPLOADED_DOCS_DIR/<pid>/).
|
| 1172 |
+
from backend.scorecard import build_scorecard as _bs
|
| 1173 |
+
_doc_for_sc = json.loads(out_json.read_text())
|
| 1174 |
+
_ir = None
|
| 1175 |
+
if insurer_slug:
|
| 1176 |
+
_rp = _settings.DATA_DIR / "reviews" / f"{insurer_slug}.json"
|
| 1177 |
+
if _rp.exists():
|
| 1178 |
+
try:
|
| 1179 |
+
_ir = json.loads(_rp.read_text())
|
| 1180 |
+
except Exception:
|
| 1181 |
+
_ir = None
|
| 1182 |
+
_sc = _bs(_doc_for_sc, insurer_reviews=_ir, profile=None)
|
| 1183 |
if _sc is not None:
|
| 1184 |
_final_completeness = float(_sc.data_completeness_pct)
|
| 1185 |
_final_grade = _sc.overall_grade
|