mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-07 19:31:45 +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.ServerTablePlayersQuery;
|
||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plan.utilities.java.Maps;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -222,14 +223,18 @@ public class JSONFactory {
|
||||
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));
|
||||
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());
|
||||
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) {
|
||||
@ -238,12 +243,12 @@ public class JSONFactory {
|
||||
String geolocation = entry.getKey();
|
||||
Ping ping = entry.getValue();
|
||||
|
||||
Map<String, Object> tableEntry = new HashMap<>();
|
||||
tableEntry.put("country", geolocation);
|
||||
tableEntry.put("avg_ping", formatters.decimals().apply(ping.getAverage()) + " ms");
|
||||
tableEntry.put("min_ping", ping.getMin() + " ms");
|
||||
tableEntry.put("max_ping", ping.getMax() + " ms");
|
||||
tableEntries.add(tableEntry);
|
||||
tableEntries.add(Maps.builder(String.class, Object.class)
|
||||
.put("country", geolocation)
|
||||
.put("avg_ping", formatters.decimals().apply(ping.getAverage()) + " ms")
|
||||
.put("min_ping", ping.getMin() + " ms")
|
||||
.put("max_ping", ping.getMax() + " ms")
|
||||
.build());
|
||||
}
|
||||
return tableEntries;
|
||||
}
|
||||
|
@ -1,32 +1,26 @@
|
||||
function loadPingTable(json, error) {
|
||||
pingTable = $("#geolocations").find("#data_ping_table").find("tbody");
|
||||
const pingTable = document.querySelector('#geolocations #data_ping_table tbody');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var countries = json;
|
||||
const countries = json.table;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var tableHtml = '';
|
||||
|
||||
for (var i = 0; i < countries.length; i++) {
|
||||
var country = countries[i];
|
||||
tableHtml += createPingTableRow(country);
|
||||
}
|
||||
|
||||
pingTable.append(tableHtml);
|
||||
pingTable.innerHTML = countries.map(createPingTableRow).join('');
|
||||
}
|
||||
|
||||
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>'
|
||||
return `<tr>
|
||||
<td>${entry.country}</td>
|
||||
<td>${entry.avg_ping}</td>
|
||||
<td>${entry.min_ping}</td>
|
||||
<td>${entry.max_ping}</td>
|
||||
</tr>`
|
||||
}
|
Loading…
Reference in New Issue
Block a user