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;
}
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());
}
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;
}
};
}
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;
}
};
}
Aggregations