Replacing stats console with a sql script
This commit is contained in:
35
gemp-lotr/db/play-stats.sql
Normal file
35
gemp-lotr/db/play-stats.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
SELECT
|
||||
G.DateOnly AS Date
|
||||
,G.game_count
|
||||
,P2.player_count
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
COUNT(*) AS game_count
|
||||
,DATE(start_date) AS DateOnly
|
||||
FROM game_history gh
|
||||
GROUP BY DateOnly
|
||||
) G
|
||||
|
||||
INNER JOIN
|
||||
(
|
||||
SELECT
|
||||
COUNT(*) AS player_count
|
||||
,P.DateOnly
|
||||
FROM (
|
||||
SELECT
|
||||
winner AS player
|
||||
,DATE(start_date) AS DateOnly
|
||||
FROM game_history gh
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
loser AS player
|
||||
,DATE(start_date) AS DateOnly
|
||||
FROM game_history gh
|
||||
) P
|
||||
GROUP BY DateOnly
|
||||
) P2
|
||||
ON P2.DateOnly = G.DateOnly
|
||||
ORDER BY G.DateOnly
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.db.DbAccess;
|
||||
import com.gempukku.lotro.db.DbGameHistoryDAO;
|
||||
import com.gempukku.lotro.db.GameHistoryDAO;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class GetStatsConsole {
|
||||
private static final SimpleDateFormat monthFormat = new SimpleDateFormat("MMM yyyy");
|
||||
private static final SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private static final SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private static final DecimalFormat percFormat = new DecimalFormat("#0.0%");
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
DbAccess dbAccess = new DbAccess();
|
||||
GameHistoryDAO gameHistoryDAO = new DbGameHistoryDAO(dbAccess);
|
||||
GameHistoryService gameHistoryService = new GameHistoryService(gameHistoryDAO);
|
||||
|
||||
createGameActiveGamesStats(gameHistoryService);
|
||||
}
|
||||
|
||||
private static void createGameActiveGamesStats(GameHistoryService gameHistoryService) throws ParseException {
|
||||
timeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
Date date = timeFormat.parse("2012-01-01 00:00:00");
|
||||
Date nextDay = timeFormat.parse("2012-01-02 00:00:00");
|
||||
Date nextWeek = timeFormat.parse("2012-01-08 00:00:00");
|
||||
|
||||
while (nextDay.getTime() < System.currentTimeMillis()) {
|
||||
int gamesCount = gameHistoryService.getGamesPlayedCount(date.getTime(), nextDay.getTime() - date.getTime());
|
||||
int playersCount = gameHistoryService.getActivePlayersCount(date.getTime(), nextWeek.getTime() - date.getTime());
|
||||
|
||||
System.out.println(dayFormat.format(date) + "," + gamesCount + "," + playersCount);
|
||||
|
||||
date.setDate(date.getDate() + 1);
|
||||
nextDay.setDate(nextDay.getDate() + 1);
|
||||
nextWeek.setDate(nextWeek.getDate() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user