Search in sources :

Example 1 with GMTimes

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

the class WorldAliasSettings method getGMTimesPerAlias.

public Map<String, GMTimes> getGMTimesPerAlias(WorldTimes worldTimes) {
    Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();
    String[] gms = GMTimes.getGMKeyArray();
    for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
        String worldName = entry.getKey();
        GMTimes gmTimes = entry.getValue();
        Optional<String> foundAlias = getAlias(worldName);
        if (!foundAlias.isPresent()) {
            addWorld(worldName);
        }
        String alias = foundAlias.orElse(worldName);
        GMTimes aliasGMTimes = gmTimesPerAlias.getOrDefault(alias, new GMTimes());
        for (String gm : gms) {
            aliasGMTimes.addTime(gm, gmTimes.getTime(gm));
        }
        gmTimesPerAlias.put(alias, aliasGMTimes);
    }
    return gmTimesPerAlias;
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes)

Example 2 with GMTimes

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

the class PieGraphFactory method worldPie.

public WorldPie worldPie(WorldTimes worldTimes) {
    WorldAliasSettings worldAliasSettings = config.getWorldAliasSettings();
    Map<String, Long> playtimePerAlias = worldAliasSettings.getPlaytimePerAlias(worldTimes);
    Map<String, GMTimes> gmTimesPerAlias = worldAliasSettings.getGMTimesPerAlias(worldTimes);
    String[] colors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
    boolean orderByPercentage = config.isTrue(DisplaySettings.ORDER_WORLD_PIE_BY_PERCENTAGE);
    return new WorldPie(playtimePerAlias, gmTimesPerAlias, colors, orderByPercentage);
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) WorldAliasSettings(com.djrapitops.plan.settings.config.WorldAliasSettings)

Example 3 with GMTimes

use of com.djrapitops.plan.gathering.domain.GMTimes 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 4 with GMTimes

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

the class WorldTimesQueries method fetchGMTimes.

public static Query<GMTimes> fetchGMTimes(long after, long before, ServerUUID serverUUID) {
    String sql = SELECT + "SUM(" + WorldTimesTable.SURVIVAL + ") as SURVIVAL," + "SUM(" + WorldTimesTable.CREATIVE + ") as CREATIVE," + "SUM(" + WorldTimesTable.ADVENTURE + ") as ADVENTURE," + "SUM(" + WorldTimesTable.SPECTATOR + ") as SPECTATOR" + FROM + WorldTimesTable.TABLE_NAME + " w1" + INNER_JOIN + SessionsTable.TABLE_NAME + " s1 on s1." + SessionsTable.ID + '=' + WorldTimesTable.SESSION_ID + WHERE + "w1." + WorldTimesTable.SERVER_UUID + "=?" + AND + SessionsTable.SESSION_START + ">=?" + AND + SessionsTable.SESSION_END + "<=?";
    return new QueryStatement<GMTimes>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, serverUUID.toString());
            statement.setLong(2, after);
            statement.setLong(3, before);
        }

        @Override
        public GMTimes processResults(ResultSet set) throws SQLException {
            return set.next() ? extractGMTimes(set, GMTimes.getGMKeyArray()) : new GMTimes();
        }
    };
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 5 with GMTimes

use of com.djrapitops.plan.gathering.domain.GMTimes 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)

Aggregations

GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)9 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)4 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 UUID (java.util.UUID)2 Nickname (com.djrapitops.plan.delivery.domain.Nickname)1 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)1 PlayerKill (com.djrapitops.plan.gathering.domain.PlayerKill)1 TPS (com.djrapitops.plan.gathering.domain.TPS)1 WorldAliasSettings (com.djrapitops.plan.settings.config.WorldAliasSettings)1 Database (com.djrapitops.plan.storage.database.Database)1 Map (java.util.Map)1 WordUtils (org.apache.commons.text.WordUtils)1 Test (org.junit.jupiter.api.Test)1