|
@@ -1,238 +0,0 @@
|
|
|
-package cn.iselab.mooctest.site.web.logic.fromDev.impl;
|
|
|
-
|
|
|
-import cn.iselab.mooctest.site.models.SubmitRecord;
|
|
|
-import cn.iselab.mooctest.site.models.Grade;
|
|
|
-import cn.iselab.mooctest.site.models.Weight;
|
|
|
-import cn.iselab.mooctest.site.rpc.dev.data.ApbcDTO;
|
|
|
-import cn.iselab.mooctest.site.rpc.dev.data.CaughtNodeDTO;
|
|
|
-import cn.iselab.mooctest.site.rpc.dev.data.MutationDTO;
|
|
|
-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.web.data.forMongo.MutationForMongoDTO;
|
|
|
-import cn.iselab.mooctest.site.web.data.fromDev.StResponse;
|
|
|
-import cn.iselab.mooctest.site.web.exception.HttpBadRequestException;
|
|
|
-import cn.iselab.mooctest.site.web.exception.IllegalOperationException;
|
|
|
-import cn.iselab.mooctest.site.web.logic.BaseLogic;
|
|
|
-import cn.iselab.mooctest.site.web.logic.CalculateSocreLogic;
|
|
|
-import cn.iselab.mooctest.site.web.logic.fromDev.APFDLogic;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author sean
|
|
|
- * @date 2017-09-05.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class APFDLogicImpl extends BaseLogic implements APFDLogic{
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CaseService caseService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- WeightService weightService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- AnalysisService analysisService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- SubmitRecordService submitRecordService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- Exam2CaseService exam2CaseService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CalculateScoreService calculateScoreService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CalculateSocreLogic calculateSocreLogic;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MongoAPIService mongoAPIService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getAPFDAnalyseofCaseInExam(Long examId, Long caseId, Long participantId) {
|
|
|
- if (weightService.getWeightByTidAndCid(examId, caseId) == null) {
|
|
|
- throw new HttpBadRequestException("unmatched examId and caseId");
|
|
|
- }
|
|
|
- Weight weight = weightService.getWeightByTidAndCid(examId, caseId);
|
|
|
- if (weight.getApfd() == 0) {
|
|
|
- throw new HttpBadRequestException(caseId + "'s APFD is 0");
|
|
|
- }
|
|
|
- if(participantId==null) {
|
|
|
- List<SubmitRecord> submitRecords = submitRecordService.getSubmittedRecordsByExamId(examId);
|
|
|
- List<Long> submittedWorkerIds = submitRecords.stream().map(assignedTask -> assignedTask.getParticipantId()).collect(Collectors.toList());
|
|
|
- LOG.info("---------------------------------start apfd analysis--------------------------------");
|
|
|
- List<ApbcDTO> apbcDTOList = submittedWorkerIds.stream().map(submittedWorkerId ->
|
|
|
- getAPFDAnalyseByExamIdAndParticipantId(examId,caseId,submittedWorkerId,weight)).collect(Collectors.toList());
|
|
|
- LOG.info("---------------------------------end apfd analysis--------------------------------");
|
|
|
- if (apbcDTOList.size() != 0 && !apbcDTOList.isEmpty()) {
|
|
|
- return StResponse.success(apbcDTOList);
|
|
|
- } else {
|
|
|
- throw new HttpBadRequestException("获取APFD分析失败");
|
|
|
- }
|
|
|
- }else {
|
|
|
- return StResponse.success(getAPFDAnalyseByExamIdAndParticipantId(examId,caseId,participantId,weight));
|
|
|
- }
|
|
|
- }
|
|
|
- @Override
|
|
|
- public ApbcDTO getAPFDAnalyseByExamIdAndParticipantId(Long examId, Long caseId, Long participantId, Weight weight) {
|
|
|
- ApbcDTO apbcDTO = analysisService.apfdAnalyze(examId, participantId, caseId, weight);
|
|
|
- if (apbcDTO == null) {
|
|
|
- throw new HttpBadRequestException("Fail to get APFD of No." + caseId);
|
|
|
- } else {
|
|
|
- List<Grade> grades = analysisService.saveApfdScore(participantId, examId, caseId, apbcDTO.getApbcScore());
|
|
|
- if (grades != null && !grades.isEmpty()) {
|
|
|
- calculateScoreService.calculatePersonalDevScore(examId, caseId, participantId);
|
|
|
- calculateSocreLogic.calculateExamScore(examId,participantId,null,false);
|
|
|
- }
|
|
|
- return apbcDTO;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getMutationAnalyseofCaseInExam(Long examId, Long caseId, Long participantId){
|
|
|
- if (weightService.getWeightByTidAndCid(examId, caseId) == null) {
|
|
|
- throw new HttpBadRequestException("unmatched examId and caseId");
|
|
|
- }
|
|
|
- Weight weight = weightService.getWeightByTidAndCid(examId, caseId);
|
|
|
- if (weight.getMutation() == 0) {
|
|
|
- throw new HttpBadRequestException(caseId + "'s 变异分析 is 0");
|
|
|
- }
|
|
|
- if(participantId==null) {
|
|
|
- List<SubmitRecord> submitRecords = submitRecordService.getSubmittedRecordsByExamId(examId);
|
|
|
- List<Long> submittedWorkerIds = submitRecords.stream().map(assignedTask -> assignedTask.getParticipantId()).collect(Collectors.toList());
|
|
|
- LOG.info("---------------------------------start mutation analysis--------------------------------");
|
|
|
- List<MutationDTO> mutationDTOS =submittedWorkerIds.stream().map( submittedWorkerId ->
|
|
|
- getMutationAnalyseByExamIdAndParticipantId(examId,caseId,submittedWorkerId)).filter(dTO-> dTO!=null).collect(Collectors.toList());
|
|
|
- LOG.info("---------------------------------end mutation analysis--------------------------------");
|
|
|
- if (mutationDTOS.size() != 0 && !mutationDTOS.isEmpty()) {
|
|
|
- return StResponse.success(mutationDTOS);
|
|
|
- } else {
|
|
|
- throw new HttpBadRequestException("获取变异分析失败");
|
|
|
- }
|
|
|
- }else {
|
|
|
- return StResponse.success(getMutationAnalyseByExamIdAndParticipantId(examId, caseId, participantId));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getMutationNodeAnalyseofCaseInExam(Long examId, Long caseId, Long participantId){
|
|
|
- if (weightService.getWeightByTidAndCid(examId, caseId) == null) {
|
|
|
- throw new HttpBadRequestException("unmatched examId and caseId");
|
|
|
- }
|
|
|
- Weight weight = weightService.getWeightByTidAndCid(examId, caseId);
|
|
|
- if (weight.getMutation() == 0) {
|
|
|
- throw new HttpBadRequestException(caseId + "'s 变异分析 is 0");
|
|
|
- }
|
|
|
- if(participantId==null) {
|
|
|
- List<SubmitRecord> submitRecords = submitRecordService.getSubmittedRecordsByExamId(examId);
|
|
|
- List<Long> submittedWorkerIds = submitRecords.stream().map(assignedTask -> assignedTask.getParticipantId()).collect(Collectors.toList());
|
|
|
- LOG.info("---------------------------------start mutation analysis--------------------------------");
|
|
|
- List<List<cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO>> mutationDTOS =submittedWorkerIds.stream().map( submittedWorkerId ->
|
|
|
- getMutationNodeAnalyseByExamIdAndParticipantId(examId,caseId,submittedWorkerId)).filter(dTO-> dTO!=null).collect(Collectors.toList());
|
|
|
- LOG.info("---------------------------------end mutation analysis--------------------------------");
|
|
|
- if (mutationDTOS.size() != 0 && !mutationDTOS.isEmpty()) {
|
|
|
- return StResponse.success(mutationDTOS);
|
|
|
- } else {
|
|
|
- throw new HttpBadRequestException("获取变异分析失败");
|
|
|
- }
|
|
|
- }else {
|
|
|
- return StResponse.success(getMutationNodeAnalyseByExamIdAndParticipantId(examId, caseId, participantId));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public MutationDTO getMutationAnalyseByExamIdAndParticipantId(Long examId, Long caseId, Long participantId){
|
|
|
- MutationDTO mutationDTO;
|
|
|
- try {
|
|
|
- mutationDTO = analysisService.mutationAnalyze(examId, participantId, caseId);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (mutationDTO == null) {
|
|
|
- throw new HttpBadRequestException("Fail to get 变异分析 of No." + caseId);
|
|
|
- } else {
|
|
|
- double mutationScore= mutationDTO.getTotal()==0?0:(double) mutationDTO.getKilled() / mutationDTO.getTotal() * 100;
|
|
|
- try {
|
|
|
- List<Grade> grades = analysisService.saveMutationScore(participantId, examId, caseId, mutationScore);
|
|
|
- if (grades != null && !grades.isEmpty()) {
|
|
|
- calculateScoreService.calculatePersonalDevScore(examId, caseId, participantId);
|
|
|
- calculateSocreLogic.calculateExamScoreAuto(examId,participantId);
|
|
|
- }
|
|
|
- List<MutationForMongoDTO> list = mongoAPIService.getMutationFromMongo(participantId, examId, caseId);
|
|
|
- if(list!=null) {
|
|
|
- MutationForMongoDTO mutationForMongoDTO = list.get(0);
|
|
|
- mutationForMongoDTO.setMutationDTO(mutationDTO);
|
|
|
- mongoAPIService.updateMutationToMongo(mutationForMongoDTO);
|
|
|
- }else {
|
|
|
- mongoAPIService.saveMutationToMongo(participantId, examId, caseId, mutationDTO);
|
|
|
- }
|
|
|
- }catch (IOException e){
|
|
|
- throw new IllegalOperationException("mongo io exception");
|
|
|
- }
|
|
|
- return mutationDTO;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO> getMutationNodeAnalyseByExamIdAndParticipantId(Long examId, Long caseId, Long workerId){
|
|
|
- List<CaughtNodeDTO> caughtNodeDTOS;
|
|
|
- try {
|
|
|
- caughtNodeDTOS = analysisService.mutationCaughtNodeAnalyze(examId,workerId,caseId);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- if (caughtNodeDTOS == null) {
|
|
|
- throw new HttpBadRequestException("Fail to get 变异分析 of No." + caseId);
|
|
|
- } else {
|
|
|
- List<cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO> dtos=caughtNodeDTOS.stream().map(dto -> {
|
|
|
- cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO node=new cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO();
|
|
|
- BeanUtils.copyProperties(dto,node);
|
|
|
- return node;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- long catchNum=dtos.stream().filter(caughtNodeDTO -> caughtNodeDTO.getIfCatch()==true).count();
|
|
|
- double mutationScore=dtos.size()==0?0:(double) catchNum/dtos.size() * 100;
|
|
|
- List<Grade> grades = analysisService.saveMutationScore(workerId, examId, caseId, mutationScore);
|
|
|
- if (grades != null && !grades.isEmpty()) {
|
|
|
- calculateScoreService.calculatePersonalDevScore(examId, caseId, workerId);
|
|
|
- calculateSocreLogic.calculateExamScoreAuto(examId,workerId);
|
|
|
- }
|
|
|
- getMutationDTO(examId,caseId,workerId);
|
|
|
- try {
|
|
|
- calculateSocreLogic.catchNode(examId, caseId, workerId, String.valueOf(System.currentTimeMillis()), dtos);
|
|
|
- }catch (Exception e){
|
|
|
- LOG.info("Fail to save caughtNodeDTO to mongo of caseId:"+caseId+" exception:"+e.getMessage());
|
|
|
- }
|
|
|
- return dtos;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getMutationDTO(Long examId, Long caseId, Long participantId){
|
|
|
- MutationDTO mutationDTO;
|
|
|
- try {
|
|
|
- mutationDTO = analysisService.mutationAnalyze(examId, participantId, caseId);
|
|
|
- List<MutationForMongoDTO> list = mongoAPIService.getMutationFromMongo(participantId, examId, caseId);
|
|
|
- if(list!=null) {
|
|
|
- MutationForMongoDTO mutationForMongoDTO = list.get(0);
|
|
|
- mutationForMongoDTO.setMutationDTO(mutationDTO);
|
|
|
- mongoAPIService.updateMutationToMongo(mutationForMongoDTO);
|
|
|
- }else {
|
|
|
- mongoAPIService.saveMutationToMongo(participantId, examId, caseId, mutationDTO);
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- LOG.info("Fail to save mutationDTO to mongo of caseId:"+caseId+" exception:"+e.getMessage());
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|