Browse Source

mvp: 修改模块分数计算逻辑

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 years ago
parent
commit
709168c989
1 changed files with 17 additions and 7 deletions
  1. 17 7
      mvp.py

+ 17 - 7
mvp.py

@@ -132,7 +132,8 @@ class Mvp:
             城市 年龄 人群分类 模块名称 分数
         :return:
         """
-        behavioral_score = scores['用户画像-行为兴趣']
+        import json
+        print(json.dumps(scores, ensure_ascii=False))
         modules = self.module_scores[crowd]
         result = []
         for key in modules.keys():
@@ -142,7 +143,7 @@ class Mvp:
             for value in values:
                 behavioral_name = value[0]
                 weight = float(value[2])
-                standard_score = [x[4] for x in behavioral_score if x[2] == behavioral_name]
+                standard_score = [x[4] for x in scores if x[2] == behavioral_name]
                 if len(standard_score) > 0:
                     score += standard_score[0] * weight
             result.append([city, age, crowd, module_name, score])
@@ -239,12 +240,16 @@ class Mvp:
         if city is not None and age is not None and crowd is not None:
             print('获取指定城市,年龄段,人群类型的数据...')
             people_uuids = self.get_people_uuid_by_type(crowd)
+            behavior_data = None
             if len(people_uuids) > 0:
                 print('{}-{}-{}'.format(city, age, crowd))
                 datas = self.behavior_tag_init(city, age, people_uuids)
                 data_start.append(datas)
-                result.extend(self.calculation_standard_score(datas, city, age, crowd))
-            module_scores.extend(self.module_score(crowd, city, age, result))
+                all_data, behavior_data_1 = self.calculation_standard_score(datas, city, age, crowd)
+                result.append(all_data)
+                behavior_data = behavior_data_1
+            if behavior_data:
+                module_scores.extend(self.module_score(crowd, city, age, behavior_data))
             pass
         else:
             print('获取所有case的数据...')
@@ -258,12 +263,16 @@ class Mvp:
                     else:
                         # print(' {}{}'.format(city, age))
                         people_uuids = self.get_people_uuid_by_type(crowd_type)
+                        behavior_data = None
                         if len(people_uuids) > 0:
                             print('{}-{}-{}'.format(city, age, crowd_type))
                             datas = self.behavior_tag_init(city, age, people_uuids)
                             data_start.append(datas)
-                            result.extend(self.calculation_standard_score(datas, city, age, crowd_type))
-                        module_scores.extend(self.module_score(crowd_type, city, age, result))
+                            all_data, behavior_data_1 = self.calculation_standard_score(datas, city, age, crowd)
+                            result.append(all_data)
+                            behavior_data = behavior_data_1
+                        if behavior_data:
+                           module_scores.extend(self.module_score(crowd_type, city, age, behavior_data))
         # return result
         # data_list = []
         # for e in data_start:
@@ -360,6 +369,7 @@ class Mvp:
     def calculation_standard_score(self, datas, city, age, crowd_type):
         scores = {}
         for key_tag_type in datas.keys():
+            print(key_tag_type)
             tag_type_data = datas[key_tag_type]
             scores_sub = []
             for key_tag in tag_type_data.keys():
@@ -377,7 +387,7 @@ class Mvp:
                 scores_sub.append([city, age, key_tag, crowd_type, f])
             scores[key_tag_type] = scores_sub
             # self.shangju_db.add_some(self.sql_9, scores)
-        return scores
+        return scores, scores['用户画像-行为兴趣']
 
     def get_crowd_people(self):
         result = {}