소스 검색

阅读率均值,阅读均值使用发布时间

luojunhui 5 달 전
부모
커밋
d8a66f2ab4
2개의 변경된 파일27개의 추가작업 그리고 24개의 파일을 삭제
  1. 2 2
      applications/functions.py
  2. 25 22
      cal_account_read_rate_avg_daily.py

+ 2 - 2
applications/functions.py

@@ -125,7 +125,7 @@ class Functions(object):
         :param date_string:
         :return:
         """
-        date_obj = datetime.strptime(__date_string=date_string, __format=string_format)
+        date_obj = datetime.strptime(date_string, string_format)
         timestamp = date_obj.timestamp()
         return int(timestamp)
 
@@ -136,5 +136,5 @@ class Functions(object):
         :param timestamp:
         """
         dt_object = datetime.utcfromtimestamp(timestamp).replace(tzinfo=timezone.utc).astimezone()
-        date_string = dt_object.strftime(__format=string_format)
+        date_string = dt_object.strftime(string_format)
         return date_string

+ 25 - 22
cal_account_read_rate_avg_daily.py

@@ -12,6 +12,7 @@ from applications.const import updateAccountReadRateTaskConst
 
 const = updateAccountReadRateTaskConst()
 functions = Functions()
+read_rate_table = "long_articles_read_rate_dev"
 
 
 def filter_outlier_data(group, key='show_view_count'):
@@ -142,7 +143,7 @@ def cal_account_read_rate(gh_id_tuple) -> DataFrame:
     )
     for line in account_article_detail:
         gh_id = line['ghId']
-        dt = functions.timestamp_to_str(timestamp=['publish_timestamp'], string_format='%Y-%m-%d')
+        dt = functions.timestamp_to_str(timestamp=line['publish_timestamp'], string_format='%Y-%m-%d')
         fans = fans_dict_each_day.get(gh_id, {}).get(dt, 0)
         line['fans'] = fans
         if fans > 1000:
@@ -193,7 +194,7 @@ def check_each_position(db_client, gh_id, index, dt, avg_rate) -> dict:
     dt = int(dt.replace("-", ""))
     select_sql = f"""
         SELECT account_name, read_rate_avg
-        FROM long_articles_read_rate
+        FROM {read_rate_table}
         WHERE gh_id = '{gh_id}' and position = {index} and dt_version < {dt}
         ORDER BY dt_version DESC limit 1;
     """
@@ -262,7 +263,7 @@ def update_single_day(dt, account_list, article_df, lam):
                     if not read_rate_avg:
                         continue
                     insert_sql = f"""
-                        INSERT INTO long_articles_read_rate
+                        INSERT INTO {read_rate_table}
                         (account_name, gh_id, position, read_rate_avg, remark, articles_count, earliest_publish_time, latest_publish_time, dt_version, is_delete)
                         values
                         (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
@@ -286,27 +287,29 @@ def update_single_day(dt, account_list, article_df, lam):
                     insert_error_list.append(e)
 
     if insert_error_list:
-        bot(
-            title="更新阅读率均值,存在sql 插入失败",
-            detail=insert_error_list
-        )
+        # bot(
+        #     title="更新阅读率均值,存在sql 插入失败",
+        #     detail=insert_error_list
+        # )
+        print(insert_error_list)
 
     if error_list:
-        bot(
-            title="更新阅读率均值,头次出现异常值通知",
-            detail={
-                "时间": dt,
-                "异常列表": error_list
-            }
-        )
-
-    if not error_list and not insert_error_list:
-        bot(
-            title="阅读率均值表,更新成功",
-            detail={
-                "日期": dt
-            }
-        )
+        # bot(
+        #     title="更新阅读率均值,头次出现异常值通知",
+        #     detail={
+        #         "时间": dt,
+        #         "异常列表": error_list
+        #     }
+        # )
+        print(error_list)
+
+    # if not error_list and not insert_error_list:
+    #     bot(
+    #         title="阅读率均值表,更新成功",
+    #         detail={
+    #             "日期": dt
+    #         }
+    #     )
 
 
 def main() -> None: