Przeglądaj źródła

添加分析页面bug信息和bug提交信息的接口

MengyangDuan 4 lat temu
rodzic
commit
5c3aaa9300

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

@@ -2,6 +2,7 @@ package edu.nju.controller;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -428,5 +429,38 @@ public class AnalyzeController {
 		}
 	}
 
+	@RequestMapping(value = "/analyseBugInfo", method = RequestMethod.GET)
+	@ResponseBody
+	public void analyseBugInfo(@RequestParam("caseId") String caseId, @RequestParam("taskId")  String taskId, HttpServletResponse response){
+		try {
+			response.setCharacterEncoding("utf-8");
+			response.setContentType("text/html;charset=utf-8");
+			PrintWriter out = response.getWriter();
+			int[][]bugInfo=aservice.getBugInfo(taskId, caseId);
+			out.print(Arrays.deepToString(bugInfo));
+			out.flush();
+			out.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+
+	@RequestMapping(value = "/analyseBugSubmitInfo", method = RequestMethod.GET)
+	@ResponseBody
+	public void analyseBugSubmitInfo(@RequestParam("caseId") String caseId, @RequestParam("taskId")  String taskId,@RequestParam("piece")  int piece, HttpServletResponse response){
+		try {
+			response.setCharacterEncoding("utf-8");
+			response.setContentType("text/html;charset=utf-8");
+			PrintWriter out = response.getWriter();
+			Map<Integer,Integer>map=aservice.getBugSubmitInfo(taskId,caseId,piece);
+			out.print(new JSONObject(map));
+			out.flush();
+			out.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
 
 }

+ 41 - 0
src/main/java/edu/nju/service/AnalyzeService.java

@@ -907,6 +907,7 @@ public class AnalyzeService {
 		return coverMap;
 	}
 
+	//将三级页面信息的jsonobject转为string
 	private List<String> getPageStr(String caseId){
 		List<String>result=new ArrayList<>();
 		Exam exam=extraService.getExam(String.valueOf(caseId));
@@ -940,6 +941,46 @@ public class AnalyzeService {
 		}
 	}
 
+	public int[][] getBugInfo(String taskId,String caseId){
+		String caseTakeId=caseId+"-"+taskId;
+		List<Bug>bugs=bdao.findByCaseid(caseTakeId);
+		int[][]bugInfo=new int[6][6];     //bug的复现程度和严重程度都为1-5
+		for(Bug bug:bugs){
+			int bugSeverity=bug.getSeverity();
+			int bugRecurrent=bug.getRecurrent();
+			bugInfo[bugSeverity][bugRecurrent]+=1;
+		}
+		return bugInfo;
+	}
+
+	public Map<Integer,Integer> getBugSubmitInfo(String taskId,String caseId,int piece){
+		Task task=taskDao.findById(taskId);
+		Map<Integer,Integer>map=new HashMap<>();
+		long startTime=0;
+		long endTime=0;
+		if(task!=null) {
+			startTime = task.getStart_time();
+			endTime = task.getEnd_time();
+		}
+		long pieceTime=(endTime-startTime)/piece;
+		String caseTakeId=caseId+"-"+taskId;
+		List<Bug>bugs=bdao.findByCaseid(caseTakeId);
+		for(Bug bug:bugs){
+			long time=Long.parseLong(bug.getCreate_time_millis());
+			int index=(int)((time-startTime)/pieceTime);
+			if(map.containsKey(index)){
+				map.replace(index,map.get(index)+1);
+			}
+			else{
+				map.put(index,1);
+			}
+		}
+		return map;
+	}
+
+
+
+
 
 
 }