|
|
@@ -1,3 +1,4 @@
|
|
|
+from database import RedisDatabaseHelper
|
|
|
from database.dao.mysql_dao import MySqlDao
|
|
|
from models import Recommend
|
|
|
from models.rank.data.config import CustConfig, ImportanceFeaturesMap, ProductConfig, DeliveryConfig
|
|
|
@@ -11,12 +12,18 @@ from utils.reports_process import feats_relation_process, build_recommend_report
|
|
|
|
|
|
logger = get_logger("utils.report")
|
|
|
|
|
|
+
|
|
|
+def _get_itemcf_key(city_uuid, product_code):
|
|
|
+ return f"fc:{city_uuid}:{product_code}"
|
|
|
+
|
|
|
+
|
|
|
class ReportUtils:
|
|
|
def __init__(self, city_uuid, product_id):
|
|
|
self._recommend_model = Recommend(city_uuid)
|
|
|
self._city_uuid = city_uuid
|
|
|
self._product_id = product_id
|
|
|
self._dao = MySqlDao()
|
|
|
+ self._redis = RedisDatabaseHelper().redis
|
|
|
self._product_data = self._dao.get_product_by_id(self._city_uuid, self._product_id)[ProductConfig.FEATURE_COLUMNS]
|
|
|
self._save_dir = os.path.join("./data/reports", city_uuid, product_id)
|
|
|
|
|
|
@@ -25,12 +32,14 @@ class ReportUtils:
|
|
|
|
|
|
def _get_recommend_data(self, cust_code_list):
|
|
|
"""获取推荐商户列表"""
|
|
|
- products_in_order = self._dao.get_product_from_order(self._city_uuid)["product_code"].unique().tolist()
|
|
|
- if self._product_id in products_in_order:
|
|
|
+ itemcf_key = _get_itemcf_key(self._city_uuid, self._product_id)
|
|
|
+ if self._redis.exists(itemcf_key):
|
|
|
+ logger.info(f"Using GBDT-LR model for report product {self._product_id}, itemcf_key={itemcf_key}")
|
|
|
recommend_data = self._recommend_model.get_recommend_list_by_gbdtlr(
|
|
|
self._product_id, cust_code_list=cust_code_list
|
|
|
)
|
|
|
else:
|
|
|
+ logger.info(f"Using Item2Vec model for report product {self._product_id}, itemcf_key not found: {itemcf_key}")
|
|
|
recommend_data = self._recommend_model.get_recommend_list_by_item2vec(
|
|
|
self._product_id, cust_code_list=cust_code_list
|
|
|
)
|
|
|
@@ -158,4 +167,4 @@ if __name__ == "__main__":
|
|
|
report = ReportUtils(city_uuid, product_id)
|
|
|
|
|
|
report.generate_eval_data(start_time, end_time)
|
|
|
-
|
|
|
+
|