use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class GraphJSONCreator method serverWorldPieJSONAsMap.
public Map<String, Object> serverWorldPieJSONAsMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
WorldTimes worldTimes = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID));
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
return Maps.builder(String.class, Object.class).put("world_series", worldPie.getSlices()).put("gm_series", worldPie.toHighChartsDrillDownMaps()).build();
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class ServerPreferencePie method turnToSlices.
private static List<PieSlice> turnToSlices(Map<ServerUUID, String> serverNames, Map<ServerUUID, WorldTimes> serverWorldTimes, String unknown) {
List<PieSlice> slices = new ArrayList<>();
for (Map.Entry<ServerUUID, WorldTimes> server : serverWorldTimes.entrySet()) {
ServerUUID serverUUID = server.getKey();
WorldTimes worldTimes = server.getValue();
String serverName = serverNames.getOrDefault(serverUUID, unknown);
long num = worldTimes.getTotal();
slices.add(new PieSlice(serverName, num));
}
return slices;
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class WorldAliasSettings method getLongestWorldPlayed.
public String getLongestWorldPlayed(FinishedSession session) {
Optional<WorldTimes> foundWorldTimes = session.getExtraData(WorldTimes.class);
if (!foundWorldTimes.isPresent()) {
return locale.get().getString(HtmlLang.UNIT_NO_DATA);
}
WorldTimes worldTimes = foundWorldTimes.orElseGet(WorldTimes::new);
Map<String, Long> playtimePerAlias = getPlaytimePerAlias(worldTimes);
long total = worldTimes.getTotal();
// Prevent arithmetic error if 0
if (total <= 0) {
total = -1;
}
long longest = 0;
String theWorld = "-";
for (Map.Entry<String, Long> entry : playtimePerAlias.entrySet()) {
String world = entry.getKey();
long time = entry.getValue();
if (time > longest) {
longest = time;
theWorld = world;
}
}
double quotient = longest * 1.0 / total;
return theWorld + " (" + percentageFormatter.get().apply(quotient) + ")";
}
use of com.djrapitops.plan.gathering.domain.WorldTimes 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.WorldTimes 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