예제 #1
0
  public Price getMedianJudgedValue(int round) throws ScoreException {
    Quantity totalValue = Quantity.ZERO;
    int judgeCount = 0;
    for (Iterator iterator = playerNameIterator(); iterator.hasNext(); ) {
      Judge judge = getJudgeOrNull((String) iterator.next());
      if (judge == null || judge.isDormant(getCurrentRound())) {
        continue;
      }
      Price estimate = judge.getEstimate(round);
      if (estimate == null) {
        continue;
      }

      totalValue = totalValue.plus(estimate);
      judgeCount += 1;
    }
    if (judgeCount == 0) {
      if (cuttingOffJudges()) {
        return Price.dollarPrice(50);
      }
      String message =
          "Judges have not entered estimates for " + getRoundLabel() + " " + round + ".";
      appendToErrorMessage(message);
      throw new ScoreException(message);
    } else {
      return marketPrice(totalValue.div(judgeCount));
    }
  }
예제 #2
0
  private void setupCutoffTimers() {
    Logger cutoffLogger = sessionLogger();
    Random random = new Random();
    int cutoffIfSimultaneous = (int) (random.nextDouble() * (latestCutoff - earliestCutoff));
    if (simultaneousCutoff) {
      cutoffLogger.info("using a simultaneous cutoff of " + cutoffIfSimultaneous + " seconds.");
    }
    Iterator<String> nameIterator = playerNameIterator();
    while (nameIterator.hasNext()) {
      Judge judge = getJudgeOrNull(nameIterator.next());
      if (judge == null) {
        continue;
      }

      int cutoff;
      if (simultaneousCutoff) {
        cutoff = cutoffIfSimultaneous;
      } else {
        cutoff = earliestCutoff + (int) (random.nextDouble() * (latestCutoff - earliestCutoff));
        cutoffLogger.info(
            "using a cutoff for judge '" + judge.getName() + "' of " + cutoff + " seconds.");
        int roundDuration = timeLimit();
        if (cutoff > roundDuration + 10) {
          cutoff = roundDuration + 10;
          cutoffLogger.info(
              "reducing timeout to " + cutoff + " (10 seconds after round finishes).");
        }
      }
      TimerTask task = judge.getCutoffTimer();
      timer.schedule(task, 1000 * cutoff);
    }
  }
예제 #3
0
  // cancel all the timers
  void otherEndTradingEvents() {
    Iterator<String> nameIterator = playerNameIterator();
    while (nameIterator.hasNext()) {
      Judge judge = getJudgeOrNull(nameIterator.next());
      if (judge == null) {
        continue;
      }

      judge.cancelCutOffTimer();
    }
  }
예제 #4
0
 public String getEstimatesHtml() {
   Session session = SessionSingleton.getSession();
   if (session == null) {
     return "";
   }
   Iterator iterator = session.playerNameSortedIterator();
   StringBuffer buff = new StringBuffer();
   printEstimatesTableHeader(session, buff);
   while (iterator.hasNext()) {
     String playerName = (String) iterator.next();
     Judge judge = getJudgeOrNull(playerName);
     if (null == judge) {
       continue;
     }
     HtmlRow.startTag(buff);
     buff.append(HtmlSimpleElement.printTableCell(playerName));
     judge.getGuessesRow(buff, session);
     HtmlRow.endTag(buff);
   }
   HtmlTable.endTagWithP(buff);
   return buff.toString();
 }