|
@@ -3,18 +3,24 @@ package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
import cn.iselab.mooctest.site.common.constant.AnswerWayConstants;
|
|
import cn.iselab.mooctest.site.common.constant.AnswerWayConstants;
|
|
|
import cn.iselab.mooctest.site.data.CaseBlock;
|
|
import cn.iselab.mooctest.site.data.CaseBlock;
|
|
|
import cn.iselab.mooctest.site.models.*;
|
|
import cn.iselab.mooctest.site.models.*;
|
|
|
|
|
+import cn.iselab.mooctest.site.rpc.dev.data.CaseMutationDTO;
|
|
|
|
|
+import cn.iselab.mooctest.site.rpc.dev.data.LineMutationDTO;
|
|
|
|
|
+import cn.iselab.mooctest.site.rpc.dev.data.MutationDTO;
|
|
|
import cn.iselab.mooctest.site.service.*;
|
|
import cn.iselab.mooctest.site.service.*;
|
|
|
|
|
+import cn.iselab.mooctest.site.service.common.MongoAPIService;
|
|
|
|
|
+import cn.iselab.mooctest.site.service.fromDev.AnalysisService;
|
|
|
import cn.iselab.mooctest.site.service.fromKibug.ScoreRuleService;
|
|
import cn.iselab.mooctest.site.service.fromKibug.ScoreRuleService;
|
|
|
import cn.iselab.mooctest.site.web.data.WeightDirtyVO;
|
|
import cn.iselab.mooctest.site.web.data.WeightDirtyVO;
|
|
|
|
|
+import cn.iselab.mooctest.site.web.data.forMongo.MutationForMongoDTO;
|
|
|
import cn.iselab.mooctest.site.web.data.fromKibug.ScoreRuleItemVO;
|
|
import cn.iselab.mooctest.site.web.data.fromKibug.ScoreRuleItemVO;
|
|
|
|
|
+import cn.iselab.mooctest.site.web.exception.HttpNotFoundException;
|
|
|
import cn.iselab.mooctest.site.web.logic.CalculateSocreLogic;
|
|
import cn.iselab.mooctest.site.web.logic.CalculateSocreLogic;
|
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Iterator;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by HenryLee on 2017/7/10.
|
|
* Created by HenryLee on 2017/7/10.
|
|
@@ -36,6 +42,10 @@ public class CalculateScoreLogicImpl implements CalculateSocreLogic {
|
|
|
private PaperService paperService;
|
|
private PaperService paperService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private TaskService taskService;
|
|
private TaskService taskService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ MongoAPIService mongoAPIService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ AnalysisService analysisService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void calculateScore(long taskId, long caseId) {
|
|
public void calculateScore(long taskId, long caseId) {
|
|
@@ -127,6 +137,96 @@ public class CalculateScoreLogicImpl implements CalculateSocreLogic {
|
|
|
return this.calculateExamScore(examId,participantId,weightDirtyVO,false);
|
|
return this.calculateExamScore(examId,participantId,weightDirtyVO,false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void calculateAllMutationScore(long examId, long caseId) throws IOException {
|
|
|
|
|
+
|
|
|
|
|
+ final double scoreOfPerMutation = 100;
|
|
|
|
|
+ Map<String, Integer> mutationTotalKilledMap = new HashMap<>();
|
|
|
|
|
+ List<MutationForMongoDTO> mutationForMongoDTOS = mongoAPIService.getMutationFromMongo(null, examId, caseId);
|
|
|
|
|
+
|
|
|
|
|
+ if(mutationForMongoDTOS == null && mutationForMongoDTOS.size() == 0)
|
|
|
|
|
+ throw new HttpNotFoundException("该考试的这道题没有变异成绩。");
|
|
|
|
|
+ for (MutationForMongoDTO mutationForMongoDTO : mutationForMongoDTOS) {
|
|
|
|
|
+ statisMutation(mutationTotalKilledMap, mutationForMongoDTO.getMutationDTO());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Double> mutationScoreMap = generatePerMutationScore(mutationTotalKilledMap, mutationForMongoDTOS,
|
|
|
|
|
+ scoreOfPerMutation);
|
|
|
|
|
+ final double baseScore = calculateBaseScore(mutationScoreMap);
|
|
|
|
|
+ for (MutationForMongoDTO mutationForMongoDTO : mutationForMongoDTOS) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ double mutationScore = calculateMutationScore(mutationForMongoDTO, mutationScoreMap, baseScore);
|
|
|
|
|
+ analysisService.saveMutationScore(mutationForMongoDTO.getStuId(), mutationForMongoDTO.getExamId(),
|
|
|
|
|
+ mutationForMongoDTO.getCaseId(), mutationScore);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private double calculateMutationScore(MutationForMongoDTO mutationForMongoDTO, Map<String, Double> mutationScoreMap,
|
|
|
|
|
+ final double baseScore) {
|
|
|
|
|
+ double sum = 0;
|
|
|
|
|
+ for (CaseMutationDTO caseMutation : mutationForMongoDTO.getMutationDTO().getDetailList()) {
|
|
|
|
|
+ for (LineMutationDTO lineMutation : caseMutation.getEachMutantsResult()) {
|
|
|
|
|
+ if(lineMutation.isKilled()) {
|
|
|
|
|
+ String key = caseMutation.getClassName() + lineMutation.getMutantId();
|
|
|
|
|
+ double score = mutationScoreMap.get(key);
|
|
|
|
|
+ sum += score;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return (sum / baseScore) * 100;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private double calculateBaseScore(Map<String, Double> mutationScoreMap) {
|
|
|
|
|
+ List<Double> scores = (List<Double>) mutationScoreMap.values();
|
|
|
|
|
+ double sum = 0;
|
|
|
|
|
+ for(Double score : scores) {
|
|
|
|
|
+ sum += score;
|
|
|
|
|
+ }
|
|
|
|
|
+ return sum;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Double> generatePerMutationScore(Map<String, Integer> mutationTotalKilledMap,
|
|
|
|
|
+ List<MutationForMongoDTO> mutationForMongoDTOS,
|
|
|
|
|
+ final double scoreOfPerMutation) {
|
|
|
|
|
+ Map<String, Double> mutationScoreMap = new HashMap<>();
|
|
|
|
|
+ MutationForMongoDTO mutationForMongoDTO = mutationForMongoDTOS.get(0);
|
|
|
|
|
+ mutationForMongoDTO.getMutationDTO().getDetailList().forEach(caseMutation -> {
|
|
|
|
|
+ caseMutation.getEachMutantsResult().forEach(lineMutation -> {
|
|
|
|
|
+ String key = caseMutation.getClassName() + lineMutation.getMutantId();
|
|
|
|
|
+ Integer killedCount = mutationTotalKilledMap.get(key);
|
|
|
|
|
+ if (killedCount == null) {
|
|
|
|
|
+ killedCount = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ mutationScoreMap.put(key, scoreOfPerMutation / killedCount);
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ return mutationScoreMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void statisMutation(Map<String, Integer> mutationTotalKilledMap, MutationDTO mutationDTO) {
|
|
|
|
|
+ mutationDTO.getDetailList().forEach(caseMutation -> {
|
|
|
|
|
+ caseMutation.getEachMutantsResult().forEach(lineMutation -> {
|
|
|
|
|
+ if(lineMutation.isKilled()) {
|
|
|
|
|
+ String key = caseMutation.getClassName() + lineMutation.getMutantId();
|
|
|
|
|
+ Integer count = mutationTotalKilledMap.get(key);
|
|
|
|
|
+ if(count != null) {
|
|
|
|
|
+ count = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ count = count + 1;
|
|
|
|
|
+ mutationTotalKilledMap.put(key, count);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
private double calculateOneScore(AssignedTask assignedTask,long examId){
|
|
private double calculateOneScore(AssignedTask assignedTask,long examId){
|
|
|
String result=assignedTask.getResult();
|
|
String result=assignedTask.getResult();
|