update blank question rule
This commit is contained in:
parent
dcd3e0a386
commit
024a9672d5
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -33,3 +33,4 @@ build/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
out/
|
out/
|
||||||
|
src/main/resources/bak.yml
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ public class PlayerController {
|
||||||
question.setOptions(result.toString());
|
question.setOptions(result.toString());
|
||||||
} else if(type == 2){
|
} else if(type == 2){
|
||||||
String options = question.getOptions();
|
String options = question.getOptions();
|
||||||
String processed = options.replaceAll("\\$\\{.*?}", "\\${}");
|
String processed = options.replaceAll("\\$(\\d+)?\\{.*?}", "\\${}");
|
||||||
String[] parts = processed.split("(?<=\\$\\{})|(?=\\$\\{})");
|
String[] parts = processed.split("(?<=\\$\\{})|(?=\\$\\{})");
|
||||||
JsonArray result = new Gson().toJsonTree(Arrays.asList(parts)).getAsJsonArray();
|
JsonArray result = new Gson().toJsonTree(Arrays.asList(parts)).getAsJsonArray();
|
||||||
question.setOptions(result.toString());
|
question.setOptions(result.toString());
|
||||||
|
|
@ -280,20 +280,45 @@ public class PlayerController {
|
||||||
List<String> resultList = new ArrayList<>();
|
List<String> resultList = new ArrayList<>();
|
||||||
JsonArray asJsonArray = JsonParser.parseString(answer).getAsJsonArray();
|
JsonArray asJsonArray = JsonParser.parseString(answer).getAsJsonArray();
|
||||||
for (JsonElement element : asJsonArray) {
|
for (JsonElement element : asJsonArray) {
|
||||||
resultList.add(element.getAsString());
|
resultList.add(element.getAsString().trim());
|
||||||
}
|
}
|
||||||
String regex = "\\$\\{(.+?)}";
|
String regex = "\\$(\\d+)?\\{(.+?)}";
|
||||||
Pattern pattern = Pattern.compile(regex);
|
Pattern pattern = Pattern.compile(regex);
|
||||||
Matcher matcher = pattern.matcher(questions.getOptions());
|
Matcher matcher = pattern.matcher(questions.getOptions());
|
||||||
List<String> result = new ArrayList<>();
|
int score = 0;
|
||||||
|
int i = 0;
|
||||||
|
int j = 0; //没有标记分数的答对题目数
|
||||||
|
int k = 0; //没有标记分数的答案数量
|
||||||
|
//后续计算之后,表示所有未标记分数的答案的总分
|
||||||
|
int maxScore = questions.getScore();
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
result.add(matcher.group(1));
|
String scoreString = matcher.group(1);
|
||||||
|
String answerString = matcher.group(2);
|
||||||
|
int parseInt = 0;
|
||||||
|
try {parseInt = Integer.parseInt(scoreString);}
|
||||||
|
catch (NumberFormatException ignored) {}
|
||||||
|
//若没有标记分数,k++
|
||||||
|
//若标记了分数,最大分数减去,后续计算未标记分数的答案的均分
|
||||||
|
if(parseInt == 0) k++;
|
||||||
|
else maxScore -= parseInt;
|
||||||
|
if (Arrays.stream(answerString.split("\\|")).toList().contains(resultList.get(i))) {
|
||||||
|
score += parseInt;
|
||||||
|
if(parseInt == 0) j++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if(resultList.equals(result)){
|
if(k > 0) {
|
||||||
playerAnswers.setScore(questions.getScore());
|
//未标记分数的答案的每题平均分
|
||||||
}else {
|
int averageScore = Math.round((float)maxScore / k);
|
||||||
playerAnswers.setScore(0);
|
//答对的未标记 * 未标记的平均分 = 未标记的答对总分
|
||||||
|
int rightScore;
|
||||||
|
//如果答对的未标记 == 总未标记,直接给未标记的满分:为了弥补四舍五入带来的误差
|
||||||
|
//否则直接给 未标记平均分 * 未标记答对
|
||||||
|
if(j == k) rightScore = maxScore;
|
||||||
|
else rightScore = averageScore * j;
|
||||||
|
score += rightScore;
|
||||||
}
|
}
|
||||||
|
playerAnswers.setScore(score);
|
||||||
}
|
}
|
||||||
answers.add(playerAnswers);
|
answers.add(playerAnswers);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/questions")
|
@RequestMapping("/api/questions")
|
||||||
|
|
@ -25,6 +27,10 @@ public class QuestionController {
|
||||||
public Result<?> saveQuestion(@RequestBody QuestionSaveDTO questionSaveDTO) {
|
public Result<?> saveQuestion(@RequestBody QuestionSaveDTO questionSaveDTO) {
|
||||||
if (questionSaveDTO != null) {
|
if (questionSaveDTO != null) {
|
||||||
Questions questions = new Questions();
|
Questions questions = new Questions();
|
||||||
|
if(questionSaveDTO.getId() != null) questions.setId(questionSaveDTO.getId());
|
||||||
|
questions.setTitle(questionSaveDTO.getTitle());
|
||||||
|
questions.setScore(questionSaveDTO.getScore());
|
||||||
|
questions.setType(questionSaveDTO.getType());
|
||||||
if(questionSaveDTO.getType() == (byte) 1){
|
if(questionSaveDTO.getType() == (byte) 1){
|
||||||
JsonArray inputArray = new JsonArray();
|
JsonArray inputArray = new JsonArray();
|
||||||
JsonArray correct = new JsonArray();
|
JsonArray correct = new JsonArray();
|
||||||
|
|
@ -45,11 +51,20 @@ public class QuestionController {
|
||||||
questions.setOptions(resultArray.toString());
|
questions.setOptions(resultArray.toString());
|
||||||
} else if (questionSaveDTO.getType() == (byte) 2) {
|
} else if (questionSaveDTO.getType() == (byte) 2) {
|
||||||
questions.setOptions(questionSaveDTO.getBlankContent());
|
questions.setOptions(questionSaveDTO.getBlankContent());
|
||||||
|
Integer originScore = questions.getScore();
|
||||||
|
String regex = "\\$(\\d+)\\{(.+?)}";
|
||||||
|
Pattern pattern = Pattern.compile(regex);
|
||||||
|
Matcher matcher = pattern.matcher(questions.getOptions());
|
||||||
|
int score = 0;
|
||||||
|
while (matcher.find()) {
|
||||||
|
String scoreString = matcher.group(1);
|
||||||
|
int parseInt = 0;
|
||||||
|
try {parseInt = Integer.parseInt(scoreString);}
|
||||||
|
catch (NumberFormatException ignored) {}
|
||||||
|
score += parseInt;
|
||||||
|
}
|
||||||
|
if(score > originScore) questions.setScore(score);
|
||||||
}
|
}
|
||||||
if(questionSaveDTO.getId() != null) questions.setId(questionSaveDTO.getId());
|
|
||||||
questions.setTitle(questionSaveDTO.getTitle());
|
|
||||||
questions.setScore(questionSaveDTO.getScore());
|
|
||||||
questions.setType(questionSaveDTO.getType());
|
|
||||||
Questions result = questionsService.saveQuestions(questions);
|
Questions result = questionsService.saveQuestions(questions);
|
||||||
return result == null ? Result.error("服务器错误") : Result.success();
|
return result == null ? Result.error("服务器错误") : Result.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ public class Players {
|
||||||
|
|
||||||
@Column(name = "create_time")
|
@Column(name = "create_time")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
@Lob
|
||||||
private String description;
|
private String description;
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "email")
|
@JoinColumn(name = "email")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user