Nix PercentileRecord.type allow gameId to be fiddled by derive class.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@432 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -215,7 +215,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("Loading " + ratings + "...");
|
log.info("Loading " + ratings + "...");
|
||||||
final int gameId = _gmgr.getGameConfig().getGameId();
|
final int gameId = getGameId();
|
||||||
CrowdServer.invoker.postUnit(new RepositoryUnit("loadRatings") {
|
CrowdServer.invoker.postUnit(new RepositoryUnit("loadRatings") {
|
||||||
public void invokePersist () throws Exception {
|
public void invokePersist () throws Exception {
|
||||||
// map the records by player id so that we can correlate with the db results
|
// map the records by player id so that we can correlate with the db results
|
||||||
@@ -256,7 +256,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("Saving " + ratings + "...");
|
log.info("Saving " + ratings + "...");
|
||||||
final int gameId = _gmgr.getGameConfig().getGameId();
|
final int gameId = getGameId();
|
||||||
CrowdServer.invoker.postUnit(new RepositoryUnit("saveRatings") {
|
CrowdServer.invoker.postUnit(new RepositoryUnit("saveRatings") {
|
||||||
public void invokePersist () throws Exception {
|
public void invokePersist () throws Exception {
|
||||||
for (Rating rating : ratings) {
|
for (Rating rating : ratings) {
|
||||||
@@ -374,6 +374,14 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
return MathUtil.bound(MINIMUM_RATING, nrat, MAXIMUM_RATING);
|
return MathUtil.bound(MINIMUM_RATING, nrat, MAXIMUM_RATING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the game id to use when reading and writing ratings.
|
||||||
|
*/
|
||||||
|
protected int getGameId ()
|
||||||
|
{
|
||||||
|
return _gmgr.getGameConfig().getGameId();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the minimum time (in seconds) a game must've lasted for it to count towards rating.
|
* Return the minimum time (in seconds) a game must've lasted for it to count towards rating.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,13 +42,6 @@ public class PercentileRecord extends PersistentRecord
|
|||||||
public static final ColumnExp GAME_ID_C =
|
public static final ColumnExp GAME_ID_C =
|
||||||
new ColumnExp(PercentileRecord.class, GAME_ID);
|
new ColumnExp(PercentileRecord.class, GAME_ID);
|
||||||
|
|
||||||
/** The column identifier for the {@link #type} field. */
|
|
||||||
public static final String TYPE = "type";
|
|
||||||
|
|
||||||
/** The qualified column identifier for the {@link #type} field. */
|
|
||||||
public static final ColumnExp TYPE_C =
|
|
||||||
new ColumnExp(PercentileRecord.class, TYPE);
|
|
||||||
|
|
||||||
/** The column identifier for the {@link #data} field. */
|
/** The column identifier for the {@link #data} field. */
|
||||||
public static final String DATA = "data";
|
public static final String DATA = "data";
|
||||||
|
|
||||||
@@ -58,16 +51,12 @@ public class PercentileRecord extends PersistentRecord
|
|||||||
// AUTO-GENERATED: FIELDS END
|
// AUTO-GENERATED: FIELDS END
|
||||||
|
|
||||||
/** Increment this value to reflect changes to this object's schema. */
|
/** Increment this value to reflect changes to this object's schema. */
|
||||||
public static final int SCHEMA_VERSION = 2;
|
public static final int SCHEMA_VERSION = 3;
|
||||||
|
|
||||||
/** The id of the game for which we're tracking a percentile distribution. */
|
/** The id of the game for which we're tracking a percentile distribution. */
|
||||||
@Id
|
@Id
|
||||||
public int gameId;
|
public int gameId;
|
||||||
|
|
||||||
/** The type of percentile distribution (games can maintain multiple distributions). */
|
|
||||||
@Id
|
|
||||||
public int type;
|
|
||||||
|
|
||||||
/** The raw percentiler data. */
|
/** The raw percentiler data. */
|
||||||
@Column(length=500)
|
@Column(length=500)
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
@@ -77,12 +66,12 @@ public class PercentileRecord extends PersistentRecord
|
|||||||
* Create and return a primary {@link Key} to identify a {@link #PercentileRecord}
|
* Create and return a primary {@link Key} to identify a {@link #PercentileRecord}
|
||||||
* with the supplied key values.
|
* with the supplied key values.
|
||||||
*/
|
*/
|
||||||
public static Key<PercentileRecord> getKey (int gameId, int type)
|
public static Key<PercentileRecord> getKey (int gameId)
|
||||||
{
|
{
|
||||||
return new Key<PercentileRecord>(
|
return new Key<PercentileRecord>(
|
||||||
PercentileRecord.class,
|
PercentileRecord.class,
|
||||||
new String[] { GAME_ID, TYPE },
|
new String[] { GAME_ID },
|
||||||
new Comparable[] { gameId, type });
|
new Comparable[] { gameId });
|
||||||
}
|
}
|
||||||
// AUTO-GENERATED: METHODS END
|
// AUTO-GENERATED: METHODS END
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class RatingRepository extends DepotRepository
|
|||||||
|
|
||||||
// TEMP
|
// TEMP
|
||||||
ctx.registerMigration(PercentileRecord.class, new EntityMigration.Retype(2, "data"));
|
ctx.registerMigration(PercentileRecord.class, new EntityMigration.Retype(2, "data"));
|
||||||
|
ctx.registerMigration(PercentileRecord.class, new EntityMigration.Drop(3, "type"));
|
||||||
// END TEMP
|
// END TEMP
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,42 +112,24 @@ public class RatingRepository extends DepotRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all percentile distributions associated with the specified game.
|
* Loads the percentile distribution associated with the specified game. null will never be
|
||||||
*
|
* returned, rather a blank percentiler will be created and returned.
|
||||||
* @return a map from type to {@link Percentiler} instance.
|
|
||||||
*/
|
*/
|
||||||
public IntMap<Percentiler> loadPercentiles (int gameId)
|
public Percentiler loadPercentile (int gameId)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
HashIntMap<Percentiler> results = new HashIntMap<Percentiler>();
|
PercentileRecord record = load(PercentileRecord.class, PercentileRecord.getKey(gameId));
|
||||||
Where where = new Where(PercentileRecord.GAME_ID_C, gameId);
|
|
||||||
for (PercentileRecord record : findAll(PercentileRecord.class, where)) {
|
|
||||||
results.put(record.type, new Percentiler(record.data));
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a particular percentiler for the specified game. null will never be returned, rather a
|
|
||||||
* blank percentiler will be created and returned.
|
|
||||||
*/
|
|
||||||
public Percentiler loadPercentile (int gameId, int type)
|
|
||||||
throws PersistenceException
|
|
||||||
{
|
|
||||||
PercentileRecord record =
|
|
||||||
load(PercentileRecord.class, PercentileRecord.getKey(gameId, type));
|
|
||||||
return (record == null) ? new Percentiler() : new Percentiler(record.data);
|
return (record == null) ? new Percentiler() : new Percentiler(record.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the supplied percentiler's data out to the database.
|
* Writes the supplied percentiler's data out to the database.
|
||||||
*/
|
*/
|
||||||
public void updatePercentile (int gameId, int type, Percentiler tiler)
|
public void updatePercentile (int gameId, Percentiler tiler)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
PercentileRecord record = new PercentileRecord();
|
PercentileRecord record = new PercentileRecord();
|
||||||
record.gameId = gameId;
|
record.gameId = gameId;
|
||||||
record.type = type;
|
|
||||||
record.data = tiler.toBytes();
|
record.data = tiler.toBytes();
|
||||||
store(record);
|
store(record);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user