Browse Source

elab_mvp: 同策数据清洗

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 years ago
parent
commit
3fd0957f30
4 changed files with 125 additions and 0 deletions
  1. 16 0
      excel_util.py
  2. 19 0
      flask_app.py
  3. BIN
      resources/tongce.xlsx
  4. 90 0
      tongce.py

+ 16 - 0
excel_util.py

@@ -193,6 +193,22 @@ class ExcelUtil:
             result[key] = behavior_data
         return result
 
+    def read_options_info(self):
+        """
+            获取选项的配置信息
+        :return:
+        """
+        work_sheet = self.read_excel_by_ox_name('行为-模块映射表')
+        rows = [row for row in work_sheet.rows][1:]
+        info = {}
+        for row in rows:
+            sub_option_value = row[12].value
+            if sub_option_value != '占位':
+                key = row[1].value + str(row[9].value)
+                # 数据类型,数据项名称,所在tab
+                info[key] = [row[15].value, row[13].value, row[14].value]
+        return info
+
 
 if __name__ == '__main__':
     import json

+ 19 - 0
flask_app.py

@@ -2,6 +2,8 @@ from flask import Flask, request
 from mvp import Mvp
 import json
 from test_info import TestInfo
+from tongce import TongCe
+
 
 app = Flask(__name__)
 
@@ -146,6 +148,23 @@ def get_uuids():
     mvp.close()
     return json.dumps(uuids, ensure_ascii=False)
 
+
+@app.route('/tongce', methods=['GET', 'POST'])
+def tongce():
+    response = {}
+    try:
+        tongce = TongCe()
+        result = tongce.get_question_info_from_db()
+        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',

BIN
resources/tongce.xlsx


+ 90 - 0
tongce.py

@@ -0,0 +1,90 @@
+from excel_util import ExcelUtil
+from mysql_db import MysqlDB
+
+
+class TongCe:
+    """
+        同策测试数据清洗
+    """
+    # 统计筒体结果
+    sql_1 = '''
+        SELECT
+			b.father_id,
+			b.father_content,
+            a.sub_question_id,
+            b.sub_question_content,
+            a.score,
+            b.sub_option_content,
+            count(1)
+        FROM
+            f_t_daren_score_2 a
+        LEFT JOIN d_shangju_tiku_02 b ON a. STATUS = b. STATUS = 1
+        WHERE
+            a.testcase_id in (84, 85, 86, 87) and
+            a.testcase_id = b.testcase_id
+        AND a.sub_question_id = b.sub_question_id
+        AND (
+            a.score = b.score
+            OR a.score = b.sub_option_id
+        )
+        GROUP BY
+			b.father_id,
+            a.sub_question_id,
+            b.sub_question_content,
+            a.score,
+            b.sub_option_content
+    '''
+
+    # 选项信息
+    sql_2 = '''
+          SELECT
+            b.id as question_id,
+            b. NAME as question_title,
+            a.id as sub_question_id,
+            a. NAME as sub_question_title,
+            d.id as option_id,
+            d.content as option_title,
+            c.id as sub_option_id,
+            c.content as sub_option_title
+        FROM
+            bq_sub_question a
+        LEFT JOIN bq_question b ON a.father_id = b.id
+        
+        LEFT JOIN bq_sub_option c ON a.id = c.sub_question_id
+        LEFT JOIN bq_option d ON c.father_id = d.id
+        WHERE
+            FIND_IN_SET(
+                a.id,
+                (
+                    SELECT
+                        GROUP_CONCAT(question_ids)
+                    FROM
+                        bq_testcase
+                    WHERE
+                        house_ids = %s
+                    GROUP BY
+                        house_ids
+                )
+            )
+        AND a. STATUS = b. STATUS = c. STATUS = 1
+        ORDER BY
+            a.id
+    '''
+
+    def __init__(self):
+        self.shangju_db = MysqlDB('shangju')
+        self.marketing_db = MysqlDB('bi_report')
+        self.linshi_db = MysqlDB('linshi', db_type=1)
+        self.options_info = ExcelUtil('工作表6', 'tongce.xlsx').read_options_info()
+
+    def get_question_info_from_db(self):
+        result = self.shangju_db.select(self.sql_2, [67])
+        insert_data = []
+        for rt in result:
+            option_configuration = self.options_info.get('67' + str(rt[6]))
+            if option_configuration and len(option_configuration) == 3:
+                rt.extend(option_configuration)
+                insert_data.append(rt)
+        return result
+
+    pass