Ver código fonte

flask_app: 增加数据更新接口update_data

mvp: 修改数据出入mysql逻辑

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 anos atrás
pai
commit
1ced3e9bb5
2 arquivos alterados com 33 adições e 25 exclusões
  1. 7 0
      flask_app.py
  2. 26 25
      mvp.py

+ 7 - 0
flask_app.py

@@ -88,6 +88,13 @@ def tag_tree():
     return json.dumps(tags, ensure_ascii=False)
 
 
+@app.route('/update_data', methods=['GET', 'POST'])
+def update_data():
+    mvp = Mvp()
+    mvp.update_data()
+    return '!!!score update finished!!!'
+
+
 if __name__ == '__main__':
     app.run(
         host='0.0.0.0',

+ 26 - 25
mvp.py

@@ -201,30 +201,31 @@ class Mvp:
             self.shangju_db.add_some(module_insert_sql, module_insert_data)
             print('模块分数更新完成...')
 
-        for key in behavior_score.keys():
-            insert_sql = self.get_insert_sql(key)
-            if insert_sql:
-                insert_data = []
-                score = behavior_score[key]
-                for data in score:
-                    city = data[0]
-                    age = data[1]
-                    tag_name = data[2]
-                    crowd = data[3]
-                    tag_score = data[4]
-                    for id in ids:
-                        city_1 = id[2]
-                        age_1 = id[1]
-                        crowd_1 = id[3]
-                        id_1 = id[0]
-                        if city == city_1 and self.age_dict[age] == age_1 and crowd == crowd_1:
-                            insert_data.append([id_1, tag_name, tag_score])
-                if len(insert_data) > 0:
-                    self.shangju_db.truncate(key)
-                    self.shangju_db.add_some(insert_sql, insert_data)
-            else:
-                print('未找到对应的表,数据无法插入...')
-        print('行为分数更新完成...')
+        for b_score in behavior_score:
+            for key in b_score.keys():
+                insert_sql = self.get_insert_sql(key)
+                if insert_sql:
+                    insert_data = []
+                    score = b_score[key]
+                    for data in score:
+                        city = data[0]
+                        age = data[1]
+                        tag_name = data[2]
+                        crowd = data[3]
+                        tag_score = data[4]
+                        for id in ids:
+                            city_1 = id[2]
+                            age_1 = id[1]
+                            crowd_1 = id[3]
+                            id_1 = id[0]
+                            if city == city_1 and self.age_dict[age] == age_1 and crowd == crowd_1:
+                                insert_data.append([id_1, tag_name, tag_score])
+                    if len(insert_data) > 0:
+                        self.shangju_db.truncate(key)
+                        self.shangju_db.add_some(insert_sql, insert_data)
+                else:
+                    print('未找到对应的表,数据无法插入...')
+            print('行为分数更新完成...')
 
     def module_score(self, crowd, city, age, scores):
         """
@@ -367,7 +368,7 @@ class Mvp:
                             print('{}-{}-{}'.format(city, age, crowd_type))
                             datas = self.behavior_tag_init(city, age, people_uuids)
                             data_start.append(datas)
-                            all_data, behavior_data_1 = self.calculation_standard_score(datas, city, age, crowd)
+                            all_data, behavior_data_1 = self.calculation_standard_score(datas, city, age, crowd_type)
                             result.append(all_data)
                             behavior_data = behavior_data_1
                         if behavior_data: