mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-04 14:31:34 +01:00
Changed ping table json format
In order to support timestamp values the json is now an object instead of an array. Previously available data is accessible via json.table
This commit is contained in:
parent
e2af7bb467
commit
0ac377bd93
@ -44,6 +44,7 @@ import com.djrapitops.plan.storage.database.queries.objects.*;
|
|||||||
import com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery;
|
import com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery;
|
import com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery;
|
||||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||||
|
import com.djrapitops.plan.utilities.java.Maps;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -222,14 +223,18 @@ public class JSONFactory {
|
|||||||
return servers;
|
return servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Map<String, Object>> pingPerGeolocation(UUID serverUUID) {
|
public Map<String, Object> pingPerGeolocation(UUID serverUUID) {
|
||||||
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID));
|
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID));
|
||||||
return turnToTableEntries(pingByGeolocation);
|
return Maps.builder(String.class, Object.class)
|
||||||
|
.put("table", turnToTableEntries(pingByGeolocation))
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Map<String, Object>> pingPerGeolocation() {
|
public Map<String, Object> pingPerGeolocation() {
|
||||||
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfNetworkByGeolocation());
|
Map<String, Ping> pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfNetworkByGeolocation());
|
||||||
return turnToTableEntries(pingByGeolocation);
|
return Maps.builder(String.class, Object.class)
|
||||||
|
.put("table", turnToTableEntries(pingByGeolocation))
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Map<String, Object>> turnToTableEntries(Map<String, Ping> pingByGeolocation) {
|
private List<Map<String, Object>> turnToTableEntries(Map<String, Ping> pingByGeolocation) {
|
||||||
@ -238,12 +243,12 @@ public class JSONFactory {
|
|||||||
String geolocation = entry.getKey();
|
String geolocation = entry.getKey();
|
||||||
Ping ping = entry.getValue();
|
Ping ping = entry.getValue();
|
||||||
|
|
||||||
Map<String, Object> tableEntry = new HashMap<>();
|
tableEntries.add(Maps.builder(String.class, Object.class)
|
||||||
tableEntry.put("country", geolocation);
|
.put("country", geolocation)
|
||||||
tableEntry.put("avg_ping", formatters.decimals().apply(ping.getAverage()) + " ms");
|
.put("avg_ping", formatters.decimals().apply(ping.getAverage()) + " ms")
|
||||||
tableEntry.put("min_ping", ping.getMin() + " ms");
|
.put("min_ping", ping.getMin() + " ms")
|
||||||
tableEntry.put("max_ping", ping.getMax() + " ms");
|
.put("max_ping", ping.getMax() + " ms")
|
||||||
tableEntries.add(tableEntry);
|
.build());
|
||||||
}
|
}
|
||||||
return tableEntries;
|
return tableEntries;
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,26 @@
|
|||||||
function loadPingTable(json, error) {
|
function loadPingTable(json, error) {
|
||||||
pingTable = $("#geolocations").find("#data_ping_table").find("tbody");
|
const pingTable = document.querySelector('#geolocations #data_ping_table tbody');
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
pingTable.append('<tr><td>Error: ' + error + '</td><td>-</td><td>-</td><td>-</td></tr>');
|
pingTable.innerHTML = `<tr><td>Error: ${error}</td><td>-</td><td>-</td><td>-</td></tr>`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var countries = json;
|
const countries = json.table;
|
||||||
|
|
||||||
if (!countries.length) {
|
if (!countries.length) {
|
||||||
pingTable.append('<tr><td>No Data</td><td>-</td><td>-</td><td>-</td></tr>');
|
pingTable.innerHTML = '<tr><td>No Data</td><td>-</td><td>-</td><td>-</td></tr>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tableHtml = '';
|
pingTable.innerHTML = countries.map(createPingTableRow).join('');
|
||||||
|
|
||||||
for (var i = 0; i < countries.length; i++) {
|
|
||||||
var country = countries[i];
|
|
||||||
tableHtml += createPingTableRow(country);
|
|
||||||
}
|
|
||||||
|
|
||||||
pingTable.append(tableHtml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPingTableRow(entry) {
|
function createPingTableRow(entry) {
|
||||||
return '<tr><td>' + entry.country +
|
return `<tr>
|
||||||
'</td><td>' + entry.avg_ping +
|
<td>${entry.country}</td>
|
||||||
'</td><td>' + entry.min_ping +
|
<td>${entry.avg_ping}</td>
|
||||||
'</td><td>' + entry.max_ping +
|
<td>${entry.min_ping}</td>
|
||||||
'</td></tr>'
|
<td>${entry.max_ping}</td>
|
||||||
|
</tr>`
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user