Search in sources :

Example 1 with ScoreCount

use of cn.edu.zjnu.acm.judge.data.dto.ScoreCount in project judge by zjnu-acm.

the class ProblemStatusController method status.

@GetMapping("/problemstatus")
@SuppressWarnings("AssignmentToMethodParameter")
public String status(HttpServletRequest request, @RequestParam("problem_id") long id, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Authentication authentication) {
    log.debug("{}", pageable);
    if (pageable.getPageSize() > 500) {
        pageable = new PageRequest(pageable.getPageNumber(), 500, pageable.getSort());
    }
    Problem problem = problemService.findOneNoI18n(id);
    List<ScoreCount> list = submissionMapper.groupByScore(null, id);
    ArrayList<String> scores = new ArrayList<>(list.size());
    ArrayList<Long> counts = new ArrayList<>(list.size());
    ArrayList<String> urls = new ArrayList<>(list.size());
    for (ScoreCount scoreCount : list) {
        int score = scoreCount.getScore();
        scores.add(ResultType.getShowsourceString(score));
        counts.add(scoreCount.getCount());
        urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score);
    }
    Page<Submission> page = submissionService.bestSubmission(null, id, pageable, problem.getSubmitUser());
    boolean isAdmin = UserDetailsServiceImpl.isAdminLoginned(request);
    boolean isSourceBrowser = UserDetailsServiceImpl.isSourceBrowser(request);
    boolean canView = isAdmin || isSourceBrowser;
    request.setAttribute("page", page);
    request.setAttribute("sa", Arrays.asList(counts, scores, urls));
    request.setAttribute("problem", problem);
    request.setAttribute("url", URLBuilder.fromRequest(request).replaceQueryParam("page").toString());
    request.setAttribute("canView", canView);
    request.setAttribute("authentication", authentication);
    return "problems/status";
}
Also used : Submission(cn.edu.zjnu.acm.judge.domain.Submission) ArrayList(java.util.ArrayList) ScoreCount(cn.edu.zjnu.acm.judge.data.dto.ScoreCount) PageRequest(org.springframework.data.domain.PageRequest) Problem(cn.edu.zjnu.acm.judge.domain.Problem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with ScoreCount

use of cn.edu.zjnu.acm.judge.data.dto.ScoreCount in project judge by zjnu-acm.

the class ContestProblemController method status.

@GetMapping(value = "{pid}/status", produces = TEXT_HTML_VALUE)
public String status(@PathVariable("contestId") long contestId, @PathVariable("pid") int problemNum, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Model model, Authentication authentication, HttpServletRequest request) {
    // check if problem exists and not disabled
    contestService.findOneByIdAndNotDisabled(contestId);
    Problem problem = contestService.getProblem(contestId, problemNum, null);
    Page<Submission> page = submissionService.bestSubmission(contestId, problem.getOrigin(), pageable, problem.getSubmitUser());
    model.addAttribute("page", page);
    List<ScoreCount> list = submissionMapper.groupByScore(contestId, problem.getOrigin());
    ArrayList<String> scores = new ArrayList<>(list.size());
    ArrayList<Long> counts = new ArrayList<>(list.size());
    ArrayList<String> urls = new ArrayList<>(list.size());
    for (ScoreCount scoreCount : list) {
        int score = scoreCount.getScore();
        scores.add(ResultType.getShowsourceString(score));
        counts.add(scoreCount.getCount());
        urls.add(request.getContextPath() + "/status?contest_id=" + contestId + "&problem_id=" + problem.getOrigin() + "&score=" + score);
    }
    boolean isAdmin = UserDetailsServiceImpl.isAdminLoginned(request);
    boolean isSourceBrowser = UserDetailsServiceImpl.isSourceBrowser(request);
    boolean canView = isAdmin || isSourceBrowser;
    request.setAttribute("page", page);
    request.setAttribute("sa", Arrays.asList(counts, scores, urls));
    request.setAttribute("problem", problem);
    request.setAttribute("url", URLBuilder.fromRequest(request).replaceQueryParam("page").toString());
    request.setAttribute("contestId", contestId);
    request.setAttribute("canView", canView);
    request.setAttribute("authentication", authentication);
    return "contests/problems-status";
}
Also used : ScoreCount(cn.edu.zjnu.acm.judge.data.dto.ScoreCount) Submission(cn.edu.zjnu.acm.judge.domain.Submission) ArrayList(java.util.ArrayList) Problem(cn.edu.zjnu.acm.judge.domain.Problem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ScoreCount (cn.edu.zjnu.acm.judge.data.dto.ScoreCount)2 Problem (cn.edu.zjnu.acm.judge.domain.Problem)2 Submission (cn.edu.zjnu.acm.judge.domain.Submission)2 ArrayList (java.util.ArrayList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 PageRequest (org.springframework.data.domain.PageRequest)1