|
|
@@ -9,26 +9,29 @@ class RankLogMonitorMapper:
|
|
|
self.pool = pool
|
|
|
self.log_service = log_service
|
|
|
|
|
|
- async def fetch_accounts(self):
|
|
|
+ async def fetch_all_articles(self) -> list[dict]:
|
|
|
query = """
|
|
|
- SELECT DISTINCT gh_id FROM rank_content_score;
|
|
|
+ SELECT gh_id, account_name, source_id, content_pool_type, strategy,
|
|
|
+ title, score, score_map, category
|
|
|
+ FROM rank_content_score;
|
|
|
"""
|
|
|
- response = await self.pool.async_fetch(query=query)
|
|
|
- return [
|
|
|
- i.get("gh_id") for i in response
|
|
|
- ]
|
|
|
+ result = await self.pool.async_fetch(query=query)
|
|
|
+ return result or []
|
|
|
|
|
|
- async def fetch_articles(self, gh_id: str):
|
|
|
+ async def fetch_articles(self, gh_id: str) -> list[dict]:
|
|
|
query = """
|
|
|
- SELECT gh_id, account_name, content_pool_type, strategy, title, score, score_map, category
|
|
|
+ SELECT gh_id, account_name, source_id, content_pool_type, strategy,
|
|
|
+ title, score, score_map, category
|
|
|
FROM rank_content_score
|
|
|
- WHERE gh_id = %s
|
|
|
- ;
|
|
|
+ WHERE gh_id = %s;
|
|
|
"""
|
|
|
- return await self.pool.async_fetch(query=query, params=(gh_id,))
|
|
|
-
|
|
|
+ result = await self.pool.async_fetch(query=query, params=(gh_id,))
|
|
|
+ return result or []
|
|
|
|
|
|
async def save_records(self, rank_date: str, records: list[dict]) -> int:
|
|
|
+ if not records:
|
|
|
+ return 0
|
|
|
+
|
|
|
now_ts = int(time.time())
|
|
|
params = []
|
|
|
for row in records:
|
|
|
@@ -37,6 +40,7 @@ class RankLogMonitorMapper:
|
|
|
rank_date,
|
|
|
row.get("account_name"),
|
|
|
row.get("gh_id"),
|
|
|
+ row.get("source_id"),
|
|
|
row.get("content_pool_type"),
|
|
|
row.get("strategy"),
|
|
|
row.get("title"),
|
|
|
@@ -50,29 +54,52 @@ class RankLogMonitorMapper:
|
|
|
row.get("his_fission_open_rate_score"),
|
|
|
row.get("crawler_days_decrease_score"),
|
|
|
row.get("similarity_score"),
|
|
|
+ row.get("publish_times_score"),
|
|
|
row.get("source_log"),
|
|
|
now_ts,
|
|
|
now_ts,
|
|
|
)
|
|
|
)
|
|
|
|
|
|
- if not params:
|
|
|
- return 0
|
|
|
- INSERT_LONG_ARTICLES_DAILY_RANK_SQL = """
|
|
|
- INSERT INTO long_articles_daily_rank
|
|
|
- (
|
|
|
- rank_date, account_name, gh_id, content_pool_type, strategy, title, score, category,
|
|
|
- account_user_category_score, category_score, flow_ctl_decrease_score, i2i_recommend_score,
|
|
|
- view_count_rate_score, his_fission_open_rate_score, crawler_days_decrease_score, similarity_score,
|
|
|
- source_log, create_timestamp, update_timestamp
|
|
|
- )
|
|
|
- VALUES
|
|
|
- (
|
|
|
- %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s
|
|
|
- );
|
|
|
- """
|
|
|
+ sql = """
|
|
|
+ INSERT INTO long_articles_daily_rank
|
|
|
+ (
|
|
|
+ rank_date, account_name, gh_id, source_id, content_pool_type, strategy,
|
|
|
+ title, score, category,
|
|
|
+ account_user_category_score, category_score, flow_ctl_decrease_score,
|
|
|
+ i2i_recommend_score, view_count_rate_score, his_fission_open_rate_score,
|
|
|
+ crawler_days_decrease_score, similarity_score, publish_times_score,
|
|
|
+ source_log, create_timestamp, update_timestamp
|
|
|
+ )
|
|
|
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
|
|
+ ON DUPLICATE KEY UPDATE
|
|
|
+ score = VALUES(score),
|
|
|
+ title = VALUES(title),
|
|
|
+ category = VALUES(category),
|
|
|
+ account_user_category_score = VALUES(account_user_category_score),
|
|
|
+ category_score = VALUES(category_score),
|
|
|
+ flow_ctl_decrease_score = VALUES(flow_ctl_decrease_score),
|
|
|
+ i2i_recommend_score = VALUES(i2i_recommend_score),
|
|
|
+ view_count_rate_score = VALUES(view_count_rate_score),
|
|
|
+ his_fission_open_rate_score = VALUES(his_fission_open_rate_score),
|
|
|
+ crawler_days_decrease_score = VALUES(crawler_days_decrease_score),
|
|
|
+ similarity_score = VALUES(similarity_score),
|
|
|
+ publish_times_score = VALUES(publish_times_score),
|
|
|
+ source_log = VALUES(source_log),
|
|
|
+ update_timestamp = VALUES(update_timestamp);
|
|
|
+ """
|
|
|
return await self.pool.async_save(
|
|
|
- query=INSERT_LONG_ARTICLES_DAILY_RANK_SQL,
|
|
|
+ query=sql,
|
|
|
params=params,
|
|
|
batch=True,
|
|
|
)
|
|
|
+
|
|
|
+ async def count_records(self, rank_date: str) -> int:
|
|
|
+ query = """
|
|
|
+ SELECT COUNT(*) AS cnt FROM long_articles_daily_rank
|
|
|
+ WHERE rank_date = %s;
|
|
|
+ """
|
|
|
+ result = await self.pool.async_fetch(query=query, params=(rank_date,))
|
|
|
+ if result:
|
|
|
+ return result[0].get("cnt", 0)
|
|
|
+ return 0
|