Search in sources :

Example 1 with BestSubmissionForm

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

the class BestSubmissionsBuilderTest method testBestSubmissions.

/**
 * Test of bestSubmissions method, of class BestSubmissionsBuilder.
 */
@Test
public void testBestSubmissions() {
    log.info("bestSubmissions");
    for (Pageable pageable : Pageables.bestSubmission()) {
        BestSubmissionForm form = BestSubmissionForm.builder().problemId(1000).build();
        log.debug(BestSubmissionsBuilder.bestSubmissions(form, pageable));
    }
}
Also used : Pageable(org.springframework.data.domain.Pageable) BestSubmissionForm(cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm) Test(org.junit.Test)

Example 2 with BestSubmissionForm

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

the class SubmissionService method bestSubmission.

public Page<Submission> bestSubmission(Long contestId, long problemId, Pageable pageable, long total) {
    BestSubmissionForm form = BestSubmissionForm.builder().contestId(contestId).problemId(problemId).build();
    List<Submission> bestSubmissions = submissionMapper.bestSubmission(form, pageable);
    return new PageImpl<>(bestSubmissions, pageable, total);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Submission(cn.edu.zjnu.acm.judge.domain.Submission) BestSubmissionForm(cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm)

Example 3 with BestSubmissionForm

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

the class BestSubmissionsBuilder method bestSubmissions.

public static String bestSubmissions(@Param("form") BestSubmissionForm form, @Param("pageable") Pageable pageable) {
    Long contestId = form.getContestId();
    long problemId = form.getProblemId();
    Set<String> dejaVu = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    Sort sort = Optional.ofNullable(pageable.getSort()).map(s -> s.and(DEFAULT_SORT)).orElse(DEFAULT_SORT);
    Sort.Order[] orders = StreamSupport.stream(sort.spliterator(), false).filter(order -> ALLOW_COLUMNS.contains(order.getProperty()) && dejaVu.add(order.getProperty())).toArray(Sort.Order[]::new);
    final int length = orders.length;
    log.debug("{}", Arrays.asList(orders));
    StringBuilder sb = new StringBuilder("select " + SubmissionMapper.LIST_COLUMNS + " from solution s where problem_id=").append(problemId).append(" and score=100 ");
    if (contestId != null) {
        sb.append("and contest_id=").append(contestId).append(' ');
    }
    for (int i = length - 1; i >= 0; --i) {
        sb.append("and(user_id");
        for (int j = 0; j <= i; ++j) {
            sb.append(',').append(orders[j].getProperty());
        }
        sb.append(")in(select user_id");
        for (int j = 0; j < i; ++j) {
            sb.append(',').append(orders[j].getProperty());
        }
        sb.append(',').append(orders[i].isAscending() ? "min" : "max").append("(").append(orders[i].getProperty()).append(")").append(orders[i].getProperty()).append(" from solution where problem_id=").append(problemId).append(" and score=100 ");
        if (contestId != null) {
            sb.append("and contest_id=").append(contestId).append(' ');
        }
    }
    for (int i = 0; i < length; ++i) {
        sb.append("group by user_id)");
    }
    if (length > 0) {
        sb.append(" order by ");
        for (int i = 0; i < length; ++i) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(orders[i].getProperty());
            if (!orders[i].isAscending()) {
                sb.append(" desc");
            }
        }
    }
    return sb.append(" limit ").append(pageable.getOffset()).append(",").append(pageable.getPageSize()).toString();
}
Also used : ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Arrays(java.util.Arrays) Slf4j(lombok.extern.slf4j.Slf4j) Param(org.apache.ibatis.annotations.Param) Optional(java.util.Optional) Set(java.util.Set) BestSubmissionForm(cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm) StreamSupport(java.util.stream.StreamSupport) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) TreeSet(java.util.TreeSet) TreeSet(java.util.TreeSet) Sort(org.springframework.data.domain.Sort)

Example 4 with BestSubmissionForm

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

the class SubmissionMapperTest method testBestSubmission.

/**
 * Test of bestSubmission method, of class SubmissionMapper.
 */
@Test
public void testBestSubmission() {
    log.info("bestSubmission");
    long problemId = 1000;
    BestSubmissionForm form = BestSubmissionForm.builder().problemId(problemId).build();
    for (Pageable pageable : Pageables.bestSubmission()) {
        instance.bestSubmission(form, pageable);
    }
}
Also used : Pageable(org.springframework.data.domain.Pageable) BestSubmissionForm(cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with BestSubmissionForm

use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm 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, @RequestParam(value = "language", required = false) Integer language, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable) {
    log.debug("{}", pageable);
    if (pageable.getPageSize() > 500) {
        pageable = PageRequest.of(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);
    }
    BestSubmissionForm form = BestSubmissionForm.builder().problemId(id).language(language).build();
    Page<Submission> page = submissionService.bestSubmission(form, pageable, problem.getSubmitUser());
    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("canView", canView);
    request.setAttribute("currentUserId", SecurityUtils.getUserId());
    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) 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