|
@@ -119,6 +119,7 @@ class FlowLedgerService:
|
|
|
"data_origin": self.data_origin,
|
|
"data_origin": self.data_origin,
|
|
|
"data_origin_label": "生产数据库" if self.data_origin == DATA_ORIGIN_PRODUCTION_DB else "本地调试缓存",
|
|
"data_origin_label": "生产数据库" if self.data_origin == DATA_ORIGIN_PRODUCTION_DB else "本地调试缓存",
|
|
|
"summary": self._summary(bundle, rows, extension_queries, media_counts, action_counts, gemini_counts),
|
|
"summary": self._summary(bundle, rows, extension_queries, media_counts, action_counts, gemini_counts),
|
|
|
|
|
+ "demand_summary": _demand_summary(bundle),
|
|
|
"rows": rows,
|
|
"rows": rows,
|
|
|
"extension_queries": extension_queries,
|
|
"extension_queries": extension_queries,
|
|
|
"debug": bundle if debug else None,
|
|
"debug": bundle if debug else None,
|
|
@@ -1192,6 +1193,46 @@ def _demand_id(bundle: dict[str, Any]) -> str:
|
|
|
return _text(source_context.get("demand_content_id") or source_context.get("id") or _evidence_pack(bundle).get("demand_content_id"))
|
|
return _text(source_context.get("demand_content_id") or source_context.get("id") or _evidence_pack(bundle).get("demand_content_id"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _demand_summary(bundle: dict[str, Any]) -> dict[str, Any]:
|
|
|
|
|
+ source_context = _record(bundle.get("source_context"))
|
|
|
|
|
+ raw = _record(source_context.get("raw_demand_content")) or source_context
|
|
|
|
|
+ ext_data = _record(raw.get("ext_data")) or _record(source_context.get("ext_data"))
|
|
|
|
|
+ evidence = _evidence_pack(bundle)
|
|
|
|
|
+ category_paths = _dedupe_texts([
|
|
|
|
|
+ _text(item.get("category_full_path") or item.get("category_path"))
|
|
|
|
|
+ for item in _list(evidence.get("category_bindings") or evidence.get("itemset_items"))
|
|
|
|
|
+ ])
|
|
|
|
|
+ extracted_points: list[str] = []
|
|
|
|
|
+ for binding in _list(evidence.get("element_bindings")):
|
|
|
|
|
+ for sample in _list(_record(binding).get("sample_elements")):
|
|
|
|
|
+ sample_record = _record(sample)
|
|
|
|
|
+ point_text = _text(sample_record.get("point_text") or sample_record.get("name"))
|
|
|
|
|
+ if not point_text:
|
|
|
|
|
+ continue
|
|
|
|
|
+ post_id = _text(sample_record.get("post_id"))
|
|
|
|
|
+ point_type = _text(sample_record.get("point_type"))
|
|
|
|
|
+ suffix = " / ".join(item for item in [point_type, f"帖子 {post_id}" if post_id else ""] if item)
|
|
|
|
|
+ extracted_points.append(f"{point_text}({suffix})" if suffix else point_text)
|
|
|
|
|
+ return {
|
|
|
|
|
+ "id": _demand_id(bundle),
|
|
|
|
|
+ "name": _text(raw.get("name") or source_context.get("name")),
|
|
|
|
|
+ "description": _text(ext_data.get("desc") or raw.get("suggestion") or source_context.get("suggestion")),
|
|
|
|
|
+ "reason": _text(ext_data.get("reason") or raw.get("reason") or source_context.get("reason")),
|
|
|
|
|
+ "source": _text(raw.get("merge_leve2") or source_context.get("merge_leve2")),
|
|
|
|
|
+ "score": raw.get("score") if raw.get("score") is not None else source_context.get("score"),
|
|
|
|
|
+ "date": _text(raw.get("dt") or source_context.get("dt")),
|
|
|
|
|
+ "type": _text(ext_data.get("type") or evidence.get("source_kind")),
|
|
|
|
|
+ "itemset_ids": _text_list(evidence.get("itemset_ids")),
|
|
|
|
|
+ "seed_terms": _text_list(evidence.get("seed_terms")),
|
|
|
|
|
+ "source_post_id": _text(evidence.get("source_post_id")),
|
|
|
|
|
+ "support": evidence.get("absolute_support") if evidence.get("absolute_support") is not None else evidence.get("support"),
|
|
|
|
|
+ "pattern_execution_id": _text(evidence.get("pattern_execution_id")),
|
|
|
|
|
+ "mining_config_id": _text(evidence.get("mining_config_id")),
|
|
|
|
|
+ "category_paths": category_paths,
|
|
|
|
|
+ "extracted_points": _dedupe_texts(extracted_points),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _source_post_id(seed_ref: dict[str, Any], source_ref: dict[str, Any], bundle: dict[str, Any]) -> str:
|
|
def _source_post_id(seed_ref: dict[str, Any], source_ref: dict[str, Any], bundle: dict[str, Any]) -> str:
|
|
|
return _text(
|
|
return _text(
|
|
|
source_ref.get("post_id")
|
|
source_ref.get("post_id")
|