Merge branch 'Linearpast:master' into master
This commit is contained in:
commit
7d6bd52e37
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -33,3 +33,4 @@ build/
|
|||
.vscode/
|
||||
|
||||
out/
|
||||
src/main/resources/bak.yml
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -10,7 +10,7 @@
|
|||
</parent>
|
||||
<groupId>com.linearpast</groupId>
|
||||
<artifactId>MinecraftManager</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
<name>MinecraftManager</name>
|
||||
<description>MinecraftManager</description>
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ public class PlayerController {
|
|||
question.setOptions(result.toString());
|
||||
} else if(type == 2){
|
||||
String options = question.getOptions();
|
||||
String processed = options.replaceAll("\\$\\{.*?}", "\\${}");
|
||||
String processed = options.replaceAll("\\$(\\d+)?\\{.*?}", "\\${}");
|
||||
String[] parts = processed.split("(?<=\\$\\{})|(?=\\$\\{})");
|
||||
JsonArray result = new Gson().toJsonTree(Arrays.asList(parts)).getAsJsonArray();
|
||||
question.setOptions(result.toString());
|
||||
|
|
@ -280,20 +280,46 @@ public class PlayerController {
|
|||
List<String> resultList = new ArrayList<>();
|
||||
JsonArray asJsonArray = JsonParser.parseString(answer).getAsJsonArray();
|
||||
for (JsonElement element : asJsonArray) {
|
||||
resultList.add(element.getAsString());
|
||||
resultList.add(element.getAsString().trim());
|
||||
}
|
||||
String regex = "\\$\\{(.+?)}";
|
||||
String regex = "\\$(\\d+)?\\{(.+?)}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
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()) {
|
||||
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)){
|
||||
playerAnswers.setScore(questions.getScore());
|
||||
}else {
|
||||
playerAnswers.setScore(0);
|
||||
if(k > 0) {
|
||||
//未标记分数的答案的每题平均分
|
||||
float averageScore = (float)maxScore / k;
|
||||
//答对的未标记 * 未标记的平均分 = 未标记的答对总分
|
||||
int rightScore;
|
||||
//如果答对的未标记 == 总未标记,直接给未标记的满分:为了弥补四舍五入带来的误差
|
||||
//否则直接给 未标记平均分 * 未标记答对
|
||||
if(j == k) rightScore = maxScore;
|
||||
else rightScore = Math.round(averageScore * j);
|
||||
score += rightScore;
|
||||
}
|
||||
playerAnswers.setScore(score);
|
||||
}
|
||||
answers.add(playerAnswers);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import org.springframework.data.domain.PageRequest;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/questions")
|
||||
|
|
@ -25,6 +27,10 @@ public class QuestionController {
|
|||
public Result<?> saveQuestion(@RequestBody QuestionSaveDTO questionSaveDTO) {
|
||||
if (questionSaveDTO != null) {
|
||||
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){
|
||||
JsonArray inputArray = new JsonArray();
|
||||
JsonArray correct = new JsonArray();
|
||||
|
|
@ -45,11 +51,20 @@ public class QuestionController {
|
|||
questions.setOptions(resultArray.toString());
|
||||
} else if (questionSaveDTO.getType() == (byte) 2) {
|
||||
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);
|
||||
return result == null ? Result.error("服务器错误") : Result.success();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user