Parcourir la source

analyzeController中getHistoricalData和extraController中findPage的添加

MengyangDuan il y a 5 ans
Parent
commit
71f39bcd2b

+ 8 - 0
src/main/java/edu/nju/controller/AnalyzeController.java

@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import edu.nju.model.AnalyseVO;
 import edu.nju.model.BugDataVO;
+import edu.nju.model.HistoricalDataVO;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -341,4 +342,11 @@ public class AnalyzeController {
 			e.printStackTrace();
 		}
 	}
+
+	@RequestMapping(value = "/historicalData")
+	@ResponseBody
+	public HistoricalDataVO getHistoricalData(Long workerId,int caseTypeId){
+		return aservice.getHistoricalData(workerId, caseTypeId);
+	}
+
 }

+ 10 - 23
src/main/java/edu/nju/controller/ExtraController.java

@@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import edu.nju.entities.*;
+import edu.nju.model.ExamVO;
+import edu.nju.model.PageExamVO;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -95,9 +97,16 @@ public class ExtraController {
 			e.printStackTrace();
 		}
 	}
+
+	//获得一场众测三级页面信息
+	@RequestMapping(value = "/getPageVo")
+	@ResponseBody
+	public PageExamVO findPage(Long examId, Long caseId) {
+		return extraService.findPageAndExam(examId,caseId);
+	}
 	
 	//使用worker_id获取测试报告
-	@RequestMapping(value = "/findByWorker")
+	@RequestMapping(value = "/findByWorkeer")
 	@ResponseBody
 	public void findByWorker(String case_take_id, String worker_id, HttpServletResponse response) {
 		try {
@@ -421,28 +430,6 @@ public class ExtraController {
 			e.printStackTrace();
 		}
 	}
-	
-	//获取页面json
-	@RequestMapping(value = "/getPageJson")
-	@ResponseBody
-	public void getPageJson(String caseId, HttpServletResponse response) {
-		try {
-			PrintWriter out = response.getWriter();
-			JSONObject result = new JSONObject();
-			Exam exam = extraService.getExam(caseId);
-			if(exam != null) { 
-				result.put("status", 200);
-				result.put("result", exam.getJson());
-			}
-			else { result.put("status", 500); }
-			out.print(result);
-			out.flush();
-			out.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
 
 
 	@RequestMapping(value = "/updateTask", method = RequestMethod.POST)

+ 5 - 0
src/main/java/edu/nju/dao/ReportDao.java

@@ -60,5 +60,10 @@ public class ReportDao {
 		query.addCriteria(Criteria.where("task_id").is(task_id));
 		return mongoOperations.find(query, Report.class);
 	}
+	public List<Report> findReportsByWorker(String worker_id) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("worker_id").is(worker_id));
+		return mongoOperations.find(query, Report.class);
+	}
 	
 }

+ 75 - 0
src/main/java/edu/nju/model/ExamVO.java

@@ -0,0 +1,75 @@
+package edu.nju.model;
+
+import java.util.Date;
+
+public class ExamVO {
+    private Long id;
+
+    private Long caseId;
+
+    private int state;
+
+    private int caseTypeId;
+
+    private Date beginTime;
+
+    private Date endTime;
+
+    public ExamVO(Long id,Long caseId, int state, int caseTypeId, Date beginTime, Date endTime) {
+        this.id = id;
+        this.caseId=caseId;
+        this.state = state;
+        this.caseTypeId = caseTypeId;
+        this.beginTime = beginTime;
+        this.endTime = endTime;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getCaseId() {
+        return caseId;
+    }
+
+    public void setCaseId(Long caseId) {
+        this.caseId = caseId;
+    }
+
+    public int getState() {
+        return state;
+    }
+
+    public void setState(int state) {
+        this.state = state;
+    }
+
+    public int getCaseTypeId() {
+        return caseTypeId;
+    }
+
+    public void setCaseTypeId(int caseTypeId) {
+        this.caseTypeId = caseTypeId;
+    }
+
+    public Date getBeginTime() {
+        return beginTime;
+    }
+
+    public void setBeginTime(Date beginTime) {
+        this.beginTime = beginTime;
+    }
+
+    public Date getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Date endTime) {
+        this.endTime = endTime;
+    }
+}
+

+ 64 - 0
src/main/java/edu/nju/model/HistoricalDataVO.java

