Commit 1447f261 authored by yangruiqiang's avatar yangruiqiang

修改brand_name

parent 657e27c5
...@@ -378,8 +378,8 @@ def zhou_report(): ...@@ -378,8 +378,8 @@ def zhou_report():
phone = data.get("phone") phone = data.get("phone")
begin = data.get("begin") begin = data.get("begin")
end = data.get("end") end = data.get("end")
brand_name = data.get("plan_name", []) brand_name = data.get("plan_name")
question_list = data.get("question_list") question_list = data.get("question_list", [])
if not phone: if not phone:
return fail("phone不能为空") return fail("phone不能为空")
...@@ -389,20 +389,23 @@ def zhou_report(): ...@@ -389,20 +389,23 @@ def zhou_report():
if not end: if not end:
return fail("end不能为空") return fail("end不能为空")
# if not brand_name:
# if not brand_name: return fail("plan_name不能为空")
# return fail("brand_name不能为空")
# if question_list is not None and not isinstance(question_list, list): # if not isinstance(question_list, list):
# return fail("question_list必须是数组") # return fail("question_list必须是数组")
try: try:
req_list = get_req_id(phone, begin, end) req_list = get_req_id(phone, begin, end)
if not req_list:
return fail("未查询到请求记录")
req_time_map = {} req_time_map = {}
req_ids = [] req_ids = []
brand_id = 0 brand_id = 0
user_id = 0 user_id = 0
for item in req_list: for item in req_list:
if item.get('plan_name') == brand_name: item_plan_name = item.get('plan_name')
if item_plan_name == brand_name:
req_id = item.get("req_id") req_id = item.get("req_id")
user_id = item.get("user_id") user_id = item.get("user_id")
brand_id = item.get("brand_library_id") brand_id = item.get("brand_library_id")
...@@ -410,11 +413,16 @@ def zhou_report(): ...@@ -410,11 +413,16 @@ def zhou_report():
req_ids.append(req_id) req_ids.append(req_id)
req_time_map[req_id] = created_at req_time_map[req_id] = created_at
if not brand_id or not user_id:
return fail("未找到对应plan_name的数据")
result = [] result = []
platform_data = get_platforms(brand_id, user_id, begin, end, question_list) platform_data = get_platforms(brand_id, user_id, begin, end, question_list) or {}
if not isinstance(platform_data, dict):
return fail("平台数据查询失败")
geo_refer_rank_overview_vos = platform_data.get('geo_refer_rank_overview_vos') geo_refer_rank_overview_vos = platform_data.get('geo_refer_rank_overview_vos') or []
brand_overview = platform_data.get('brand_overview') brand_overview = platform_data.get('brand_overview') or {}
for item in geo_refer_rank_overview_vos: for item in geo_refer_rank_overview_vos:
result.append({ result.append({
"平台": plat_form_map.get(item.get("platform"), item.get("platform")), "平台": plat_form_map.get(item.get("platform"), item.get("platform")),
...@@ -443,7 +451,7 @@ def zhou_report(): ...@@ -443,7 +451,7 @@ def zhou_report():
# 概览数据 # 概览数据
# 分平台数据 # 分平台数据
all_word = get_all_word_rank(brand_id, user_id, begin, end, question_list) all_word = get_all_word_rank(brand_id, user_id, begin, end, question_list) or []
all_word_result = [] all_word_result = []
for all in all_word: for all in all_word:
all_word_result.append({ all_word_result.append({
...@@ -456,7 +464,7 @@ def zhou_report(): ...@@ -456,7 +464,7 @@ def zhou_report():
# 全部品牌词数据 # 全部品牌词数据
overview_result = [] overview_result = []
sentiment_overview = get_sentiment_overview(brand_id, user_id, begin, end, question_list) sentiment_overview = get_sentiment_overview(brand_id, user_id, begin, end, question_list) or {}
overview_result.append( overview_result.append(
{ {
...@@ -472,19 +480,20 @@ def zhou_report(): ...@@ -472,19 +480,20 @@ def zhou_report():
} }
) )
platform_sentiment_result = [] platform_sentiment_result = []
platform_sentiment = get_platforms_sentiment(brand_id, user_id, begin, end, question_list) platform_sentiment = get_platforms_sentiment(brand_id, user_id, begin, end, question_list) or []
for pla in platform_sentiment: for pla in platform_sentiment:
sentiment_count = pla.get('sentiment_count') or 1
platform_sentiment_result.append({ platform_sentiment_result.append({
"平台": plat_form_map.get(pla.get("platform"), pla.get("platform")), "平台": plat_form_map.get(pla.get("platform"), pla.get("platform")),
"正面": round(pla.get('positive_count') / pla.get('sentiment_count'), 2), "正面": round((pla.get('positive_count') or 0) / sentiment_count, 2),
"中性": round(pla.get('neutral_count') / pla.get('sentiment_count'), 2), "中性": round((pla.get('neutral_count') or 0) / sentiment_count, 2),
"负面": round(pla.get('negative_count') / pla.get('sentiment_count'), 2), "负面": round((pla.get('negative_count') or 0) / sentiment_count, 2),
"提及品牌次数": pla.get('brand_words_count'), "提及品牌次数": pla.get('brand_words_count'),
"引用来源": pla.get('source_count'), "引用来源": pla.get('source_count'),
}) })
platform_list = ["DB", "DP", "TYQW", "TXYB", "BDAI", "DOUBA", "DPA", "DYAI", "KIMI", "WXYY"] platform_list = ["DB", "DP", "TYQW", "TXYB", "BDAI", "DOUBA", "DPA", "DYAI", "KIMI", "WXYY"]
url_top_40 = get_url_top40(user_id, brand_id, begin, end, platform_list, question_list) url_top_40 = get_url_top40(user_id, brand_id, begin, end, platform_list, question_list) or []
url_top_40_result = [] url_top_40_result = []
for url in url_top_40: for url in url_top_40:
url_top_40_result.append({ url_top_40_result.append({
...@@ -493,7 +502,7 @@ def zhou_report(): ...@@ -493,7 +502,7 @@ def zhou_report():
"引用占比": url.get('quote_ratio_percent'), "引用占比": url.get('quote_ratio_percent'),
}) })
site_category = get_site_category(brand_id, user_id, begin, end, platform_list, question_list) site_category = get_site_category(brand_id, user_id, begin, end, platform_list, question_list) or []
site_category_result = [] site_category_result = []
for site in site_category: for site in site_category:
site_category_result.append({ site_category_result.append({
...@@ -504,9 +513,9 @@ def zhou_report(): ...@@ -504,9 +513,9 @@ def zhou_report():
"引用率": site.get('quote_rate'), "引用率": site.get('quote_rate'),
}) })
quote_mention_word_cloud = get_quote_mention_word_cloud(brand_id, user_id, begin, end, question_list) quote_mention_word_cloud = get_quote_mention_word_cloud(brand_id, user_id, begin, end, question_list) or {}
positive_top = quote_mention_word_cloud.get('positive_top') positive_top = quote_mention_word_cloud.get('positive_top') or []
negative_top = quote_mention_word_cloud.get('negative_top') negative_top = quote_mention_word_cloud.get('negative_top') or []
positive_top_result = [] positive_top_result = []
for positive in positive_top: for positive in positive_top:
positive_top_result.append({ positive_top_result.append({
...@@ -521,7 +530,7 @@ def zhou_report(): ...@@ -521,7 +530,7 @@ def zhou_report():
"出现次数": negative.get('count'), "出现次数": negative.get('count'),
}) })
quto_statistics_result = [] quto_statistics_result = []
quto_statistics = get_quto_statistics(brand_id, user_id, begin, end, question_list) quto_statistics = get_quto_statistics(brand_id, user_id, begin, end, question_list) or {}
quto_statistics_result.append({ quto_statistics_result.append({
"引用文章数": quto_statistics.get('resource_count'), "引用文章数": quto_statistics.get('resource_count'),
"引用次数": quto_statistics.get('total_log_count'), "引用次数": quto_statistics.get('total_log_count'),
...@@ -544,4 +553,5 @@ def zhou_report(): ...@@ -544,4 +553,5 @@ def zhou_report():
} }
return success(static_data) return success(static_data)
except Exception as e: except Exception as e:
return fail('fail') logger.exception(f"/feishu/static处理失败: {e}")
\ No newline at end of file return fail('fail')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment