Search in sources :

Example 21 with Problem

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

the class ContestProblemController method showProblem.

@GetMapping("{pid}")
public String showProblem(@PathVariable("contestId") long contestId, @PathVariable("pid") long problemNum, Model model, @Nullable Locale locale) {
    Contest contest = contestService.getContestAndProblemsNotDisabled(contestId, null, locale);
    if (!contest.isStarted()) {
        throw new BusinessException(BusinessCode.CONTEST_NOT_STARTED, contest.getId(), contest.getStartTime());
    }
    Problem problem = contestService.getProblem(contestId, problemNum, locale);
    model.addAttribute("problem", problem);
    model.addAttribute("problems", contest.getProblems());
    model.addAttribute("isSpecial", systemService.isSpecialJudge(problem.getOrigin()));
    List<Long> problemsId = contest.getProblems().stream().map(Problem::getOrigin).collect(ImmutableList.toImmutableList());
    String index = contestService.toProblemIndex(problemsId.indexOf(problem.getOrigin()));
    String title1 = index + ":" + problem.getOrigin() + " -- " + problem.getTitle();
    String title2 = index + ":" + problem.getTitle();
    model.addAttribute("title1", title1);
    model.addAttribute("title2", title2);
    return "contests/problem";
}
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) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 22 with Problem

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

Example 23 with Problem

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

the class ProblemControllerTest method testDataDir.

/**
 * Test of dataDir method, of class ProblemController.
 *
 * {@link ProblemController#dataDir(long)}
 */
@Test
public void testDataDir() throws Exception {
    log.info("dataDir");
    Problem problem = mockDataService.problem();
    MvcResult result = mvc.perform(get("/api/problems/{id}/dataDir", problem.getId()).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
    objectMapper.readTree(result.getResponse().getContentAsString()).hasNonNull("dataDir");
}
Also used : Problem(cn.edu.zjnu.acm.judge.domain.Problem) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with Problem

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

the class ProblemServiceImpl method attachment.

@Override
public List<String> attachment(long problemId, String requestLocale) {
    MarkupParser parser = new MarkupParser(ParseConfiguration.htmlConfiguration());
    Problem problem = findOne(problemId, requestLocale);
    String description = problem.getDescription();
    String input = problem.getInput();
    String output = problem.getOutput();
    String hint = problem.getHint();
    String source = problem.getSource();
    @SuppressWarnings("CollectionWithoutInitialCapacity") List<String> list = new ArrayList<>();
    for (String string : new String[] { description, input, output, hint, source }) {
        try {
            if (string == null) {
                continue;
            }
            parser.parse(string, new AbstractMarkupHandler() {

                @Override
                public void handleAttribute(char[] buffer, int nameOffset, int nameLen, int nameLine, int nameCol, int operatorOffset, int operatorLen, int operatorLine, int operatorCol, int valueContentOffset, int valueContentLen, int valueOuterOffset, int valueOuterLen, int valueLine, int valueCol) {
                    String name = new String(buffer, nameOffset, nameLen);
                    if (name.equalsIgnoreCase("href") || name.equalsIgnoreCase("src")) {
                        String value = new String(buffer, valueContentOffset, valueContentLen);
                        list.add(value);
                    }
                }
            });
        } catch (ParseException ex) {
            log.error("", ex);
        }
    }
    return list;
}
Also used : AbstractMarkupHandler(org.attoparser.AbstractMarkupHandler) ArrayList(java.util.ArrayList) Problem(cn.edu.zjnu.acm.judge.domain.Problem) ParseException(org.attoparser.ParseException) MarkupParser(org.attoparser.MarkupParser)

Example 25 with Problem

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

the class ProblemServiceImpl method updateSelective.

@Override
@Transactional
public void updateSelective(long problemId, Problem p, @Nullable 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.setCreatedTime(null);
    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) Transactional(org.springframework.transaction.annotation.Transactional)

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