Selaa lähdekoodia

tongce: 调整选择结果为其他城市的答题结果

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 vuotta sitten
vanhempi
commit
5d3a759460
2 muutettua tiedostoa jossa 112 lisäystä ja 0 poistoa
  1. 16 0
      flask_app.py
  2. 96 0
      tongce.py

+ 16 - 0
flask_app.py

@@ -181,6 +181,22 @@ def tongce_data():
     return json.dumps(response, ensure_ascii=False)
 
 
+@app.route('/update_other_city', methods=['GET', 'POST'])
+def update_other_city():
+    response = {}
+    try:
+        tongce = TongCe()
+        result = tongce.other_city_clean()
+        response['code'] = 0
+        response['message'] = '成功'
+        response['data'] = result
+    except Exception as e:
+        response['code'] = 1
+        response['message'] = '失败:' + str(e)
+        return json.dumps(response, ensure_ascii=False)
+    return json.dumps(response, ensure_ascii=False)
+
+
 if __name__ == '__main__':
     app.run(
         host='0.0.0.0',

+ 96 - 0
tongce.py

@@ -580,6 +580,102 @@ class TongCe:
         print()
 
 
+    sql_17 = '''
+            SELECT
+                id,
+                uuid,
+                created,
+                `status`,
+                sub_question_id,
+                testcase_id,
+                title,
+                score,
+                province,
+	            city,
+	            district
+            FROM
+                f_t_daren_score_2
+            WHERE
+                testcase_id IN (84, 85, 86, 87)
+            AND sub_question_id = 377
+            AND score = 2917
+            AND (
+                city IN (
+                    '昆明市',
+                    '西安市',
+                    '咸阳市',
+                    '郑州市',
+                    '洛阳市',
+                    '武汉市',
+                    '襄阳市',
+                    '重庆市',
+                    '璧山'
+                )
+                OR province IN (
+                    '昆明市',
+                    '西安市',
+                    '咸阳市',
+                    '郑州市',
+                    '洛阳市',
+                    '武汉市',
+                    '襄阳市',
+                    '重庆市',
+                    '璧山'
+                )
+                OR district IN (
+                    '昆明市',
+                    '西安市',
+                    '咸阳市',
+                    '郑州市',
+                    '洛阳市',
+                    '武汉市',
+                    '襄阳市',
+                    '重庆市',
+                    '璧山区'
+                )
+            )
+    '''
+
+    sql_18 = '''
+            update f_t_daren_score_2 set score = %s where id = %s
+    '''
+
+    city_info = {
+        '昆明市': 2918,
+        '西安市': 2919,
+        '咸阳市': 2920,
+        '郑州市': 2921,
+        '洛阳市': 2922,
+        '武汉市': 2923,
+        '襄阳市': 2924,
+        '重庆市': 2925,
+        '璧山市': 2926
+    }
+
+    def other_city_clean(self):
+        update_data = []
+        need_update_data = self.marketing_db.select(self.sql_17)
+        for nd in need_update_data:
+            id = nd[0]
+            province = nd[8]
+            city = nd[9]
+            district = nd[10]
+            bishan = self.city_info.get(district)
+            if bishan:
+                update_data.append([bishan, id])
+            else:
+                city_id = self.city_info.get(city)
+                if city_id:
+                    update_data.append([city_id, id])
+                else:
+                    province_id = self.city_info.get(province)
+                    if province_id:
+                        update_data.append([province_id, id])
+        self.marketing_db.add_some(self.sql_18, update_data)
+
+        return len(update_data)
+
+
 if __name__ == '__main__':
     tongce = TongCe()
     tongce.insert_into_rule()