Search in sources :

Example 26 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class ServerPageExporter method exportHtml.

private void exportHtml(Path toDirectory, Server server) throws IOException {
    ServerUUID serverUUID = server.getUuid();
    Path to = toDirectory.resolve(serverInfo.getServer().isProxy() ? "server/" + toFileName(server.getName()) : "server").resolve("index.html");
    Page page = pageFactory.serverPage(serverUUID);
    // Fixes refreshingJsonRequest ignoring old data of export
    String html = StringUtils.replaceEach(page.toHtml(), new String[] { "loadOptimizedPerformanceGraph, 'performance', true);", "loadServerCalendar, 'online-activity-overview', true);", "}, 'playerlist', true);", "<head>" }, new String[] { "loadOptimizedPerformanceGraph, 'performance');", "loadServerCalendar, 'online-activity-overview');", "}, 'playerlist');", "<head><style>.refresh-element {display: none;}</style>" });
    export(to, exportPaths.resolveExportPaths(html));
}
Also used : Path(java.nio.file.Path) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Page(com.djrapitops.plan.delivery.rendering.pages.Page)

Example 27 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class PingMutator method addPingToSessions.

public void addPingToSessions(List<FinishedSession> sessions) {
    if (sessions.isEmpty())
        return;
    Comparator<DateHolder> comparator = new DateHolderOldestComparator();
    sessions.sort(comparator);
    pings.sort(comparator);
    Map<ServerUUID, SortedMap<Long, Ping>> pingByServer = sortByServers(pings);
    Map<ServerUUID, List<FinishedSession>> sessionsByServer = SessionsMutator.sortByServers(sessions);
    for (Map.Entry<ServerUUID, SortedMap<Long, Ping>> entry : pingByServer.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        SortedMap<Long, Ping> pingOfServer = entry.getValue();
        if (pingOfServer.isEmpty())
            continue;
        List<FinishedSession> sessionsOfServer = sessionsByServer.getOrDefault(serverUUID, Collections.emptyList());
        double pingCount = 0.0;
        int pingEntries = 0;
        for (FinishedSession session : sessionsOfServer) {
            long start = session.getDate();
            long end = session.getEnd();
            if (end < start)
                continue;
            // Calculate average ping for each session with a section of the Ping map
            SortedMap<Long, Ping> duringSession = pingOfServer.subMap(start, end);
            for (Ping ping : duringSession.values()) {
                pingCount += ping.getAverage();
                pingEntries++;
            }
            if (pingEntries != 0) {
                session.getExtraData().put(AveragePing.class, new AveragePing(pingCount / pingEntries));
            }
            pingCount = 0.0;
            pingEntries = 0;
        }
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) DateHolder(com.djrapitops.plan.delivery.domain.DateHolder) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Ping(com.djrapitops.plan.gathering.domain.Ping) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) DateHolderOldestComparator(com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)

Example 28 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class PingMutator method sortByServers.

public static Map<ServerUUID, SortedMap<Long, Ping>> sortByServers(List<Ping> pings) {
    Map<ServerUUID, SortedMap<Long, Ping>> sorted = new HashMap<>();
    for (Ping ping : pings) {
        ServerUUID serverUUID = ping.getServerUUID();
        SortedMap<Long, Ping> serverSessions = sorted.getOrDefault(serverUUID, new TreeMap<>());
        serverSessions.put(ping.getDate(), ping);
        sorted.put(serverUUID, serverSessions);
    }
    return sorted;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Ping(com.djrapitops.plan.gathering.domain.Ping) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing)

Example 29 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID 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 30 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class PlayerOnlineListener method actOnQuitEvent.

private void actOnQuitEvent(ClientConnectionEvent.Disconnect event) {
    long time = System.currentTimeMillis();
    Player player = event.getTargetEntity();
    String playerName = player.getName();
    UUID playerUUID = player.getUniqueId();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    SpongeAFKListener.afkTracker.loggedOut(playerUUID, time);
    nicknameCache.removeDisplayName(playerUUID);
    dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, () -> isBanned(player.getProfile())));
    sessionCache.endSession(playerUUID, time).ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID)

Aggregations

ServerUUID (com.djrapitops.plan.identification.ServerUUID)105 UUID (java.util.UUID)26 ResultSet (java.sql.ResultSet)23 PreparedStatement (java.sql.PreparedStatement)21 Database (com.djrapitops.plan.storage.database.Database)17 Test (org.junit.jupiter.api.Test)17 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)14 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)12 Nickname (com.djrapitops.plan.delivery.domain.Nickname)11 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)11 Server (com.djrapitops.plan.identification.Server)11 HashMap (java.util.HashMap)11 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)9 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)9 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)9 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)9 Lists (com.djrapitops.plan.utilities.java.Lists)9 CallEvents (com.djrapitops.plan.extension.CallEvents)8 List (java.util.List)8 Map (java.util.Map)8