|
@@ -1,6 +1,8 @@
|
|
|
package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
|
|
|
+import cn.iselab.mooctest.site.models.Task;
|
|
|
import cn.iselab.mooctest.site.service.CaseGraphService;
|
|
|
+import cn.iselab.mooctest.site.service.ExamService;
|
|
|
import cn.iselab.mooctest.site.service.UserCatchService;
|
|
|
import cn.iselab.mooctest.site.web.data.SimilarityResultVO;
|
|
|
import cn.iselab.mooctest.site.web.data.UserVO;
|
|
@@ -12,6 +14,7 @@ import cn.iselab.mooctest.site.web.logic.UserLogic;
|
|
|
import com.google.common.collect.Ordering;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import java.sql.Timestamp;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -31,6 +34,11 @@ public class SimilarityLogicImpl implements SimilarityLogic{
|
|
|
@Autowired
|
|
|
private UserLogic userLogic;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamService examService;
|
|
|
+
|
|
|
+ private static int NUMBEROFUNIS = 40;
|
|
|
+
|
|
|
@Override
|
|
|
public List<SimilarityResultVO> getTopSimilarResultInCase(Long examId, Long caseId, String type) {
|
|
|
List<SimilarityResultVO> result = new LinkedList<>();
|
|
@@ -87,6 +95,94 @@ public class SimilarityLogicImpl implements SimilarityLogic{
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HashMap<String, int[]> getMatrixOfProgress(Long examId, Long caseId, String type, Long userId) {
|
|
|
+ HashMap<String, int[]> result = new HashMap<>();
|
|
|
+ List<Node> nodeList = caseGraphService.getCaseGraph(caseId).getNodes().stream().filter(node -> node.getCategory().equals(type)).collect(Collectors.toList());
|
|
|
+ Task task = examService.getExamByIdAndParticipantIdIfPermited(examId, userId);
|
|
|
+ Set<String> nodeNameSet = new HashSet<>();
|
|
|
+ for(Node node: nodeList) {
|
|
|
+ nodeNameSet.add(node.getName());
|
|
|
+ }
|
|
|
+ List<UserCatchDTO> userCatchDTOS = userCatchService.getUserCatchDTOs(userId, examId, caseId);
|
|
|
+ if(userCatchDTOS.size()==0 || userCatchDTOS.get(0).getCatchDTOs().size()==0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<CatchDTO> catchDTOS = userCatchDTOS.get(0).getCatchDTOs().stream().filter(node -> node.getCategory().equals(type)).collect(Collectors.toList());
|
|
|
+ List<String> sortedTimestamp = getSortedTimeStamp(catchDTOS, type);
|
|
|
+ HashMap<String, int[]> initMatrix = getNodeTimeInitMatrix(sortedTimestamp, catchDTOS, nodeNameSet);
|
|
|
+ result = getExtendedMatrix(task.getBeginTime(), task.getEndTime(), initMatrix, sortedTimestamp);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 现在的需求是根据examId caseId userId type 得到一个二位矩阵,具体的形式用HashMap表达
|
|
|
+ // 根据type获得所有的node
|
|
|
+ // 初始化矩阵
|
|
|
+ //
|
|
|
+
|
|
|
+ private List<String> getSortedTimeStamp(List<CatchDTO> catchDTOS, String type) {
|
|
|
+ List<String> result = null;
|
|
|
+ Set<String> timestampSet = new HashSet<>();
|
|
|
+ for(CatchDTO catchDTO: catchDTOS) {
|
|
|
+ timestampSet.add(catchDTO.getUploadTime());
|
|
|
+ }
|
|
|
+ result = new ArrayList<String>(timestampSet);
|
|
|
+ Collections.sort(result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<String, int[]> getNodeTimeInitMatrix(List<String> sortedTimestamp, List<CatchDTO> resourceCatchDTOS, Set<String> nodeNameSet) {
|
|
|
+ HashMap<String, int[]> initMatrix = new HashMap<String, int[]>();
|
|
|
+ for(String nodeName: nodeNameSet) {
|
|
|
+ initMatrix.put(nodeName, new int[sortedTimestamp.size()]);
|
|
|
+ }
|
|
|
+ for(CatchDTO catchDTO: resourceCatchDTOS) {
|
|
|
+ initMatrix.get(catchDTO.getNodeName())[sortedTimestamp.indexOf(catchDTO.getUploadTime())] = 1;
|
|
|
+ }
|
|
|
+ return initMatrix;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<String, int[]> getExtendedMatrix(Timestamp startTime, Timestamp endTime, HashMap<String, int[]> initMatrix, List<String> sortedTimestamp) {
|
|
|
+ HashMap<String, int[]> result = new HashMap<>();
|
|
|
+ Long[] stamp = new Long[NUMBEROFUNIS];
|
|
|
+ Long start = startTime.getTime();
|
|
|
+ Long end = endTime.getTime();
|
|
|
+ Long unit = (end - start) / NUMBEROFUNIS;
|
|
|
+ for(int i=0; i< NUMBEROFUNIS; i++) {
|
|
|
+ stamp[i] = start + unit * (i+1);
|
|
|
+ }
|
|
|
+ for(String nodeName: initMatrix.keySet()) {
|
|
|
+ result.put(nodeName, extendOneRow(initMatrix.get(nodeName), sortedTimestamp, stamp));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先把提交的时间戳落入区间,0右边一直是0,1右边是1,
|
|
|
+ private int[] extendOneRow(int[] initRow, List<String> sortedTimestamp, Long[] standardStamp) {
|
|
|
+ int[] result = new int[NUMBEROFUNIS];
|
|
|
+ Long[] sortedTimestampLong = new Long[sortedTimestamp.size()];
|
|
|
+ for(int i=0; i < sortedTimestamp.size(); i++) {
|
|
|
+ sortedTimestampLong[i] = stamp2long(sortedTimestamp.get(i));
|
|
|
+ }
|
|
|
+ int flag = 0;
|
|
|
+ for(int i = 0, index = 0; i < NUMBEROFUNIS ; i++) {
|
|
|
+ if( sortedTimestampLong[index] > standardStamp[i] ) {
|
|
|
+ flag = initRow[index];
|
|
|
+ result[i] = flag;
|
|
|
+ }else{
|
|
|
+ if(index+1< sortedTimestamp.size()) {
|
|
|
+ index ++;
|
|
|
+ i -- ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long stamp2long(String stamp) {
|
|
|
+ return new Long(stamp);
|
|
|
+ }
|
|
|
+
|
|
|
private HashMap<Long, int[]> getUsersMap(Long examId, Long caseId, String type) {
|
|
|
HashMap<Long, int[]> result = new HashMap<>();
|
|
|
List<UserCatchDTO> userCatchDTOList = userCatchService.getUserCatchDTOs(null, examId, caseId);
|