Search in sources :

Example 6 with WorldTimes

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

the class PerServerMutator method worldTimesPerServer.

public Map<ServerUUID, WorldTimes> worldTimesPerServer() {
    Map<ServerUUID, WorldTimes> timesMap = new HashMap<>();
    for (Map.Entry<ServerUUID, DataContainer> entry : data.entrySet()) {
        DataContainer container = entry.getValue();
        timesMap.put(entry.getKey(), container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes()));
    }
    return timesMap;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

Example 7 with WorldTimes

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

the class ServerAccordion method asMaps.

public List<Map<String, Object>> asMaps() {
    List<Map<String, Object>> servers = new ArrayList<>();
    for (Map.Entry<ServerUUID, DataContainer> entry : perServer.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        DataContainer ofServer = entry.getValue();
        Map<String, Object> server = new HashMap<>();
        String serverName = serverNames.getOrDefault(serverUUID, unknown);
        WorldTimes worldTimes = ofServer.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes());
        SessionsMutator sessionsMutator = SessionsMutator.forContainer(ofServer);
        server.put("server_name", serverName);
        server.put("banned", ofServer.getValue(PerServerKeys.BANNED).orElse(false));
        server.put("operator", ofServer.getValue(PerServerKeys.OPERATOR).orElse(false));
        server.put("registered", year.apply(ofServer.getValue(PerServerKeys.REGISTERED).orElse(0L)));
        server.put("last_seen", year.apply(sessionsMutator.toLastSeen()));
        server.put("join_address", ofServer.getValue(PerServerKeys.JOIN_ADDRESS).orElse("-"));
        server.put("session_count", sessionsMutator.count());
        server.put("playtime", timeAmount.apply(sessionsMutator.toPlaytime()));
        server.put("afk_time", timeAmount.apply(sessionsMutator.toAfkTime()));
        server.put("session_median", timeAmount.apply(sessionsMutator.toMedianSessionLength()));
        server.put("longest_session_length", timeAmount.apply(sessionsMutator.toLongestSessionLength()));
        server.put("mob_kills", sessionsMutator.toMobKillCount());
        server.put("player_kills", sessionsMutator.toPlayerKillCount());
        server.put("deaths", sessionsMutator.toDeathCount());
        WorldPie worldPie = graphs.pie().worldPie(worldTimes);
        server.put("world_pie_series", worldPie.getSlices());
        server.put("gm_series", worldPie.toHighChartsDrillDownMaps());
        servers.add(server);
    }
    return servers;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie) HashMap(java.util.HashMap) Map(java.util.Map) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Example 8 with WorldTimes

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

the class WorldTimesQueries method fetchServerTotalWorldTimes.

/**
 * Sum total playtime per world on a server.
 *
 * @param serverUUID Server UUID of the Plan server.
 * @return WorldTimes with world name - playtime ms information.
 */
public static Query<WorldTimes> fetchServerTotalWorldTimes(ServerUUID serverUUID) {
    String sql = SELECT_WORLD_TIMES_STATEMENT_START + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID + "=?" + GROUP_BY + WORLD_COLUMN;
    return new QueryStatement<WorldTimes>(sql, 1000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, serverUUID.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 9 with WorldTimes

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

the class WorldTimesTable method addSessionWorldTimesToBatch.

public static void addSessionWorldTimesToBatch(PreparedStatement statement, FinishedSession session, String[] gms) throws SQLException {
    UUID uuid = session.getPlayerUUID();
    ServerUUID serverUUID = session.getServerUUID();
    Optional<WorldTimes> worldTimes = session.getExtraData().get(WorldTimes.class);
    if (!worldTimes.isPresent())
        return;
    for (Map.Entry<String, GMTimes> worldTimesEntry : worldTimes.get().getWorldTimes().entrySet()) {
        String worldName = worldTimesEntry.getKey();
        GMTimes gmTimes = worldTimesEntry.getValue();
        // Session ID select statement
        statement.setString(1, uuid.toString());
        statement.setString(2, serverUUID.toString());
        statement.setLong(3, session.getStart());
        statement.setLong(4, session.getEnd());
        // World ID select statement
        statement.setString(5, worldName);
        statement.setString(6, serverUUID.toString());
        statement.setString(7, uuid.toString());
        statement.setString(8, serverUUID.toString());
        statement.setLong(9, gmTimes.getTime(gms[0]));
        statement.setLong(10, gmTimes.getTime(gms[1]));
        statement.setLong(11, gmTimes.getTime(gms[2]));
        statement.setLong(12, gmTimes.getTime(gms[3]));
        statement.addBatch();
    }
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) Map(java.util.Map)

Example 10 with WorldTimes

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

the class PlayerJSONCreator method createJSONAsMap.

public Map<String, Object> createJSONAsMap(UUID playerUUID) {
    Database db = dbSystem.getDatabase();
    Map<ServerUUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
    String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
    PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
    SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
    Map<ServerUUID, WorldTimes> worldTimesPerServer = PerServerMutator.forContainer(player).worldTimesPerServer();
    List<Map<String, Object>> serverAccordion = new ServerAccordion(player, serverNames, graphs, year, timeAmount, locale.getString(GenericLang.UNKNOWN)).asMaps();
    List<PlayerKill> kills = player.getValue(PlayerKeys.PLAYER_KILLS).orElse(Collections.emptyList());
    List<PlayerKill> deaths = player.getValue(PlayerKeys.PLAYER_DEATHS_KILLS).orElse(Collections.emptyList());
    PingMutator.forContainer(player).addPingToSessions(sessionsMutator.all());
    Map<String, Object> data = new HashMap<>();
    data.put("info", createInfoJSONMap(player, serverNames));
    data.put("online_activity", createOnlineActivityJSONMap(sessionsMutator));
    data.put("kill_data", createPvPPvEMap(player));
    data.put("nicknames", player.getValue(PlayerKeys.NICKNAMES).map(nicks -> Nickname.fromDataNicknames(nicks, serverNames, year)).orElse(Collections.emptyList()));
    data.put("connections", player.getValue(PlayerKeys.GEO_INFO).map(geoInfo -> ConnectionInfo.fromGeoInfo(geoInfo, year)).orElse(Collections.emptyList()));
    data.put("player_kills", new PlayerKillMutator(kills).filterNonSelfKills().toJSONAsMap(formatters));
    data.put("player_deaths", new PlayerKillMutator(deaths).toJSONAsMap(formatters));
    data.put("sessions", sessionsMutator.sort(new DateHolderRecentComparator()).toServerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters));
    data.put("sessions_per_page", config.get(DisplaySettings.SESSIONS_PER_PAGE));
    data.put("servers", serverAccordion);
    data.put("punchcard_series", graphs.special().punchCard(sessionsMutator).getDots());
    WorldPie worldPie = graphs.pie().worldPie(player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes()));
    data.put("world_pie_series", worldPie.getSlices());
    data.put("gm_series", worldPie.toHighChartsDrillDownMaps());
    data.put("calendar_series", graphs.calendar().playerCalendar(player).getEntries());
    data.put("server_pie_series", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).getSlices());
    data.put("server_pie_colors", pieColors);
    // Monday
    data.put("first_day", 1);
    return data;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Database(com.djrapitops.plan.storage.database.Database) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)

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