Ejemplo n.º 1
0
  @Transactional(readOnly = true)
  public Result viewProblem(long contestId, long contestProblemId)
      throws ContestNotFoundException, ContestProblemNotFoundException {
    Contest contest = contestService.findContestById(contestId);
    ContestProblem contestProblem = contestProblemService.findContestProblemById(contestProblemId);
    if (!ContestControllerUtils.getInstance()
            .isAllowedToEnterContest(contest, IdentityUtils.getUserJid())
        || !isAllowedToViewProblem(contest, contestProblem)) {
      return ContestControllerUtils.getInstance()
          .tryEnteringContest(contest, IdentityUtils.getUserJid());
    }

    long submissionsLeft = -1;
    if (contestProblem.getSubmissionsLimit() != 0) {
      submissionsLeft =
          contestProblem.getSubmissionsLimit()
              - programmingSubmissionService.countProgrammingSubmissionsByUserJid(
                  contest.getJid(), contestProblem.getProblemJid(), IdentityUtils.getUserJid());
    }

    SandalphonProgrammingProblemStatementRenderRequestParam param =
        new SandalphonProgrammingProblemStatementRenderRequestParam();

    param.setProblemSecret(contestProblem.getProblemSecret());
    param.setCurrentMillis(System.currentTimeMillis());
    param.setStatementLanguage(ContestControllerUtils.getInstance().getCurrentStatementLanguage());
    param.setSwitchStatementLanguageUrl(
        routes.ContestProblemController.switchLanguage(contestId, contestProblemId)
            .absoluteURL(request(), request().secure()));
    param.setPostSubmitUrl(
        org.iatoki.judgels.uriel.contest.submission.programming.routes
            .ContestProgrammingSubmissionController.postSubmitProblem(
                contest.getId(), contestProblem.getProblemJid())
            .absoluteURL(request(), request().secure()));
    param.setReasonNotAllowedToSubmit(null);

    Set<String> allowedGradingLanguages;

    if (contest.isICPC()) {
      allowedGradingLanguages =
          ((ICPCContestStyleConfig) contest.getStyleConfig())
              .getLanguageRestriction()
              .getAllowedLanguageNames();
    } else {
      allowedGradingLanguages =
          ((IOIContestStyleConfig) contest.getStyleConfig())
              .getLanguageRestriction()
              .getAllowedLanguageNames();
    }

    param.setAllowedGradingLanguages(StringUtils.join(allowedGradingLanguages, ","));

    String requestUrl =
        sandalphonClientAPI.getProgrammingProblemStatementRenderAPIEndpoint(
            contestProblem.getProblemJid());
    String requestBody =
        sandalphonClientAPI.constructProgrammingProblemStatementRenderAPIRequestBody(
            contestProblem.getProblemJid(), param);

    LazyHtml content;
    if (UrielProperties.getInstance().isContestCritial(contest.getJid())) {
      content =
          new LazyHtml(
              viewProblemCriticalView.render(
                  requestUrl,
                  requestBody,
                  submissionsLeft,
                  contestProblem.getStatus() == ContestProblemStatus.CLOSED,
                  contest,
                  contestProblem));
    } else {
      content =
          new LazyHtml(
              viewProblemView.render(
                  requestUrl,
                  requestBody,
                  submissionsLeft,
                  contestProblem.getStatus() == ContestProblemStatus.CLOSED));
    }
    ContestControllerUtils.getInstance()
        .appendTabsLayout(content, contest, IdentityUtils.getUserJid());
    UrielControllerUtils.getInstance().appendSidebarLayout(content);
    appendBreadcrumbsLayout(
        content,
        contest,
        new InternalLink(
            Messages.get("status.contestant"),
            routes.ContestProblemController.viewUsedProblems(contest.getId())),
        new InternalLink(
            contestProblem.getAlias(),
            routes.ContestProblemController.viewProblem(contest.getId(), contestProblem.getId())));

    UrielControllerUtils.getInstance().appendTemplateLayout(content, "Contest - Problem - View");

    return UrielControllerUtils.getInstance().lazyOk(content);
  }
