|
@@ -399,7 +399,11 @@ def build_demand_export_rows(
|
|
|
def attach_wxindex_metadata(
|
|
def attach_wxindex_metadata(
|
|
|
export_rows: list[dict[str, Any]],
|
|
export_rows: list[dict[str, Any]],
|
|
|
trend_json: dict[str, Any] | None,
|
|
trend_json: dict[str, Any] | None,
|
|
|
|
|
+ *,
|
|
|
|
|
+ wxindex_threshold: float = WXINDEX_EXPORT_THRESHOLD,
|
|
|
) -> list[dict[str, Any]]:
|
|
) -> list[dict[str, Any]]:
|
|
|
|
|
+ from app.hot_content.demand_hive_export import is_export_row_as_demand
|
|
|
|
|
+
|
|
|
latest_score = (
|
|
latest_score = (
|
|
|
get_latest_wxindex_score(trend_json)
|
|
get_latest_wxindex_score(trend_json)
|
|
|
if isinstance(trend_json, dict)
|
|
if isinstance(trend_json, dict)
|
|
@@ -408,11 +412,23 @@ def attach_wxindex_metadata(
|
|
|
trend = get_wxindex_trend(trend_json) if isinstance(trend_json, dict) else ""
|
|
trend = get_wxindex_trend(trend_json) if isinstance(trend_json, dict) else ""
|
|
|
wxindex_keyword = get_wxindex_keyword(trend_json)
|
|
wxindex_keyword = get_wxindex_keyword(trend_json)
|
|
|
all_hot_keywords = format_wxindex_keywords(trend_json)
|
|
all_hot_keywords = format_wxindex_keywords(trend_json)
|
|
|
|
|
+ has_record_wxindex = latest_score is not None
|
|
|
|
|
+ record_wxindex_score = float(latest_score or 0)
|
|
|
|
|
+ # is_as_demand 与 ODPS 规则一致,需用落库后的 wxindex_latest_score 做标题门槛判断
|
|
|
|
|
+ gate_rows: list[dict[str, Any]] = []
|
|
|
|
|
+ for row in export_rows:
|
|
|
|
|
+ matched = str(row.get("matched_demand") or "").strip()
|
|
|
|
|
+ gate_row = dict(row)
|
|
|
|
|
+ if has_record_wxindex and _has_matched_demand_text(matched):
|
|
|
|
|
+ gate_row["wxindex_latest_score"] = record_wxindex_score
|
|
|
|
|
+ else:
|
|
|
|
|
+ gate_row["wxindex_latest_score"] = 0.0
|
|
|
|
|
+ gate_rows.append(gate_row)
|
|
|
|
|
+
|
|
|
rows: list[dict[str, Any]] = []
|
|
rows: list[dict[str, Any]] = []
|
|
|
for row in export_rows:
|
|
for row in export_rows:
|
|
|
matched_demand = str(row.get("matched_demand") or "").strip()
|
|
matched_demand = str(row.get("matched_demand") or "").strip()
|
|
|
has_matched_demand = _has_matched_demand_text(matched_demand)
|
|
has_matched_demand = _has_matched_demand_text(matched_demand)
|
|
|
- has_record_wxindex = latest_score is not None
|
|
|
|
|
|
|
|
|
|
if has_record_wxindex and has_matched_demand:
|
|
if has_record_wxindex and has_matched_demand:
|
|
|
wxindex_score = float(latest_score)
|
|
wxindex_score = float(latest_score)
|
|
@@ -433,6 +449,11 @@ def attach_wxindex_metadata(
|
|
|
"all_hot_keywords": all_hot_keywords,
|
|
"all_hot_keywords": all_hot_keywords,
|
|
|
"wxindex_latest_score": wxindex_score,
|
|
"wxindex_latest_score": wxindex_score,
|
|
|
"wxindex_trend": wxindex_trend_value,
|
|
"wxindex_trend": wxindex_trend_value,
|
|
|
|
|
+ "is_as_demand": is_export_row_as_demand(
|
|
|
|
|
+ normalized_row,
|
|
|
|
|
+ gate_rows,
|
|
|
|
|
+ wxindex_threshold=wxindex_threshold,
|
|
|
|
|
+ ),
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
return rows
|
|
return rows
|
|
@@ -480,6 +501,7 @@ def export_existing_records(
|
|
|
*,
|
|
*,
|
|
|
dry_run: bool,
|
|
dry_run: bool,
|
|
|
verbose: bool,
|
|
verbose: bool,
|
|
|
|
|
+ wxindex_threshold: float = WXINDEX_EXPORT_THRESHOLD,
|
|
|
) -> dict[str, int]:
|
|
) -> dict[str, int]:
|
|
|
summary = {
|
|
summary = {
|
|
|
"scanned": 0,
|
|
"scanned": 0,
|
|
@@ -516,6 +538,7 @@ def export_existing_records(
|
|
|
trend_json=trend_json if isinstance(trend_json, dict) else None,
|
|
trend_json=trend_json if isinstance(trend_json, dict) else None,
|
|
|
),
|
|
),
|
|
|
trend_json if isinstance(trend_json, dict) else None,
|
|
trend_json if isinstance(trend_json, dict) else None,
|
|
|
|
|
+ wxindex_threshold=wxindex_threshold,
|
|
|
)
|
|
)
|
|
|
if not export_rows:
|
|
if not export_rows:
|
|
|
summary["no_export_rows"] += 1
|
|
summary["no_export_rows"] += 1
|
|
@@ -593,6 +616,7 @@ def main(argv: list[str] | None = None) -> dict[str, int]:
|
|
|
records,
|
|
records,
|
|
|
dry_run=args.dry_run,
|
|
dry_run=args.dry_run,
|
|
|
verbose=args.verbose,
|
|
verbose=args.verbose,
|
|
|
|
|
+ wxindex_threshold=config.wxindex_score_threshold,
|
|
|
)
|
|
)
|
|
|
finally:
|
|
finally:
|
|
|
repository.close()
|
|
repository.close()
|