Final leaderboard repository changes for Jon
This commit is contained in:
parent
fa1cd00c22
commit
f34a2946c4
@ -21,16 +21,12 @@ public class LeaderboardRepository extends RepositoryBase
|
||||
{
|
||||
private static final int SEASON = 1;
|
||||
|
||||
private static final String CREATE_ALL_TIME = "CREATE TABLE accountStatsAllTime (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, date DATE NOT NULL, PRIMARY KEY (id), UNIQUE INDEX accountStatIndex(accountId, statId, date), INDEX valueIndex(value), FOREIGN KEY (accountId) REFERENCES Account.accounts(id), FOREIGN KEY (statId) REFERENCES Account.stats(id));";
|
||||
private static final String CREATE_ALL_TIME = "CREATE TABLE accountStatsAllTime (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, PRIMARY KEY (id), UNIQUE INDEX accountStatIndex(accountId, statId), INDEX valueIndex(value), FOREIGN KEY (accountId) REFERENCES Account.accounts(id), FOREIGN KEY (statId) REFERENCES Account.stats(id));";
|
||||
private static final String CREATE_SEASONAL = "CREATE TABLE accountStatsSeasonal (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, date DATE NOT NULL, season INT NOT NULL, PRIMARY KEY (id), UNIQUE INDEX accountStatIndex(accountId, statId, date, season), INDEX valueIndex(value), INDEX seasonIndex(season), FOREIGN KEY (accountId) REFERENCES Account.accounts(id), FOREIGN KEY (statId) REFERENCES Account.stats(id));";
|
||||
|
||||
private static final String INSERT_STAT = "INSERT INTO accountStatsSeasonal (accountId, statId, value, date, season) VALUES (?, (SELECT id FROM stats WHERE name=?), ?, CURDATE(), " + SEASON + ") ON DUPLICATE KEY UPDATE value=value+VALUES(value);";
|
||||
|
||||
private static final String FETCH_STAT_ALL = "SELECT a.name, sl.value FROM accountStatsAllTime AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=(SELECT id FROM stats WHERE name=%STAT%) ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
private static final String FETCH_STAT_YEARLY = "SELECT a.name, sl.value FROM accountStatsAllTime AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=(SELECT id FROM stats WHERE name=%STAT%) ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
private static final String FETCH_STAT_MONTHLY = "SELECT a.name, sl.value FROM accountStatsAllTime AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE MONTH(sl.date) = MONTH(CURDATE()) AND YEAR(`date`) = YEAR(CURDATE()) AND sl.statId=(SELECT id FROM stats WHERE name=%STAT%) ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
private static final String FETCH_STAT_WEEKLY = "SELECT a.name, sl.value FROM accountStatsAllTime AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEARWEEK(sl.date, 1) = YEARWEEK(CURDATE(), 1) AND sl.statId=(SELECT id FROM stats WHERE name=%STAT%) ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
private static final String FETCH_STAT_DAILY = "SELECT a.name, sl.value FROM accountStatsAllTime AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.date = CURDATE() AND sl.statId=(SELECT id FROM stats WHERE name=%STAT%) ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
|
||||
private static final String FETCH_STAT_ALL_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=(SELECT id FROM stats WHERE name=%STAT%) AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
private static final String FETCH_STAT_YEARLY_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=(SELECT id FROM stats WHERE name=%STAT%) AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
|
||||
@ -137,13 +133,9 @@ public class LeaderboardRepository extends RepositoryBase
|
||||
|
||||
public static enum LeaderboardSQLType
|
||||
{
|
||||
DAILY(FETCH_STAT_DAILY),
|
||||
DAILY_SEASON(FETCH_STAT_DAILY_SEASON),
|
||||
WEEKLY(FETCH_STAT_WEEKLY),
|
||||
WEEKLY_SEASON(FETCH_STAT_WEEKLY_SEASON),
|
||||
MONTHLY(FETCH_STAT_MONTHLY),
|
||||
MONTHLY_SEASON(FETCH_STAT_MONTHLY_SEASON),
|
||||
YEARLY(FETCH_STAT_YEARLY),
|
||||
YEARLY_SEASON(FETCH_STAT_YEARLY_SEASON),
|
||||
ALL(FETCH_STAT_ALL),
|
||||
ALL_SEASON(FETCH_STAT_ALL_SEASON)
|
||||
|
Loading…
Reference in New Issue
Block a user