|
@@ -8,7 +8,7 @@ from pandas import DataFrame
|
|
|
from argparse import ArgumentParser
|
|
|
from datetime import datetime
|
|
|
|
|
|
-from applications import DeNetMysql, PQMySQL, longArticlesMySQL, bot, Functions
|
|
|
+from applications import DeNetMysql, PQMySQL, longArticlesMySQL, bot, Functions, create_feishu_columns_sheet
|
|
|
from applications.const import updateAccountReadRateTaskConst
|
|
|
from config import apolloConfig
|
|
|
|
|
@@ -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"
|
|
|
+read_rate_table = "long_articles_read_rate_dev"
|
|
|
|
|
|
|
|
|
def filter_outlier_data(group, key='show_view_count'):
|
|
@@ -213,11 +213,11 @@ def check_each_position(db_client, gh_id, index, dt, avg_rate) -> dict:
|
|
|
return {}
|
|
|
else:
|
|
|
response = {
|
|
|
- "账号名称": account_name,
|
|
|
- "位置": index,
|
|
|
- "当天阅读率均值": Functions().float_to_percentage(avg_rate),
|
|
|
- "前一天阅读率均值": Functions().float_to_percentage(previous_read_rate_avg),
|
|
|
- "相对变化率": Functions().float_to_percentage(relative_value)
|
|
|
+ "account_name": account_name,
|
|
|
+ "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)
|
|
|
}
|
|
|
return response
|
|
|
|
|
@@ -265,32 +265,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(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(
|
|
@@ -299,12 +299,20 @@ def update_single_day(dt, account_list, article_df, lam):
|
|
|
)
|
|
|
|
|
|
if error_list:
|
|
|
+ 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="相对变化率")
|
|
|
+ ]
|
|
|
bot(
|
|
|
title="更新阅读率均值,头次出现异常值通知",
|
|
|
detail={
|
|
|
- "时间": dt,
|
|
|
- "异常列表": error_list
|
|
|
- }
|
|
|
+ "columns": columns,
|
|
|
+ "rows": error_list
|
|
|
+ },
|
|
|
+ table=True
|
|
|
)
|
|
|
|
|
|
if not error_list and not insert_error_list:
|