|
@@ -1,18 +1,34 @@
|
|
|
package edu.nju.service;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import edu.nju.algorithm.progress.BugForProgress;
|
|
|
+import edu.nju.algorithm.progress.TaskClosePrediction;
|
|
|
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.DataMaskingUtil;
|
|
|
import edu.nju.util.HTTP;
|
|
|
+import edu.nju.util.TimeUtil;
|
|
|
+import edu.nju.util.TransUtil;
|
|
|
+import org.apache.commons.lang3.EnumUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
@Service
|
|
|
public class AnalyzeService {
|
|
@@ -52,6 +68,43 @@ public class AnalyzeService {
|
|
|
|
|
|
@Autowired
|
|
|
TestCaseDao testCaseDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ThumsUpDao thumsUpDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BugHistoryDao bugHistoryDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserLabelDao userLabelDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExtraService extraService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ShortTokenDao shortTokenDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamDao examDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CrowdTestDao crowdTestDao;
|
|
|
+
|
|
|
+ @Value("${server.host}")
|
|
|
+ private String serverHost;
|
|
|
+ @Value("${report.port}")
|
|
|
+ private String serverPort;
|
|
|
+
|
|
|
+ private static String[] radarInfo = {"发现bug能力","描述bug能力","经验值","bug有效率","众测平均得分"};
|
|
|
+ private static int[] radarValueStart = {70,80,60,50,70};
|
|
|
+ private static List<String> mockLabels = Arrays.asList("移动应用","Android","ios","鸿蒙os","华为","MacOS","Windows10",
|
|
|
+ "小米","Web测试","发现bug能力强","页面覆盖率高","互动性强",
|
|
|
+ "社交类app","江苏省南京市");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Logger logger= LoggerFactory.getLogger(RecommendService.class);
|
|
|
|
|
|
//获取所有bug
|
|
|
public List<String> getValid(String case_take_id) {
|
|
@@ -101,7 +154,7 @@ public class AnalyzeService {
|
|
|
Bug bug=bugMap.get(bugMirror.getId());
|
|
|
BugHistory bugHistory=hdao.findByid(bugMirror.getId());
|
|
|
if(bug!=null&&bugHistory!=null){
|
|
|
- BugSeverity bugSeveritsy=BugSeverity.getValue(2);
|
|
|
+ BugSeverity bugSeveritsy=BugSeverity.getValue(bug.getSeverity());
|
|
|
String bugSeverity=bugSeveritsy.toString();
|
|
|
BugScore bugScore=bsdao.findById(bug.getId());
|
|
|
int score=bugScore==null?0:bugScore.getGrade();
|
|
@@ -129,7 +182,7 @@ public class AnalyzeService {
|
|
|
List<Report> reports = reportDao.findByExamId(examId);
|
|
|
for(Report report : reports) {
|
|
|
if(report!=null) {
|
|
|
- String workerId=findWorkerId(report.getId());
|
|
|
+ String workerId=report.getWorker_id();
|
|
|
if(!workerId.equals("")&&!result.contains(workerId))
|
|
|
result.add(Long.parseLong(workerId));
|
|
|
}
|
|
@@ -215,83 +268,122 @@ public class AnalyzeService {
|
|
|
|
|
|
//todo 搞清楚究竟是通过哪种方式写回主站分数
|
|
|
public JSONArray getScores(String case_take_id) {
|
|
|
- Map<String, Integer> reviewScore = new HashMap<String, Integer>(); //评审他人bug得分
|
|
|
- Map<String, Integer> bugScore = new HashMap<String, Integer>(); //系统或专家评审你的bug得分
|
|
|
- Map<String, Integer> finalScores = new HashMap<String, Integer>(); //计算bug得分
|
|
|
- JSONArray json = new JSONArray();
|
|
|
-
|
|
|
- //获取所有bugID
|
|
|
- List<String> bugIdList = getValid(case_take_id);
|
|
|
- //获取bug本身得分
|
|
|
- for(String bugId: bugIdList) {
|
|
|
- BugScore temp = bsdao.findById(bugId);
|
|
|
- if(temp != null) {bugScore.put(bugId, temp.getGrade());}
|
|
|
- else {bugScore.put(bugId, 0);}
|
|
|
- }
|
|
|
-
|
|
|
- //计算树状bug得分
|
|
|
- countScore(case_take_id, finalScores, bugScore);
|
|
|
+// Map<String, Integer> reviewScore = new HashMap<String, Integer>(); //评审他人bug得分
|
|
|
+// Map<String, Integer> bugScore = new HashMap<String, Integer>(); //系统或专家评审你的bug得分
|
|
|
+// Map<String, Integer> finalScores = new HashMap<String, Integer>(); //计算bug得分
|
|
|
+// JSONArray json = new JSONArray();
|
|
|
+//
|
|
|
+// //获取所有bugID
|
|
|
+// List<String> bugIdList = getValid(case_take_id);
|
|
|
+// logger.info(String.valueOf(bugIdList.size()));
|
|
|
+// //获取bug本身得分
|
|
|
+// for(String bugId: bugIdList) {
|
|
|
+// BugScore temp = bsdao.findById(bugId);
|
|
|
+// if(temp != null) {bugScore.put(bugId, temp.getGrade());}
|
|
|
+// else {bugScore.put(bugId, 0);}
|
|
|
+// }
|
|
|
+//
|
|
|
+// //计算树状bug得分
|
|
|
+// countScore(case_take_id, finalScores, bugScore);
|
|
|
+//
|
|
|
+// //计算审查得分
|
|
|
+// for(String bug: bugIdList) {
|
|
|
+// BugMirror mirror = mdao.findById(bug);
|
|
|
+// if(mirror == null) { continue; }
|
|
|
+// int grade = bugScore.getOrDefault(bug, 0);
|
|
|
+// int thumbsScore=0;
|
|
|
+// if(grade>=0&&grade<3){
|
|
|
+// thumbsScore=-2;
|
|
|
+// }else if(grade<5){
|
|
|
+// thumbsScore=-1;
|
|
|
+// }else if(grade<8){
|
|
|
+// thumbsScore=1;
|
|
|
+// }else{
|
|
|
+// thumbsScore=2;
|
|
|
+// }
|
|
|
+// //点赞点踩积分减分
|
|
|
+// ThumsUp(thumbsScore,reviewScore,mirror);
|
|
|
+// }
|
|
|
+// int maxReviewScore=0;
|
|
|
+// int maxReportScore=0;
|
|
|
+// for(Map.Entry<String, Integer> entry : reviewScore.entrySet()) {
|
|
|
+// //审查得分低于零分按零分算
|
|
|
+// if(entry.getValue() < 0) { reviewScore.put(entry.getKey(), 0); }
|
|
|
+// if(entry.getValue()>maxReviewScore){
|
|
|
+// maxReviewScore=entry.getValue();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //将bug得分汇总为report得分
|
|
|
+// Map<String, Integer> reportScore = new HashMap<String, Integer>();
|
|
|
+// for(String bugId: bugIdList) {
|
|
|
+// BugMirror mirror = mdao.findById(bugId);
|
|
|
+// if(mirror == null) { continue; }
|
|
|
+// String reportId=mirror.getReport_id();
|
|
|
+// //出现过bug和bugMirror中没有reportId的问题,需要单独检查
|
|
|
+// if(reportId!=null) {
|
|
|
+// reportScore.put(reportId, finalScores.getOrDefault(bugId, 0) + reportScore.getOrDefault(reportId, 0));
|
|
|
+// if (reportScore.get(reportId) > maxReportScore) {
|
|
|
+// maxReportScore = reportScore.get(reportId);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //确保被除数不为0
|
|
|
+// if(maxReportScore==0){
|
|
|
+// maxReportScore=1;
|
|
|
+// }
|
|
|
+// if(maxReviewScore==0){
|
|
|
+// maxReviewScore=1;
|
|
|
+// }
|
|
|
+// //得分要以最高分为满分
|
|
|
+// for(Map.Entry<String, Integer> entry : reportScore.entrySet()) {
|
|
|
+// JSONObject json_temp = new JSONObject();
|
|
|
+// json_temp.put("report_id", entry.getKey());
|
|
|
+// json_temp.put("worker_id", findWorkerId(entry.getKey()));
|
|
|
+// json_temp.put("名字", report_trans(entry.getKey()));
|
|
|
+// json_temp.put("报告得分", (entry.getValue()/maxReportScore)*100);
|
|
|
+// json_temp.put("审查得分", (reviewScore.getOrDefault(entry.getKey(), 0)/maxReviewScore)*100);
|
|
|
+// json.put(json_temp);
|
|
|
+// }
|
|
|
|
|
|
- //计算审查得分
|
|
|
- for(String bug: bugIdList) {
|
|
|
- BugMirror mirror = mdao.findById(bug);
|
|
|
- if(mirror == null) { continue; }
|
|
|
- int grade = bugScore.getOrDefault(bug, 0);
|
|
|
- int thumbsScore=0;
|
|
|
- if(grade>=0&&grade<3){
|
|
|
- thumbsScore=-2;
|
|
|
- }else if(grade<5){
|
|
|
- thumbsScore=-1;
|
|
|
- }else if(grade<8){
|
|
|
- thumbsScore=1;
|
|
|
- }else{
|
|
|
- thumbsScore=2;
|
|
|
- }
|
|
|
- //点赞点踩积分减分
|
|
|
- ThumsUp(thumbsScore,reviewScore,mirror);
|
|
|
- }
|
|
|
- int maxReviewScore=0;
|
|
|
- int maxReportScore=0;
|
|
|
- for(Map.Entry<String, Integer> entry : reviewScore.entrySet()) {
|
|
|
- //审查得分低于零分按零分算
|
|
|
- if(entry.getValue() < 0) { reviewScore.put(entry.getKey(), 0); }
|
|
|
- if(entry.getValue()>maxReviewScore){
|
|
|
- maxReviewScore=entry.getValue();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //将bug得分汇总为report得分
|
|
|
- Map<String, Integer> reportScore = new HashMap<String, Integer>();
|
|
|
- for(String bugId: bugIdList) {
|
|
|
- BugMirror mirror = mdao.findById(bugId);
|
|
|
- if(mirror == null) { continue; }
|
|
|
- String reportId=mirror.getReport_id();
|
|
|
- //出现过bug和bugMirror中没有reportId的问题,需要单独检查
|
|
|
- if(reportId!=null) {
|
|
|
- reportScore.put(reportId, finalScores.getOrDefault(bugId, 0) + reportScore.getOrDefault(reportId, 0));
|
|
|
- if (reportScore.get(reportId) > maxReportScore) {
|
|
|
- maxReportScore = reportScore.get(reportId);
|
|
|
+ List<Report> reportList=reportDao.findByCaseTakeId(case_take_id);
|
|
|
+ HashMap<String,Integer> hashMap=new HashMap<>();
|
|
|
+ int maxScore=0;
|
|
|
+ for(Report report:reportList){
|
|
|
+ String workerId=report.getWorker_id();
|
|
|
+ hashMap.put(workerId,0);
|
|
|
+ List<Bug> bugList=bdao.findByReport(report.getId(),case_take_id);
|
|
|
+// logger.info(String.valueOf(bugList.size()));
|
|
|
+ for(Bug bug:bugList){
|
|
|
+ if(bug!=null) {
|
|
|
+ logger.info(bug.getId());
|
|
|
+ BugScore bugScore = bsdao.findById(bug.getId());
|
|
|
+ int score = hashMap.get(workerId);
|
|
|
+ if (bugScore != null) {
|
|
|
+ score += bugScore.getGrade();
|
|
|
+ logger.info(String.valueOf(bugScore.getGrade()));
|
|
|
+ }
|
|
|
+ if (score > maxScore) {
|
|
|
+ maxScore = score;
|
|
|
+ }
|
|
|
+ hashMap.put(workerId, score);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //确保被除数不为0
|
|
|
- if(maxReportScore==0){
|
|
|
- maxReportScore=1;
|
|
|
- }
|
|
|
- if(maxReviewScore==0){
|
|
|
- maxReviewScore=1;
|
|
|
- }
|
|
|
- //得分要以最高分为满分
|
|
|
- for(Map.Entry<String, Integer> entry : reportScore.entrySet()) {
|
|
|
+ logger.info(String.valueOf(maxScore));
|
|
|
+ JSONArray json = new JSONArray();
|
|
|
+ for(Map.Entry<String, Integer> entry : hashMap.entrySet()) {
|
|
|
+ String key=entry.getKey();
|
|
|
+ int value=entry.getValue();
|
|
|
+ value=(value*100/maxScore);
|
|
|
JSONObject json_temp = new JSONObject();
|
|
|
- json_temp.put("report_id", entry.getKey());
|
|
|
- json_temp.put("worker_id", findWorkerId(entry.getKey()));
|
|
|
- json_temp.put("名字", report_trans(entry.getKey()));
|
|
|
- json_temp.put("报告得分", (entry.getValue()/maxReportScore)*100);
|
|
|
- json_temp.put("审查得分", (reviewScore.getOrDefault(entry.getKey(), 0)/maxReviewScore)*100);
|
|
|
+ json_temp.put("worker_id",key);
|
|
|
+ json_temp.put("score",value);
|
|
|
json.put(json_temp);
|
|
|
}
|
|
|
//把分写回主站
|
|
|
+// logger.info("计算结束");
|
|
|
+ logger.info(json.toString());
|
|
|
writeScores(case_take_id, json);
|
|
|
return json;
|
|
|
}
|
|
@@ -415,24 +507,51 @@ public class AnalyzeService {
|
|
|
}
|
|
|
|
|
|
private void writeScores(String case_take_id, JSONArray array) {
|
|
|
- String host = "http://www.mooctest.net";
|
|
|
- String url = "/api/common/uploadCaseScore";
|
|
|
+// String host = "http://www.mooctest.net";
|
|
|
+// String url = "/api/common/uploadCaseScore";
|
|
|
+// String[] ids = case_take_id.split("-");
|
|
|
+// String param1 = "caseId=" + ids[0] + "&examId=" + ids[1];
|
|
|
+// for(int i = 0; i < array.length(); i ++) {
|
|
|
+// JSONObject json = (JSONObject)array.get(i);
|
|
|
+// String worker_id = json.get("worker_id").toString();
|
|
|
+// //报告得分*0.7+审查得分*0.3
|
|
|
+//// int bugScore=Integer.parseInt(json.get("报告得分").toString());
|
|
|
+//// int reviewScore=Integer.parseInt(json.get("审查得分").toString());
|
|
|
+// double score = json.getDouble("score");
|
|
|
+// if(worker_id.equals("")) { continue; }
|
|
|
+// if(score<0){
|
|
|
+// score=0;
|
|
|
+// }
|
|
|
+// if(score > 100) { score = 100; }
|
|
|
+// String param2 = "&userId=" + worker_id + "&score=" + score;
|
|
|
+// HTTP.sendPut(host, url, param1 + param2);
|
|
|
+// logger.info("---------------");
|
|
|
+// logger.info(worker_id);
|
|
|
+// }
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ String url = "http://www.test.mooctest.net/api/common/uploadCaseScore";
|
|
|
String[] ids = case_take_id.split("-");
|
|
|
- String param1 = "caseId=" + ids[0] + "&examId=" + ids[1];
|
|
|
for(int i = 0; i < array.length(); i ++) {
|
|
|
+ MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
|
|
|
+
|
|
|
JSONObject json = (JSONObject)array.get(i);
|
|
|
String worker_id = json.get("worker_id").toString();
|
|
|
- //报告得分*0.7+审查得分*0.3
|
|
|
- int bugScore=Integer.parseInt(json.get("报告得分").toString());
|
|
|
- int reviewScore=Integer.parseInt(json.get("审查得分").toString());
|
|
|
- double score = bugScore*0.7+reviewScore*0.3;
|
|
|
- if(score <= 0 || worker_id.equals("")) { continue; }
|
|
|
- if(score > 100) { score = 100; }
|
|
|
- String param2 = "&userId=" + worker_id + "&score=" + score;
|
|
|
- HTTP.sendPut(host, url, param1 + param2);
|
|
|
+ paramMap.add("examId", ids[1]);
|
|
|
+ paramMap.add("caseId", ids[0]);
|
|
|
+ paramMap.add("userId", worker_id);
|
|
|
+ paramMap.add("score", json.getDouble("score"));
|
|
|
+ template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);
|
|
|
+ template.put(url, httpEntity);
|
|
|
+ logger.info("workerId:" +worker_id);
|
|
|
+ logger.info("score:" +json.getDouble("score"));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private String report_trans(String report_id) {
|
|
|
String name = studao.findById(report_id);
|
|
|
if(name == null || name.equals("null")) { return report_id;}
|
|
@@ -465,6 +584,97 @@ public class AnalyzeService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public AnalysePeopleVO getReviewAnalysePeopleVO(String caseId,String taskId,String workerId) {
|
|
|
+ Task task=taskDao.findById(taskId);
|
|
|
+ AnalysePeopleVO res = new AnalysePeopleVO();
|
|
|
+ if(task!=null)res.setTaskName(task.getName());
|
|
|
+ String caseTakeId = caseId+"-"+taskId;
|
|
|
+ // 部分数据从主战接口中取得
|
|
|
+ String result = HTTP.sendGet("http://114.55.91.83:8191/api/user/" + workerId, "");
|
|
|
+ if (result != null && !result.equals("")) {
|
|
|
+ JSONObject json = new JSONObject(result);
|
|
|
+ if (json.has("name") && !json.isNull("name")) {
|
|
|
+ res.setName(DataMaskingUtil.nameMasking(json.getString("name")));
|
|
|
+ }
|
|
|
+ if (json.has("school") && !json.isNull("school")) {
|
|
|
+ res.setSchool( json.getString("school"));
|
|
|
+ }
|
|
|
+ if (json.has("province") && !json.isNull("province")) {
|
|
|
+ res.setProvince(json.getString("province"));
|
|
|
+ }
|
|
|
+ if (json.has("city") && !json.isNull("city")) {
|
|
|
+ res.setCity(json.getString("city"));
|
|
|
+ }
|
|
|
+ if (json.has("createTime") && !json.isNull("createTime")) {
|
|
|
+ res.setRegisterTime(json.getLong("createTime"));
|
|
|
+ }
|
|
|
+ res.setPhotoUrl(DataMaskingUtil.getDefaultMooctestUrl());//使用默认的慕测头像
|
|
|
+// if (json.has("photoUrl") && !json.isNull("photoUrl")) {
|
|
|
+// res.setPhotoUrl(json.getString("photoUrl"));
|
|
|
+// }
|
|
|
+ }
|
|
|
+ //用户lebels
|
|
|
+ res.setLabels(getUserLabels(workerId));
|
|
|
+ Report userReport = extraService.findByWorker(caseTakeId,workerId);
|
|
|
+ List<Bug> bugList = extraService.getBugList(userReport.getId(),caseTakeId);
|
|
|
+ Collections.sort(bugList, Comparator.comparing(Bug::getCreate_time_millis));
|
|
|
+ JSONArray array=new JSONArray();
|
|
|
+// Map<String,Integer> severityCount = new HashMap<>();
|
|
|
+// int [] severityValueCount = new int[5];
|
|
|
+ for(Bug bug : bugList){
|
|
|
+// severityValueCount[bug.getSeverity()]++;
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("content",bug.getTitle());
|
|
|
+ object.put("timestamp", TimeUtil.timestamp2MonthDayHour(bug.getCreate_time_millis(),8));
|
|
|
+ array.put(object);
|
|
|
+ }
|
|
|
+// int severityMax = Arrays.stream(severityValueCount).max().getAsInt();
|
|
|
+// for(int i = 0 ;i<severityValueCount.length;i++){
|
|
|
+// severityCount.put(BugSeverity.getValue(i).toString(),severityValueCount[i]*100/severityMax);
|
|
|
+// }
|
|
|
+ JSONArray radarLabel = new JSONArray();
|
|
|
+ JSONArray radarData = new JSONArray();
|
|
|
+ for(int i =0;i<radarInfo.length;i++){
|
|
|
+ radarLabel.put(radarInfo[i]);
|
|
|
+ radarData.put(radarValueStart[i]+workerId.length()>4?workerId.charAt(i)-'0':0);
|
|
|
+ }
|
|
|
+ JSONObject userRadar = new JSONObject();
|
|
|
+ userRadar.put("labels",radarLabel);
|
|
|
+ userRadar.put("data",radarData);
|
|
|
+ res.setUserRadar(userRadar);
|
|
|
+ res.setFirstActivate(bugList.size()==0?0:Long.parseLong(bugList.get(0).getCreate_time_millis()));
|
|
|
+ res.setLastActivate(bugList.size()==0?0:Long.parseLong(bugList.get(bugList.size()-1).getCreate_time_millis()));
|
|
|
+ res.setBugList(bugList);
|
|
|
+ res.setTimeLine(array);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getTimeDistribute(String workerId){
|
|
|
+ List<Report>reports=reportDao.findReportsByWorker(String.valueOf(workerId));
|
|
|
+ reports = reports.stream().filter(e->{
|
|
|
+ return Long.parseLong(e.getCreate_time_millis()) > monthAgoStart(5);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ List<Bug> bugs = new ArrayList<>();
|
|
|
+ for(Report report : reports){
|
|
|
+ bugs.addAll(bdao.findByReport(report.getId(),report.getCase_take_id()));
|
|
|
+ }
|
|
|
+ Map<String,Integer> data = new HashMap<>(6);
|
|
|
+ for(Bug bug : bugs){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private long monthAgoStart(int offset){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ calendar.add(Calendar.MONTH, -offset);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH,1);
|
|
|
+ return calendar.getTimeInMillis();
|
|
|
+ }
|
|
|
+
|
|
|
public AnalyseVO getReviewAnalyseVO(String caseId, String taskId){
|
|
|
Task task=taskDao.findById(taskId);
|
|
|
long startTime=0;
|
|
@@ -573,5 +783,405 @@ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户信息获取用户的labels
|
|
|
+ * @param wordkId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getUserLabels(String wordkId){
|
|
|
+ List<UserLabel> labels = userLabelDao.findLabelsByWorkerId(wordkId);
|
|
|
+ List<String> userLabels = labels.stream().map(UserLabel::getLabel).collect(Collectors.toList());
|
|
|
+ userLabels.addAll(mockLabels);
|
|
|
+ return userLabels;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public AnalyseVO2 getReviewAnalyseVO2(String caseId, String taskId){
|
|
|
+
|
|
|
+// Cache<String,String> cache = CacheBuilder.newBuilder().build();
|
|
|
+// cache.put("word","Hello Guava Cache");
|
|
|
+// System.out.println(cache.getIfPresent("word"));
|
|
|
+
|
|
|
+ Exam exam = examDao.findById(caseId);
|
|
|
+ Task task=taskDao.findById(taskId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ long startTime=0;
|
|
|
+ long endTime=0;
|
|
|
+ String taskName="";
|
|
|
+ double writeMins=0.0;
|
|
|
+ if(task!=null) {
|
|
|
+ startTime = task.getStart_time();
|
|
|
+ endTime = task.getEnd_time();
|
|
|
+ writeMins = task.getTotal_mins();
|
|
|
+ }
|
|
|
+ if(exam!=null){
|
|
|
+ taskName = exam.getName();
|
|
|
+ }
|
|
|
+ String caseTakeId=caseId+"-"+taskId;
|
|
|
+ List<Bug>bugs=bdao.findByCaseid(caseTakeId);
|
|
|
+ int bugNum=bugs.size();
|
|
|
+ List<Report>reports=reportDao.findByCaseTakeId(caseTakeId);
|
|
|
+ List<String>reportIds=new ArrayList<>();
|
|
|
+ int reportNum=reports.size();
|
|
|
+ int testCaseNum=0;
|
|
|
+
|
|
|
+ Map<String,String>reportWorkerMap=new HashMap<>();
|
|
|
+ for(Report report:reports){
|
|
|
+ reportIds.add(report.getId());
|
|
|
+ reportWorkerMap.put(report.getId(),report.getWorker_id());
|
|
|
+ }
|
|
|
+ List<TestCase>testCases=testCaseDao.findByReports(reportIds);
|
|
|
+ testCaseNum+=testCases.size();
|
|
|
+ List<BugMirror>bugMirrors=mdao.findByCase(caseTakeId);
|
|
|
+ int likeNum=0;
|
|
|
+ int dislikeNum=0;
|
|
|
+ for(BugMirror bugMirror:bugMirrors){
|
|
|
+ if(bugMirror.getGood()!=null){
|
|
|
+ likeNum+=bugMirror.getGood().size();
|
|
|
+ }
|
|
|
+ if(bugMirror.getBad()!=null){
|
|
|
+ dislikeNum+=bugMirror.getBad().size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String>bugIds=new ArrayList<>();
|
|
|
+ Map<String,String>bugWorkerMap=new HashMap<>();
|
|
|
+ for(Bug bug:bugs){
|
|
|
+ bugIds.add(bug.getId());
|
|
|
+ String reportId=bug.getReport_id();
|
|
|
+ if(reportId!=null) {
|
|
|
+ String workerId=reportWorkerMap.get(reportId);
|
|
|
+ if (workerId!=null) {
|
|
|
+ bugWorkerMap.put(bug.getId(),workerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Integer,Integer>gradeDistribution=new HashMap<>();
|
|
|
+ Map<String,Integer>workerDistribution=new HashMap<>();
|
|
|
+ List<BugScore>bugScores=bsdao.findByIds(bugIds);
|
|
|
+ for(BugScore bugScore:bugScores){
|
|
|
+ int grade = bugScore.getGrade();
|
|
|
+ String workerId=bugWorkerMap.get(bugScore.getId());
|
|
|
+ if(workerId!=null){
|
|
|
+ if (workerDistribution.containsKey(workerId)) {
|
|
|
+ workerDistribution.replace(workerId, workerDistribution.get(workerId) + grade);
|
|
|
+ } else {
|
|
|
+ workerDistribution.put(workerId, grade);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (gradeDistribution.containsKey(grade)) {
|
|
|
+ gradeDistribution.replace(grade, gradeDistribution.get(grade) + 1);
|
|
|
+ } else {
|
|
|
+ gradeDistribution.put(grade, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int forkNum=0;
|
|
|
+ List<BugHistory>bugHistories=bugHistoryDao.findBugHistoryList(bugIds);
|
|
|
+ for(BugHistory bugHistory:bugHistories){
|
|
|
+ if(bugHistory.getChildren()!=null&&bugHistory.getChildren().size()!=0){
|
|
|
+ forkNum+=1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //分数排序
|
|
|
+ List<Map.Entry<String, Integer>> list = new ArrayList<>(workerDistribution.entrySet());
|
|
|
+ Collections.sort(list, new Comparator<Map.Entry<String, Integer>>()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2)
|
|
|
+ {
|
|
|
+ return o2.getValue().compareTo(o1.getValue());
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<WorkerVO>workerRank=new ArrayList<>();
|
|
|
+ Map<String,Integer>provinceDistribute=new HashMap<>();
|
|
|
+ for(int i=0;i<list.size();i++) {
|
|
|
+ String workerId = list.get(i).getKey();
|
|
|
+ int grade=list.get(i).getValue();
|
|
|
+ String result = HTTP.sendGet("http://114.55.91.83:8191/api/user/" + workerId, "");
|
|
|
+ String name = "";
|
|
|
+ String school = "";
|
|
|
+ String province="";
|
|
|
+ if (result != null && !result.equals("")) {
|
|
|
+ JSONObject json = new JSONObject(result);
|
|
|
+ if (json.has("name") && !json.isNull("name")) {
|
|
|
+// name = json.getString("name");
|
|
|
+ name = DataMaskingUtil.nameMasking(json.getString("name"));
|
|
|
+ }
|
|
|
+ if (json.has("school") && !json.isNull("school")) {
|
|
|
+ school = json.getString("school");
|
|
|
+ }
|
|
|
+ if (json.has("province") && !json.isNull("province")) {
|
|
|
+ province = json.getString("province");
|
|
|
+ if(province.endsWith("省")||province.endsWith("市")){
|
|
|
+ province=province.substring(0,province.length()-1);
|
|
|
+ }
|
|
|
+ if (provinceDistribute.containsKey(province)) {
|
|
|
+ provinceDistribute.replace(province, provinceDistribute.get(province) + 1);
|
|
|
+ } else {
|
|
|
+ provinceDistribute.put(province, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WorkerVO workerVO=new WorkerVO(workerId,name,school,grade);
|
|
|
+ workerRank.add(workerVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray workerDistribute=new JSONArray();
|
|
|
+ for(Map.Entry<String, Integer> entry : provinceDistribute.entrySet()){
|
|
|
+ String mapKey = entry.getKey();
|
|
|
+ int mapValue = entry.getValue();
|
|
|
+ JSONObject jsonObject=new JSONObject();
|
|
|
+ jsonObject.put("name",mapKey);
|
|
|
+ jsonObject.put("value",mapValue);
|
|
|
+ workerDistribute.put(jsonObject);
|
|
|
+ }
|
|
|
+ Map<String,Integer>coverMap=getPageCover(taskId,caseId);
|
|
|
+ int size=coverMap.size();
|
|
|
+ int noBugPage=0;
|
|
|
+ for (Map.Entry<String, Integer> entry : coverMap.entrySet()) {
|
|
|
+ if(entry.getValue()==0){
|
|
|
+ noBugPage++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double pageCover=1 - noBugPage*1.0/size;
|
|
|
+ AnalyseVO2 analyseVO=new AnalyseVO2(likeNum,dislikeNum,forkNum,reportNum,testCaseNum,bugNum,startTime,endTime,reportNum,taskName,workerDistribute,workerRank,gradeDistribution,pageCover);
|
|
|
+ StringBuffer managerCheckUrl = new StringBuffer("http://");
|
|
|
+ managerCheckUrl.append(serverHost).append(":").append(serverPort).append("/report/managerCheck/")
|
|
|
+ .append(taskId).append("/").append(caseId);
|
|
|
+ if(reports.size()!=0)
|
|
|
+ managerCheckUrl.append("?identity=0&report_id=").append(reports.get(0).getId())
|
|
|
+ .append("&worker_id=").append(reports.get(0).getWorker_id());
|
|
|
+ analyseVO.setManagerCheck(managerCheckUrl.toString());
|
|
|
+ return analyseVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String,Integer> getPageCover(String taskId,String caseId){
|
|
|
+ String caseTakeId=caseId+"-"+taskId;
|
|
|
+ Map<String,Integer>coverMap=getBugDetail(caseTakeId);
|
|
|
+ List<String>pageStr=getPageStr(caseId);
|
|
|
+ for(String page:pageStr){
|
|
|
+ if(!coverMap.containsKey(page)){
|
|
|
+ coverMap.put(page,0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return coverMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将三级页面信息的jsonobject转为string
|
|
|
+ private List<String> getPageStr(String caseId){
|
|
|
+ List<String>result=new ArrayList<>();
|
|
|
+ Exam exam=extraService.getExam(String.valueOf(caseId));
|
|
|
+ JSONArray jsonArray=new JSONArray(exam.getJson());
|
|
|
+ LinkedList<String> res = new LinkedList<>();
|
|
|
+ if(jsonArray==null){
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ for(int i=0;i<jsonArray.length();i++){
|
|
|
+ JSONObject jsonObject=jsonArray.getJSONObject(i);
|
|
|
+ if(jsonObject==null||jsonObject.getString("item")==null)
|
|
|
+ return res;
|
|
|
+ solve(jsonObject, jsonObject.getString("item")+"-", res);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void solve(JSONObject jsonObject, String cur, LinkedList<String> res) {
|
|
|
+ if(jsonObject==null||jsonObject.getString("item")==null)
|
|
|
+ return;
|
|
|
+ cur+=jsonObject.getString("item");
|
|
|
+ if (!jsonObject.has("children")||jsonObject.get("children")==null) {
|
|
|
+ res.add(cur);
|
|
|
+ } else {
|
|
|
+ JSONArray jsonArray=jsonObject.getJSONArray("children");
|
|
|
+ for(int i=0;i<jsonArray.length();i++){
|
|
|
+ JSONObject jsonObject1=jsonArray.getJSONObject(i);
|
|
|
+ solve(jsonObject1,cur+"-",res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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<String,Integer> getBugSubmitInfo(String taskId,String caseId,int piece){
|
|
|
+ Map<Integer,Integer>map=new HashMap<>(piece);
|
|
|
+ Map<String,Integer> res = new HashMap<>(piece);
|
|
|
+ if(piece<=0)return res;
|
|
|
+ Task task=taskDao.findById(taskId);
|
|
|
+ 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);
|
|
|
+ map.put(0,0);
|
|
|
+ for(Bug bug:bugs){
|
|
|
+ long time=Long.parseLong(bug.getCreate_time_millis());
|
|
|
+ int index=(int)((time-startTime)/pieceTime)+1;
|
|
|
+ if(map.containsKey(index)){
|
|
|
+ map.replace(index,map.get(index)+1);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ map.put(index,1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(Map.Entry<Integer,Integer> e : map.entrySet()){
|
|
|
+ res.put(TimeUtil.timestamp2DayHour(startTime+e.getKey()*pieceTime,8),e.getValue());
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ShortToken tokenToDetail(String token){
|
|
|
+ return shortTokenDao.findByTokenString(token);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ShortToken findTokenByDetail(String examId,String caseID,String userId){
|
|
|
+ return shortTokenDao.findByDetailInfo(examId,caseID,userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String saveShortToken(ShortToken shortToken){
|
|
|
+ return shortTokenDao.save(shortToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Double crowdTestProgressFromDB(String caseId,String taskId){
|
|
|
+ String case_take_id=caseId+"-"+taskId;
|
|
|
+ CrowdTest crowdTest=crowdTestDao.findByCaseTakeId(case_take_id);
|
|
|
+ if(crowdTest==null){
|
|
|
+ return crowdTestProgress(caseId,taskId);
|
|
|
+ }else{
|
|
|
+ return crowdTest.getProgress();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Double crowdTestProgress(String caseId,String taskId) {
|
|
|
+ SimpleDateFormat formatLine = new SimpleDateFormat ("yyyy/MM/dd HH:mm");
|
|
|
+ SimpleDateFormat formatCon = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<BugForProgress> bugForProgressList=new ArrayList<>();
|
|
|
+ String caseTakeId=caseId+"-"+taskId;
|
|
|
+ List<Report> reportList = reportDao.findByCaseTakeId(caseTakeId);
|
|
|
+ for (Report report : reportList) {
|
|
|
+ String reportId = report.getId();
|
|
|
+ List<TestCase> testCaseList = testCaseDao.findByReport(reportId);
|
|
|
+ for (TestCase testCase : testCaseList) {
|
|
|
+ String testCaseId = testCase.getId();
|
|
|
+ List<String> bugIdList = ctbdao.findById(testCaseId);
|
|
|
+ for (String bugId : bugIdList) {
|
|
|
+ Bug bug = bdao.findByid(bugId);
|
|
|
+ if (bug != null) {
|
|
|
+ BugForProgress bugForProgress = new BugForProgress();
|
|
|
+ bugForProgress.setId(bugId);
|
|
|
+ bugForProgress.setTestCaseId(testCaseId);
|
|
|
+ bugForProgress.setTestCaseName(testCase.getName());
|
|
|
+ bugForProgress.setUserId(report.getWorker_id());
|
|
|
+ //bug基本属性
|
|
|
+ bugForProgress.setSeverity(TransUtil.severityTransFromInt(bug.getSeverity()));
|
|
|
+ bugForProgress.setBugPage(bug.getBug_page());
|
|
|
+ bugForProgress.setTitle(bug.getTitle());
|
|
|
+ bugForProgress.setDescription(bug.getDescription());
|
|
|
+ String time = TransUtil.formatTimeMillis(bug.getCreate_time_millis());
|
|
|
+ time = transferString(time);
|
|
|
+ Date submitTime = null;
|
|
|
+ try {
|
|
|
+ if (time.contains("-")) {
|
|
|
+ submitTime = formatCon.parse(time);
|
|
|
+ } else {
|
|
|
+ submitTime = formatLine.parse(time);
|
|
|
+ }
|
|
|
+ }catch (ParseException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ bugForProgress.setBugCreateTime(submitTime);
|
|
|
+ bugForProgressList.add(bugForProgress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bugForProgressList.sort(new Comparator<BugForProgress>() {
|
|
|
+ @Override
|
|
|
+ public int compare(BugForProgress o1, BugForProgress o2) {
|
|
|
+ Date d1 = o1.getBugCreateTime();
|
|
|
+ Date d2 = o2.getBugCreateTime();
|
|
|
+ if (d1.before(d2)) {
|
|
|
+ return -1;
|
|
|
+ } else {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ TaskClosePrediction closePrediction = new TaskClosePrediction();
|
|
|
+ Double completeRatio = closePrediction.determineTaskProgressStatus(bugForProgressList);
|
|
|
+ completeRatio = completeRatio.intValue() * 1.0;
|
|
|
+ CrowdTest crowdTest=new CrowdTest();
|
|
|
+ crowdTest.setCaseId(caseId);
|
|
|
+ crowdTest.setTaskId(taskId);
|
|
|
+ crowdTest.setId(caseTakeId);
|
|
|
+ crowdTest.setCaseTakeId(caseTakeId);
|
|
|
+ crowdTest.setProgress(completeRatio);
|
|
|
+ crowdTestDao.save(crowdTest);
|
|
|
+ return completeRatio;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String transferString ( String str ){
|
|
|
+ String result = str;
|
|
|
+ result = result.replaceAll( "\r\n", " " );
|
|
|
+ result = result.replaceAll( "\r", " " );
|
|
|
+ result = result.replaceAll( "\n", " " );
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|