计算平均分

master
xiaoCJ 4 months ago
parent b7051dc993
commit 760d543337

@ -170,11 +170,15 @@ public class TheoryTestServiceImpl implements TheoryTestService {
if (record.getAverageScore() == null) {
record.setAverageScore(score);
} else {
Integer examCount = record.getExamCount();
BigDecimal averageScore = record.getAverageScore();
BigDecimal multiply = averageScore.multiply(BigDecimal.valueOf(examCount));
BigDecimal newAvg = multiply.add(score).divide(BigDecimal.valueOf(examCount), 2, RoundingMode.HALF_UP);
record.setAverageScore(newAvg);
StuTheoryExamExample example = new StuTheoryExamExample();
example.createCriteria().andUserIdEqualTo(userId).andAnsweredEqualTo(true);
List<StuTheoryExamWithBLOBs> stuTheoryExamWithBLOBs = theoryExamMapper.selectByExampleWithBLOBs(example);
BigDecimal totalScore = stuTheoryExamWithBLOBs.stream()
.map(StuTheoryExamWithBLOBs::getScore)
.reduce(BigDecimal.ZERO, BigDecimal::add)
.add(score);
BigDecimal avgScore = totalScore.divide(BigDecimal.valueOf(stuTheoryExamWithBLOBs.size()+1), 2, RoundingMode.HALF_UP);
record.setAverageScore(avgScore);
}
}
theoryRecordMapper.updateByPrimaryKey(record);
@ -525,13 +529,14 @@ public class TheoryTestServiceImpl implements TheoryTestService {
}
public static void main(String[] args) {
String singleStuAnswer = ", , , ,"+" ,";
String singleStuAnswer = ", , , ," + " ,";
System.out.println(singleStuAnswer);
String[] split = singleStuAnswer.split(", ");
for (String s : split) {
System.out.println(s);
}
}
@Override
public List<StuTheoryExamDetailDto> getTheoryTestDetail(String theoryExamId, Integer index, Integer size) throws IOException {
ArrayList<String> idsList = new ArrayList<>();

Loading…
Cancel
Save