Browse Source

mvp: 人群分类信息获取逻辑调整

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

+ 25 - 22
mvp.py

@@ -44,7 +44,7 @@ class Mvp:
         '空间需求图谱-空间拓普图': ['mvp_innovate_space_space_top', ''],
         '模块分数': ['mvp_crowd_info_module', 'module_name']
     }
-    crowd_info = {
+    crowd_info_1 = {
         1973: 'A',
         1974: 'B',
         1975: 'C',
@@ -151,7 +151,7 @@ class Mvp:
     # 根据用户uuid获取城市信息
     sql_16 = 'SELECT a.uuid, b.sub_option_content FROM f_t_daren_score_2 a LEFT JOIN d_shangju_tiku_02 b ON ' \
              'a.testcase_id = b.testcase_id WHERE a.sub_question_id = b.sub_question_id AND (a.score = b.score OR ' \
-             'a.score = b.sub_option_id) AND a.uuid = %sAND a.sub_question_id = 303 and a.status = b.status = 1 '
+             'a.score = b.sub_option_id) AND a.uuid = %s AND a.sub_question_id = 303 and a.status = b.status = 1 '
 
     # 答题人人群分类信息
     sql_17 = 'SELECT a.uuid, b.sub_option_id FROM f_t_daren_score_2 a LEFT JOIN d_shangju_tiku_02 b ON a.testcase_id ' \
@@ -227,36 +227,39 @@ class Mvp:
             sub_option_ids = people[4]
             testcaseid = people[5]
 
-            if str(city).strip():
+            if str(city).find('市') != -1:
                 city = str(city).split('市')[0] + '市'
 
-            if str(nld).strip():
+            if str(nld).find(',') != -1:
                 nld_1 = list(str(nld).split(','))
                 if len(nld) > 0:
                     nld_1 = nld[0]
             else:
                 nld_1 = '无年龄'
 
-            testcastids = list(map(int, str(testcaseid).split(',')))
             crowd = []
-            if len(testcastids) > 0:
-                gt_75 = [x for x in testcastids if x in [75, 76, 77, 78]]
-                if city is None and len(gt_75) > 0:
-                    # 从答题结果中获取城市信息
-                    citys = self.marketing_db.select(self.sql_16, [uuid])
-                    if len(citys) > 0:
-                        city = citys[0][1]
-                    else:
-                        city = '无城市'
+            if str(testcaseid).find(',') != -1:
+                testcastids = list(map(int, str(testcaseid).split(',')))
+                if len(testcastids) > 0:
+                    gt_75 = [x for x in testcastids if x in [75, 76, 77, 78]]
+                    if city is None and len(gt_75) > 0:
+                        # 从答题结果中获取城市信息
+                        citys = self.marketing_db.select(self.sql_16, [uuid])
+                        if len(citys) > 0:
+                            city = citys[0][1]
+                        else:
+                            city = '无城市'
             # 根据用户子选项id集合,获取用户的人群分类
-                if len(gt_75) > 0:
-                    # 特定的测试人群分类从答题结果中获取
-                    sub_option_ids = self.marketing_db.select(self.sql_17, [uuid])
-                    for option in sub_option_ids:
-                        crowd.append(self.crowd_info[option[1]])
-            else:
-                if str(sub_option_ids).strip():
-                    crowd.extend(self.get_people_uuid_by_sub_option_ids(sub_option_ids))
+                    if len(gt_75) > 0:
+                        # 特定的测试人群分类从答题结果中获取
+                        sub_option_ids = self.marketing_db.select(self.sql_17, [uuid])
+                        for option in sub_option_ids:
+                            crowd_type = self.crowd_info_1.get(option[1])
+                            if crowd:
+                                crowd.append(crowd_type)
+                    else:
+                        if str(sub_option_ids).strip():
+                            crowd.extend(self.get_people_uuid_by_sub_option_ids(sub_option_ids))
             if city is None:
                 city = '无城市'
             people_info = PeopleInfo(uuid, city, nld_1, sex, crowd)