com.threerings.parlor.rating.server.persist
Class RatingRepository

java.lang.Object
  extended by com.samskivert.depot.DepotRepository
      extended by com.threerings.parlor.rating.server.persist.RatingRepository

public class RatingRepository
extends com.samskivert.depot.DepotRepository

Handles the persistent storage of per-user per-game ratings.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.samskivert.depot.DepotRepository
com.samskivert.depot.DepotRepository.CacheStrategy
 
Field Summary
 
Fields inherited from class com.samskivert.depot.DepotRepository
_ctx, _dataMigs
 
Constructor Summary
RatingRepository(com.samskivert.depot.PersistenceContext ctx)
          Initialize the RatingRepository.
 
Method Summary
 void deletePercentile(int gameId, int gameMode)
          Deletes the percentile record for the specified game and game mode.
 void deleteRating(int gameId, int playerId)
          Deletes the specified rating record.
protected  void getManagedRecords(Set<Class<? extends com.samskivert.depot.PersistentRecord>> classes)
           
 Collection<RatingRecord> getMostRecentRatings(Collection<Integer> playerIds, Collection<Integer> gameIds, int gameIdSign)
          Load the most recently entered rating for each of a collection of players.
 Collection<RatingRecord> getMostRecentRatings(Collection<Integer> playerIds, int gameIdSign)
          Load the most recently entered rating for each of a collection of players.
 RatingRecord getRating(int gameId, int playerId)
          Loads the rating for the given player for the given game and returns it as a RatingRecord object, or null if the player has no previous rating for the game.
 List<RatingRecord> getRatings(int gameId, Integer... players)
          Fetch the ratings registered for any of the given players for the given game and return them as a list of RatingRecord objects.
 List<RatingRecord> getRatings(int playerId, long since, int count)
          Fetch and return all the registered RatingRecord rows for the given player.
 List<RatingRecord> getTopRatings(int gameId, int limit, long since, Set<Integer> playerIds)
          Returns the top-ratings for the specified game.
 Percentiler loadPercentile(int gameId, int gameMode)
          Loads the percentile distribution associated with the specified game and mode. null will never be returned, rather a blank percentiler will be created and returned.
 Map<Integer,Percentiler> loadPercentiles(int gameId)
          Loads all the percentile distributions associated with the specified game.
 void purgeGame(int gameId)
          Deletes all rating and percentile records for the specified game.
 void purgePlayers(Collection<Integer> playerIds)
          Deletes all rating records for the specified players.
 void setRating(int gameId, int playerId, int rating, int experience)
          Set the rating and experience for a given player and game.
 void updatePercentile(int gameId, int gameMode, Percentiler tiler)
          Writes the supplied percentiler's data out to the database.
 
Methods inherited from class com.samskivert.depot.DepotRepository
delete, delete, deleteAll, deleteAll, deleteAll, deleteAll, doUpdate, findAll, findAll, findAll, findAll, findAllKeys, findAllKeys, from, init, insert, load, load, load, load, loadAll, loadAll, makeValue, map, registerMigration, requireNotComputed, resolveRecords, runMigration, store, update, update, updatePartial, updatePartial, updatePartial, updatePartial, updatePartial
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RatingRepository

@Inject
public RatingRepository(com.samskivert.depot.PersistenceContext ctx)
Initialize the RatingRepository.

Method Detail

getRating

public RatingRecord getRating(int gameId,
                              int playerId)
Loads the rating for the given player for the given game and returns it as a RatingRecord object, or null if the player has no previous rating for the game.


getRatings

public List<RatingRecord> getRatings(int gameId,
                                     Integer... players)
Fetch the ratings registered for any of the given players for the given game and return them as a list of RatingRecord objects. The size of this list is no less than zero and no greater than the number of given players.


getRatings

public List<RatingRecord> getRatings(int playerId,
                                     long since,
                                     int count)
Fetch and return all the registered RatingRecord rows for the given player. Ratings will be returned in order of most recently to least recently updated.

Parameters:
since - ratings last updated more than this number of milliseconds in the past will be ommitted from the result list. Supplying -1 will return all ratings regardless of age.
count - the maximum number of ratings to return or -1 for all ratings.

getTopRatings

public List<RatingRecord> getTopRatings(int gameId,
                                        int limit,
                                        long since,
                                        Set<Integer> playerIds)
Returns the top-ratings for the specified game. Players with equal rating will be sorted most recently played first.

Parameters:
since - an absolute number of milliseconds (ie. 10*24*60*60*1000L). Players that have not updated their rating within this many milliseconds in the past will be omitted from the results. Supply zero to omit this filter.
playerIds - an optional list of player ids to which to limit the top-rankings search.

setRating

public void setRating(int gameId,
                      int playerId,
                      int rating,
                      int experience)
Set the rating and experience for a given player and game. This method will either update or create a row.


deleteRating

public void deleteRating(int gameId,
                         int playerId)
Deletes the specified rating record.


loadPercentile

public Percentiler loadPercentile(int gameId,
                                  int gameMode)
Loads the percentile distribution associated with the specified game and mode. null will never be returned, rather a blank percentiler will be created and returned.


loadPercentiles

public Map<Integer,Percentiler> loadPercentiles(int gameId)
Loads all the percentile distributions associated with the specified game. The percentilers will be mapped by their game mode. The map may be zero size if the game has recorded no distributions.


updatePercentile

public void updatePercentile(int gameId,
                             int gameMode,
                             Percentiler tiler)
Writes the supplied percentiler's data out to the database.


deletePercentile

public void deletePercentile(int gameId,
                             int gameMode)
Deletes the percentile record for the specified game and game mode.


purgeGame

public void purgeGame(int gameId)
Deletes all rating and percentile records for the specified game.


purgePlayers

public void purgePlayers(Collection<Integer> playerIds)
Deletes all rating records for the specified players.


getMostRecentRatings

public Collection<RatingRecord> getMostRecentRatings(Collection<Integer> playerIds,
                                                     int gameIdSign)
Load the most recently entered rating for each of a collection of players. The search may be limited to only negative or positive id's since applications may use the sign to indicate game mode.

Parameters:
gameIdSign - if non-zero, limits the search to game ids of matching sign

getMostRecentRatings

public Collection<RatingRecord> getMostRecentRatings(Collection<Integer> playerIds,
                                                     Collection<Integer> gameIds,
                                                     int gameIdSign)
Load the most recently entered rating for each of a collection of players. The search may be limited to a specific collection of games.

Parameters:
gameIds - if not null, limits the search to the specific game ids
gameIdSign - if non-zero, limits the search to game ids of matching sign

getManagedRecords

protected void getManagedRecords(Set<Class<? extends com.samskivert.depot.PersistentRecord>> classes)
Specified by:
getManagedRecords in class com.samskivert.depot.DepotRepository