@@ -0,0 +1,64 @@
+package edu.nju.model;
+
+
+import java.util.List;
+
+public class HistoricalDataVO {
+    private int reportNum;
+
+    private List<Double>scoreList;  //各个报告的得分
+
+    private Double totalScore;   //报告总分
+
+    private int participateNum;   //参加的和本次考试类型有关的众包测试次数
+
+    private int totalParticipateNum;  //参加众包考试次数
+
+    public HistoricalDataVO(int reportNum, List<Double> scoreList, Double totalScore, int participateNum, int totalParticipateNum) {
+        this.reportNum = reportNum;
+        this.scoreList = scoreList;
+        this.totalScore = totalScore;
+        this.participateNum = participateNum;
+        this.totalParticipateNum = totalParticipateNum;
+    }
+
+    public int getReportNum() {
+        return reportNum;
+    }
+
+    public void setReportNum(int reportNum) {
+        this.reportNum = reportNum;
+    }
+
+    public List<Double> getScoreList() {
+        return scoreList;
+    }
+
+    public void setScoreList(List<Double> scoreList) {
+        this.scoreList = scoreList;
+    }
+
+    public Double getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(Double totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public int getParticipateNum() {
+        return participateNum;
+    }
+
+    public void setParticipateNum(int participateNum) {
+        this.participateNum = participateNum;
+    }
+
+    public int getTotalParticipateNum() {
+        return totalParticipateNum;
+    }
+
+    public void setTotalParticipateNum(int totalParticipateNum) {
+        this.totalParticipateNum = totalParticipateNum;
+    }
+}

+ 59 - 0
src/main/java/edu/nju/model/PageExamVO.java

@@ -0,0 +1,59 @@
+package edu.nju.model;
+
+public class PageExamVO {
+
+    private Long examId;
+
+    private Long caseId;
+
+    private ExamVO examVO;
+
+    private int caseTypeId;   //web:0 app:1
+
+    private String pageContent;
+
+    public PageExamVO(Long examId,Long caseId) {
+        this.examId = examId;
+        this.caseId = caseId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long id) {
+        this.examId = id;
+    }
+
+    public Long getCaseId() {
+        return caseId;
+    }
+
+    public void setCaseId(Long caseId) {
+        this.caseId = caseId;
+    }
+
+    public ExamVO getExamVO() {
+        return examVO;
+    }
+
+    public void setExamVO(ExamVO examVO) {
+        this.examVO = examVO;
+    }
+
+    public int getCaseTypeId() {
+        return caseTypeId;
+    }
+
+    public void setCaseTypeId(int caseTypeId) {
+        this.caseTypeId = caseTypeId;
+    }
+
+    public String getPageContent() {
+        return pageContent;
+    }
+
+    public void setPageContent(String pageContent) {
+        this.pageContent = pageContent;
+    }
+}

+ 5 - 0
src/main/java/edu/nju/model/WebBrand.java

@@ -0,0 +1,5 @@
+package edu.nju.model;
+
+public enum WebBrand {
+    windows,linux,macos
+}

+ 33 - 4
src/main/java/edu/nju/service/AnalyzeService.java

@@ -4,11 +4,9 @@ import java.util.*;
 
 import edu.nju.dao.*;
 import edu.nju.entities.*;
-import edu.nju.model.AnalyseVO;
-import edu.nju.model.BugDataVO;
-import edu.nju.model.BugSeverity;
-import edu.nju.model.WorkerVO;
+import edu.nju.model.*;
 import edu.nju.util.HTTP;
+import org.apache.commons.lang3.EnumUtils;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -573,5 +571,36 @@ public class AnalyzeService {
 		return analyseVO;
 	}
 
+	public HistoricalDataVO getHistoricalData(Long workerId, int caseTypeId){
+		List<Report>reports=reportDao.findReportsByWorker(String.valueOf(workerId));
+		int reportNum=reports.size();
+		List<Double>reportScoreList=new ArrayList<>();
+		double totalScore=0;
+		int participateSimilarNum=0;
+		for(Report report:reports){
+			String reportId=report.getId();
+			List<String>bugIds=bdao.findByReport(reportId);
+			double score=0;
+			for(String bugId:bugIds){
+				BugScore bugScore=bsdao.findById(bugId);
+				if(bugScore!=null) {
+					score += bugScore.getGrade();
+				}
+			}
+			totalScore+=score;
+			reportScoreList.add(score);
+			int itemCaseType=1;
+			String brand=report.getDevice_os();
+			if(EnumUtils.isValidEnum(WebBrand.class, brand)){
+				itemCaseType=0;
+			}
+			if(itemCaseType==caseTypeId){
+				participateSimilarNum++;
+			}
+		}
+		HistoricalDataVO historicalDataVO=new HistoricalDataVO(reportNum,reportScoreList,totalScore,participateSimilarNum,reportNum);
+		return historicalDataVO;
+	}
+
 
 }

+ 43 - 2
src/main/java/edu/nju/service/ExtraService.java

@@ -9,9 +9,9 @@ import java.util.*;
 
 import edu.nju.dao.*;
 import edu.nju.entities.*;
-import edu.nju.model.BugRecurrent;
-import edu.nju.model.BugSeverity;
+import edu.nju.model.*;
 import edu.nju.util.*;
+import org.apache.commons.lang3.EnumUtils;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -276,6 +276,47 @@ public class ExtraService {
 		return null;
 	}
 
+	public PageExamVO findPageAndExam(long examId, long caseId){
+		PageExamVO pageExamVO=new PageExamVO(examId,caseId);
+		Exam examCase=getExam(String.valueOf(caseId));
+		pageExamVO.setPageContent(examCase.getJson());
+		String json=examCase.getPaper_type();
+		int caseTypeId=getPaperType(json);
+		pageExamVO.setCaseTypeId(caseTypeId);
+		Task task=taskDao.findById(String.valueOf(examId));
+		Date startTime=null;
+		Date endTime=null;
+		if(task!=null){
+			startTime=new Date(task.getStart_time());
+			endTime=new Date(task.getEnd_time());
+		}
+		ExamVO examVO=new ExamVO(examId,caseId,0,caseTypeId,startTime,endTime);
+		pageExamVO.setExamVO(examVO);
+		return pageExamVO;
+	}
+
+	private int getPaperType(String json){
+		//json=json.substring(1,json.length()-1);
+		JSONObject jsonObject = new JSONObject(json);
+		JSONArray jsonArray=jsonObject.getJSONArray("subTitles");
+		int caseTypeId=1;//这里只对WEB和APP进行了判断
+		for(int i=0;i<jsonArray.length();i++) {
+			JSONObject item = jsonArray.getJSONObject(i);
+			String label=item.getString("name");
+			if(label.equals("操作系统")){
+				JSONArray brandList=item.getJSONArray("value");
+				String brand=String.valueOf(brandList.get(0));
+				if(EnumUtils.isValidEnum(WebBrand.class, brand)){
+					caseTypeId=0;
+				}
+				break;
+			}
+		}
+		return caseTypeId;
+	}
+
+
+