瀏覽代碼

报表调试

xiatian 6 年之前
父節點
當前提交
0c7f841028

+ 3 - 0
examcloud-task-dao/src/main/java/cn/com/qmth/examcloud/task/dao/ReportsComputeRepo.java

@@ -16,6 +16,9 @@ public interface ReportsComputeRepo
 		extends
 			JpaRepository<ReportsComputeEntity, Long>,
 			JpaSpecificationExecutor<ReportsComputeEntity> {
+	@Query(value = "SELECT count(1) FROM EC_T_REPORTS_COMPUTE t "+
+			"WHERE t.status ='NONE'", nativeQuery = true)
+	public int getTodoDataCount();
 	@Query(value = "SELECT t.* FROM EC_T_REPORTS_COMPUTE t "+
 			"WHERE t.id>?1 and t.status ='NONE' ORDER BY t.id limit ?2", nativeQuery = true)
 	public List<ReportsComputeEntity> findTodoData(Long startId,Integer limit);

+ 1 - 1
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/ReportsComputeService.java

@@ -5,7 +5,7 @@ import java.util.List;
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
 
 public interface ReportsComputeService {
-	
+	public int getTodoDataCount();
 	public List<ReportsComputeEntity> findTodoData(Long startId,Integer limit);
 	public void compute(ReportsComputeEntity et);
 	public void updateToComputing(ReportsComputeEntity et);

+ 5 - 3
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/consumer/ReportsComputeConsumer.java

@@ -17,11 +17,13 @@ public class ReportsComputeConsumer extends Consumer<ReportsComputeEntity> {
 	@Override
 	public void consume(ReportsComputeEntity et) {
 		logger.info("***************************报表计算开始,projectId:"+et.getProjectId());
-		// 修改报表计算任务状态
-		reportsComputeService.updateToComputing(et);
 		try {
+			// 修改报表计算任务状态
+			reportsComputeService.updateToComputing(et);
 			//计算报表
 			reportsComputeService.compute(et);
+			// 修改报表计算任务状态
+			reportsComputeService.updateToSuccess(et);
 		} catch (ReportsComputeStopException e) {
 			//计算终止
 			reportsComputeService.updateToStop(et);
@@ -29,7 +31,7 @@ public class ReportsComputeConsumer extends Consumer<ReportsComputeEntity> {
 			reportsComputeService.clearStopingFlag(et.getId());
 			//计算出错
 			reportsComputeService.updateToFail(et,"系统错误");
-			logger.error("***************************报表计算出错,projectId:"+et.getProjectId());
+			logger.error("***************************报表计算出错,projectId:"+et.getProjectId(),e);
 		}
 		logger.info("***************************报表计算结束,projectId:"+et.getProjectId());
 	}

+ 21 - 0
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/dto/TopicScoreDto.java

@@ -1,6 +1,10 @@
 package cn.com.qmth.examcloud.task.service.dto;
 
 public class TopicScoreDto {
+	private String questionId;
+	
+	//套题题序
+	private Integer questionOrder;
 	private double total;
 	private double avg;
 	private long count;
@@ -28,4 +32,21 @@ public class TopicScoreDto {
 	public void setCount(long count) {
 		this.count = count;
 	}
+
+	public String getQuestionId() {
+		return questionId;
+	}
+
+	public void setQuestionId(String questionId) {
+		this.questionId = questionId;
+	}
+
+	public Integer getQuestionOrder() {
+		return questionOrder;
+	}
+
+	public void setQuestionOrder(Integer questionOrder) {
+		this.questionOrder = questionOrder;
+	}
+	
 }

+ 75 - 21
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/ReportsComputeServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.task.service.impl;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -196,6 +197,13 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			ExamCourseDataReportBean bean = examCourseDataReport.get(key);
 			bean.setStd(std(scores.get(key), bean.getAvgScore()));
 		}
+		// 计算差异系数
+		for (String key : examCourseDataReport.keySet()) {
+			ExamCourseDataReportBean bean = examCourseDataReport.get(key);
+			bean.setCdi(getPercentage(bean.getStd(), bean.getAvgScore()));
+			bean.setAvgScore(getTwoDecimal(bean.getAvgScore()));
+		}
+		
 		// 判断任务终止
 		checkIsStoping(et.getId());
 		// 计算basePaperId对应的难度系数
@@ -333,22 +341,40 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 
 	private Double avgDifficultyDegree(String dataKey, Map<String, Set<String>> basePapers,
 			Map<String, Double> basePapersDegree) {
+		//考试课程对应的basePapers
 		Set<String> set = basePapers.get(dataKey);
-		if (set == null) {
+		if (set == null||set.size()==0) {
 			return null;
 		}
 		double total = 0.0;
+		//算平均难度时剔除没有难度系数的试卷
+		int nullCount=0;
 		for (String s : set) {
-			total = total + basePapersDegree.get(s);
+			Double td=basePapersDegree.get(s);
+			if(td==null) {
+				nullCount++;
+			}else {
+				total = total + basePapersDegree.get(s);
+			}
 		}
-		return total / set.size();
+		if(nullCount==set.size()) {
+			return null;
+		}
+		return getTwoDecimal(total / (set.size()-nullCount));
 	}
 
-	private double difficultyDegree(Map<String, TopicScoreDto> map) {
+	private Double difficultyDegree(Map<String, TopicScoreDto> map) {
+		//剔除整张卷子没有小题答题的
+		if(map==null||map.size()==0) {
+			return null;
+		}
 		double totalAvg = 0.0;
 		double totalFull = 0.0;
 		for (String k : map.keySet()) {
 			TopicScoreDto dto = map.get(k);
+			if(dto.getTotal()==0) {
+				throw new StatusException("100001", "小题满分不能为0 QuestionId:"+dto.getQuestionId()+" QuestionOrder:"+dto.getQuestionOrder());
+			}
 			totalAvg = totalAvg + dto.getAvg();
 			totalFull = totalFull + dto.getTotal();
 		}
@@ -364,7 +390,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			total += Math.pow((list.get(i) - average), 2);
 		}
 		double standardDeviation = Math.sqrt(total / list.size());
-		return standardDeviation;
+		return getTwoDecimal(standardDeviation);
 	}
 
 	/**
@@ -388,7 +414,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			if (list == null || list.size() == 0) {
 				break;
 			}
-			startId = list.get(list.size() - 1).getExamStudentId();
+			startId = res.getNextId();
 			for (ExamStudentDataBean st : list) {
 				// 判断任务终止
 				checkIsStoping(jobId);
@@ -412,7 +438,6 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		// 学习中心id集合
 		Set<Long> ordIds = (Set<Long>) result.get("ordIds");
 		ordIds.add(st.getOrgId());
-		Map<String, List<Double>> scores = (Map<String, List<Double>>) result.get("scores");
 		Map<String, ExamOrgReportBean> examOrgReport = (Map<String, ExamOrgReportBean>) result.get("examOrgReport");
 		String key = st.getExamId() + "-" + st.getOrgId();
 		ExamOrgReportBean bean = examOrgReport.get(key);
@@ -432,6 +457,9 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			bean.setParticipantCount(bean.getParticipantCount() + 1);
 		}
 		// 及格人数
+		if (!st.getAbsent() && st.getScore()==null) {
+			throw new StatusException("10030","未缺考的考生分数不能为空 ExamStudentId:"+st.getExamStudentId());
+		}
 		if (!st.getAbsent() && st.getScore() >= pro.getPassScore()) {
 			bean.setPassCount(bean.getPassCount() + 1);
 		}
@@ -439,16 +467,6 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		if (!st.getAbsent()) {
 			addPartitionData(st.getScore(), pro, bean.getPartitionData());
 		}
-		// 分数集合
-		if (!st.getAbsent()) {
-			List<Double> list = scores.get(key);
-			if (list == null) {
-				list = new ArrayList<Double>();
-				scores.put(key, list);
-			}
-			list.add(st.getScore());
-		}
-
 	}
 
 	/**
@@ -505,6 +523,8 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		// 设置满分数值
 		if (st.getTotalScore() != null) {
 			bean.setTotalScore(st.getTotalScore());
+		}else {
+			throw new StatusException("10020","试卷满分不能为空 ExamStudentId:"+st.getExamStudentId());
 		}
 		// 最高分
 		if (!st.getAbsent() && st.getScore() > bean.getMaxScore()) {
@@ -551,6 +571,14 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 				.get("basePapersTopicScore");
 
 		if (!st.getAbsent()) {
+			Map<String, List<Double>> scores = (Map<String, List<Double>>) result.get("scores");
+			// 分数集合-计算标准差
+			List<Double> list = scores.get(key);
+			if (list == null) {
+				list = new ArrayList<Double>();
+				scores.put(key, list);
+			}
+			list.add(st.getScore());
 			// 考试课程对应的basePaperId集合
 			Set<String> set = basePapers.get(key);
 			if (set == null) {
@@ -567,6 +595,10 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 			}
 			// 考生小题得分详情
 			List<ExamStudentScoreDataBean> scoreDetails = st.getScoreDetails();
+			if(scoreDetails==null||scoreDetails.size()==0) {
+				throw new StatusException("10040","考生小题得分详情不能为空 ExamStudentId:"+st.getExamStudentId());
+			}
+			
 			// 计算每个小题的平均分
 			for (ExamStudentScoreDataBean b : scoreDetails) {
 				if (b.getScore() != null) {
@@ -575,6 +607,8 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 					TopicScoreDto tem = temmap.get(topicScoreKey);
 					if (tem == null) {
 						tem = new TopicScoreDto();
+						tem.setQuestionId(b.getQuestionId());
+						tem.setQuestionOrder(b.getQuestionOrder());
 						tem.setTotal(b.getTotalScore());
 						temmap.put(topicScoreKey, tem);
 					}
@@ -609,7 +643,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		et.setStartTime(new Date());
 		reportsComputeRepo.save(et);
 		UpdateProjectStatusReq req = new UpdateProjectStatusReq();
-		req.setProjectId(et.getId());
+		req.setProjectId(et.getProjectId());
 		req.setStatus(2);
 		projectCloudService.updateProjectStatus(req);
 	}
@@ -621,7 +655,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		et.setEndTime(new Date());
 		reportsComputeRepo.save(et);
 		UpdateProjectStatusReq req = new UpdateProjectStatusReq();
-		req.setProjectId(et.getId());
+		req.setProjectId(et.getProjectId());
 		req.setStatus(3);
 		projectCloudService.updateProjectStatus(req);
 	}
@@ -634,7 +668,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		et.setEndTime(new Date());
 		reportsComputeRepo.save(et);
 		UpdateProjectStatusReq req = new UpdateProjectStatusReq();
-		req.setProjectId(et.getId());
+		req.setProjectId(et.getProjectId());
 		req.setStatus(4);
 		projectCloudService.updateProjectStatus(req);
 	}
@@ -656,7 +690,7 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		et.setEndTime(new Date());
 		reportsComputeRepo.save(et);
 		UpdateProjectStatusReq req = new UpdateProjectStatusReq();
-		req.setProjectId(et.getId());
+		req.setProjectId(et.getProjectId());
 		req.setStatus(5);
 		projectCloudService.updateProjectStatus(req);
 		// 清除缓存终止标志
@@ -678,4 +712,24 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		reportsComputeRepo.save(e);
 	}
 
+	@Override
+	public int getTodoDataCount() {
+		return reportsComputeRepo.getTodoDataCount();
+	}
+	private Double getPercentage(Double a, Double b) {
+		if (b == 0) {
+			return null;
+		}
+		BigDecimal bd = new BigDecimal(a * 100 / b);
+		Double tem = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+		return tem;
+	}
+	private Double getTwoDecimal(Double b) {
+		if (b == null) {
+			return b;
+		}
+		BigDecimal bd = new BigDecimal(b);
+		Double tem = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+		return tem;
+	}
 }

+ 5 - 2
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/job/ReportsComputeTask.java

@@ -21,8 +21,11 @@ public class ReportsComputeTask extends AbstractTask {
 	
 	@Override
 	public void run(ScheduleJob scheduleJob) throws Exception {
-		ReportsComputeProducer pro=new ReportsComputeProducer();
-		pro.startDispose(ReportsComputeConsumer.class, 10, null);
+		int c=reportsComputeService.getTodoDataCount();
+		if(c>0) {
+			ReportsComputeProducer pro=new ReportsComputeProducer();
+			pro.startDispose(ReportsComputeConsumer.class, c>10?10:c, null);
+		}
 	}
 
 	@Override