mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-07 04:18:26 +02:00
Playerbase graphs to network page
This commit is contained in:
parent
986a753918
commit
9d865ad516
@ -25,6 +25,7 @@ import com.djrapitops.plan.data.store.objects.DateMap;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.queries.analysis.ActivityIndexQueries;
|
||||
import com.djrapitops.plan.db.access.queries.analysis.NetworkActivityIndexQueries;
|
||||
import com.djrapitops.plan.db.access.queries.analysis.PlayerCountQueries;
|
||||
import com.djrapitops.plan.db.access.queries.objects.*;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
@ -169,6 +170,27 @@ public class GraphJSONParser {
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public Map<String, Object> activityGraphsJSONAsMap() {
|
||||
Database db = dbSystem.getDatabase();
|
||||
long date = System.currentTimeMillis();
|
||||
Long threshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
|
||||
|
||||
DateMap<Map<String, Integer>> activityData = new DateMap<>();
|
||||
for (long time = date; time >= date - TimeAmount.MONTH.toMillis(2L); time -= TimeAmount.WEEK.toMillis(1L)) {
|
||||
activityData.put(time, db.query(NetworkActivityIndexQueries.fetchActivityIndexGroupingsOn(time, threshold)));
|
||||
}
|
||||
|
||||
Map.Entry<Long, Map<String, Integer>> lastActivityEntry = activityData.lastEntry();
|
||||
Pie activityPie = graphs.pie().activityPie(lastActivityEntry != null ? lastActivityEntry.getValue() : Collections.emptyMap());
|
||||
StackGraph activityStackGraph = graphs.stack().activityStackGraph(activityData);
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("activity_series", activityStackGraph.getDataSets());
|
||||
dataMap.put("activity_labels", activityStackGraph.getLabels());
|
||||
dataMap.put("activity_pie_series", activityPie.getSlices());
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public Map<String, Object> geolocationGraphsJSONAsMap(UUID serverUUID) {
|
||||
Database db = dbSystem.getDatabase();
|
||||
Map<String, Integer> geolocationCounts = db.query(GeoInfoQueries.serverGeolocationCounts(serverUUID));
|
||||
|
@ -54,11 +54,16 @@ public class GraphsJSONHandler implements PageHandler {
|
||||
|
||||
@Override
|
||||
public Response getResponse(Request request, RequestTarget target) throws WebException {
|
||||
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
|
||||
String type = target.getParameter("type")
|
||||
.orElseThrow(() -> new BadRequestException("'type' parameter was not defined."));
|
||||
|
||||
if (target.getParameter("server").isPresent()) {
|
||||
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
|
||||
return generateGraphDataJSONOfType(type, serverUUID);
|
||||
}
|
||||
// Assume network
|
||||
return generateGraphDataJSONOfType(type);
|
||||
}
|
||||
|
||||
private JSONResponse generateGraphDataJSONOfType(String type, UUID serverUUID) throws BadRequestException {
|
||||
switch (type) {
|
||||
@ -83,6 +88,15 @@ public class GraphsJSONHandler implements PageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private JSONResponse generateGraphDataJSONOfType(String type) throws BadRequestException {
|
||||
switch (type) {
|
||||
case "activity":
|
||||
return new JSONResponse(graphJSON.activityGraphsJSONAsMap());
|
||||
default:
|
||||
throw new BadRequestException("unknown 'type' parameter: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
||||
return auth.getWebUser().getPermLevel() <= 0;
|
||||
|
@ -1288,6 +1288,19 @@
|
||||
setLoadingText('Calculating values..');
|
||||
jsonRequest("../v1/network/playerbaseOverview", loadPlayerbaseOverviewValues);
|
||||
setLoadingText('Rendering graphs..');
|
||||
|
||||
jsonRequest("../v1/graph?type=activity", function (json, error) {
|
||||
if (json) {
|
||||
activityPie('activityPie', {
|
||||
name: 'Players', colorByPoint: true, data: json.activity_pie_series
|
||||
});
|
||||
stackChart('activityStackGraph', json.activity_labels, json.activity_series, 'Players');
|
||||
} else if (error) {
|
||||
$('#activityPie').text("Failed to load graph data: " + error);
|
||||
$('#activityStackGraph').text("Failed to load graph data: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
setLoadingText('Sorting players table..');
|
||||
setLoadingText('Almost done..');
|
||||
var navButtons = document.getElementsByClassName("nav-button");
|
||||
|
Loading…
Reference in New Issue
Block a user