Ping table to Geolocations tab (network page)

This commit is contained in:
Rsl1122 2019-08-23 11:03:28 +03:00
parent cbce9ff5aa
commit a3f00c7916
5 changed files with 72 additions and 14 deletions

View File

@ -244,4 +244,55 @@ public class PingQueries {
}
};
}
public static Query<Map<String, Ping>> fetchPingDataOfNetworkByGeolocation() {
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" +
GROUP_BY + GeoInfoTable.GEOLOCATION;
return new QueryAllStatement<Map<String, Ping>>(selectPingByGeolocation) {
@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,
null,
set.getInt("minPing"),
set.getInt("maxPing"),
set.getInt("avgPing")
);
pingByGeolocation.put(set.getString(GeoInfoTable.GEOLOCATION), ping);
}
return pingByGeolocation;
}
};
}
}

View File

@ -160,6 +160,15 @@ public class JSONFactory {
public List<Map<String, Object>> pingPerGeolocation(UUID serverUUID) {
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID));
return turnToTableEntries(pingByGeolocation);
}
public List<Map<String, Object>> pingPerGeolocation() {
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfNetworkByGeolocation());
return turnToTableEntries(pingByGeolocation);
}
private List<Map<String, Object>> turnToTableEntries(Map<String, Ping> pingByGeolocation) {
List<Map<String, Object>> tableEntries = new ArrayList<>();
for (Map.Entry<String, Ping> entry : pingByGeolocation.entrySet()) {
String geolocation = entry.getKey();
@ -174,4 +183,5 @@ public class JSONFactory {
}
return tableEntries;
}
}

View File

@ -35,10 +35,10 @@ import javax.inject.Singleton;
* @author Rsl1122
*/
@Singleton
public class NeworkJSONHandler extends TreePageHandler {
public class NetworkJSONHandler extends TreePageHandler {
@Inject
public NeworkJSONHandler(
public NetworkJSONHandler(
ResponseFactory responseFactory,
JSONFactory jsonFactory,
NetworkOverviewJSONParser networkOverviewJSONParser,
@ -49,6 +49,7 @@ public class NeworkJSONHandler extends TreePageHandler {
registerPage("overview", networkOverviewJSONParser);
registerPage("playerbaseOverview", playerBaseOverviewJSONParser);
registerPage("servers", jsonFactory::serversAsJSONMaps);
registerPage("pingTable", jsonFactory::pingPerGeolocation);
}
private <T> void registerPage(String identifier, NetworkTabJSONParser<T> tabJSONParser) {

View File

@ -54,7 +54,7 @@ public class RootJSONHandler extends TreePageHandler {
PlayerBaseOverviewJSONParser playerBaseOverviewJSONParser,
PerformanceJSONParser performanceJSONParser,
PlayerJSONHandler playerJSONHandler,
NeworkJSONHandler neworkJSONHandler
NetworkJSONHandler networkJSONHandler
) {
super(responseFactory);
@ -75,7 +75,7 @@ public class RootJSONHandler extends TreePageHandler {
registerPage("performanceOverview", performanceJSONParser);
registerPage("player", playerJSONHandler);
registerPage("network", neworkJSONHandler);
registerPage("network", networkJSONHandler);
}
private <T> void registerPage(String identifier, ServerTabJSONParser<T> tabJSONParser) {

View File

@ -607,7 +607,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">
@ -645,7 +645,7 @@
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>
@ -654,14 +654,7 @@
<th><i class=" fa fa-fw fa-signal"></i> Best Ping</th>
</tr>
</thead>
<tbody>
<tr>
<td>Local Machine</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
<tbody></tbody>
</table>
</div>
</div>
@ -874,6 +867,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/network-values.js"></script>
@ -1006,6 +1000,8 @@
setLoadingText('Sorting out plugin tables..');
jsonRequest("../v1/network/pingTable", loadPingTable);
$('.server-name').text('${networkDisplayName}');
$('.player-plugin-table').DataTable({
responsive: true