|
@@ -39,9 +39,6 @@ class Mvp:
|
|
|
# 获取父选项和父题id
|
|
|
sql_2 = 'select a.id, a.content, b.id, b.name from bq_option a left join bq_question b on a.question_id = b.id ' \
|
|
|
'where a.serial_number = %s and b.serial_number = %s and a.status = b.status = 1 '
|
|
|
- # 数据插入表mvp_question_classification
|
|
|
- sql_3 = 'insert into mvp_question_classification(question_serial_number, question_content, ' \
|
|
|
- 'option_serial_number, option_content, tag, corr) values(%s, %s, %s, %s, %s, %s) '
|
|
|
|
|
|
# 获取答题人的年龄段集合
|
|
|
sql_4 = 'select nld from f_t_daren_score_2 group by nld'
|
|
@@ -60,18 +57,27 @@ class Mvp:
|
|
|
sql_7 = 'select group_type from bq_testcase where status = 1 and FIND_IN_SET(%s, question_ids)'
|
|
|
|
|
|
# 根据子选项id统计答题数
|
|
|
- sql_8 = 'SELECT count(uuid) FROM f_t_daren_score_2 a LEFT JOIN d_shangju_tiku_02 b ON a.sub_question_id = ' \
|
|
|
- 'b.sub_question_id AND a.score = b.score WHERE a.testcase_id = b.testcase_id and b.sub_option_id in %s' \
|
|
|
+ sql_8 = 'SELECT count(1) FROM f_t_daren_score_2 a LEFT JOIN d_shangju_tiku_02 b ON a.sub_question_id = ' \
|
|
|
+ 'b.sub_question_id AND a.score = b.score and a.testcase_id = b.testcase_id WHERE b.sub_option_id in %s' \
|
|
|
'and (a.city = %s or a.province = %s) and a.nld = %s and a.uuid in %s'
|
|
|
|
|
|
- # 计算值写入表汇总
|
|
|
- sql_9 = 'insert into mvp_standard_score(city, age, tag, crowd_type, score) VALUES(%s, %s, %s, %s, %s)'
|
|
|
-
|
|
|
# 获取一个uuid下答题的子选项id列表
|
|
|
sql_10 = 'select DISTINCT uuid, GROUP_CONCAT(DISTINCT b.sub_option_id) from f_t_daren_score_2 a left join ' \
|
|
|
'd_shangju_tiku_02 b on a.sub_question_id = b.sub_question_id and a.score = b.score where a.status = ' \
|
|
|
'b.status = 1 group by uuid '
|
|
|
|
|
|
+ # 向表mvp_crowd_info插入数据
|
|
|
+ sql_11 = 'insert into mvp_crowd_info(age_area, city_name, crowd_type, status) values(%s, %s, %s, 1)'
|
|
|
+
|
|
|
+ # 向表mvp_crowd_info_behavior中插入数据
|
|
|
+ sql_12 = 'insert into mvp_crowd_info_behavior(crowd_info_id, behavioral_interest, standard_value, status) values(' \
|
|
|
+ '%s, %s, ' \
|
|
|
+ '%s, 1) '
|
|
|
+
|
|
|
+ # 向表
|
|
|
+ sql_13 = 'insert into mvp_crowd_info_module(crowd_info_id, module_name, standard_value, status) values (%s, %s, ' \
|
|
|
+ '%s, 1) '
|
|
|
+
|
|
|
def __init__(self, path=None):
|
|
|
self.shangju_db = MysqlDB('shangju')
|
|
|
self.marketing_db = MysqlDB('bi_report')
|
|
@@ -157,7 +163,7 @@ class Mvp:
|
|
|
result.append([city, age, crowd, module_name, score])
|
|
|
return result
|
|
|
|
|
|
- def insert(self, scores):
|
|
|
+ def insert_mvp_crowd_info(self, scores):
|
|
|
"""
|
|
|
计算数据写入数据库中,供接口查看
|
|
|
:param scores:
|
|
@@ -243,7 +249,6 @@ class Mvp:
|
|
|
group_types.append(g_t[0])
|
|
|
sub_option_ids.append(sub_option_id)
|
|
|
# 计算子选项在答题记录中的点击数
|
|
|
-
|
|
|
sub_options_count = 0
|
|
|
if len(sub_option_ids) > 0:
|
|
|
result_1 = self.marketing_db.select(self.sql_8, [sub_option_ids, city, city, age, people_uuids])
|
|
@@ -317,7 +322,7 @@ class Mvp:
|
|
|
uuid = people[0]
|
|
|
sub_option_ids = list(map(int, str(people[1]).split(',')))
|
|
|
# list(set(a).intersection(set(b)))
|
|
|
- if len(list(set(sub_option_ids).intersection(set(type_sub_option_ids)))) > 0:
|
|
|
+ if len(list(set(sub_option_ids).intersection(set(type_sub_option_ids)))) > 0 and uuid not in uuids:
|
|
|
uuids.append(uuid)
|
|
|
return uuids
|
|
|
|
|
@@ -535,7 +540,7 @@ def get_city_age_crowd():
|
|
|
:return:
|
|
|
"""
|
|
|
mvp = Mvp()
|
|
|
- infos = {'城市': mvp.citys, '年龄段': mvp.age}
|
|
|
+ infos = {'城市': mvp.citys, '年龄段': mvp.age, '人群分类': mvp.crowd}
|
|
|
mvp.shangju_db.close()
|
|
|
mvp.marketing_db.close()
|
|
|
return json.dumps(infos, ensure_ascii=False)
|