Search in sources :

Example 1 with SessionStartComparator

use of com.djrapitops.plan.utilities.comparators.SessionStartComparator in project Plan by plan-player-analytics.

the class JSONFactory method networkSessionsAsJSONMap.

public List<Map<String, Object>> networkSessionsAsJSONMap() {
    Database db = dbSystem.getDatabase();
    Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
    List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessions(perPageLimit));
    // Add online sessions
    if (serverInfo.getServer().isProxy()) {
        addActiveSessions(sessions);
        sessions.sort(new SessionStartComparator());
        while (true) {
            int size = sessions.size();
            if (size <= perPageLimit)
                break;
            // Remove last until it fits.
            sessions.remove(size - 1);
        }
    }
    List<Map<String, Object>> sessionMaps = new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
    // Add network_server property so that sessions have a server page link
    sessionMaps.forEach(map -> map.put("network_server", map.get("server_name")));
    return sessionMaps;
}
Also used : Database(com.djrapitops.plan.storage.database.Database) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Example 2 with SessionStartComparator

use of com.djrapitops.plan.utilities.comparators.SessionStartComparator in project Plan by plan-player-analytics.

the class JSONFactory method serverSessionsAsJSONMap.

public List<Map<String, Object>> serverSessionsAsJSONMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
    List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessionsOfServer(serverUUID, perPageLimit));
    // Add online sessions
    if (serverUUID.equals(serverInfo.getServerUUID())) {
        addActiveSessions(sessions);
        sessions.sort(new SessionStartComparator());
        while (true) {
            int size = sessions.size();
            if (size <= perPageLimit)
                break;
            // Remove last until it fits.
            sessions.remove(size - 1);
        }
    }
    return new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
}
Also used : Database(com.djrapitops.plan.storage.database.Database) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Aggregations

SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)2 Database (com.djrapitops.plan.storage.database.Database)2 SessionStartComparator (com.djrapitops.plan.utilities.comparators.SessionStartComparator)2