Parcourir la source

mvp: 增加统计测试数据接口

Signed-off-by: binren <zhangbr@elab-plus.com>
binren il y a 5 ans
Parent
commit
60ad214f95
3 fichiers modifiés avec 128 ajouts et 1 suppressions
  1. 9 0
      flask_app.py
  2. 2 1
      mvp.py
  3. 117 0
      test_info.py

+ 9 - 0
flask_app.py

@@ -1,6 +1,7 @@
 from flask import Flask, request
 from mvp import Mvp
 import json
+from test_info import TestInfo
 
 app = Flask(__name__)
 
@@ -125,6 +126,14 @@ def test_api():
     return '成功'
 
 
+@app.route('/testcase_info', methods=['GET', 'POST'])
+def testcase_info():
+    testcase_id = request.args.get('id', default=None, type=str)
+    ti = TestInfo()
+    result = ti.test_detail_info(testcase_id)
+    return json.dump(result, ensure_ascii=False)
+
+
 if __name__ == '__main__':
     app.run(
         host='0.0.0.0',

+ 2 - 1
mvp.py

@@ -28,7 +28,8 @@ class Mvp:
     city_list = ['上海市', '上海周边']
 
     # 用户画像-消费结构 用户画像-生活方式
-    # no 空间需求图谱-单品偏好', '空间需求图谱-精装关注点', '空间需求图谱-空间特性偏好
+    # 需要更新的模块:用户画像-性别、用户画像-行业、用户画像-出行方式、
+    # 用户画像-消费结构、用户画像-生活方式、用户画像-社交模式、用户画像-审美偏好
     tag_table = {
         '用户画像-审美偏好': ['mvp_crowd_info_aesthetic_preference', 'aesthetic_preference'],
         '用户画像-行为兴趣': ['mvp_crowd_info_behavior', 'behavioral_interest'],

+ 117 - 0
test_info.py

@@ -0,0 +1,117 @@
+from mysql_db import MysqlDB
+from itertools import groupby
+
+
+
+class TestInfo(object):
+    """
+        测试回收情况
+    """
+    # 获取测试的答题记录情况
+    sql_1 = '''
+        SELECT
+            a.testcase_id,
+            a.title,
+            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 = %s 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
+            a.testcase_id,
+            a.title,
+            a.sub_question_id,
+            b.sub_question_content,
+            a.score,
+            b.sub_option_content
+    '''
+
+    # 获取测试题信息
+    sql_2 = '''
+        SELECT
+            id,
+            group_type,
+            title,
+            house_ids,
+            creator,
+            created,
+            updator,
+            updated
+        FROM
+            bq_testcase
+        WHERE
+            STATUS = 1
+    '''
+
+    # 统计测试完成人数
+    sql_3 = '''
+        SELECT
+            COUNT(DISTINCT uuid)
+        FROM
+            f_t_daren_score_2 a
+        WHERE
+            testcase_id = %s
+        AND is_last = 1
+    '''
+
+    # 统计参与答题人数
+    sql_4 = '''
+        SELECT
+            COUNT(DISTINCT uuid)
+        FROM
+            f_t_daren_score_2 a
+        WHERE
+            testcase_id = 77 
+    '''
+
+    def __init__(self):
+        # self.shangju_db = MysqlDB('shangju')
+        self.bi_report_db = MysqlDB('bi_report')
+
+    def test_detail_info(self, testcase_id):
+        """
+            查看每套测试回收数据的量
+        :return:
+        """
+        response = {}
+        try:
+            people = self.bi_report_db.select(self.sql_4, [testcase_id])[0][0]
+            finished = self.bi_report_db.select(self.sql_3, [testcase_id])[0][0]
+            result = self.bi_report_db.select(self.sql_1, [testcase_id])
+            answers = []
+            for index, data in enumerate(result):
+                if index == 0:
+                    response['testcase_id'] = data[0]
+                    response['title'] = data[1]
+                    if people != 0:
+                        response['答题完成率'] = float(finished) / float(people)
+                    else:
+                        response['答题完成率'] = '无法统计'
+                answers.append([data[2], data[3], data[4], data[5], data[6]])
+
+            answers.sort(key=lambda obj: obj[0])
+            sub_question_data = []
+            for sub_question_id, others in groupby(answers, key=lambda obj: obj[0]):
+                sub_question = {}
+                sub_question['id'] = sub_question_id
+                sub_question['题干'] = others[0][1]
+                sub_option = []
+                for th in others:
+                    sub_option.append([th[2], th[3], th[4]])
+                sub_question['option'] = sub_option
+                sub_option.append(sub_question)
+            response['答题结果统计'] = sub_question_data
+        except Exception as e:
+            response['error'] = str(e)
+        return response