Search in sources :

Example 11 with Problem

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

the class ContestServiceImpl method getContestAndProblems.

@Nonnull
@Override
public Contest getContestAndProblems(long contestId, Locale locale) {
    Contest contest = checkedGet(contestId);
    List<Problem> problems = contestProblemMapper.getProblems(contestId, null, 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 12 with Problem

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

the class SubmissionServiceImpl method contestSubmit.

@Override
public CompletableFuture<?> contestSubmit(int languageId, String source, String userId, String ip, long contestId, long problemNum) {
    check(languageId, source, userId);
    Contest contest = contestService.findOneByIdAndNotDisabled(contestId);
    // contest not started yet, can't submit the problem.
    if (!contest.isStarted()) {
        throw new BusinessException(BusinessCode.CONTEST_PROBLEM_NOT_FOUND, contestId, problemNum);
    }
    Problem problem = contestService.getProblem(contestId, problemNum, null);
    return submit0(Submission.builder().contest(contest.isEnded() ? null : contestId).problem(problem.getOrigin()).ip(ip), source, userId, languageId, true);
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Problem(cn.edu.zjnu.acm.judge.domain.Problem) Contest(cn.edu.zjnu.acm.judge.domain.Contest)

Example 13 with Problem

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

the class ContestService method getContestAndProblemsNotDisabled.

@Nonnull
public Contest getContestAndProblemsNotDisabled(long contestId, String userId, Locale locale) {
    Contest contest = getEnabledContest(contestId);
    List<Problem> problems = contestMapper.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 14 with Problem

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

the class ContestService method getProblemsMap.

public Map<Long, long[]> getProblemsMap(long id) {
    List<Problem> problems = contestMapper.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 : Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) ObjIntConsumer(java.util.function.ObjIntConsumer) Contest(cn.edu.zjnu.acm.judge.domain.Contest) 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) EnumSet(java.util.EnumSet) 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) Transactional(org.springframework.transaction.annotation.Transactional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Problem(cn.edu.zjnu.acm.judge.domain.Problem)

Example 15 with Problem

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

the class JudgeService method toCompletableFuture.

CompletableFuture<?> toCompletableFuture(Executor executor, long submissionId) {
    return CompletableFuture.runAsync(() -> {
        Submission submission = submissionMapper.findOne(submissionId);
        if (submission == null) {
            throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND);
        }
        Problem problem = problemService.findOneNoI18n(submission.getProblem());
        RunRecord runRecord = RunRecord.builder().submissionId(submission.getId()).language(languageService.getAvailableLanguage(submission.getLanguage())).problemId(submission.getProblem()).userId(submission.getUser()).source(submissionMapper.findSourceById(submissionId)).memoryLimit(problem.getMemoryLimit()).timeLimit(problem.getTimeLimit()).build();
        judgeInternal(runRecord);
    }, executor);
}
Also used : RunRecord(cn.edu.zjnu.acm.judge.data.dto.RunRecord) BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Submission(cn.edu.zjnu.acm.judge.domain.Submission) Problem(cn.edu.zjnu.acm.judge.domain.Problem)

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