Ejemplo n.º 2
0
  @Override
  public ScoreboardContent computeScoreboardContent(
      Contest contest,
      ScoreboardState state,
      List<ProgrammingSubmission> submissions,
      Map<String, Date> contestantStartTimes,
      Map<String, URL> userJidToImageMap) {

    ICPCContestStyleConfig icpcStyleConfig = (ICPCContestStyleConfig) contest.getStyleConfig();
    ScoreboardEntryComparator<ICPCScoreboardEntry> comparator = new ICPCScoreboardEntryComparator();

    Map<String, Map<String, Integer>> attemptsMap = Maps.newHashMap();
    Map<String, Map<String, Long>> penaltyMap = Maps.newHashMap();
    Map<String, Map<String, Integer>> problemStateMap = Maps.newHashMap();
    Map<String, Long> lastAcceptedPenaltyMap = Maps.newHashMap();
    Set<String> acceptedProblemJids = Sets.newHashSet();

    for (String contestantJid : state.getContestantJids()) {
      attemptsMap.put(contestantJid, Maps.newHashMap());
      penaltyMap.put(contestantJid, Maps.newHashMap());
      problemStateMap.put(contestantJid, Maps.newHashMap());

      for (String problemJid : state.getProblemJids()) {
        attemptsMap.get(contestantJid).put(problemJid, 0);
        penaltyMap.get(contestantJid).put(problemJid, 0L);
        lastAcceptedPenaltyMap.put(contestantJid, 0L);
        problemStateMap
            .get(contestantJid)
            .put(problemJid, ICPCScoreboardEntry.State.NOT_ACCEPTED.ordinal());
      }
    }

    for (ProgrammingSubmission submission : submissions) {
      String contestantJid = submission.getAuthorJid();
      String problemJid = submission.getProblemJid();

      if (!attemptsMap.containsKey(contestantJid)) {
        continue;
      }
      if (!attemptsMap.get(contestantJid).containsKey(problemJid)) {
        continue;
      }
      if (problemStateMap.get(contestantJid).get(problemJid)
          != ICPCScoreboardEntry.State.NOT_ACCEPTED.ordinal()) {
        continue;
      }

      Verdict verdict = submission.getLatestVerdict();

      if (verdict.getCode().equals("?")) {
        continue;
      }

      int attempts = attemptsMap.get(contestantJid).get(problemJid);
      attemptsMap.get(contestantJid).put(problemJid, attempts + 1);

      long penaltyInMilliseconds =
          computeSubmissionPenaltyInMilliseconds(
              contest, contestantStartTimes.get(contestantJid), submission.getTime());
      penaltyMap.get(contestantJid).put(problemJid, convertPenaltyToMinutes(penaltyInMilliseconds));

      if (verdict.getCode().equals("AC")) {
        if (acceptedProblemJids.contains(problemJid)) {
          problemStateMap
              .get(contestantJid)
              .put(problemJid, ICPCScoreboardEntry.State.ACCEPTED.ordinal());
        } else {
          problemStateMap
              .get(contestantJid)
              .put(problemJid, ICPCScoreboardEntry.State.FIRST_ACCEPTED.ordinal());
          acceptedProblemJids.add(problemJid);
        }

        lastAcceptedPenaltyMap.put(contestantJid, penaltyInMilliseconds);
      }
    }

    List<ICPCScoreboardEntry> entries = Lists.newArrayList();

    for (String contestantJid : state.getContestantJids()) {
      ICPCScoreboardEntry entry = new ICPCScoreboardEntry();
      entry.contestantJid = contestantJid;
      entry.imageURL = userJidToImageMap.get(contestantJid);

      for (String problemJid : state.getProblemJids()) {
        int attempts = attemptsMap.get(contestantJid).get(problemJid);
        long penalty = penaltyMap.get(contestantJid).get(problemJid);
        long lastAcceptedPenalty = lastAcceptedPenaltyMap.get(contestantJid);
        int problemState = problemStateMap.get(contestantJid).get(problemJid);

        entry.attemptsList.add(attempts);
        entry.penaltyList.add(penalty);
        entry.lastAcceptedPenalty = lastAcceptedPenalty;
        entry.problemStateList.add(problemState);

        if (problemState != ICPCScoreboardEntry.State.NOT_ACCEPTED.ordinal()) {
          entry.totalAccepted++;
          entry.totalPenalties +=
              icpcStyleConfig.getWrongSubmissionPenalty() * (attempts - 1) + penalty;
        }
      }

      entries.add(entry);
    }

    sortEntriesAndAssignRanks(comparator, entries);

    return new ICPCScoreboardContent(entries);
  }