|
@@ -2,21 +2,8 @@
|
|
|
@author: luojunhui
|
|
|
"""
|
|
|
|
|
|
-
|
|
|
-def get_account_interest_by_top(account_nickname, min_time, max_time, rate):
|
|
|
- return 1, 2
|
|
|
-
|
|
|
-
|
|
|
-def get_account_interest_by_avg(account_nickname, min_time, max_time, rate):
|
|
|
- return 1, 2
|
|
|
-
|
|
|
-
|
|
|
-def get_sim_score_cross_mean(a, b, c):
|
|
|
- return {"1": "2"}
|
|
|
-
|
|
|
-
|
|
|
-def get_sim_score_cross_avg(a, b, c):
|
|
|
- return {"1": "2"}
|
|
|
+import requests
|
|
|
+from applications.articleTools import ArticleDBTools
|
|
|
|
|
|
|
|
|
class AccountServer(object):
|
|
@@ -24,7 +11,7 @@ class AccountServer(object):
|
|
|
获取标题和公众号文章的相关性
|
|
|
"""
|
|
|
|
|
|
- def __init__(self, params):
|
|
|
+ def __init__(self, mysql_client, params):
|
|
|
self.account_name_list = None
|
|
|
self.sim_type = None
|
|
|
self.interest_type = None
|
|
@@ -33,6 +20,29 @@ class AccountServer(object):
|
|
|
self.rate = None
|
|
|
self.title_list = None
|
|
|
self.params = params
|
|
|
+ self.AT = ArticleDBTools(mysql_client)
|
|
|
+
|
|
|
+ async def request_for_nlp(self, title_list, account_interest, account_weight):
|
|
|
+ """
|
|
|
+ nlp process
|
|
|
+ """
|
|
|
+ headers = {"Content-Type": "application/json"}
|
|
|
+ url = "http://localhost:6060/nlp"
|
|
|
+ body = {
|
|
|
+ "data": {
|
|
|
+ "text_list_a": title_list,
|
|
|
+ "text_list_b": account_interest,
|
|
|
+ "score_list_b": account_weight,
|
|
|
+ "symbol": 1,
|
|
|
+ },
|
|
|
+ "function": (
|
|
|
+ "similarities_cross_mean"
|
|
|
+ if self.sim_type == "mean"
|
|
|
+ else "similarities_cross_avg"
|
|
|
+ ),
|
|
|
+ }
|
|
|
+ response = requests.post(url=url, headers=headers, json=body)
|
|
|
+ return response
|
|
|
|
|
|
def checkParams(self):
|
|
|
"""
|
|
@@ -40,47 +50,70 @@ class AccountServer(object):
|
|
|
:return:
|
|
|
"""
|
|
|
try:
|
|
|
- self.title_list = self.params['text_list']
|
|
|
+ self.title_list = self.params["text_list"]
|
|
|
self.account_name_list = self.params.get("account_nickname_list", [])
|
|
|
self.rate = self.params.get("rate", 0.1)
|
|
|
- self.max_time = self.params.get("max_time", 0.1)
|
|
|
- self.min_time = self.params.get("min_time", 0.1)
|
|
|
- self.interest_type = self.params.get("interest_type", "by_top")
|
|
|
+ self.max_time = self.params.get("max_time")
|
|
|
+ self.min_time = self.params.get("min_time")
|
|
|
+ self.interest_type = self.params.get("interest_type", "top")
|
|
|
self.sim_type = self.params.get("sim_type", "mean")
|
|
|
return None
|
|
|
except Exception as e:
|
|
|
- response = {
|
|
|
- "error": "Params error",
|
|
|
- "detail": str(e)
|
|
|
- }
|
|
|
+ response = {"error": "Params error", "detail": str(e)}
|
|
|
return response
|
|
|
|
|
|
- def getEachAccountScoreList(self, account_name):
|
|
|
+ async def getAccountInterest(
|
|
|
+ self,
|
|
|
+ account_name,
|
|
|
+ method,
|
|
|
+ rate=None,
|
|
|
+ msg_type=None,
|
|
|
+ index_list=None,
|
|
|
+ min_time=None,
|
|
|
+ max_time=None,
|
|
|
+ ):
|
|
|
+ """
|
|
|
+ 获取账号的兴趣类型
|
|
|
+ :param account_name:
|
|
|
+ :param max_time:
|
|
|
+ :param min_time:
|
|
|
+ :param index_list:
|
|
|
+ :param msg_type:
|
|
|
+ :param keys_dict:
|
|
|
+ :param rate:
|
|
|
+ :param gh_id:
|
|
|
+ :param method:
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ good_df, bad_df = await self.AT.get_good_bad_articles(
|
|
|
+ account_name=account_name,
|
|
|
+ method=method,
|
|
|
+ msg_type=msg_type,
|
|
|
+ index_list=index_list,
|
|
|
+ min_time=min_time,
|
|
|
+ max_time=max_time,
|
|
|
+ rate=rate,
|
|
|
+ )
|
|
|
+ view_count_list = good_df["show_view_count"]
|
|
|
+ title_list = good_df["title"]
|
|
|
+ return title_list, view_count_list
|
|
|
+
|
|
|
+ async def getEachAccountScoreList(self, account_name):
|
|
|
"""
|
|
|
获取和单个账号的相关性分数
|
|
|
:return:
|
|
|
"""
|
|
|
try:
|
|
|
- account_interest, account_weight = (
|
|
|
- get_account_interest_by_top(
|
|
|
- account_nickname=account_name,
|
|
|
- min_time=self.min_time,
|
|
|
- max_time=self.max_time,
|
|
|
- rate=self.rate,
|
|
|
- )
|
|
|
- if self.interest_type == "by_top"
|
|
|
- else get_account_interest_by_avg(
|
|
|
- account_nickname=account_name,
|
|
|
- min_time=self.min_time,
|
|
|
- max_time=self.max_time,
|
|
|
- rate=self.rate,
|
|
|
- )
|
|
|
+ account_interest, account_weight = await self.getAccountInterest(
|
|
|
+ account_name=account_name,
|
|
|
+ method=self.interest_type,
|
|
|
)
|
|
|
- res = (
|
|
|
- get_sim_score_cross_mean(self.title_list, account_interest, account_weight)
|
|
|
- if self.sim_type == "mean"
|
|
|
- else get_sim_score_cross_avg(self.title_list, account_interest, account_weight)
|
|
|
+ response = await self.request_for_nlp(
|
|
|
+ title_list=self.title_list,
|
|
|
+ account_interest=account_interest,
|
|
|
+ account_weight=account_weight,
|
|
|
)
|
|
|
+ res = response.json()
|
|
|
sim_key = "score_list_mean" if self.sim_type == "mean" else "score_list_avg"
|
|
|
return {
|
|
|
"score_list": res[sim_key],
|
|
@@ -90,10 +123,10 @@ class AccountServer(object):
|
|
|
print(e)
|
|
|
return {
|
|
|
"score_list": [0] * len(self.title_list),
|
|
|
- "text_list_max": self.title_list
|
|
|
+ "text_list_max": self.title_list,
|
|
|
}
|
|
|
|
|
|
- def getAccountListScoreList(self):
|
|
|
+ async def getAccountListScoreList(self):
|
|
|
"""
|
|
|
获取AccountList中每一个账号的相关性分数
|
|
|
:return:
|
|
@@ -103,12 +136,14 @@ class AccountServer(object):
|
|
|
if response.get(accountName):
|
|
|
continue
|
|
|
else:
|
|
|
- response[accountName] = self.getEachAccountScoreList(account_name=accountName)
|
|
|
+ response[accountName] = await self.getEachAccountScoreList(account_name=accountName)
|
|
|
return response
|
|
|
|
|
|
- def deal(self):
|
|
|
+ async def deal(self):
|
|
|
"""
|
|
|
Deal Function
|
|
|
:return:
|
|
|
"""
|
|
|
- return self.checkParams() if self.checkParams() else self.getAccountListScoreList()
|
|
|
+ return (
|
|
|
+ self.checkParams() if self.checkParams() else await self.getAccountListScoreList()
|
|
|
+ )
|