Bladeren bron

elab_mvp: 代码逻辑调整

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 jaren geleden
bovenliggende
commit
03ee72d5f1
2 gewijzigde bestanden met toevoegingen van 52 en 49 verwijderingen
  1. 11 11
      entity.py
  2. 41 38
      mvp.py

+ 11 - 11
entity.py

@@ -16,25 +16,25 @@ class PeopleInfo:
         '95-99年生': '95后'
     }
 
-    def __init__(self, uuid, city=None, age=None, sex=None, crowd=None):
-        if crowd is None:
-            crowd = []
+    def __init__(self, uuid, city, age, sex, crowd):
         self.uuid = uuid
-        if city == '上海市' or city == '一线':
-            self.city = '上海市'
-        elif city in ['无锡市', '杭州市', '苏州市', '宁波市']:
-            self.city = '上海周边'
+        if city is None:
+            self.city = '无城市'
         else:
-            self.city = city
+            if city == '上海市' or city == '一线':
+                self.city = '上海市'
+            elif city in ['无锡市', '杭州市', '苏州市', '宁波市']:
+                self.city = '上海周边'
+            else:
+                self.city = '其他'
         age_1 = self.age_dict.get(age)
         if age_1:
             self.age = age_1
         else:
-            age = ''
-        self.age = age
+            self.age = '无年龄'
         self.sex = sex
         self.crowd = crowd
 
 
 if __name__ == '__main__':
-    print('1'.split(','))
+    print(len(''))

+ 41 - 38
mvp.py

@@ -129,11 +129,11 @@ class Mvp:
     sql_15 = '''
         SELECT
             a.uuid,
-            GROUP_CONCAT(DISTINCT a.city, a.province) AS city,
-            GROUP_CONCAT(DISTINCT a.nld) AS nld,
-            GROUP_CONCAT(DISTINCT a.sex) AS sex,
-            GROUP_CONCAT(DISTINCT b.sub_option_id),
-            GROUP_CONCAT(DISTINCT a.testcase_id)
+            IFNULL(GROUP_CONCAT(DISTINCT a.city, a.province), 00) AS city,
+            IFNULL(GROUP_CONCAT(DISTINCT a.nld), 00) AS nld,
+            IFNULL(GROUP_CONCAT(DISTINCT a.sex), 00) AS sex,
+            IFNULL(GROUP_CONCAT(DISTINCT b.sub_option_id), 00) as sub_option_ids,
+            IFNULL(GROUP_CONCAT(DISTINCT a.testcase_id), 00) as testcase_ids
         FROM
             f_t_daren_score_2 a
         LEFT JOIN d_shangju_tiku_02 b ON a.testcase_id = b.testcase_id
@@ -245,39 +245,42 @@ class Mvp:
         """
         people_info_city = self.marketing_db.select(self.sql_15)
         people_infos = []
-        # for people in people_info_city:
-        #     uuid = people[0]
-        #     city = people[1]
-        #     if city:
-        #         city = str(city).split('市')[0] + '市'
-        #     nld = people[2]
-        #     if nld:
-        #         nld_1 = list(str(people[2]).split(','))
-        #         if len(nld) > 0:
-        #             nld_1 = nld[0]
-        #     else:
-        #         nld_1 = ''
-        #     sex = people[3]
-        #     sub_option_ids = people[4]
-        #     testcaseid = people[5]
-        #     testcastids = list(map(int, str(testcaseid).split(',')))
-        #     gt_75 = [x for x in testcastids if x > 75]
-        #     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]
-        #     # 根据用户子选项id集合,获取用户的人群分类
-        #     crowd = []
-        #     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:
-        #         crowd.extend(self.get_people_uuid_by_sub_option_ids(sub_option_ids))
-        #     people_info = PeopleInfo(uuid, city, nld_1, sex, crowd)
-        #     people_infos.append(people_info)
+        for people in people_info_city:
+            uuid = people[0]
+            city = people[1]
+            if str(city).strip():
+                city = str(city).split('市')[0] + '市'
+            nld = people[2]
+            if str(nld).strip():
+                nld_1 = list(str(people[2]).split(','))
+                if len(nld) > 0:
+                    nld_1 = nld[0]
+            else:
+                nld_1 = ''
+            sex = people[3]
+            sub_option_ids = people[4]
+            testcaseid = people[5]
+            testcastids = list(map(int, str(testcaseid).split(',')))
+            gt_75 = [x for x in testcastids if x > 75]
+            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集合,获取用户的人群分类
+            crowd = []
+            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))
+            people_info = PeopleInfo(uuid, city, nld_1, sex, crowd)
+            people_infos.append(people_info)
         return people_infos
 
     def people_filter(self, city, nld, crowd):