Search in sources :

Example 11 with WorldTimes

use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.

the class GraphJSONCreator method serverWorldPieJSONAsMap.

public Map<String, Object> serverWorldPieJSONAsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    WorldTimes worldTimes = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID));
    WorldPie worldPie = graphs.pie().worldPie(worldTimes);
    return Maps.builder(String.class, Object.class).put("world_series", worldPie.getSlices()).put("gm_series", worldPie.toHighChartsDrillDownMaps()).build();
}
Also used : Database(com.djrapitops.plan.storage.database.Database) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

Example 12 with WorldTimes

use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.

the class ServerPreferencePie method turnToSlices.

private static List<PieSlice> turnToSlices(Map<ServerUUID, String> serverNames, Map<ServerUUID, WorldTimes> serverWorldTimes, String unknown) {
    List<PieSlice> slices = new ArrayList<>();
    for (Map.Entry<ServerUUID, WorldTimes> server : serverWorldTimes.entrySet()) {
        ServerUUID serverUUID = server.getKey();
        WorldTimes worldTimes = server.getValue();
        String serverName = serverNames.getOrDefault(serverUUID, unknown);
        long num = worldTimes.getTotal();
        slices.add(new PieSlice(serverName, num));
    }
    return slices;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ArrayList(java.util.ArrayList) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Map(java.util.Map)

Example 13 with WorldTimes

use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.

the class WorldAliasSettings method getLongestWorldPlayed.

public String getLongestWorldPlayed(FinishedSession session) {
    Optional<WorldTimes> foundWorldTimes = session.getExtraData(WorldTimes.class);
    if (!foundWorldTimes.isPresent()) {
        return locale.get().getString(HtmlLang.UNIT_NO_DATA);
    }
    WorldTimes worldTimes = foundWorldTimes.orElseGet(WorldTimes::new);
    Map<String, Long> playtimePerAlias = getPlaytimePerAlias(worldTimes);
    long total = worldTimes.getTotal();
    // Prevent arithmetic error if 0
    if (total <= 0) {
        total = -1;
    }
    long longest = 0;
    String theWorld = "-";
    for (Map.Entry<String, Long> entry : playtimePerAlias.entrySet()) {
        String world = entry.getKey();
        long time = entry.getValue();
        if (time > longest) {
            longest = time;
            theWorld = world;
        }
    }
    double quotient = longest * 1.0 / total;
    return theWorld + " (" + percentageFormatter.get().apply(quotient) + ")";
}
Also used : WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

Example 14 with WorldTimes

use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.

the class WorldTimesQueries method fetchPlayerTotalWorldTimes.

/**
 * Sum total playtime per world on all servers.
 *
 * @param playerUUID UUID of the player.
 * @return WorldTimes with world name - playtime ms information.
 */
public static Query<WorldTimes> fetchPlayerTotalWorldTimes(UUID playerUUID) {
    String sql = SELECT_WORLD_TIMES_STATEMENT_START + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.USER_UUID + "=?" + GROUP_BY + WORLD_COLUMN;
    return new QueryStatement<WorldTimes>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, playerUUID.toString());
        }

        @Override
        public WorldTimes processResults(ResultSet set) throws SQLException {
            String[] gms = GMTimes.getGMKeyArray();
            WorldTimes worldTimes = new WorldTimes();
            while (set.next()) {
                String worldName = set.getString(WORLD_COLUMN);
                GMTimes gmTimes = extractGMTimes(set, gms);
                worldTimes.setGMTimesForWorld(worldName, gmTimes);
            }
            return worldTimes;
        }
    };
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 15 with WorldTimes

use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.

the class WorldTimesQueries method fetchPlayerWorldTimesOnServers.

/**
 * Find total world times of the player on servers.
 *
 * @param playerUUID UUID of the player.
 * @return Map: Server UUID - WorldTimes total for the server
 */
public static Query<Map<ServerUUID, WorldTimes>> fetchPlayerWorldTimesOnServers(UUID playerUUID) {
    String sql = SELECT_WORLD_TIMES_STATEMENT_START + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID + ',' + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.USER_UUID + "=?" + GROUP_BY + WORLD_COLUMN + ',' + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID;
    return new QueryStatement<Map<ServerUUID, WorldTimes>>(sql, 1000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, playerUUID.toString());
        }

        @Override
        public Map<ServerUUID, WorldTimes> processResults(ResultSet set) throws SQLException {
            String[] gms = GMTimes.getGMKeyArray();
            Map<ServerUUID, WorldTimes> worldTimesMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(WorldTimesTable.SERVER_UUID));
                WorldTimes worldTimes = worldTimesMap.getOrDefault(serverUUID, new WorldTimes());
                String worldName = set.getString(WORLD_COLUMN);
                GMTimes gmTimes = extractGMTimes(set, gms);
                worldTimes.setGMTimesForWorld(worldName, gmTimes);
                worldTimesMap.put(serverUUID, worldTimes);
            }
            return worldTimesMap;
        }
    };
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Aggregations

WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)20 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)8 ServerUUID (com.djrapitops.plan.identification.ServerUUID)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)7 Test (org.junit.jupiter.api.Test)7 GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)5 PreparedStatement (java.sql.PreparedStatement)4 DataContainer (com.djrapitops.plan.delivery.domain.container.DataContainer)3 WorldPie (com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)3 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)3 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)3 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)3 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)3 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)3 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)3 ResultSet (java.sql.ResultSet)3 Map (java.util.Map)3 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)2 Database (com.djrapitops.plan.storage.database.Database)2 ArrayList (java.util.ArrayList)2