|
@@ -2,7 +2,10 @@ package edu.nju.service;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.google.common.cache.Cache;
|
|
|
+import com.google.common.cache.CacheBuilder;
|
|
|
import edu.nju.dao.*;
|
|
|
import edu.nju.entities.*;
|
|
|
import edu.nju.model.*;
|
|
@@ -61,9 +64,22 @@ public class AnalyzeService {
|
|
|
@Autowired
|
|
|
TestCaseDao testCaseDao;
|
|
|
|
|
|
+
|
|
|
@Value("${mainsite.url}")
|
|
|
String mainSiteUrl;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ThumsUpDao thumsUpDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BugHistoryDao bugHistoryDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserLabelDao userLabelDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExtraService extraService;
|
|
|
+
|
|
|
|
|
|
Logger logger= LoggerFactory.getLogger(RecommendService.class);
|
|
|
|
|
@@ -545,6 +561,53 @@ 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(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"));
|
|
|
+ }
|
|
|
+ if (json.has("photoUrl") && !json.isNull("photoUrl")) {
|
|
|
+ res.setPhotoUrl(json.getString("photoUrl"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ res.setLabels(getUserLabels(workerId));
|
|
|
+ Report userReport = extraService.findByWorker(caseTakeId,workerId);
|
|
|
+ List<Bug> bugList = extraService.getBugList(userReport.getId(),caseTakeId);
|
|
|
+ long firstActivate = Long.MAX_VALUE ;
|
|
|
+ long lastActivate = 0 ;
|
|
|
+ long cur ;
|
|
|
+ for(Bug bug : bugList){
|
|
|
+ cur = Long.parseLong(bug.getCreate_time_millis());
|
|
|
+ if(firstActivate>cur)firstActivate = cur;
|
|
|
+ if(lastActivate<cur)lastActivate=cur;
|
|
|
+ }
|
|
|
+ if(firstActivate == Long.MAX_VALUE)firstActivate = 0 ;
|
|
|
+ res.setFirstActivate(firstActivate);
|
|
|
+ res.setLastActivate(lastActivate);
|
|
|
+ res.setBugList(bugList);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
public AnalyseVO getReviewAnalyseVO(String caseId, String taskId){
|
|
|
Task task=taskDao.findById(taskId);
|
|
|
long startTime=0;
|
|
@@ -684,5 +747,153 @@ public class AnalyzeService {
|
|
|
return historicalDataVO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 根据用户信息获取用户的labels
|
|
|
+ * @param wordkId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getUserLabels(String wordkId){
|
|
|
+ List<UserLabel> labels = userLabelDao.findLabelsByWorkerId(wordkId);
|
|
|
+ return labels.stream().map(UserLabel::getLabel).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public AnalyseVO2 getReviewAnalyseVO2(String caseId, String taskId){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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();
|
|
|
+ taskName = task.getName();
|
|
|
+ writeMins = task.getTotal_mins();
|
|
|
+ }
|
|
|
+ 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<ThumsUp>thumsUps=thumsUpDao.findByReports(reportIds);
|
|
|
+ int likeNum=0;
|
|
|
+ int dislikeNum=0;
|
|
|
+ for(ThumsUp thumsUp:thumsUps){
|
|
|
+ if(thumsUp.getThums()!=null){
|
|
|
+ likeNum+=thumsUp.getThums().size();
|
|
|
+ }
|
|
|
+ if(thumsUp.getDiss()!=null){
|
|
|
+ dislikeNum+=thumsUp.getDiss().size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,Integer>workerDistribution=new HashMap<>();
|
|
|
+ List<String>bugIds=new ArrayList<>();
|
|
|
+ for(Bug bug:bugs){
|
|
|
+ bugIds.add(bug.getId());
|
|
|
+ String reportId=bug.getReport_id();
|
|
|
+ if(reportId!=null) {
|
|
|
+ String workerId=reportWorkerMap.get(reportId);
|
|
|
+ if (workerId!=null) {
|
|
|
+ int grade=0;
|
|
|
+ if (workerDistribution.containsKey(workerId)) {
|
|
|
+ workerDistribution.replace(workerId, workerDistribution.get(workerId) + grade);
|
|
|
+ } else {
|
|
|
+ workerDistribution.put(workerId, grade);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Integer,Integer>gradeDistribution=new HashMap<>();
|
|
|
+ List<BugScore>bugScores=bsdao.findByIds(bugIds);
|
|
|
+ for(BugScore bugScore:bugScores){
|
|
|
+ int grade = bugScore.getGrade();
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ AnalyseVO2 analyseVO=new AnalyseVO2(likeNum,dislikeNum,forkNum,reportNum,testCaseNum,bugNum,startTime,endTime,reportNum,taskName,workerDistribute,workerRank,gradeDistribution);
|
|
|
+ return analyseVO;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|