Implemented world pie endpoint

This commit is contained in:
Rsl1122 2019-07-06 17:29:23 +03:00
parent 8b84ed78b7
commit 9d3045cfcc
4 changed files with 37 additions and 7 deletions

View File

@ -20,18 +20,23 @@ import com.djrapitops.plan.data.store.mutators.MutatorFunctions;
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
import com.djrapitops.plan.data.store.mutators.TPSMutator;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.containers.ServerPlayerContainersQuery;
import com.djrapitops.plan.db.access.queries.objects.SessionQueries;
import com.djrapitops.plan.db.access.queries.objects.TPSQueries;
import com.djrapitops.plan.db.access.queries.objects.WorldTimesQueries;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.TimeSettings;
import com.djrapitops.plan.utilities.html.graphs.Graphs;
import com.djrapitops.plan.utilities.html.graphs.line.LineGraphFactory;
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@ -104,4 +109,15 @@ public class GraphJSONParser {
).toCalendarSeries() +
",\"firstDay\":" + 1 + '}';
}
public Map<String, Object> serverWorldPieJSONAsMap(UUID serverUUID) {
Database db = dbSystem.getDatabase();
WorldTimes worldTimes = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID));
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("world_series", worldPie.getSlices());
dataMap.put("gm_series", worldPie.toHighChartsDrillDownMaps());
return dataMap;
}
}

View File

@ -57,18 +57,19 @@ public class GraphsJSONHandler implements PageHandler {
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
String type = target.getParameter("type")
.orElseThrow(() -> new BadRequestException("'type' parameter was not defined."));
String graphDataJSON = generateGraphDataJSONOfType(type, serverUUID);
return new JSONResponse(graphDataJSON);
return generateGraphDataJSONOfType(type, serverUUID);
}
private String generateGraphDataJSONOfType(String type, UUID serverUUID) throws BadRequestException {
private JSONResponse generateGraphDataJSONOfType(String type, UUID serverUUID) throws BadRequestException {
switch (type) {
case "performance":
return graphJSON.performanceGraphJSON(serverUUID);
return new JSONResponse(graphJSON.performanceGraphJSON(serverUUID));
case "uniqueAndNew":
return graphJSON.uniqueAndNewGraphJSON(serverUUID);
return new JSONResponse(graphJSON.uniqueAndNewGraphJSON(serverUUID));
case "serverCalendar":
return graphJSON.serverCalendarJSON(serverUUID);
return new JSONResponse(graphJSON.serverCalendarJSON(serverUUID));
case "worldPie":
return new JSONResponse<>(graphJSON.serverWorldPieJSONAsMap(serverUUID));
default:
throw new BadRequestException("unknown 'type' parameter: " + type);
}

View File

@ -535,7 +535,9 @@
class="far fa-fw fa-clock col-teal"></i>
World Playtime</h6>
</div>
<div class="chart-pie"></div>
<div class="chart-pie" id="worldPie">
<span class="loader"></span>
</div>
</div>
<!-- Insights -->
<div class="card shadow mb-4">
@ -1770,6 +1772,16 @@
}
});
jsonRequest("../v1/graph?type=worldPie&serverName=${serverName}", function (json, error) {
if (data) {
var worldSeries = {name: 'World Playtime', colorByPoint: true, data: json.world_series};
var gmSeries = json.gm_series;
worldPie("worldPie", worldSeries, gmSeries);
} else if (error) {
$('#worldpie').text("Failed to load graph data: " + error)
}
});
jsonRequest("../v1/graph?type=uniqueAndNew&serverName=${serverName}", function (data, error) {
if (data) {
var uniquePlayers = {

View File

@ -77,3 +77,4 @@ Type | Description
`performance` | TPS data points for last 6 months: Players Online, TPS, CPU, RAM, Chunks, Entities, Disk Space
`uniqueAndNew` | Player data points for each day, how many unique and how many new players were there each day. Last 180 days
`calendar` | Calendar data points for each day there is data for. Last 2 years.
`worldPie` | World Pie data of all sessions combined