Search in sources :

Example 6 with Contest

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

the class ContestService method getContestAndProblems.

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

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

the class ContestProblemController method problems.

@GetMapping
public String problems(Model model, Locale locale, @PathVariable("contestId") long contestId, Authentication authentication) {
    Contest contest = contestService.getContestAndProblemsNotDisabled(contestId, authentication != null ? authentication.getName() : null, locale);
    model.addAttribute("contestId", contestId);
    model.addAttribute("contest", contest);
    if (contest.isStarted()) {
        model.addAttribute("problems", contest.getProblems());
    } else {
        contest.setProblems(null);
    }
    return "contests/problems";
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with Contest

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

the class ContestStatisticsController method contestStatistics.

@GetMapping(value = "/conteststatistics", produces = TEXT_HTML_VALUE)
public String contestStatistics(HttpServletRequest request, Model model, @RequestParam("contest_id") long contestId) throws SQLException {
    Instant now = Instant.now();
    Contest contest = contestService.findOneByIdAndNotDisabled(contestId);
    String title = contest.getTitle();
    Instant endTime = contest.getEndTime();
    model.addAttribute("contestId", contestId);
    model.addAttribute("title", "Contest Statistics");
    StringBuilder sb = new StringBuilder("<p align=center><font size=5 color=blue>Contest Statistics--");
    sb.append(HtmlEscape.escapeHtml4Xml(title));
    if (!contest.isEnded()) {
        if (endTime != null) {
            sb.append("<br/>Time to go:").append(JudgeUtils.formatTime(now, endTime));
        } else {
            sb.append("<br/>Time to go Infinity");
        }
    }
    sb.append("</font></p>" + "<TABLE align=center cellSpacing=0 cellPadding=0 width=600 border=1 class=table-back style=\"border-collapse: collapse\" bordercolor=#FFF>" + "<tr bgcolor=#6589D1><th>&nbsp;</th><th>100</th><th>99~70</th><th>69~31</th><th>30~1</th><th>0</th><th>CE</th><th>Others</th><th>Total</th>");
    Map<Integer, Language> languages = languageService.getAvailableLanguages();
    int languageCount = languages.size();
    StringBuilder sql = new StringBuilder(600).append("select ");
    for (int i : languages.keySet()) {
        sql.append("sum(if(language=").append(i).append(",1,0)) g").append(i).append(",");
    }
    sql.append("s.problem_id,sum(if(score=100,1,0)) A,sum(if(score<100 and score >=70,1,0)) B,sum(if(score<70 and score >30,1,0)) D,sum(if(score>0 and score <=30,1,0)) C,sum(if(score=0,1,0)) E,sum(if(score=-7,1,0)) F,sum(if(score<-7 or score > 100,1,0)) G,count(*) Total from contest_problem cp left join solution s on cp.problem_id=s.problem_id and cp.contest_id=s.contest_id where s.contest_id=? group by cp.problem_id order by cp.num");
    String[] judgeStatus = { "A", "B", "C", "D", "E", "F", "G", "Total" };
    long[] byScore = new long[judgeStatus.length];
    long[] byLanguage = new long[languageCount];
    sb.append("<th>&nbsp;</th>");
    languages.values().stream().map(Language::getName).map(HtmlEscape::escapeHtml4Xml).forEach(languageName -> sb.append("<th>").append(languageName).append("</th>"));
    sb.append("</tr>");
    log.debug("{}", sql);
    Map<Long, long[]> problemsMap = contestService.getProblemsMap(contestId);
    try (Connection conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql.toString())) {
        ps.setLong(1, contestId);
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                long problemId = rs.getLong("problem_id");
                long[] num = problemsMap.get(problemId);
                if (num != null) {
                    sb.append("<tr><th><a href=contests/").append(contestId).append("/problems/").append(num[1]).append(".html>").append(contestService.toProblemIndex(num[0])).append("</a></th>");
                }
                for (int i = 0; i < judgeStatus.length; ++i) {
                    long value = rs.getLong(judgeStatus[i]);
                    byScore[i] += value;
                    if (value == 0) {
                        sb.append("<td>&nbsp;</td>");
                    } else if (i == judgeStatus.length - 1) {
                        sb.append("<th><a href=status?contest_id=").append(contestId).append("&problem_id=").append(problemId).append(">").append(value).append("</a></th>");
                    } else {
                        sb.append("<td>").append(value).append("</td>");
                    }
                }
                sb.append("<td>&nbsp;</td>");
                for (int i = 0; i < languageCount; ++i) {
                    long value = rs.getLong(i + 1);
                    byLanguage[i] += value;
                    if (value == 0) {
                        sb.append("<td>&nbsp;</td>");
                    } else {
                        sb.append("<td>").append(value).append("</td>");
                    }
                }
                sb.append("</tr>");
            }
        }
    }
    sb.append("<tr><th>Total</th>");
    for (int i = 0; i < judgeStatus.length; ++i) {
        if (byScore[i] == 0) {
            sb.append("<td>&nbsp;</td>");
        } else if (i == judgeStatus.length - 1) {
            sb.append("<th>").append(byScore[i]).append("</th>");
        } else {
            sb.append("<td>").append(byScore[i]).append("</td>");
        }
    }
    sb.append("<td>&nbsp;</td>");
    for (int i = 0; i < languageCount; ++i) {
        if (byLanguage[i] == 0) {
            sb.append("<td>&nbsp;</td>");
        } else {
            sb.append("<td>").append(byLanguage[i]).append("</td>");
        }
    }
    sb.append("</tr></table>");
    model.addAttribute("content", sb.toString());
    return "legacy";
}
Also used : Instant(java.time.Instant) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Language(cn.edu.zjnu.acm.judge.domain.Language) ResultSet(java.sql.ResultSet) Contest(cn.edu.zjnu.acm.judge.domain.Contest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 9 with Contest

use of cn.edu.zjnu.acm.judge.domain.Contest 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 10 with Contest

use of cn.edu.zjnu.acm.judge.domain.Contest 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, 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());
    Path dataPath = judgeConfiguration.getDataDirectory(problem.getOrigin());
    model.addAttribute("isSpecial", Files.exists(dataPath.resolve(JudgeConfiguration.VALIDATE_FILE_NAME)));
    List<Long> problemsId = contest.getProblems().stream().map(Problem::getOrigin).collect(Collectors.toList());
    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 : Path(java.nio.file.Path) 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)

Aggregations

Contest (cn.edu.zjnu.acm.judge.domain.Contest)13 Problem (cn.edu.zjnu.acm.judge.domain.Problem)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)3 Nonnull (javax.annotation.Nonnull)3 Instant (java.time.Instant)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 Language (cn.edu.zjnu.acm.judge.domain.Language)1 Submission (cn.edu.zjnu.acm.judge.domain.Submission)1 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)1 Path (java.nio.file.Path)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1