Search in sources :

Example 16 with Problem

use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.

the class ProblemService method updateSelective.

public void updateSelective(long problemId, Problem p, String requestLocale) {
    Problem problem = problemMapper.findOne(problemId, requestLocale);
    if (problem == null) {
        throw new BusinessException(BusinessCode.PROBLEM_NOT_FOUND, problemId);
    }
    String locale = convert(requestLocale);
    if (locale != null) {
        problemMapper.touchI18n(problemId, locale);
    }
    p.setModifiedTime(Instant.now());
    problemMapper.updateSelective(problemId, p, locale);
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Problem(cn.edu.zjnu.acm.judge.domain.Problem)

Example 17 with Problem

use of cn.edu.zjnu.acm.judge.domain.Problem 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)

Example 18 with Problem

use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.

the class ContestServiceImpl method getContestAndProblemsNotDisabled.

@Nonnull
@Override
public Contest getContestAndProblemsNotDisabled(long contestId, @Nullable String userId, Locale locale) {
    Contest contest = getEnabledContest(contestId);
    List<Problem> problems = contestProblemMapper.getProblems(contestId, userId, localeService.resolve(locale));
    contest.setProblems(problems);
    return contest;
}
Also used : Problem(cn.edu.zjnu.acm.judge.domain.Problem) Contest(cn.edu.zjnu.acm.judge.domain.Contest) Nonnull(javax.annotation.Nonnull)

Example 19 with Problem

use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.

the class ContestServiceImpl method getProblemsMap.

@Override
public Map<Long, long[]> getProblemsMap(long id) {
    List<Problem> problems = contestProblemMapper.getProblems(id, null, null);
    AtomicInteger atomic = new AtomicInteger();
    return problems.stream().collect(ImmutableMap.toImmutableMap(Problem::getOrigin, problem -> new long[] { atomic.getAndIncrement(), problem.getId() }));
}
Also used : ContestProblemMapper(cn.edu.zjnu.acm.judge.mapper.ContestProblemMapper) Arrays(java.util.Arrays) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CompletableFuture(java.util.concurrent.CompletableFuture) ObjIntConsumer(java.util.function.ObjIntConsumer) Contest(cn.edu.zjnu.acm.judge.domain.Contest) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) ContestStatus(cn.edu.zjnu.acm.judge.data.form.ContestStatus) ContestForm(cn.edu.zjnu.acm.judge.data.form.ContestForm) SpecialCall(cn.edu.zjnu.acm.judge.util.SpecialCall) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) LocaleService(cn.edu.zjnu.acm.judge.service.LocaleService) EnumSet(java.util.EnumSet) Nullable(javax.annotation.Nullable) BusinessCode(cn.edu.zjnu.acm.judge.exception.BusinessCode) SubmissionMapper(cn.edu.zjnu.acm.judge.mapper.SubmissionMapper) EnumUtils(cn.edu.zjnu.acm.judge.util.EnumUtils) ImmutableMap(com.google.common.collect.ImmutableMap) BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) ContestMapper(cn.edu.zjnu.acm.judge.mapper.ContestMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Problem(cn.edu.zjnu.acm.judge.domain.Problem) IOException(java.io.IOException) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Optional(java.util.Optional) Comparator(java.util.Comparator) ContestService(cn.edu.zjnu.acm.judge.service.ContestService) Transactional(org.springframework.transaction.annotation.Transactional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Problem(cn.edu.zjnu.acm.judge.domain.Problem)

Example 20 with Problem

use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.

the class ShowProblemController method showProblem.

@GetMapping("showproblem")
public String showProblem(Model model, @RequestParam("problem_id") long problemId, @Nullable Locale locale) {
    Problem problem = getProblem(problemId, locale);
    model.addAttribute("problem", problem);
    model.addAttribute("isSpecial", systemService.isSpecialJudge(problemId));
    String title1 = problemId + " -- " + problem.getTitle();
    String title2 = problem.getTitle();
    model.addAttribute("title1", title1);
    model.addAttribute("title2", title2);
    return "problems/view";
}
Also used : Problem(cn.edu.zjnu.acm.judge.domain.Problem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Problem (cn.edu.zjnu.acm.judge.domain.Problem)26 Contest (cn.edu.zjnu.acm.judge.domain.Contest)10 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)10 Nonnull (javax.annotation.Nonnull)7 Submission (cn.edu.zjnu.acm.judge.domain.Submission)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 ArrayList (java.util.ArrayList)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 ScoreCount (cn.edu.zjnu.acm.judge.data.dto.ScoreCount)4 Test (org.junit.jupiter.api.Test)4 BusinessCode (cn.edu.zjnu.acm.judge.exception.BusinessCode)3 IOException (java.io.IOException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 BestSubmissionForm (cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm)2 ContestForm (cn.edu.zjnu.acm.judge.data.form.ContestForm)2 ContestStatus (cn.edu.zjnu.acm.judge.data.form.ContestStatus)2 ContestMapper (cn.edu.zjnu.acm.judge.mapper.ContestMapper)2 SubmissionMapper (cn.edu.zjnu.acm.judge.mapper.SubmissionMapper)2 EnumUtils (cn.edu.zjnu.acm.judge.util.EnumUtils)2 SpecialCall (cn.edu.zjnu.acm.judge.util.SpecialCall)2