|
@@ -43,7 +43,7 @@ def _text(resp):
|
|
def add_dummy_users(namePrefix = 'testuser-', password = 'test', number = 10):
|
|
def add_dummy_users(namePrefix = 'testuser-', password = 'test', number = 10):
|
|
groups = add_groups()
|
|
groups = add_groups()
|
|
users = []
|
|
users = []
|
|
- nicknames = ['小强', '小张', '小李子', '大王']
|
|
|
|
|
|
+ nicknames = ['小强', '小张', '小李', '大王']
|
|
firstNames = ['一', '二', '三', '四', '五']
|
|
firstNames = ['一', '二', '三', '四', '五']
|
|
lastNames = ['张', '王', '李', '杜', '靳']
|
|
lastNames = ['张', '王', '李', '杜', '靳']
|
|
for i in range(number):
|
|
for i in range(number):
|
|
@@ -107,7 +107,8 @@ def create_exams(namePrefix='测试考试-', number=2, tags=[]):
|
|
'name': namePrefix + _random_string(3),
|
|
'name': namePrefix + _random_string(3),
|
|
'description': '可以回家做',
|
|
'description': '可以回家做',
|
|
'duration': random.randint(0, 863) * 100, # seconds
|
|
'duration': random.randint(0, 863) * 100, # seconds
|
|
- 'tags': tags
|
|
|
|
|
|
+ 'tags': tags,
|
|
|
|
+ 'startTime': '2021-05-01T10:00:00'
|
|
}
|
|
}
|
|
resp = create_exam(new_exam)
|
|
resp = create_exam(new_exam)
|
|
exams.append(_text(resp)['id'])
|
|
exams.append(_text(resp)['id'])
|
|
@@ -123,7 +124,7 @@ def create_questions(namePrefix='qtest-', number=10, from_file=False):
|
|
if from_file:
|
|
if from_file:
|
|
files = os.listdir('./demo-questions/')
|
|
files = os.listdir('./demo-questions/')
|
|
for file_name in files:
|
|
for file_name in files:
|
|
- with open('./demo-questions/' + file_name, 'r') as read_obj:
|
|
|
|
|
|
+ with open('./demo-questions/' + file_name, encoding="UTF-8") as read_obj:
|
|
print('loading ' + file_name + ' to db')
|
|
print('loading ' + file_name + ' to db')
|
|
exam_tag = file_name.split('-')[1]
|
|
exam_tag = file_name.split('-')[1]
|
|
exam_prefix = file_name.split('-')[0]
|
|
exam_prefix = file_name.split('-')[0]
|
|
@@ -150,7 +151,14 @@ def create_questions(namePrefix='qtest-', number=10, from_file=False):
|
|
level = row[10];
|
|
level = row[10];
|
|
tags = []
|
|
tags = []
|
|
if len(row[11]) > 0:
|
|
if len(row[11]) > 0:
|
|
- tags.append(row[11])
|
|
|
|
|
|
+ if row[11] == '线路工':
|
|
|
|
+ tags.append('XianLuGong')
|
|
|
|
+ elif row[11] == '桥隧工':
|
|
|
|
+ tags.append('QiaoSuiGong')
|
|
|
|
+ elif row[11] == '大型线路机械司机':
|
|
|
|
+ tags.append('DaXingXianLuJiXieSiJi')
|
|
|
|
+ elif row[11] == '测量工':
|
|
|
|
+ tags.append('CeLiangGong')
|
|
if len(content) == 0 or len(qType) == 0 or len(answers) == 0 or len(finalAnswer) == 0:
|
|
if len(content) == 0 or len(qType) == 0 or len(answers) == 0 or len(finalAnswer) == 0:
|
|
print('Skip due to required info missing')
|
|
print('Skip due to required info missing')
|
|
continue
|
|
continue
|
|
@@ -164,6 +172,7 @@ def create_questions(namePrefix='qtest-', number=10, from_file=False):
|
|
'questionLevel': level,
|
|
'questionLevel': level,
|
|
'tags': tags,
|
|
'tags': tags,
|
|
'answerAnalysis': answerAnalysis,
|
|
'answerAnalysis': answerAnalysis,
|
|
|
|
+
|
|
}
|
|
}
|
|
resp = create_question(question)
|
|
resp = create_question(question)
|
|
random_exam_id = exams[random.randint(0, len(exams)-1)]
|
|
random_exam_id = exams[random.randint(0, len(exams)-1)]
|
|
@@ -171,7 +180,7 @@ def create_questions(namePrefix='qtest-', number=10, from_file=False):
|
|
'questionId': _text(resp)['id']
|
|
'questionId': _text(resp)['id']
|
|
}
|
|
}
|
|
# if random number equals to magic number, then add tag 今日必练
|
|
# if random number equals to magic number, then add tag 今日必练
|
|
- if random.randint(0, 10) == 3:
|
|
|
|
|
|
+ if random.randint(0, 100) == 3:
|
|
add_tag(datetime.today().strftime('%Y%m%d'), questionId=_text(resp)['id'])
|
|
add_tag(datetime.today().strftime('%Y%m%d'), questionId=_text(resp)['id'])
|
|
# add newly created question to a random exam
|
|
# add newly created question to a random exam
|
|
add_question_to_exam(random_exam_id, [exam_to_question])
|
|
add_question_to_exam(random_exam_id, [exam_to_question])
|
|
@@ -235,13 +244,34 @@ def create_categories(namePrefix= 'testCategory-', number=3):
|
|
print ('created ' + str(len(categories)) + ' categories: ' + ','.join(categories))
|
|
print ('created ' + str(len(categories)) + ' categories: ' + ','.join(categories))
|
|
return categories
|
|
return categories
|
|
|
|
|
|
|
|
+def create_2_levels_categories(root_level, second_levels):
|
|
|
|
+ resp = create_category(root_level)
|
|
|
|
+ parent_id = _text(resp)['id']
|
|
|
|
+ children = []
|
|
|
|
+ for category_name in second_levels:
|
|
|
|
+ child = create_category(category_name)
|
|
|
|
+ child_id = _text(child)['id']
|
|
|
|
+ update_category(child_id, {
|
|
|
|
+ 'parentId': parent_id
|
|
|
|
+ })
|
|
|
|
+ children.append(child_id)
|
|
|
|
+ return children
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
def create_specific_categories():
|
|
def create_specific_categories():
|
|
categories = []
|
|
categories = []
|
|
resp = show_root_categories()
|
|
resp = show_root_categories()
|
|
if len(_text(resp)) == 0:
|
|
if len(_text(resp)) == 0:
|
|
- for name in ['历史', '科普', '知识']: #所有类别
|
|
|
|
- resp = create_category(name)
|
|
|
|
- categories.append(_text(resp)['id'])
|
|
|
|
|
|
+ categories.extend(create_2_levels_categories('思政', ['党规党纪', '思想理论', '党史故事']))
|
|
|
|
+ categories.extend(create_2_levels_categories('安全', ['劳动安全', '作业安全', '事故案例']))
|
|
|
|
+ categories.extend(create_2_levels_categories('理论', ['基础理论', '专业理论']))
|
|
|
|
+ categories.extend(create_2_levels_categories('实作', ['作业指导书', '作业技巧', '应急处置']))
|
|
|
|
+ categories.extend(create_2_levels_categories('教材', ['文字', '音像', '课件']))
|
|
|
|
+ categories.extend(create_2_levels_categories('法纪', ['国家法律', '法纪法规', '交通规则']))
|
|
|
|
+ categories.extend(create_2_levels_categories('健康', ['健康知识', '健康养生', '心理辅导']))
|
|
|
|
+ categories.extend(create_2_levels_categories('集萃', ['旅游', '摄影','诗词', '名篇']))
|
|
else:
|
|
else:
|
|
print('Skip creating specific categories')
|
|
print('Skip creating specific categories')
|
|
root_categories = _text(resp)
|
|
root_categories = _text(resp)
|
|
@@ -250,7 +280,7 @@ def create_specific_categories():
|
|
return categories
|
|
return categories
|
|
|
|
|
|
def read_material_from_file(file_name):
|
|
def read_material_from_file(file_name):
|
|
- file = open('./demo-materials/' + file_name, 'r')
|
|
|
|
|
|
+ file = open('./demo-materials/' + file_name, encoding="UTF-8")
|
|
file_lines = file.readlines()
|
|
file_lines = file.readlines()
|
|
count = 0
|
|
count = 0
|
|
content = ''
|
|
content = ''
|
|
@@ -347,11 +377,47 @@ def get_tag(tag):
|
|
url = WEBSITE_PREFIX + '/tags/' + tag
|
|
url = WEBSITE_PREFIX + '/tags/' + tag
|
|
return requests.get(url)
|
|
return requests.get(url)
|
|
|
|
|
|
|
|
+def delete_all_exams():
|
|
|
|
+ url = WEBSITE_PREFIX + '/admin/exams'
|
|
|
|
+ return requests.delete(url)
|
|
|
|
+
|
|
|
|
+def delete_all_questions():
|
|
|
|
+ url = WEBSITE_PREFIX + '/admin/questions'
|
|
|
|
+ return requests.delete(url)
|
|
|
|
+
|
|
|
|
+def delete_all_categories():
|
|
|
|
+ url = WEBSITE_PREFIX + '/admin/categories'
|
|
|
|
+ return requests.delete(url)
|
|
|
|
+
|
|
|
|
+def delete_all_tags():
|
|
|
|
+ url = WEBSITE_PREFIX + '/admin/tags'
|
|
|
|
+ return requests.delete(url)
|
|
|
|
+
|
|
|
|
+def delete_all_materials():
|
|
|
|
+ url = WEBSITE_PREFIX + '/admin/materials'
|
|
|
|
+ return requests.delete(url)
|
|
|
|
+
|
|
|
|
+def delete_all_comments():
|
|
|
|
+ url = WEBSITE_PREFIX + '/admin/comments'
|
|
|
|
+ return requests.delete(url)
|
|
|
|
+
|
|
if override:
|
|
if override:
|
|
all_users = json.loads(get_all_users().text)
|
|
all_users = json.loads(get_all_users().text)
|
|
for user in all_users:
|
|
for user in all_users:
|
|
delete_user(user['userName'])
|
|
delete_user(user['userName'])
|
|
print('deleted all users')
|
|
print('deleted all users')
|
|
|
|
+ delete_all_exams()
|
|
|
|
+ print('deleted all exams')
|
|
|
|
+ delete_all_questions()
|
|
|
|
+ print('deleted all questions')
|
|
|
|
+ delete_all_categories()
|
|
|
|
+ print('deleted all categories')
|
|
|
|
+ delete_all_tags()
|
|
|
|
+ print('deleted all tags')
|
|
|
|
+ delete_all_materials()
|
|
|
|
+ print('deleted all materials')
|
|
|
|
+ delete_all_comments()
|
|
|
|
+ print('deleted all comments')
|
|
if want_user:
|
|
if want_user:
|
|
add_dummy_users()
|
|
add_dummy_users()
|
|
else:
|
|
else:
|