|
@@ -647,6 +647,9 @@ func random(count int) int {
|
|
|
}
|
|
|
|
|
|
func chooseAnswer2(wd selenium.WebDriver, questions []QuestionInfo, questionM map[string][]string) error {
|
|
|
+ if config.Conf.NewStyle {
|
|
|
+ return chooseAnswer2New(wd, questions, questionM)
|
|
|
+ }
|
|
|
emptyCount := 0
|
|
|
if false {
|
|
|
emptyCount = 3
|
|
@@ -804,6 +807,167 @@ func chooseAnswer2(wd selenium.WebDriver, questions []QuestionInfo, questionM ma
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func chooseAnswer2New(wd selenium.WebDriver, questions []QuestionInfo, questionM map[string][]string) error {
|
|
|
+ emptyCount := 0
|
|
|
+ if false {
|
|
|
+ emptyCount = 3
|
|
|
+ }
|
|
|
+ // 选择或判断题目号
|
|
|
+ originNumber := map[int]bool{}
|
|
|
+ // 选择或判断最大题目号
|
|
|
+ maxNumber := 0
|
|
|
+ // 先收集答案
|
|
|
+ for i, _ := range questions {
|
|
|
+ questions[i].ChoosedAnswer = []int{}
|
|
|
+ fmt.Printf("\n题目类型:%s\n", getTagName(questions[i].Tag))
|
|
|
+ fmt.Printf("题目:%s\n", questions[i].Text)
|
|
|
+
|
|
|
+ for _, v := range questions[i].AnswerArray {
|
|
|
+ fmt.Printf("选项:%s\n", v.Text)
|
|
|
+ }
|
|
|
+ if questions[i].Tag == 4 {
|
|
|
+ shortAnswer(questions[i], questionM)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(questions[i].AnswerArray) == 0 {
|
|
|
+ return errors.New(fmt.Sprintf("%s 选项为空", questions[i].Text))
|
|
|
+
|
|
|
+ }
|
|
|
+ str := TrimSpace(questions[i].Text)
|
|
|
+ str = ParseHan(str)
|
|
|
+ //str = trimQuestionPrefix(str)
|
|
|
+ str = fmt.Sprintf("%d-", questions[i].Tag) + str
|
|
|
+
|
|
|
+ answerstrs, _ := questionM[str]
|
|
|
+
|
|
|
+ if len(answerstrs) == 0 || answerstrs[0] == "" {
|
|
|
+ emptyCount++
|
|
|
+ if emptyCount > config.Conf.QuestionCount {
|
|
|
+ return errors.New(fmt.Sprintf("%s 题库答案为空", questions[i].Text))
|
|
|
+ }
|
|
|
+ fmt.Printf("%s 题库答案为空, 空答案数小于%d,进行随机选择", questions[i].Text, config.Conf.QuestionCount)
|
|
|
+ questions[i].ChoosedAnswer = append(questions[i].ChoosedAnswer, random(len(questions[i].AnswerArray)))
|
|
|
+ continue
|
|
|
+
|
|
|
+ }
|
|
|
+ find := 0
|
|
|
+ // 单选
|
|
|
+ if questions[i].Tag == 1 {
|
|
|
+ //answerstrs = answerstrs[:1]
|
|
|
+ }
|
|
|
+ if questions[i].Tag == 3 {
|
|
|
+ //fmt.Printf("*****************************************:%s,%v\n", questions[i].Text,answerstrs)
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, answerstr := range answerstrs {
|
|
|
+ if answerstr == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for j, _ := range questions[i].AnswerArray {
|
|
|
+ if questions[i].Tag == 1 && find > 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ right := false
|
|
|
+ if questions[i].Tag == 1 || questions[i].Tag == 3 {
|
|
|
+ //right = TrimSpace(answerstr) == TrimSpace(v.Text)
|
|
|
+ right = j == SelectAnswerFlagMap[answerstr]
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //right = tryEqual(answerstr, TrimSpace(v.Text))
|
|
|
+ right = j == JudgeAnswerMap[answerstr]
|
|
|
+ }
|
|
|
+
|
|
|
+ if right {
|
|
|
+ fmt.Printf("选择答案:%s\n", answerstr)
|
|
|
+ questions[i].ChoosedAnswer = append(questions[i].ChoosedAnswer, j)
|
|
|
+ originNumber[i] = true
|
|
|
+ maxNumber = i
|
|
|
+ //ppp, _ := v.Radio.Element.FindElement(selenium.ByXPATH, "./following-sibling::span")
|
|
|
+ //txt, _ := ppp.Text()
|
|
|
+ //fmt.Printf("kkkkkkkkkkkkkkkkkkk:%s,%s\n", txt, answerstr)
|
|
|
+ if questions[i].Tag == 3 {
|
|
|
+ //time.Sleep(10*time.Second)
|
|
|
+ }
|
|
|
+ find++
|
|
|
+ //time.Sleep(1 * time.Second)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if find == 0 {
|
|
|
+ emptyCount++
|
|
|
+ if emptyCount > config.Conf.QuestionCount {
|
|
|
+ return errors.New(fmt.Sprintf("%s 题库答案为空2", questions[i].Text))
|
|
|
+ }
|
|
|
+ fmt.Printf("未找到匹配答案,题库中的答案有:%v\n", answerstrs)
|
|
|
+ questions[i].ChoosedAnswer = append(questions[i].ChoosedAnswer, random(len(questions[i].AnswerArray)))
|
|
|
+ continue
|
|
|
+ //return errors.New(fmt.Sprintf("%s 未找到匹配答案", questions[i].Text))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择答案, 先随机生成需故意填错的错误题号
|
|
|
+ errorNumber := getRandErrorNumber(emptyCount, originNumber, maxNumber)
|
|
|
+ defer func() {
|
|
|
+ errorNumber = nil
|
|
|
+ }()
|
|
|
+
|
|
|
+ for i, _ := range questions {
|
|
|
+ if len(questions[i].ChoosedAnswer) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 不需要故意填错
|
|
|
+ if !errorNumber[i] {
|
|
|
+ for _, v := range questions[i].ChoosedAnswer {
|
|
|
+ err := tryClick(wd, questions[i].AnswerArray[v].Radio.Element)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("点击答案错误:%v\n", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 需要故意填错时,随机选择错误答案
|
|
|
+
|
|
|
+ // 正确答案map
|
|
|
+ cm := map[int]bool{}
|
|
|
+ for _, j := range questions[i].ChoosedAnswer {
|
|
|
+ cm[j] = true
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可供选择的错误答案
|
|
|
+ array := []int{}
|
|
|
+ for j, _ := range questions[i].AnswerArray {
|
|
|
+ if !cm[j] {
|
|
|
+ array = append(array, j)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 随机生成索引
|
|
|
+ arrayIndex := random(len(array))
|
|
|
+
|
|
|
+ // 获取错误答案索引
|
|
|
+ errorIndex := 0
|
|
|
+ if len(array) > 0 {
|
|
|
+ errorIndex = array[arrayIndex]
|
|
|
+ } else {
|
|
|
+ errorIndex = random(len(questions[i].AnswerArray))
|
|
|
+ }
|
|
|
+ err := tryClick(wd, questions[i].AnswerArray[errorIndex].Radio.Element)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("点击答案错误:%v\n", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func chooseAnswer(wd selenium.WebDriver, questions []QuestionInfo, questionM map[string][]string) error {
|
|
|
// 正常选择答案
|
|
|
if !config.Conf.QuestionRandom {
|
|
@@ -1698,6 +1862,9 @@ func examHandle(wd selenium.WebDriver, courseId, moduleId, id string, qustionM m
|
|
|
}
|
|
|
|
|
|
// 提交试卷
|
|
|
+ if config.Conf.SleepTime > 0 {
|
|
|
+ time.Sleep(time.Duration(config.Conf.SleepTime) * time.Second)
|
|
|
+ }
|
|
|
fmt.Printf("开始提交\n")
|
|
|
err = examHandleSubmit(wd)
|
|
|
fmt.Printf("examHandleSubmit:%v\n", err)
|