Ping table to Geolocations tab (server page)

This commit is contained in:
Rsl1122 2019-08-23 10:55:14 +03:00
parent a389dff035
commit cbce9ff5aa
7 changed files with 126 additions and 23 deletions

View File

@ -161,19 +161,19 @@ public class GeoInfoQueries {
}
public static Query<Map<String, Integer>> serverGeolocationCounts(UUID serverUUID) {
String subQuery1 = SELECT +
String selectGeolocations = SELECT +
GeoInfoTable.USER_UUID + ", " +
GeoInfoTable.GEOLOCATION + ", " +
GeoInfoTable.LAST_USED +
FROM + GeoInfoTable.TABLE_NAME;
String subQuery2 = SELECT +
String selectLatestGeolocationDate = SELECT +
GeoInfoTable.USER_UUID + ", " +
"MAX(" + GeoInfoTable.LAST_USED + ") as m" +
FROM + GeoInfoTable.TABLE_NAME +
GROUP_BY + GeoInfoTable.USER_UUID;
String sql = SELECT + GeoInfoTable.GEOLOCATION + ", COUNT(1) as c FROM (" +
"(" + subQuery1 + ") AS q1" +
INNER_JOIN + "(" + subQuery2 + ") AS q2 ON q1.uuid = q2.uuid" +
"(" + selectGeolocations + ") AS q1" +
INNER_JOIN + "(" + selectLatestGeolocationDate + ") AS q2 ON q1.uuid = q2.uuid" +
INNER_JOIN + UserInfoTable.TABLE_NAME + " u on u." + UserInfoTable.USER_UUID + "=q1.uuid)" +
WHERE + GeoInfoTable.LAST_USED + "=m" +
AND + "u." + UserInfoTable.SERVER_UUID + "=?" +

View File

@ -21,6 +21,7 @@ import com.djrapitops.plan.data.container.Ping;
import com.djrapitops.plan.db.access.Query;
import com.djrapitops.plan.db.access.QueryAllStatement;
import com.djrapitops.plan.db.access.QueryStatement;
import com.djrapitops.plan.db.sql.tables.GeoInfoTable;
import com.djrapitops.plan.db.sql.tables.PingTable;
import java.sql.PreparedStatement;
@ -186,4 +187,61 @@ public class PingQueries {
}
};
}
public static Query<Map<String, Ping>> fetchPingDataOfServerByGeolocation(UUID serverUUID) {
String selectPingOfServer = SELECT +
PingTable.MAX_PING + ", " +
PingTable.MIN_PING + ", " +
PingTable.AVG_PING + ", " +
PingTable.USER_UUID + ", " +
PingTable.SERVER_UUID +
FROM + PingTable.TABLE_NAME;
String selectGeolocations = SELECT +
GeoInfoTable.USER_UUID + ", " +
GeoInfoTable.GEOLOCATION + ", " +
GeoInfoTable.LAST_USED +
FROM + GeoInfoTable.TABLE_NAME;
String selectLatestGeolocationDate = SELECT +
GeoInfoTable.USER_UUID + ", " +
"MAX(" + GeoInfoTable.LAST_USED + ") as m" +
FROM + GeoInfoTable.TABLE_NAME +
GROUP_BY + GeoInfoTable.USER_UUID;
String selectPingByGeolocation = SELECT + GeoInfoTable.GEOLOCATION +
", MIN(" + PingTable.MIN_PING + ") as minPing" +
", MAX(" + PingTable.MAX_PING + ") as maxPing" +
", AVG(" + PingTable.AVG_PING + ") as avgPing" +
FROM + "(" +
"(" + selectGeolocations + ") AS q1" +
INNER_JOIN + "(" + selectLatestGeolocationDate + ") AS q2 ON q1.uuid = q2.uuid" +
INNER_JOIN + '(' + selectPingOfServer + ") sp on sp." + PingTable.USER_UUID + "=q1.uuid)" +
WHERE + GeoInfoTable.LAST_USED + "=m" +
AND + "sp." + PingTable.SERVER_UUID + "=?" +
GROUP_BY + GeoInfoTable.GEOLOCATION;
return new QueryStatement<Map<String, Ping>>(selectPingByGeolocation) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
@Override
public Map<String, Ping> processResults(ResultSet set) throws SQLException {
// TreeMap to sort alphabetically
Map<String, Ping> pingByGeolocation = new TreeMap<>();
while (set.next()) {
Ping ping = new Ping(
0L,
serverUUID,
set.getInt("minPing"),
set.getInt("maxPing"),
set.getInt("avgPing")
);
pingByGeolocation.put(set.getString(GeoInfoTable.GEOLOCATION), ping);
}
return pingByGeolocation;
}
};
}
}

View File

