| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- package edu.nju.service;
- import java.util.*;
- import edu.nju.dao.BugDao;
- import edu.nju.entities.Bug;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import edu.nju.dao.BugHistoryDao;
- import edu.nju.dao.BugMirrorDao;
- import edu.nju.dao.BugPageDao;
- import edu.nju.entities.BugHistory;
- import edu.nju.entities.BugMirror;
- import edu.nju.entities.BugPage;
- @Service
- public class HistoryService {
-
- @Autowired
- BugHistoryDao historydao;
-
- @Autowired
- BugMirrorDao mirrordao;
-
- @Autowired
- BugPageDao pagedao;
-
- @Autowired
- RecommendService recservice;
-
- @Autowired
- AnalyzeService aservice;
- @Autowired
- BugPageDao bugPageDao;
- @Autowired
- BugDao bugDao;
-
- public BugHistory getHistory(String id) {
- return historydao.findByid(id);
- }
-
- public List<String> parents(String id) {
- Stack<String> stack = new Stack<String>();
- List<String> result = new ArrayList<String>();
- String parent = getHistory(id).getParent();
- while(!parent.equals("null")) {
- stack.push(parent);
- parent = getHistory(parent).getParent();
- }
- while(!stack.isEmpty()) {
- result.add(stack.pop());
- }
- result.add(id);
- return result;
- }
-
- public List<BugMirror> getNew(String case_take_id, String report_id) {
- List<String> ids = historydao.findRoots(recservice.getListIds(case_take_id));
- List<String> filter = new ArrayList<String>();
- if(ids.size() > 2) {
- int n = ids.size();
- filter.add(ids.get(n - 1));
- filter.add(ids.get(n - 2));
- } else {
- for(String id : ids) {
- filter.add(id);
- }
- }
- return mirrordao.findByIds(filter, report_id);
- }
-
- public List<String> getRoots(String case_take_id) {
- return historydao.findRoots(aservice.getValid(case_take_id));
- }
-
- public List<String> getTreeRoots(String case_take_id) {
- List<String> all = new ArrayList<String>();
- for(String id : getRoots(case_take_id)) {
- if(getHistory(id).getChildren().size() > 0) { all.add(id); }
- }
- return all;
- }
-
- public List<String> getInvalid(Set<String> ids) {
- List<String> result = new ArrayList<String>();
- for(String id: ids) {
- if(!mirrordao.findById(id).isFlag()) {result.add(id);}
- }
- return result;
- }
-
- public List<String> getInvalid(List<String> ids) {
- List<String> result = new ArrayList<String>();
- for(String id: ids) {
- if(!mirrordao.findById(id).isFlag()) {result.add(id);}
- }
- return result;
- }
- //单一状bug热度排序
- public void hotSortSingle(List<String> ids){
- Collections.shuffle(ids);
- ids.sort(new Comparator<String>() {
- public int compare(String id1, String id2) {
- BugMirror bugMirror1=mirrordao.findById(id1);
- BugMirror bugMirror2=mirrordao.findById(id2);
- return (bugMirror1.getGood().size()+bugMirror1.getBad().size()) - (bugMirror2.getGood().size()+bugMirror2.getBad().size());
- }
- });
- }
- //树状bug热度排序
- public void hotSortTree(List<String> ids){
- Collections.shuffle(ids);
- ids.sort(new Comparator<String>() {
- public int compare(String id1, String id2) {
- int hot1= getTreeHot(id1);
- int hot2= getTreeHot(id2);
- return hot1-hot2;
- }
- });
- }
- //获取树状bug热度
- private int getTreeHot(String id){
- BugHistory bugHistory=historydao.findByid(id);
- if(bugHistory.getChildren().size()==0){
- BugMirror bugMirror=mirrordao.findById(id);
- return bugMirror.getGood().size()+bugMirror.getBad().size();
- }else{
- BugMirror bugMirror=mirrordao.findById(id);
- int hot=bugMirror.getGood().size()+bugMirror.getBad().size();
- for(String childId:bugHistory.getChildren()){
- hot+=getTreeHot(childId);
- }
- return hot;
- }
- }
-
- public Set<String> filter(List<List<String>> lists) {
- Set<String> set = new HashSet<String>();
- for(List<String> list : lists) {
- for(String id: list) {
- set.add(id);
- }
- }
- return set;
- }
-
- //获取评分时树的信息
- public List<String> getDetail(String id) {
- List<String> result = new ArrayList<String>();
- List<List<String>> paths = getDepth(id);
- List<Set<String>> widths = new ArrayList<Set<String>>();
- Set<String> ids = new HashSet<String>();
- int max_height = 0;
- int max_width = 0;
- int count = 0;
- String flag = "true";
- for(List<String> path: paths) {
- max_height = Math.max(max_height, path.size());
- for(int i = 0; i < path.size(); i ++) {
- String temp = path.get(i);
- ids.add(temp);
- if(widths.size() <= i) {
- Set<String> set = new HashSet<String>();
- set.add(temp);
- widths.add(set);
- }
- else {widths.get(i).add(temp);}
- }
- }
- for(Set<String> width: widths) {
- max_width = Math.max(max_width, width.size());
- }
- for(String str: ids) {
- if(aservice.getGrade(str) == -1) {
- flag = "false";
- break;
- }
- }
- count = ids.size();
- result.add(id);
- result.add(Integer.toString(max_width));
- result.add(Integer.toString(max_height));
- result.add(Integer.toString(count));
- result.add(flag);
- result.add(recservice.getTitle(id));
- return result;
- }
-
- public void pageFilter(List<String> all, String page) {
- if(page.equals("null")) { return; }
- List<BugPage> mirrors = pagedao.findByIds(all);
- String[] pages = page.split("-");
- for(BugPage mirror : mirrors) {
- if(pages.length > 0 && !mirror.getPage1().equals(pages[0])) {
- all.remove(mirror.getId());
- continue;
- }
- if(pages.length > 1 && !mirror.getPage2().equals(pages[1])) {
- all.remove(mirror.getId());
- continue;
- }
- if(pages.length > 2 && !mirror.getPage3().equals(pages[2])) {
- all.remove(mirror.getId());
- continue;
- }
- }
- }
-
- public List<List<String>> getDepth(String id) {
- BugHistory root = historydao.findByid(id);
- List<List<String>> result = new ArrayList<List<String>>();
- if(root == null) { return result;}
- List<String> list = new ArrayList<String>();
- list.add(root.getId());
- dfs(root, result, list);
- return result;
- }
-
- private void dfs(BugHistory root, List<List<String>> result, List<String> list) {
- List<String> children = root.getChildren();
- if(children.size() != 0) {
- for(String child : children) {
- list.add(child);
- dfs(historydao.findByid(child), result, list);
- list.remove(child);
- }
- } else {
- result.add(new ArrayList<String>(list));
- }
- }
- public List<String> getBugIdListByPage(String case_take_id,String page,String start,String count){
- List<BugPage> bugPageList=bugPageDao.findByPage(case_take_id,page,start,count);
- List<String> bugIdList=new ArrayList<>();
- for(BugPage bugPage:bugPageList){
- bugIdList.add(bugPage.getId());
- }
- return bugIdList;
- }
- }
|