mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-03 01:10:17 +01:00
Players table now served via JSON.
This commit is contained in:
parent
e035dc67fc
commit
77885704ca
@ -69,7 +69,6 @@ public class ExtensionServerPlayerDataTableQuery implements Query<Map<UUID, Exte
|
||||
String sql = SELECT +
|
||||
"v1." + ExtensionPlayerValueTable.USER_UUID + " as uuid," +
|
||||
"v1." + ExtensionPlayerValueTable.DOUBLE_VALUE + " as double_value," +
|
||||
"v1." + ExtensionPlayerValueTable.PERCENTAGE_VALUE + " as percentage_value," +
|
||||
"v1." + ExtensionPlayerValueTable.LONG_VALUE + " as long_value," +
|
||||
"v1." + ExtensionPlayerValueTable.STRING_VALUE + " as string_value," +
|
||||
"p1." + ExtensionProviderTable.PROVIDER_NAME + " as provider_name," +
|
||||
@ -85,6 +84,7 @@ public class ExtensionServerPlayerDataTableQuery implements Query<Map<UUID, Exte
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i1 on i1." + ExtensionIconTable.ID + "=p1." + ExtensionProviderTable.ICON_ID +
|
||||
WHERE + "e1." + ExtensionPluginTable.SERVER_UUID + "=?" +
|
||||
AND + " v1." + ExtensionPlayerValueTable.BOOLEAN_VALUE + IS_NULL + // Don't select Boolean value rows
|
||||
AND + " v1." + ExtensionPlayerValueTable.PERCENTAGE_VALUE + IS_NULL + // Don't select Percentage value rows
|
||||
AND + " p1." + ExtensionProviderTable.IS_PLAYER_NAME + "=?";
|
||||
|
||||
return new QueryStatement<Map<UUID, ExtensionTabData>>(sql, 1000) {
|
||||
@ -124,12 +124,6 @@ public class ExtensionServerPlayerDataTableQuery implements Query<Map<UUID, Exte
|
||||
return;
|
||||
}
|
||||
|
||||
double percentageValue = set.getDouble(ExtensionPlayerValueTable.PERCENTAGE_VALUE);
|
||||
if (!set.wasNull()) {
|
||||
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
|
||||
return;
|
||||
}
|
||||
|
||||
long numberValue = set.getLong(ExtensionPlayerValueTable.LONG_VALUE);
|
||||
if (!set.wasNull()) {
|
||||
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
|
||||
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plan.utilities.html.icon.Family;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -58,7 +57,6 @@ public class PlayersTableJSONParser {
|
||||
private Map<FormatType, Formatter<Long>> numberFormatters;
|
||||
|
||||
private Formatter<Double> decimalFormatter;
|
||||
private Formatter<Double> percentageFormatter;
|
||||
|
||||
public PlayersTableJSONParser(
|
||||
// Data
|
||||
@ -75,7 +73,7 @@ public class PlayersTableJSONParser {
|
||||
extensionDescriptives = extensionData.values().stream()
|
||||
.map(ExtensionTabData::getDescriptives)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct().sorted()
|
||||
.distinct().sorted((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()))
|
||||
.collect(Collectors.toList());
|
||||
// Settings
|
||||
this.maxPlayers = maxPlayers;
|
||||
@ -90,8 +88,6 @@ public class PlayersTableJSONParser {
|
||||
numberFormatters.put(FormatType.NONE, Object::toString);
|
||||
|
||||
this.decimalFormatter = formatters.decimals();
|
||||
this.percentageFormatter = formatters.percentage();
|
||||
|
||||
}
|
||||
|
||||
public String toJSONString() {
|
||||
@ -120,12 +116,12 @@ public class PlayersTableJSONParser {
|
||||
if (currentPlayerNumber > 0) {
|
||||
dataJSON.append(','); // Previous item
|
||||
}
|
||||
dataJSON.append('['); // Start new item
|
||||
dataJSON.append('{'); // Start new item
|
||||
|
||||
appendPlayerData(dataJSON, planAPI, now, player);
|
||||
appendExtensionData(dataJSON, extensionData.getOrDefault(playerUUID, new ExtensionTabData.Factory(null).build()));
|
||||
|
||||
dataJSON.append(']'); // Close new item
|
||||
dataJSON.append('}'); // Close new item
|
||||
|
||||
currentPlayerNumber++;
|
||||
}
|
||||
@ -151,18 +147,23 @@ public class PlayersTableJSONParser {
|
||||
|
||||
Html link = openPlayerPageInNewTab ? Html.LINK_EXTERNAL : Html.LINK;
|
||||
|
||||
String display = "{\"display\":\"";
|
||||
String sort = "\",\"sort\": ";
|
||||
dataJSON
|
||||
.append(makeDataEntry(link.parse(url, name), "name")).append(',')
|
||||
.append(makeDataEntry(activityIndex.getValue(), activityString, "index")).append(',')
|
||||
.append(makeDataEntry(playtime, numberFormatters.get(FormatType.TIME_MILLISECONDS).apply(playtime), "playtime")).append(',')
|
||||
.append(makeDataEntry(loginTimes, "sessions")).append(',')
|
||||
.append(makeDataEntry(registered, numberFormatters.get(FormatType.DATE_YEAR).apply(registered), "registered")).append(',')
|
||||
.append(makeDataEntry(lastSeen, numberFormatters.get(FormatType.DATE_YEAR).apply(lastSeen), "seen")).append(',')
|
||||
.append(makeDataEntry(geolocation, "geolocation"))
|
||||
;
|
||||
}
|
||||
|
||||
appendData(dataJSON,
|
||||
'"' + link.parse(url, name).replace('"', '\'') + '"',
|
||||
display + activityString + sort + activityIndex.getValue() + '}',
|
||||
display + numberFormatters.get(FormatType.TIME_MILLISECONDS).apply(playtime) + sort + playtime + '}',
|
||||
loginTimes,
|
||||
display + numberFormatters.get(FormatType.DATE_YEAR).apply(registered) + sort + registered + '}',
|
||||
display + numberFormatters.get(FormatType.DATE_YEAR).apply(lastSeen) + sort + lastSeen + '}',
|
||||
'"' + geolocation + '"'
|
||||
);
|
||||
private String makeDataEntry(Object data, String dataName) {
|
||||
return "\"" + dataName + "\":\"" + data.toString().replace('"', '\'') + "\"";
|
||||
}
|
||||
|
||||
private String makeDataEntry(Object data, String formatted, String dataName) {
|
||||
return "\"" + dataName + "\":{\"v\":\"" + data.toString().replace('"', '\'') + "\", \"d\":\"" + formatted.replace('"', '\'') + "\"}";
|
||||
}
|
||||
|
||||
private void appendExtensionData(StringBuilder dataJSON, ExtensionTabData tabData) {
|
||||
@ -172,16 +173,9 @@ public class PlayersTableJSONParser {
|
||||
|
||||
// If it's a double, append a double
|
||||
Optional<ExtensionDoubleData> doubleValue = tabData.getDouble(key);
|
||||
if (doubleValue.isPresent()) {
|
||||
dataJSON.append(doubleValue.get().getFormattedValue(decimalFormatter));
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's a percentage, append a percentage
|
||||
Optional<ExtensionDoubleData> percentageValue = tabData.getPercentage(key);
|
||||
if (percentageValue.isPresent()) {
|
||||
dataJSON.append("{\"display\": \"").append(percentageValue.get().getFormattedValue(percentageFormatter))
|
||||
.append("\",\"sort\": ").append(percentageValue.get().getRawValue()).append('}');
|
||||
if (doubleValue.isPresent()) {
|
||||
dataJSON.append(makeDataEntry(doubleValue.get().getRawValue(), doubleValue.get().getFormattedValue(decimalFormatter), key));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -189,68 +183,48 @@ public class PlayersTableJSONParser {
|
||||
if (numberValue.isPresent()) {
|
||||
ExtensionNumberData numberData = numberValue.get();
|
||||
FormatType formatType = numberData.getFormatType();
|
||||
if (formatType == FormatType.NONE) {
|
||||
// If it's a number, append a number
|
||||
dataJSON.append(numberData.getFormattedValue(numberFormatters.get(formatType)));
|
||||
} else {
|
||||
// If it's a formatted number, append a formatted number and sort by the number value
|
||||
dataJSON.append("{\"display\": \"").append(numberData.getFormattedValue(numberFormatters.get(formatType)))
|
||||
.append("\",\"sort\": ").append(numberData.getRawValue()).append('}');
|
||||
}
|
||||
dataJSON.append(makeDataEntry(numberData.getRawValue(), numberData.getFormattedValue(numberFormatters.get(formatType)), key));
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's a String append a String, otherwise the player has no value for this extension provider.
|
||||
String stringValue = tabData.getString(key).map(ExtensionStringData::getFormattedValue).orElse("-");
|
||||
dataJSON.append('"').append(stringValue).append('"');
|
||||
}
|
||||
}
|
||||
|
||||
private void appendData(StringBuilder dataJSON, Serializable... dataRows) {
|
||||
int max = dataRows.length;
|
||||
for (int i = 0; i < max; i++) {
|
||||
dataJSON.append(dataRows[i]);
|
||||
if (i < max - 1) {
|
||||
dataJSON.append(',');
|
||||
}
|
||||
dataJSON.append(makeDataEntry(stringValue, stringValue, key));
|
||||
}
|
||||
}
|
||||
|
||||
private String parseColumnHeaders() {
|
||||
StringBuilder columnHeaders = new StringBuilder("[");
|
||||
|
||||
appendDataHeaders(columnHeaders,
|
||||
Icon.called("user") + " Name",
|
||||
Icon.called("check") + " Activity Index",
|
||||
Icon.called("clock").of(Family.REGULAR) + " Playtime",
|
||||
Icon.called("calendar-plus").of(Family.REGULAR) + " Sessions",
|
||||
Icon.called("user-plus") + " Registered",
|
||||
Icon.called("calendar-check").of(Family.REGULAR) + " Last Seen",
|
||||
Icon.called("globe") + " Geolocation"
|
||||
);
|
||||
// Is the data for the column formatted
|
||||
|
||||
columnHeaders
|
||||
.append(makeColumnHeader(Icon.called("user") + " Name", "name")).append(',')
|
||||
.append(makeFColumnHeader(Icon.called("check") + " Activity Index", "index")).append(',')
|
||||
.append(makeFColumnHeader(Icon.called("clock").of(Family.REGULAR) + " Playtime", "playtime")).append(',')
|
||||
.append(makeColumnHeader(Icon.called("calendar-plus").of(Family.REGULAR) + " Sessions", "sessions")).append(',')
|
||||
.append(makeFColumnHeader(Icon.called("user-plus") + " Registered", "registered")).append(',')
|
||||
.append(makeFColumnHeader(Icon.called("calendar-check").of(Family.REGULAR) + " Last Seen", "seen")).append(',')
|
||||
.append(makeColumnHeader(Icon.called("globe") + " Geolocation", "geolocation"));
|
||||
|
||||
appendExtensionHeaders(columnHeaders);
|
||||
|
||||
return columnHeaders.append(']').toString();
|
||||
}
|
||||
|
||||
private void appendDataHeaders(StringBuilder columnHeaders, Serializable... headers) {
|
||||
int max = headers.length;
|
||||
for (int i = 0; i < max; i++) {
|
||||
columnHeaders.append("{\"title\": \"").append(headers[i].toString().replace('"', '\'')).append("\"}");
|
||||
if (i < max - 1) {
|
||||
columnHeaders.append(',');
|
||||
}
|
||||
}
|
||||
private String makeColumnHeader(String title, String dataProperty) {
|
||||
return "{\"title\": \"" + title.replace('"', '\'') + "\",\"data\":\"" + dataProperty + "\"}";
|
||||
}
|
||||
|
||||
private String makeFColumnHeader(String title, String dataProperty) {
|
||||
return "{\"title\": \"" + title.replace('"', '\'') + "\",\"data\":{\"_\":\"" + dataProperty + ".v\",\"display\":\"" + dataProperty + ".d\"}}";
|
||||
}
|
||||
|
||||
private void appendExtensionHeaders(StringBuilder columnHeaders) {
|
||||
for (ExtensionDescriptive provider : extensionDescriptives) {
|
||||
columnHeaders.append(',');
|
||||
columnHeaders.append("{\"title\": \"")
|
||||
.append(Icon.fromExtensionIcon(provider.getIcon().setColor(Color.NONE)).toHtml().replace('"', '\''))
|
||||
.append(' ').append(provider.getText())
|
||||
.append("\"}");
|
||||
String headerText = Icon.fromExtensionIcon(provider.getIcon().setColor(Color.NONE)).toHtml().replace('"', '\'') + ' ' + provider.getText();
|
||||
columnHeaders.append(makeFColumnHeader(headerText, provider.getName()));
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,8 @@
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">
|
||||
|
||||
<!-- Bootstrap Core Css -->
|
||||
<link href="plugins/bootstrap/css/bootstrap.css" rel="stylesheet">
|
||||
<link crossorigin="anonymous" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
|
||||
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" rel="stylesheet">
|
||||
|
||||
<!-- Waves Effect Css -->
|
||||
<link href="plugins/node-waves/waves.css" rel="stylesheet"/>
|
||||
@ -384,7 +385,7 @@
|
||||
class="pull-right"><b>${playersLastPeak}</b> Players</span></li>
|
||||
<li><i class="col-blue fa fa-fw fa-line-chart"></i> All Time Peak:
|
||||
${bestPeakTime}<span
|
||||
class="pull-right"><b>${playersBestPeak}</b> Players</span></li>
|
||||
class="pull-right"><b>${playersBestPeak}</b> Players</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -1054,10 +1055,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="body">
|
||||
<div class="table-responsive">
|
||||
${tablePlayerlist}
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-striped table-hover player-table dataTable"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1162,7 +1161,8 @@
|
||||
</section>
|
||||
|
||||
<!-- Bootstrap Core Js -->
|
||||
<script src="plugins/bootstrap/js/bootstrap.js"></script>
|
||||
<script crossorigin="anonymous" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
|
||||
src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
|
||||
|
||||
<!-- Slimscroll Plugin Js -->
|
||||
<script src="plugins/jquery-slimscroll/jquery.slimscroll.js"></script>
|
||||
@ -1171,8 +1171,8 @@
|
||||
<script src="plugins/node-waves/waves.js"></script>
|
||||
|
||||
<!-- Jquery Table Plugin Js -->
|
||||
<script src="plugins/jquery-datatable/jquery.dataTables.js"></script>
|
||||
<script src="plugins/jquery-datatable/skin/bootstrap/js/dataTables.bootstrap.js"></script>
|
||||
<link href="https://cdn.datatables.net/v/bs/dt-1.10.18/datatables.min.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="https://cdn.datatables.net/v/bs/dt-1.10.18/datatables.min.js" type="text/javascript"></script>
|
||||
|
||||
<!-- HighCharts -->
|
||||
<script src="https://code.highcharts.com/stock/highstock.js"></script>
|
||||
@ -1482,11 +1482,6 @@
|
||||
<!-- Plan load script -->
|
||||
<script>
|
||||
$(function () {
|
||||
|
||||
$('.player-table').DataTable({
|
||||
responsive: true,
|
||||
"order": [[5, "desc"]]
|
||||
});
|
||||
$('.player-plugin-table').DataTable({
|
||||
responsive: true
|
||||
});
|
||||
@ -1527,6 +1522,32 @@
|
||||
diskChart('diskGraph', [series.disk]);
|
||||
${sessionTabGraphViewFunctions}
|
||||
|
||||
setTimeout(function () {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
try {
|
||||
var playersTableData = JSON.parse(this.responseText);
|
||||
$('.player-table').DataTable({
|
||||
responsive: true,
|
||||
columns: playersTableData.columns,
|
||||
data: playersTableData.data,
|
||||
order: [[5, "desc"]]
|
||||
})
|
||||
} catch (e) {
|
||||
$('.player-table').DataTable({
|
||||
responsive: true,
|
||||
columns: [{title: "Error"}],
|
||||
data: [["Failed to load Players table data: "]],
|
||||
order: [[5, "desc"]]
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", "../json/players?serverName=${serverName}", true);
|
||||
xhttp.send();
|
||||
}, 0);
|
||||
|
||||
/**/
|
||||
|
||||
function openFunc(i) {
|
||||
|
Loading…
Reference in New Issue
Block a user