Esempio n. 1
0
  /**
   * Gets the most recently added item not rated yet (new item in the platform).
   *
   * @return The most recently added item not rated yet.
   */
  public Long getLastItemAddedNotRated() {
    Long lastItemAdded = null;
    Date threshold = null;

    for (Long itemId : idao.getItemIds()) {
      List<Rating> ratings = iedao.getEventsForItem(itemId, Rating.class);
      Date firstTimestamp = new Date(ratings.get(0).getTimestamp() * 1000);
      if (threshold == null) {
        threshold = firstTimestamp;
        lastItemAdded = itemId;
      }

      for (Rating r : ratings) {
        Date timestamp = new Date(r.getTimestamp() * 1000);
        if (timestamp.before(firstTimestamp)) firstTimestamp = timestamp;
      }

      if (firstTimestamp.after(threshold)) {
        threshold = firstTimestamp;
        lastItemAdded = itemId;
      }
    }

    return lastItemAdded;
  }
Esempio n. 2
0
  /**
   * Gets the most popular item, i.e. the item with the greatest number of ratings, in a certain
   * period of time (last week/month/year/ever).
   *
   * @param period Period of time to consider.
   * @return The most popular item.
   */
  @SuppressWarnings("deprecation")
  public Long getMostPopularItem(Period period) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(getLastTimestamp());

    Date thresholdDate = null;
    switch (period) {
      case LAST_WEEK:
        cal.add(Calendar.DATE, -7);
        thresholdDate = cal.getTime();
        break;
      case LAST_MONTH:
        cal.add(Calendar.DATE, -30);
        thresholdDate = cal.getTime();
        break;
      case LAST_YEAR:
        cal.add(Calendar.DATE, -365);
        thresholdDate = cal.getTime();
        break;
      case EVER:
        break;
    }

    Long idItemMostPopular = null;
    int max = 0;
    for (Long itemId : idao.getItemIds()) {
      List<Event> events = iedao.getEventsForItem(itemId);
      int count = 0;
      if (thresholdDate == null) count = events.size();
      else {
        thresholdDate.setHours(0);
        thresholdDate.setMinutes(0);
        thresholdDate.setSeconds(0);
        for (Event ev : events) {
          Date rateDate = new Date(ev.getTimestamp() * 1000);
          if (rateDate.after(thresholdDate)) count++;
        }
      }

      if (count > max) {
        idItemMostPopular = itemId;
        max = count;
      }
    }

    return idItemMostPopular;
  }
Esempio n. 3
0
  /**
   * Gets the last positively rated item (the last item added in the platform rated in a positive
   * way). An item is "positively rated" if its rate is equals or greater than the global mean of
   * all ratings.
   *
   * @return The last positively rated item.
   */
  public Long getLastPositivelyRatedItem() {
    Long lastPositivelyRatedItem = null;
    Date recentDate = getFirstTimestamp();

    for (Long itemId : idao.getItemIds()) {
      List<Rating> ratings = iedao.getEventsForItem(itemId, Rating.class);
      int threshold = getPositiveRatingThreshold(ratings);
      Date date = getFirstTimestamp();

      for (Rating rating : ratings) {
        Date dateR = new Date(rating.getTimestamp() * 1000);
        if (rating.getValue() >= threshold && dateR.after(date)) date = dateR;
      }

      if (date.after(recentDate)) recentDate = date;
      lastPositivelyRatedItem = itemId;
    }

    return lastPositivelyRatedItem;
  }