Replacing stats console with a sql script

This commit is contained in:
Christian 'ketura' McCarty
2023-03-12 22:09:44 -05:00
parent 5a1da08991
commit bb80552044
2 changed files with 35 additions and 44 deletions

View 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

View File

@@ -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);
}
}
}