Search in sources :

Example 6 with BestSubmissionForm

use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm in project judge by zjnu-acm.

the class ContestProblemController method status.

@GetMapping("{pid}/status")
public String status(@PathVariable("contestId") long contestId, @PathVariable("pid") int problemNum, @RequestParam(value = "language", required = false) Integer language, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Model model, HttpServletRequest request) {
    // check if problem exists and not disabled
    contestService.findOneByIdAndNotDisabled(contestId);
    Problem problem = contestService.getProblem(contestId, problemNum, null);
    BestSubmissionForm form = BestSubmissionForm.builder().contestId(contestId).problemId(problem.getOrigin()).language(language).build();
    Page<Submission> page = submissionService.bestSubmission(form, 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.isAdministrator(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", URIBuilder.fromRequest(request).replaceQueryParam("page").toString());
    request.setAttribute("contestId", contestId);
    request.setAttribute("canView", canView);
    request.setAttribute("currentUserId", SecurityUtils.getUserId());
    return "contests/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) Problem(cn.edu.zjnu.acm.judge.domain.Problem) BestSubmissionForm(cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

BestSubmissionForm (cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm)6 Submission (cn.edu.zjnu.acm.judge.domain.Submission)3 Pageable (org.springframework.data.domain.Pageable)3 ScoreCount (cn.edu.zjnu.acm.judge.data.dto.ScoreCount)2 Problem (cn.edu.zjnu.acm.judge.domain.Problem)2 ArrayList (java.util.ArrayList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 StreamSupport (java.util.stream.StreamSupport)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Param (org.apache.ibatis.annotations.Param)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 PageImpl (org.springframework.data.domain.PageImpl)1 Sort (org.springframework.data.domain.Sort)1