|
@@ -1,5 +1,6 @@
|
|
|
package edu.nju.service;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
import edu.nju.dao.*;
|
|
@@ -9,8 +10,16 @@ import edu.nju.util.HTTP;
|
|
|
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.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 {
|
|
@@ -50,6 +59,9 @@ public class AnalyzeService {
|
|
|
|
|
|
@Autowired
|
|
|
TestCaseDao testCaseDao;
|
|
|
+
|
|
|
+
|
|
|
+ Logger logger= LoggerFactory.getLogger(RecommendService.class);
|
|
|
|
|
|
//获取所有bug
|
|
|
public List<String> getValid(String case_take_id) {
|
|
@@ -213,83 +225,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);
|
|
|
-
|
|
|
- //计算审查得分
|
|
|
- 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);
|
|
|
+// 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);
|
|
|
+// }
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
@@ -413,24 +464,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.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;}
|