|
@@ -16,7 +16,7 @@ const = updateAccountReadRateTaskConst()
|
|
|
config = apolloConfig()
|
|
|
unauthorized_account = json.loads(config.getConfigValue("unauthorized_gh_id_fans"))
|
|
|
functions = Functions()
|
|
|
-read_rate_table = "long_articles_read_rate_dev"
|
|
|
+read_rate_table = "long_articles_read_rate"
|
|
|
|
|
|
|
|
|
def filter_outlier_data(group, key='show_view_count'):
|
|
@@ -217,7 +217,12 @@ def check_each_position(db_client, gh_id, index, dt, avg_rate) -> dict:
|
|
|
"position": index,
|
|
|
"read_rate_avg_yesterday": Functions().float_to_percentage(avg_rate),
|
|
|
"read_rate_avg_the_day_before_yesterday": Functions().float_to_percentage(previous_read_rate_avg),
|
|
|
- "relative_change_rate": Functions().float_to_percentage(relative_value)
|
|
|
+ "relative_change_rate": [
|
|
|
+ {
|
|
|
+ "text": Functions().float_to_percentage(relative_value),
|
|
|
+ "color": "red" if relative_value < 0 else "green"
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
return response
|
|
|
|
|
@@ -264,33 +269,32 @@ def update_single_day(dt, account_list, article_df, lam):
|
|
|
)
|
|
|
if error_obj:
|
|
|
error_list.append(error_obj)
|
|
|
- # continue
|
|
|
- # try:
|
|
|
- # if not read_rate_avg:
|
|
|
- # continue
|
|
|
- # insert_sql = f"""
|
|
|
- # 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);
|
|
|
- # """
|
|
|
- # lam.update(
|
|
|
- # sql=insert_sql,
|
|
|
- # params=(
|
|
|
- # account['account_name'],
|
|
|
- # account['gh_id'],
|
|
|
- # index,
|
|
|
- # read_rate_avg,
|
|
|
- # "从 {} 开始往前计算 31 天".format(dt),
|
|
|
- # articles_count,
|
|
|
- # functions.timestamp_to_str(timestamp=min_publish_time, string_format='%Y-%m-%d'),
|
|
|
- # functions.timestamp_to_str(timestamp=max_publish_time, string_format='%Y-%m-%d'),
|
|
|
- # avg_date.replace("-", ""),
|
|
|
- # 0
|
|
|
- # )
|
|
|
- # )
|
|
|
- # except Exception as e:
|
|
|
- # insert_error_list.append(str(e))
|
|
|
+ try:
|
|
|
+ if not read_rate_avg:
|
|
|
+ continue
|
|
|
+ insert_sql = f"""
|
|
|
+ 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);
|
|
|
+ """
|
|
|
+ lam.update(
|
|
|
+ sql=insert_sql,
|
|
|
+ params=(
|
|
|
+ account['account_name'],
|
|
|
+ account['gh_id'],
|
|
|
+ index,
|
|
|
+ read_rate_avg,
|
|
|
+ "从 {} 开始往前计算 31 天".format(dt),
|
|
|
+ articles_count,
|
|
|
+ functions.timestamp_to_str(timestamp=min_publish_time, string_format='%Y-%m-%d'),
|
|
|
+ functions.timestamp_to_str(timestamp=max_publish_time, string_format='%Y-%m-%d'),
|
|
|
+ avg_date.replace("-", ""),
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ )
|
|
|
+ except Exception as e:
|
|
|
+ insert_error_list.append(str(e))
|
|
|
|
|
|
if insert_error_list:
|
|
|
bot(
|
|
@@ -302,9 +306,12 @@ def update_single_day(dt, account_list, article_df, lam):
|
|
|
columns = [
|
|
|
create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="account_name", display_name="账号名称"),
|
|
|
create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="position", display_name="文章位置"),
|
|
|
- create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="read_rate_avg_yesterday", display_name="昨日阅读率均值"),
|
|
|
- create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="read_rate_avg_the_day_before_yesterday", display_name="前天阅读率均值"),
|
|
|
- create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="relative_change_rate", display_name="相对变化率")
|
|
|
+ create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="read_rate_avg_yesterday",
|
|
|
+ display_name="昨日阅读率均值"),
|
|
|
+ create_feishu_columns_sheet(sheet_type="plain_text", sheet_name="read_rate_avg_the_day_before_yesterday",
|
|
|
+ display_name="前天阅读率均值"),
|
|
|
+ create_feishu_columns_sheet(sheet_type="options", sheet_name="relative_change_rate",
|
|
|
+ display_name="相对变化率")
|
|
|
]
|
|
|
bot(
|
|
|
title="更新阅读率均值,头次出现异常值通知",
|