Browse Source

flask_app: 抽取数据调整代码逻辑

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 years ago
parent
commit
749f985dc1
1 changed files with 21 additions and 24 deletions
  1. 21 24
      flask_app.py

+ 21 - 24
flask_app.py

@@ -74,10 +74,12 @@ class Mvp:
              '%s, %s, ' \
              '%s, 1) '
 
-    # 向表
+    # 向表mvp_crowd_info_module中插入数据
     sql_13 = 'insert into mvp_crowd_info_module(crowd_info_id, module_name, standard_value, status) values (%s, %s, ' \
              '%s, 1) '
 
+    sql_14 = 'select a.id, a.age_area, a.city_name, a.crowd_type from mvp_crowd_info a where a.status = 1'
+
     def __init__(self, path=None):
         self.shangju_db = MysqlDB('shangju')
         self.marketing_db = MysqlDB('bi_report')
@@ -120,28 +122,10 @@ class Mvp:
         # self.shangju_db.add_some(self.sql_3, datas)
         scores_behavioral = self.city_age_crowd(city, age, crowd)
         scores_module = self.module_score(crowd, city, age, scores_behavioral['score'])
-        result = {'行为兴趣分值': scores_behavioral, '模块分值': scores_module}
+        result = {'行为兴趣分值': scores_behavioral['score'], '模块分值': scores_module}
         print('update finished!!!')
         return result
 
-    def write_behavioral_data_into_table(self):
-        """
-            行为兴趣计算数据写入数据库
-        :return:
-        """
-        scores_all = []
-        for city in self.citys:
-            for age in self.age:
-                if city != '上海市' and age != '85-89年生':
-                    for crowd_type in self.crowd:
-                        # print(' {}{}'.format(city, age))
-                        people_uuids = self.get_people_uuid_by_type(crowd_type)
-                        if len(people_uuids) > 0:
-                            print('{}-{}-{}'.format(city, age, crowd_type))
-                            datas = self.behavior_tag_init(city, age, people_uuids)
-                            scores = self.calculation_standard_score(datas, city, age, crowd_type)
-                            scores_all.extend(scores)
-
     def module_score(self, crowd, city, age, scores):
         """
             模块分数计算
@@ -163,13 +147,24 @@ class Mvp:
             result.append([city, age, crowd, module_name, score])
         return result
 
-    def insert_mvp_crowd_info(self, scores):
+    def insert_data(self, scores_behavioral, scores_module):
         """
             计算数据写入数据库中,供接口查看
-        :param scores:
+        :param scores_module:
+        :param scores_behavioral:
         :return:
         """
         # todo
+        infos = []
+        for city in self.citys:
+            for age in self.age:
+                for c_type in self.crowd:
+                    age_area = self.age_dict.get(age)
+                    if age_area:
+                        infos.append([age_area, city, c_type])
+        self.shangju_db.add_some(self.sql_11, infos)
+
+        ids = self.shangju_db.select(self.sql_14)
         pass
 
     def init_age(self):
@@ -194,7 +189,8 @@ class Mvp:
             pass
         else:
             print('获取所有case的数据...')
-            for city in self.citys:
+            # for city in self.citys:
+            for city in ['上海市', '杭州市', '苏州市', '无锡市', '宁波市']:
                 for age in self.age:
                     if city != '上海市' and age != '85-89年生':
                         for crowd_type in self.crowd:
@@ -215,7 +211,8 @@ class Mvp:
                     ele.extend(sub_e)
                     data_list.append(ele)
             pass
-        return {'score': result, 'data': data_list}
+        return {'score': result}
+        # return {'score': result, 'data': data_list}
 
     def behavior_tag_init(self, city, age, people_uuids):
         result = {}