Added support for tracking multiple percentilers for a particular game.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@766 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -42,6 +42,13 @@ public class PercentileRecord extends PersistentRecord
|
||||
public static final ColumnExp GAME_ID_C =
|
||||
new ColumnExp(PercentileRecord.class, GAME_ID);
|
||||
|
||||
/** The column identifier for the {@link #gameMode} field. */
|
||||
public static final String GAME_MODE = "gameMode";
|
||||
|
||||
/** The qualified column identifier for the {@link #gameMode} field. */
|
||||
public static final ColumnExp GAME_MODE_C =
|
||||
new ColumnExp(PercentileRecord.class, GAME_MODE);
|
||||
|
||||
/** The column identifier for the {@link #data} field. */
|
||||
public static final String DATA = "data";
|
||||
|
||||
@@ -51,11 +58,13 @@ public class PercentileRecord extends PersistentRecord
|
||||
// AUTO-GENERATED: FIELDS END
|
||||
|
||||
/** Increment this value to reflect changes to this object's schema. */
|
||||
public static final int SCHEMA_VERSION = 3;
|
||||
public static final int SCHEMA_VERSION = 4;
|
||||
|
||||
/** The id of the game for which we're tracking a percentile distribution. */
|
||||
@Id
|
||||
public int gameId;
|
||||
@Id public int gameId;
|
||||
|
||||
/** The mode of the game. Games can maintain distributions for many different modes. */
|
||||
@Id public int gameMode;
|
||||
|
||||
/** The raw percentiler data. */
|
||||
@Column(length=500)
|
||||
@@ -66,12 +75,12 @@ public class PercentileRecord extends PersistentRecord
|
||||
* Create and return a primary {@link Key} to identify a {@link PercentileRecord}
|
||||
* with the supplied key values.
|
||||
*/
|
||||
public static Key<PercentileRecord> getKey (int gameId)
|
||||
public static Key<PercentileRecord> getKey (int gameId, int gameMode)
|
||||
{
|
||||
return new Key<PercentileRecord>(
|
||||
PercentileRecord.class,
|
||||
new String[] { GAME_ID },
|
||||
new Comparable[] { gameId });
|
||||
new String[] { GAME_ID, GAME_MODE },
|
||||
new Comparable[] { gameId, gameMode });
|
||||
}
|
||||
// AUTO-GENERATED: METHODS END
|
||||
}
|
||||
|
||||
@@ -26,8 +26,10 @@ import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -157,26 +159,51 @@ public class RatingRepository extends DepotRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the percentile distribution associated with the specified game. null will never be
|
||||
* returned, rather a blank percentiler will be created and returned.
|
||||
* 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.
|
||||
*/
|
||||
public Percentiler loadPercentile (int gameId)
|
||||
public Percentiler loadPercentile (int gameId, int gameMode)
|
||||
{
|
||||
PercentileRecord record = load(PercentileRecord.class, PercentileRecord.getKey(gameId));
|
||||
PercentileRecord record = load(
|
||||
PercentileRecord.class, PercentileRecord.getKey(gameId, gameMode));
|
||||
return (record == null) ? new Percentiler() : new Percentiler(record.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public Map<Integer, Percentiler> loadPercentiles (int gameId)
|
||||
{
|
||||
Map<Integer, Percentiler> tilers = Maps.newHashMap();
|
||||
for (PercentileRecord record : findAll(
|
||||
PercentileRecord.class, new Where(PercentileRecord.GAME_ID_C, gameId))) {
|
||||
tilers.put(record.gameMode, new Percentiler(record.data));
|
||||
}
|
||||
return tilers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the supplied percentiler's data out to the database.
|
||||
*/
|
||||
public void updatePercentile (int gameId, Percentiler tiler)
|
||||
public void updatePercentile (int gameId, int gameMode, Percentiler tiler)
|
||||
{
|
||||
PercentileRecord record = new PercentileRecord();
|
||||
record.gameId = gameId;
|
||||
record.gameMode = gameMode;
|
||||
record.data = tiler.toBytes();
|
||||
store(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all percentile records for the specified game.
|
||||
*/
|
||||
public void deletePercentiles (int gameId)
|
||||
{
|
||||
deleteAll(PercentileRecord.class, new Where(PercentileRecord.GAME_ID_C, gameId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getManagedRecords (Set<Class<? extends PersistentRecord>> classes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user