Commit 657e27c5 authored by yangruiqiang's avatar yangruiqiang

修改question_list

parent 7d6df9f1
......@@ -192,23 +192,26 @@ def get_req_id(phone, begin, end):
'Authorization': ''
}
response = requests.request("GET", url, headers=headers, data=payload)
response = requests.request("GET", url, headers=headers, data=payload, timeout=30)
return response.json().get('data')
def get_url_top40(user_id, brand_library_id, begin, end, p):
def get_url_top40(user_id, brand_library_id, begin, end, p, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/trends"
if isinstance(p, str):
p = [p]
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f'{begin} 00:00:00',
"end_time": f'{end} 23:59:59',
"limit": 40,
"platform_list": p
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Authorization': '',
'Content-Type': 'application/json'
......@@ -239,15 +242,18 @@ def generate_date_list(start_date: str, end_date: str):
return result
def get_refer_rate_heatmap(brand_library_id, user_id, begin_time, end_time):
def get_refer_rate_heatmap(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/platforms"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59"
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -275,15 +281,18 @@ def get_refer_rate_heatmap(brand_library_id, user_id, begin_time, end_time):
return []
# print(response.text)
def get_platforms(brand_library_id, user_id, begin_time, end_time):
def get_platforms(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/platforms"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59"
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -312,16 +321,19 @@ def get_platforms(brand_library_id, user_id, begin_time, end_time):
# print(response.text)
def get_all_word_rank(brand_library_id, user_id, begin_time, end_time):
def get_all_word_rank(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/all_word_rank"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59",
"last": True
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -349,15 +361,18 @@ def get_all_word_rank(brand_library_id, user_id, begin_time, end_time):
return []
def get_sentiment_overview(brand_library_id, user_id, begin_time, end_time):
def get_sentiment_overview(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/overview"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59"
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -386,16 +401,19 @@ def get_sentiment_overview(brand_library_id, user_id, begin_time, end_time):
# print(response.text)
def get_platforms_sentiment(brand_library_id, user_id, begin_time, end_time):
def get_platforms_sentiment(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/platforms/sentiment"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59",
"last": True
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -419,17 +437,20 @@ def get_platforms_sentiment(brand_library_id, user_id, begin_time, end_time):
return []
def get_site_category(brand_library_id, user_id, begin_time, end_time, p):
def get_site_category(brand_library_id, user_id, begin_time, end_time, p, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/statistics/site_category"
if isinstance(p, str):
p = [p]
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59",
"platform_list": p,
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -454,15 +475,18 @@ def get_site_category(brand_library_id, user_id, begin_time, end_time, p):
return []
def get_quote_mention_word_cloud(brand_library_id, user_id, begin_time, end_time):
def get_quote_mention_word_cloud(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/quote_mention_word_cloud"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59"
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......@@ -487,15 +511,18 @@ def get_quote_mention_word_cloud(brand_library_id, user_id, begin_time, end_time
return []
def get_quto_statistics(brand_library_id, user_id, begin_time, end_time):
def get_quto_statistics(brand_library_id, user_id, begin_time, end_time, question_list=None):
url = "https://openapi.aidso.com/openapi/ywt/statistics"
payload = json.dumps({
payload_data = {
"brand_library_id": brand_library_id,
"user_id": user_id,
"begin_time": f"{begin_time} 00:00:00",
"end_time": f"{end_time} 23:59:59"
})
}
if question_list is not None:
payload_data["question_list"] = question_list
payload = json.dumps(payload_data)
headers = {
'Content-Type': 'application/json'
}
......
......@@ -312,7 +312,7 @@ def qian_report():
phone = data.get("phone")
begin = data.get("begin")
end = data.get("end")
brand_name = data.get("brand_name", [])
brand_name = data.get("plan_name", [])
platform = data.get("platform") # 非必填,可能是 None
if not phone:
......@@ -324,10 +324,10 @@ def qian_report():
if not end:
return fail("end不能为空")
if not brand_name:
return fail("brand_name不能为空")
if not isinstance(brand_name, list):
return fail("brand_name必须是数组")
# if not brand_name:
# return fail("brand_name不能为空")
# if not isinstance(brand_name, list):
# return fail("brand_name必须是数组")
if platform and not isinstance(platform, list):
return fail("platform必须是数组")
......@@ -338,7 +338,7 @@ def qian_report():
req_ids = []
for b in brand_name:
for item in req_list:
if item.get('brand_name') == b:
if item.get('plan_name') == b:
req_id = item.get("req_id")
created_at = item.get("created_at")
req_ids.append(req_id)
......@@ -378,7 +378,8 @@ def zhou_report():
phone = data.get("phone")
begin = data.get("begin")
end = data.get("end")
brand_name = data.get("brand_name", [])
brand_name = data.get("plan_name", [])
question_list = data.get("question_list")
if not phone:
return fail("phone不能为空")
......@@ -388,9 +389,12 @@ def zhou_report():
if not end:
return fail("end不能为空")
#
# if not brand_name:
# return fail("brand_name不能为空")
if not brand_name:
return fail("brand_name不能为空")
# if question_list is not None and not isinstance(question_list, list):
# return fail("question_list必须是数组")
try:
req_list = get_req_id(phone, begin, end)
req_time_map = {}
......@@ -398,7 +402,7 @@ def zhou_report():
brand_id = 0
user_id = 0
for item in req_list:
if item.get('brand_name') == brand_name:
if item.get('plan_name') == brand_name:
req_id = item.get("req_id")
user_id = item.get("user_id")
brand_id = item.get("brand_library_id")
......@@ -407,7 +411,7 @@ def zhou_report():
req_time_map[req_id] = created_at
result = []
platform_data = get_platforms(brand_id, user_id, begin, end)
platform_data = get_platforms(brand_id, user_id, begin, end, question_list)
geo_refer_rank_overview_vos = platform_data.get('geo_refer_rank_overview_vos')
brand_overview = platform_data.get('brand_overview')
......@@ -439,7 +443,7 @@ def zhou_report():
# 概览数据
# 分平台数据
all_word = get_all_word_rank(brand_id, user_id, begin, end)
all_word = get_all_word_rank(brand_id, user_id, begin, end, question_list)
all_word_result = []
for all in all_word:
all_word_result.append({
......@@ -452,7 +456,7 @@ def zhou_report():
# 全部品牌词数据
overview_result = []
sentiment_overview = get_sentiment_overview(brand_id, user_id, begin, end)
sentiment_overview = get_sentiment_overview(brand_id, user_id, begin, end, question_list)
overview_result.append(
{
......@@ -468,7 +472,7 @@ def zhou_report():
}
)
platform_sentiment_result = []
platform_sentiment = get_platforms_sentiment(brand_id, user_id, begin, end)
platform_sentiment = get_platforms_sentiment(brand_id, user_id, begin, end, question_list)
for pla in platform_sentiment:
platform_sentiment_result.append({
"平台": plat_form_map.get(pla.get("platform"), pla.get("platform")),
......@@ -480,7 +484,7 @@ def zhou_report():
})
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)
url_top_40 = get_url_top40(user_id, brand_id, begin, end, platform_list, question_list)
url_top_40_result = []
for url in url_top_40:
url_top_40_result.append({
......@@ -489,7 +493,7 @@ def zhou_report():
"引用占比": url.get('quote_ratio_percent'),
})
site_category = get_site_category(brand_id, user_id, begin, end, platform_list)
site_category = get_site_category(brand_id, user_id, begin, end, platform_list, question_list)
site_category_result = []
for site in site_category:
site_category_result.append({
......@@ -500,7 +504,7 @@ def zhou_report():
"引用率": site.get('quote_rate'),
})
quote_mention_word_cloud = get_quote_mention_word_cloud(brand_id, user_id, begin, end)
quote_mention_word_cloud = get_quote_mention_word_cloud(brand_id, user_id, begin, end, question_list)
positive_top = quote_mention_word_cloud.get('positive_top')
negative_top = quote_mention_word_cloud.get('negative_top')
positive_top_result = []
......@@ -517,14 +521,14 @@ def zhou_report():
"出现次数": negative.get('count'),
})
quto_statistics_result = []
quto_statistics = get_quto_statistics(brand_id, user_id, begin, end)
quto_statistics = get_quto_statistics(brand_id, user_id, begin, end, question_list)
quto_statistics_result.append({
"引用文章数": quto_statistics.get('resource_count'),
"引用次数": quto_statistics.get('total_log_count'),
"引用网站": quto_statistics.get('site_count'),
})
refer_rate_heatmap = get_refer_rate_heatmap(brand_id, user_id, begin, end)
refer_rate_heatmap = get_refer_rate_heatmap(brand_id, user_id, begin, end, question_list)
static_data = {
"brand_overview_result":brand_overview_result,
"result":result,
......
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