|
@@ -124,11 +124,21 @@ 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, encoding="UTF-8") as read_obj:
|
|
|
|
|
|
+ with open('./demo-questions/' + file_name, 'r') 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]
|
|
|
|
+ tags = []
|
|
|
|
+ if len(exam_tag) > 0:
|
|
|
|
+ if exam_tag == '线路工':
|
|
|
|
+ tags.append('XianLuGong')
|
|
|
|
+ elif exam_tag == '桥隧工':
|
|
|
|
+ tags.append('QiaoSuiGong')
|
|
|
|
+ elif exam_tag == '大型线路机械司机':
|
|
|
|
+ tags.append('DaXingXianLuJiXieSiJi')
|
|
|
|
+ elif exam_tag == '测量工':
|
|
|
|
+ tags.append('CeLiangGong')
|
|
exam_prefix = file_name.split('-')[0]
|
|
exam_prefix = file_name.split('-')[0]
|
|
- exams = create_exams(namePrefix=exam_prefix + '-' + exam_tag, number=6, tags=[exam_tag])
|
|
|
|
|
|
+ exams = create_exams(namePrefix=exam_prefix + '-' + exam_tag, number=6, tags=tags)
|
|
csv_reader = reader(read_obj)
|
|
csv_reader = reader(read_obj)
|
|
for row in csv_reader:
|
|
for row in csv_reader:
|
|
qNumber = row[0]
|
|
qNumber = row[0]
|
|
@@ -149,16 +159,6 @@ def create_questions(namePrefix='qtest-', number=10, from_file=False):
|
|
answerAnalysis = row[8]
|
|
answerAnalysis = row[8]
|
|
keyword = row[9];
|
|
keyword = row[9];
|
|
level = row[10];
|
|
level = row[10];
|
|
- tags = []
|
|
|
|
- if len(row[11]) > 0:
|
|
|
|
- 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
|
|
@@ -181,6 +181,7 @@ def create_questions(namePrefix='qtest-', number=10, from_file=False):
|
|
}
|
|
}
|
|
# if random number equals to magic number, then add tag 今日必练
|
|
# if random number equals to magic number, then add tag 今日必练
|
|
if random.randint(0, 100) == 3:
|
|
if random.randint(0, 100) == 3:
|
|
|
|
+ print('going to add tag to question')
|
|
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])
|
|
@@ -257,9 +258,6 @@ def create_2_levels_categories(root_level, second_levels):
|
|
children.append(child_id)
|
|
children.append(child_id)
|
|
return children
|
|
return children
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def create_specific_categories():
|
|
def create_specific_categories():
|
|
categories = []
|
|
categories = []
|
|
resp = show_root_categories()
|
|
resp = show_root_categories()
|
|
@@ -280,7 +278,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, encoding="UTF-8")
|
|
|
|
|
|
+ file = open('./demo-materials/' + file_name, 'r')
|
|
file_lines = file.readlines()
|
|
file_lines = file.readlines()
|
|
count = 0
|
|
count = 0
|
|
content = ''
|
|
content = ''
|
|
@@ -296,6 +294,10 @@ def read_material_from_file(file_name):
|
|
count+=1
|
|
count+=1
|
|
return title, content
|
|
return title, content
|
|
|
|
|
|
|
|
+def random_pick_tags():
|
|
|
|
+ tags = ['CeLiangGong', 'DaXingXianLuJiXieSiJi', 'QiaoSuiGong', 'XianLuGong']
|
|
|
|
+ return tags[random.randint(0, len(tags)-1)]
|
|
|
|
+
|
|
def create_learning_materials(namePrefix='测试资料-', number=20, from_file=False):
|
|
def create_learning_materials(namePrefix='测试资料-', number=20, from_file=False):
|
|
categories = []
|
|
categories = []
|
|
if not from_file:
|
|
if not from_file:
|
|
@@ -311,10 +313,12 @@ def create_learning_materials(namePrefix='测试资料-', number=20, from_file=F
|
|
'userId': randomly_pick_user(),
|
|
'userId': randomly_pick_user(),
|
|
'type': 'ARTICLE',
|
|
'type': 'ARTICLE',
|
|
'contents': content,
|
|
'contents': content,
|
|
|
|
+ 'tags': [random_pick_tags()]
|
|
})
|
|
})
|
|
materialId = _text(material)['id']
|
|
materialId = _text(material)['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, 10) == 3:
|
|
|
|
+ print('going to add tag to material')
|
|
add_tag(datetime.today().strftime('%Y%m%d'), materialId=materialId)
|
|
add_tag(datetime.today().strftime('%Y%m%d'), materialId=materialId)
|
|
materials.append(materialId)
|
|
materials.append(materialId)
|
|
random_category = categories[random.randint(0, len(categories)-1)]
|
|
random_category = categories[random.randint(0, len(categories)-1)]
|