Search in sources :

Example 6 with GMTimes

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

the class SessionsOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    List<TPS> tpsData = db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID));
    TPSMutator tpsMutator = new TPSMutator(tpsData);
    Map<String, Object> insights = new HashMap<>();
    long uptime = TimeUnit.DAYS.toMillis(30L) - tpsMutator.serverDownTime();
    long occupied = tpsMutator.serverOccupiedTime();
    insights.put("server_occupied", timeAmount.apply(occupied));
    insights.put("server_occupied_perc", percentage.apply(Percentage.calculate(occupied, uptime, -1)));
    Long playtime = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
    Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now, serverUUID));
    insights.put("total_playtime", timeAmount.apply(playtime));
    insights.put("afk_time", timeAmount.apply(afkTime));
    insights.put("afk_time_perc", percentage.apply(Percentage.calculate(afkTime, playtime, -1)));
    GMTimes gmTimes = db.query(WorldTimesQueries.fetchGMTimes(monthAgo, now, serverUUID));
    Optional<String> mostUsedGameMode = gmTimes.getMostUsedGameMode();
    Long longestGMTime = mostUsedGameMode.map(gmTimes::getTime).orElse(-1L);
    insights.put("most_active_gamemode", mostUsedGameMode.map(WordUtils::capitalizeFully).orElse("Not Known"));
    insights.put("most_active_gamemode_perc", percentage.apply(Percentage.calculate(longestGMTime, playtime, -1)));
    return insights;
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) WordUtils(org.apache.commons.text.WordUtils) TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 7 with GMTimes

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

the class ImportBuilderTest method userDataBuilderConstructsCorrectItem.

@Test
void userDataBuilderConstructsCorrectItem() {
    UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
    UUID uuid = UUID.randomUUID();
    PlayerKill playerKill = TestData.getPlayerKill(uuid, uuid, TestConstants.SERVER_UUID, randomString, 1);
    GMTimes gmTimes = new GMTimes(randomString, randomInt);
    UserImportData data = builder.uuid(uuid).banned().banned(false).op().ips(randomString, randomString).ips(Collections.singletonList(randomString)).kills(playerKill, playerKill, playerKill).kills(Collections.singleton(playerKill)).name(randomString).registered(randomInt).timesKicked(randomInt).mobKills(randomInt).worldTimes(randomString, randomInt, randomInt, randomInt, randomInt).worldTimes(randomString, gmTimes).deaths(randomInt).worldTimes(ImmutableMap.of(randomString, gmTimes)).nicknames(randomString, randomString).nicknames(Collections.singletonList(new Nickname(randomString, System.currentTimeMillis(), TestConstants.SERVER_UUID))).build();
    assertNotNull(data);
    assertFalse(data.isBanned());
    assertTrue(data.isOp());
    assertEquals(randomInt, data.getDeaths());
    assertEquals(1, data.getWorldTimes().size());
    assertEquals(3, data.getIps().size());
    assertEquals(playerKill, data.getKills().get(0));
    assertEquals(randomInt, data.getMobKills());
    assertEquals(3, data.getNicknames().size());
    assertEquals(randomInt, data.getTimesKicked());
    assertEquals(uuid, data.getUuid());
    assertEquals(randomString, data.getName());
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) UUID(java.util.UUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Example 8 with GMTimes

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

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

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