浏览代码

tongce: 增加同策数据的清洗

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 年之前
父节点
当前提交
926a369e4b
共有 2 个文件被更改,包括 74 次插入0 次删除
  1. 16 0
      flask_app.py
  2. 58 0
      tongce.py

+ 16 - 0
flask_app.py

@@ -165,6 +165,22 @@ def tongce():
     return json.dumps(response, ensure_ascii=False)
 
 
+@app.route('/tongce_data', methods=['GET', 'POST'])
+def tongce_data():
+    response = {}
+    try:
+        tongce = TongCe()
+        result = tongce.tongce_answer_info()
+        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',

+ 58 - 0
tongce.py

@@ -152,6 +152,43 @@ class TongCe:
             (%s, %s, 1, 'binren', now())
     '''
 
+    sql_7 = '''
+            SELECT 
+                a.testcase_id,
+                a.uuid,
+                GROUP_CONCAT(
+                    DISTINCT b.sub_option_content
+                )
+            FROM
+                f_t_daren_score_2 a
+            LEFT JOIN d_shangju_tiku_02 b ON a.score = b.sub_option_id
+            WHERE
+                a.testcase_id IN (84, 85, 86, 87)
+            AND b.father_id IN (47, 48, 234, 254)
+            and a.sub_question_id = b.sub_question_id and a.testcase_id = b.testcase_id
+            GROUP BY
+                a.testcase_id,
+                a.uuid
+    '''
+    sql_8 = '''
+            SELECT
+                a.uuid,
+                a.title,
+                a.testcase_id,
+                b.father_id,
+                b.father_content,
+                b.sub_option_id,
+                b.sub_option_content
+            FROM
+                f_t_daren_score_2 a
+            LEFT JOIN d_shangju_tiku_02 b ON a.score = b.sub_option_id
+            WHERE
+                a.testcase_id = b.testcase_id
+            AND a.sub_question_id = b.sub_question_id
+            AND a.testcase_id IN (84, 85, 86, 87)
+    '''
+
+
     def __init__(self):
         self.shangju_db = MysqlDB('shangju')
         self.marketing_db = MysqlDB('bi_report')
@@ -221,6 +258,27 @@ class TongCe:
             self.linshi_db.add_some(self.sql_6, dispaly_data)
         return {'插入数据条数': len(dispaly_data), 'scores': dispaly_data}
 
+    # 同策答题人身份信息整理
+    # 性别父题id: 47
+    # 年龄父题id:48
+    # 支付力父题id:234
+    # 城市父题id: 254
+    def tongce_answer_info(self):
+        people_info = self.marketing_db.select(self.sql_7)
+        people_dict = {}
+        for pi in people_info:
+            people_dict[pi[1] + str(pi[0])] = pi
+        answers = self.marketing_db.select(self.sql_8)
+        result = []
+        for aw in answers:
+            aw = list(aw)
+            people = people_dict.get(aw[0] + str(aw[2]))
+            if people:
+                for pl in str(people[2]).split(','):
+                    aw.append(pl)
+            result.append(aw)
+        return result
+
 
 if __name__ == '__main__':
     pass