|  | @@ -21,10 +21,11 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |          self.max_time = None
 | 
	
		
			
				|  |  |          self.rate = None
 | 
	
		
			
				|  |  |          self.title_list = None
 | 
	
		
			
				|  |  | +        self.view_count_filter = None
 | 
	
		
			
				|  |  |          self.params = params
 | 
	
		
			
				|  |  |          self.AT = ArticleDBTools(mysql_client)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async def request_for_nlp(self, title_list, account_interest, account_weight):
 | 
	
		
			
				|  |  | +    async def request_for_nlp(self, title_list, account_interest, interest_weight):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          nlp process
 | 
	
		
			
				|  |  |          """
 | 
	
	
		
			
				|  | @@ -34,7 +35,7 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |              "data": {
 | 
	
		
			
				|  |  |                  "text_list_a": [i.replace("'", "") for i in title_list],
 | 
	
		
			
				|  |  |                  "text_list_b": [i.replace("'", "") for i in account_interest],
 | 
	
		
			
				|  |  | -                "score_list_b": account_weight,
 | 
	
		
			
				|  |  | +                "score_list_b": interest_weight,
 | 
	
		
			
				|  |  |                  "symbol": 1,
 | 
	
		
			
				|  |  |              },
 | 
	
		
			
				|  |  |              "function": "similarities_cross_mean" if self.sim_type == "mean" else "similarities_cross_avg"
 | 
	
	
		
			
				|  | @@ -49,7 +50,7 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |                      print("Received empty response")
 | 
	
		
			
				|  |  |                      return {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    def checkParams(self):
 | 
	
		
			
				|  |  | +    def check_params(self):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          校验传参
 | 
	
		
			
				|  |  |          :return:
 | 
	
	
		
			
				|  | @@ -68,10 +69,10 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |              response = {"error": "Params error", "detail": str(e)}
 | 
	
		
			
				|  |  |              return response
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async def getAccountInterest(
 | 
	
		
			
				|  |  | +    async def get_account_interest(
 | 
	
		
			
				|  |  |          self,
 | 
	
		
			
				|  |  |          account_name,
 | 
	
		
			
				|  |  | -        method,
 | 
	
		
			
				|  |  | +        interest_type,
 | 
	
		
			
				|  |  |          view_count_filter,
 | 
	
		
			
				|  |  |          rate=None,
 | 
	
		
			
				|  |  |          msg_type=None,
 | 
	
	
		
			
				|  | @@ -86,15 +87,14 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |          :param min_time:
 | 
	
		
			
				|  |  |          :param index_list:
 | 
	
		
			
				|  |  |          :param msg_type:
 | 
	
		
			
				|  |  | -        :param keys_dict:
 | 
	
		
			
				|  |  |          :param rate:
 | 
	
		
			
				|  |  | -        :param gh_id:
 | 
	
		
			
				|  |  | -        :param method:
 | 
	
		
			
				|  |  | +        :param interest_type:
 | 
	
		
			
				|  |  | +        :param view_count_filter:
 | 
	
		
			
				|  |  |          :return:
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          good_df, bad_df = await self.AT.get_good_bad_articles(
 | 
	
		
			
				|  |  |              account_name=account_name,
 | 
	
		
			
				|  |  | -            method=method,
 | 
	
		
			
				|  |  | +            interest_type=interest_type,
 | 
	
		
			
				|  |  |              msg_type=msg_type,
 | 
	
		
			
				|  |  |              index_list=index_list,
 | 
	
		
			
				|  |  |              min_time=min_time,
 | 
	
	
		
			
				|  | @@ -102,34 +102,40 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |              rate=rate,
 | 
	
		
			
				|  |  |              view_count_filter=view_count_filter,
 | 
	
		
			
				|  |  |          )
 | 
	
		
			
				|  |  | -        view_count_list = good_df["show_view_count"].values.tolist()
 | 
	
		
			
				|  |  | -        title_list = good_df["title"].values.tolist()
 | 
	
		
			
				|  |  | -        print(view_count_list)
 | 
	
		
			
				|  |  | -        print(title_list)
 | 
	
		
			
				|  |  | -        return title_list, view_count_list
 | 
	
		
			
				|  |  | +        extend_dicts = {
 | 
	
		
			
				|  |  | +            'view_count': good_df["show_view_count"].values.tolist(),
 | 
	
		
			
				|  |  | +            'view_count_rate': (good_df["show_view_count"] / good_df["view_count_avg"]).values.tolist()
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        account_interest = good_df["title"].values.tolist()
 | 
	
		
			
				|  |  | +        print(account_interest)
 | 
	
		
			
				|  |  | +        print(extend_dicts)
 | 
	
		
			
				|  |  | +        return account_interest, extend_dicts
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async def getEachAccountScoreList(self, account_name):
 | 
	
		
			
				|  |  | +    async def get_each_account_score_list(self, account_name):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          获取和单个账号的相关性分数
 | 
	
		
			
				|  |  |          :return:
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  | -            account_interest, account_weight = await self.getAccountInterest(
 | 
	
		
			
				|  |  | +            account_interest, extend_dicts = await self.get_account_interest(
 | 
	
		
			
				|  |  |                  account_name=account_name,
 | 
	
		
			
				|  |  | -                method=self.interest_type,
 | 
	
		
			
				|  |  | +                interest_type=self.interest_type,
 | 
	
		
			
				|  |  |                  rate=self.rate,
 | 
	
		
			
				|  |  |                  view_count_filter=self.view_count_filter,
 | 
	
		
			
				|  |  |                  min_time=self.min_time,
 | 
	
		
			
				|  |  |                  max_time=self.max_time,
 | 
	
		
			
				|  |  |              )
 | 
	
		
			
				|  |  | -            sim_key = "score_list_mean" if self.sim_type == "mean" else "score_list_avg"
 | 
	
		
			
				|  |  | +            interest_weight = extend_dicts['view_count']
 | 
	
		
			
				|  |  | +            if self.sim_type == "weighted_by_view_count_rate":
 | 
	
		
			
				|  |  | +                interest_weight = extend_dicts['view_count_rate']
 | 
	
		
			
				|  |  |              response = await self.request_for_nlp(
 | 
	
		
			
				|  |  |                  title_list=self.title_list,
 | 
	
		
			
				|  |  |                  account_interest=account_interest,
 | 
	
		
			
				|  |  | -                account_weight=account_weight
 | 
	
		
			
				|  |  | +                interest_weight=interest_weight
 | 
	
		
			
				|  |  |              )
 | 
	
		
			
				|  |  | +            score_list_key = "score_list_mean" if self.sim_type == "mean" else "score_list_avg"
 | 
	
		
			
				|  |  |              return {
 | 
	
		
			
				|  |  | -                "score_list": response[sim_key],
 | 
	
		
			
				|  |  | +                "score_list": response[score_list_key],
 | 
	
		
			
				|  |  |                  "text_list_max": response["text_list_max"],
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          except Exception as e:
 | 
	
	
		
			
				|  | @@ -139,7 +145,7 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |                  "text_list_max": self.title_list,
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    async def getAccountListScoreList(self):
 | 
	
		
			
				|  |  | +    async def get_account_list_score_list(self):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          获取AccountList中每一个账号的相关性分数
 | 
	
		
			
				|  |  |          :return:
 | 
	
	
		
			
				|  | @@ -149,7 +155,7 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |              if response.get(accountName):
 | 
	
		
			
				|  |  |                  continue
 | 
	
		
			
				|  |  |              else:
 | 
	
		
			
				|  |  | -                response[accountName] = await self.getEachAccountScoreList(account_name=accountName)
 | 
	
		
			
				|  |  | +                response[accountName] = await self.get_each_account_score_list(account_name=accountName)
 | 
	
		
			
				|  |  |          return response
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      async def deal(self):
 | 
	
	
		
			
				|  | @@ -158,5 +164,5 @@ class AccountServer(object):
 | 
	
		
			
				|  |  |          :return:
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          return (
 | 
	
		
			
				|  |  | -            self.checkParams() if self.checkParams() else await self.getAccountListScoreList()
 | 
	
		
			
				|  |  | +            self.check_params() if self.check_params() else await self.get_account_list_score_list()
 | 
	
		
			
				|  |  |          )
 |