Browse Source

flask_app: 修改行为兴趣接口behavioral_statistics的逻辑

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 years ago
parent
commit
86ce870940
1 changed files with 30 additions and 3 deletions
  1. 30 3
      flask_app.py

+ 30 - 3
flask_app.py

@@ -93,9 +93,9 @@ class Mvp:
         citys.extend([x[0] for x in citys_info if x[0] is not None])
         return citys
 
-    def write_tag(self, city=None, age=None, crowd=None):
+    def query_behavioral_info(self, city=None, age=None, crowd=None):
         """
-            将excel中的配置信息写入到数据库表中
+            查询行为兴趣信息
         :return:
         """
         # datas = []
@@ -115,6 +115,33 @@ class Mvp:
         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 insert(self, scores):
+        """
+            计算数据写入数据库中,供接口查看
+        :param scores:
+        :return:
+        """
+        # todo
+        pass
+
     def init_age(self):
         """
            获取答题数据中的年龄
@@ -419,7 +446,7 @@ def behavioral_statistics():
     crowd = request.args.get('crowd', default=None, type=str)
     print(city, age, crowd)
     mvp = Mvp()
-    scores = mvp.write_tag(city, age, crowd)
+    scores = mvp.query_behavioral_info(city, age, crowd)
     mvp.shangju_db.close()
     mvp.marketing_db.close()
     return json.dumps(scores, ensure_ascii=False)