Exemplo n.º 1
0
  @Override
  public String toString() {
    Map<String, Object> m = new ListOrderedMap<String, Object>();
    m.put("Scale Factor", this.scale_factor);
    m.put("Loader Start", this.loaderStartTime);
    m.put("Loader Stop", this.loaderStopTime);
    m.put(
        "Last CloseAuctions",
        (this.lastCloseAuctionsTime.getTime() > 0 ? this.lastCloseAuctionsTime : null));
    m.put("Client Start", this.clientStartTime);
    m.put("Current Virtual Time", this.currentTime);
    m.put("Pending ItemCommentResponses", this.pending_commentResponses.size());

    // Item Queues
    Histogram<ItemStatus> itemCounts = new Histogram<ItemStatus>(true);
    for (ItemStatus status : ItemStatus.values()) {
      int cnt = 0;
      switch (status) {
        case OPEN:
          cnt = this.items_available.size();
          break;
        case ENDING_SOON:
          cnt = this.items_endingSoon.size();
          break;
        case WAITING_FOR_PURCHASE:
          cnt = this.items_waitingForPurchase.size();
          break;
        case CLOSED:
          cnt = this.items_completed.size();
          break;
        default:
          assert (false) : "Unexpected " + status;
      } // SWITCH
      itemCounts.put(status, cnt);
    }
    m.put("Item Queues", itemCounts);

    return (StringUtil.formatMaps(m));
  }
Exemplo n.º 2
0
  /**
   * Get a random buyer UserId, where the probability that a particular user is selected increases
   * based on the number of bids that they have made in the past. We won't allow the last bidder to
   * be selected again
   *
   * @param previousBidders
   * @return
   */
  public UserId getRandomBuyerId(Histogram<UserId> previousBidders, UserId... exclude) {
    // This is very inefficient, but it's probably good enough for now
    tmp_userIdHistogram.clear();
    tmp_userIdHistogram.putHistogram(previousBidders);
    for (UserId ex : exclude) tmp_userIdHistogram.removeAll(ex);
    tmp_userIdHistogram.put(this.getRandomBuyerId(exclude));
    try {
      LOG.trace("New Histogram:\n" + tmp_userIdHistogram);
    } catch (NullPointerException ex) {
      for (UserId user_id : tmp_userIdHistogram.values()) {
        System.err.println(
            String.format(
                "%s => NEW:%s / ORIG:%s",
                user_id, tmp_userIdHistogram.get(user_id), previousBidders.get(user_id)));
      }
      throw ex;
    }

    FlatHistogram<UserId> rand_h = new FlatHistogram<UserId>(rng, tmp_userIdHistogram);
    return (rand_h.nextValue());
  }