@ -16,6 +16,7 @@
*/
package com.djrapitops.plan.system.json;
import com.djrapitops.plan.data.container.Ping;
import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.container.TPS;
@ -26,10 +27,7 @@ import com.djrapitops.plan.data.store.objects.DateObj;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.analysis.PlayerCountQueries;
import com.djrapitops.plan.db.access.queries.containers.ServerPlayersTableContainersQuery;
import com.djrapitops.plan.db.access.queries.objects.KillQueries;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.db.access.queries.objects.SessionQueries;
import com.djrapitops.plan.db.access.queries.objects.TPSQueries;
import com.djrapitops.plan.db.access.queries.objects.*;
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerPlayerDataTableQuery;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.Server;
@ -159,4 +157,21 @@ public class JSONFactory {
});
return servers;
}
public List<Map<String, Object>> pingPerGeolocation(UUID serverUUID) {
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID));
List<Map<String, Object>> tableEntries = new ArrayList<>();
for (Map.Entry<String, Ping> entry : pingByGeolocation.entrySet()) {
String geolocation = entry.getKey();
Ping ping = entry.getValue();
Map<String, Object> tableEntry = new HashMap<>();
tableEntry.put("country", geolocation);
tableEntry.put("avg_ping", ping.getAverage());
tableEntry.put("min_ping", ping.getMin());
tableEntry.put("max_ping", ping.getMax());
tableEntries.add(tableEntry);
}
return tableEntries;
}
}

View File

@ -41,6 +41,7 @@ public class RootJSONHandler extends TreePageHandler {
public RootJSONHandler(
ResponseFactory responseFactory,
Identifiers identifiers,
JSONFactory jsonFactory,
GraphsJSONHandler graphsJSONHandler,
SessionsJSONHandler sessionsJSONHandler,
PlayersTableJSONHandler playersTableJSONHandler,
@ -62,6 +63,7 @@ public class RootJSONHandler extends TreePageHandler {
registerPage("players", playersTableJSONHandler);
registerPage("sessions", sessionsJSONHandler);
registerPage("kills", playerKillsJSONHandler);
registerPage("pingTable", jsonFactory::pingPerGeolocation);
registerPage("graph", graphsJSONHandler);
registerPage("extensions", pluginTabJSONParser);

View File

@ -0,0 +1,32 @@
function loadPingTable(json, error) {
pingTable = $("#geolocations").find("#data_ping_table").find("tbody");
if (error) {
pingTable.append('<tr><td>Error: ' + error + '</td><td>-</td><td>-</td><td>-</td></tr>');
return;
}
var countries = json;
if (!countries.length) {
pingTable.append('<tr><td>No Ping Data</td><td>-</td><td>-</td><td>-</td></tr>');
return;
}
var tableHtml = '';
for (var i = 0; i < countries.length; i++) {
var country = countries[i];
tableHtml += createPingTableRow(country);
}
pingTable.append(tableHtml);
}
function createPingTableRow(entry) {
return '<tr><td>' + entry.country +
'</td><td>' + entry.avg_ping +
'</td><td>' + entry.min_ping +
'</td><td>' + entry.max_ping +
'</td></tr>'
}

View File

@ -1,15 +1,16 @@
function loadSessionAccordion(json, error) {
sessionTable = $("#sessions-overview").find("#tableAccordion").find("tbody");
if (error) {
$('#sessions-overview').addClass('forbidden'); // TODO Figure out 403
sessionTable.append('<tr><td>Error: ' + error + '</td><td>-</td><td>-</td><td>-</td></tr>');
return;
}
sessionTable = $("#sessions-overview").find("#tableAccordion").find("tbody");
var sessions = json.sessions;
if (!sessions.length) {
sessionTable.append('<tr><td>No Sessions</td><td>-</td><td>-</td><td>-</td></tr>')
sessionTable.append('<tr><td>No Sessions</td><td>-</td><td>-</td><td>-</td></tr>');
return;
}
// sessions_per_page can be undefined (-> NaN) or higher than amount of sessions.

View File

@ -895,7 +895,7 @@
</div> <!-- /.container-fluid -->
</div> <!-- End of Player List tab -->
<!-- Begin Geolocations Tab -->
<div class="tab">
<div class="tab" id="geolocations">
<div class="container-fluid mt-4">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
@ -939,23 +939,16 @@
Connection Information</h6>
</div>
<div class="scrollbar">
<table class="table">
<table class="table" id="data_ping_table">
<thead class="bg-amber">
<tr>
<th><i class=" fa fa-fw fa-globe"></i> Country</th>
<th><i class=" fa fa-fw fa-signal"></i> Average Ping</th>
<th><i class=" fa fa-fw fa-signal"></i> Worst Ping</th>
<th><i class=" fa fa-fw fa-signal"></i> Best Ping</th>
<th><i class=" fa fa-fw fa-signal"></i> Worst Ping</th>
</tr>
</thead>
<tbody>
<tr>
<td>Local Machine</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
<tbody></tbody>
</table>
</div>
</div>
@ -1365,6 +1358,7 @@
<!-- Page level custom scripts -->
<script src="js/sessionAccordion.js"></script>
<script src="js/pingTable.js"></script>
<script src="js/graphs.js"></script>
<script src="js/server-values.js"></script>
@ -1670,6 +1664,7 @@
}
});
jsonRequest("../v1/kills?server=${serverName}", loadPlayerKills);
jsonRequest("../v1/pingTable?server=${serverName}", loadPingTable);
$('.server-name').text('${serverName}');
$('.player-plugin-table').DataTable({