|
@@ -59,12 +59,17 @@ class Item2VecModel:
|
|
|
.sort_values(["sale_qty", "cust_code"], ascending=[False, True])
|
|
.sort_values(["sale_qty", "cust_code"], ascending=[False, True])
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- # 将 cust_code_list 中不在候选集的商户补入,sale_qty=0 参与归一化
|
|
|
|
|
|
|
+ # 将 cust_code_list 中不在候选集的商户补入,查询其在相似品规上的真实销量参与归一化
|
|
|
existing_custs = set(recommend_cust["cust_code"].tolist())
|
|
existing_custs = set(recommend_cust["cust_code"].tolist())
|
|
|
- extra_rows = [{"cust_code": c, "sale_qty": 0} for c in cust_code_list if c not in existing_custs]
|
|
|
|
|
- if extra_rows:
|
|
|
|
|
- extra_df = pd.DataFrame(extra_rows)
|
|
|
|
|
- recommend_cust = pd.concat([recommend_cust, extra_df], ignore_index=True)
|
|
|
|
|
|
|
+ missing_custs = [c for c in cust_code_list if c not in existing_custs]
|
|
|
|
|
+ if missing_custs:
|
|
|
|
|
+ extra_order = self._dao.get_order_by_cust_ids_and_product_ids(self._city_uuid, missing_custs, product_list)
|
|
|
|
|
+ if not extra_order.empty:
|
|
|
|
|
+ extra_order["sale_qty"] = extra_order["sale_qty"].fillna(0)
|
|
|
|
|
+ extra_order = extra_order.groupby("cust_code", as_index=False)["sale_qty"].sum()
|
|
|
|
|
+ else:
|
|
|
|
|
+ extra_order = pd.DataFrame({"cust_code": missing_custs, "sale_qty": 0})
|
|
|
|
|
+ recommend_cust = pd.concat([recommend_cust, extra_order], ignore_index=True)
|
|
|
|
|
|
|
|
if recommend_cust.empty:
|
|
if recommend_cust.empty:
|
|
|
logger.warning(f"No candidates found for product {product_code} and cust_code_list is empty — returning empty list")
|
|
logger.warning(f"No candidates found for product {product_code} and cust_code_list is empty — returning empty list")
|