mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-11 01:41:55 +01:00
WorldPie can now be sorted by descending time percentage #377
This commit is contained in:
parent
7b33c1a43e
commit
d0eb8a53f3
@ -26,6 +26,7 @@ public enum Settings {
|
|||||||
DEV_MODE("Plugin.Dev"),
|
DEV_MODE("Plugin.Dev"),
|
||||||
USE_SERVER_TIME("Customization.UseServerTime"),
|
USE_SERVER_TIME("Customization.UseServerTime"),
|
||||||
DISPLAY_SESSIONS_AS_TABLE("Customization.Display.SessionsAsTable"),
|
DISPLAY_SESSIONS_AS_TABLE("Customization.Display.SessionsAsTable"),
|
||||||
|
ORDER_WORLD_PIE_BY_PERC("Customization.Display.OrderWorldPieByPercentage"),
|
||||||
|
|
||||||
// Integer
|
// Integer
|
||||||
WEBSERVER_PORT("WebServer.Port"),
|
WEBSERVER_PORT("WebServer.Port"),
|
||||||
|
@ -22,11 +22,23 @@ public class WorldPieCreator {
|
|||||||
* @return String array, index 0: Series data, 1: drilldown data
|
* @return String array, index 0: Series data, 1: drilldown data
|
||||||
*/
|
*/
|
||||||
public static String[] createSeriesData(WorldTimes worldTimes) {
|
public static String[] createSeriesData(WorldTimes worldTimes) {
|
||||||
|
List<PieSlice> slices = turnToSlices(worldTimes);
|
||||||
|
|
||||||
|
if (Settings.ORDER_WORLD_PIE_BY_PERC.isTrue()) {
|
||||||
|
slices.sort(new PieSliceComparator());
|
||||||
|
}
|
||||||
|
|
||||||
|
String seriesData = buildSeries(slices);
|
||||||
|
|
||||||
|
String drilldownData = createDrilldownData(worldTimes);
|
||||||
|
|
||||||
|
return new String[]{seriesData, drilldownData};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<PieSlice> turnToSlices(WorldTimes worldTimes) {
|
||||||
String[] colors = Settings.THEME_GRAPH_WORLD_PIE.toString().split(", ");
|
String[] colors = Settings.THEME_GRAPH_WORLD_PIE.toString().split(", ");
|
||||||
int colLenght = colors.length;
|
int colLenght = colors.length;
|
||||||
|
|
||||||
StringBuilder seriesBuilder = new StringBuilder("[");
|
|
||||||
int i = 0;
|
|
||||||
// WorldTimes Map<String, GMTimes> (GMTimes.getTotal)
|
// WorldTimes Map<String, GMTimes> (GMTimes.getTotal)
|
||||||
Map<String, Long> playtimePerWorld = worldTimes.getWorldTimes().entrySet().stream()
|
Map<String, Long> playtimePerWorld = worldTimes.getWorldTimes().entrySet().stream()
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getTotal()));
|
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getTotal()));
|
||||||
@ -36,19 +48,24 @@ public class WorldPieCreator {
|
|||||||
List<String> worlds = new ArrayList<>(playtimePerAlias.keySet());
|
List<String> worlds = new ArrayList<>(playtimePerAlias.keySet());
|
||||||
Collections.sort(worlds);
|
Collections.sort(worlds);
|
||||||
|
|
||||||
int size = playtimePerAlias.size();
|
List<PieSlice> slices = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
for (String alias : worlds) {
|
for (String alias : worlds) {
|
||||||
Long value = playtimePerAlias.getOrDefault(alias, 0L);
|
Long value = playtimePerAlias.getOrDefault(alias, 0L);
|
||||||
if (value == 0L) {
|
if (value != 0L) {
|
||||||
i++;
|
slices.add(new PieSlice(alias, value, colors[i % colLenght]));
|
||||||
continue;
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return slices;
|
||||||
}
|
}
|
||||||
seriesBuilder.append("{name:'").append(alias)
|
|
||||||
.append("',y:").append(value)
|
|
||||||
.append(",color:").append(colors[i % colLenght])
|
|
||||||
.append(",drilldown: '").append(alias).append("'");
|
|
||||||
|
|
||||||
seriesBuilder.append("}");
|
private static String buildSeries(List<PieSlice> slices) {
|
||||||
|
StringBuilder seriesBuilder = new StringBuilder("[");
|
||||||
|
int i = 0;
|
||||||
|
int size = slices.size();
|
||||||
|
for (PieSlice slice : slices) {
|
||||||
|
seriesBuilder.append(slice.toString());
|
||||||
if (i < size - 1) {
|
if (i < size - 1) {
|
||||||
seriesBuilder.append(",");
|
seriesBuilder.append(",");
|
||||||
}
|
}
|
||||||
@ -56,11 +73,7 @@ public class WorldPieCreator {
|
|||||||
}
|
}
|
||||||
seriesBuilder.append("]");
|
seriesBuilder.append("]");
|
||||||
|
|
||||||
String seriesData = seriesBuilder.toString();
|
return seriesBuilder.toString();
|
||||||
|
|
||||||
String drilldownData = createDrilldownData(worldTimes);
|
|
||||||
|
|
||||||
return new String[]{seriesData, drilldownData};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Long> transformToAliases(Map<String, Long> playtimePerWorld) {
|
private static Map<String, Long> transformToAliases(Map<String, Long> playtimePerWorld) {
|
||||||
@ -168,3 +181,34 @@ public class WorldPieCreator {
|
|||||||
drilldownBuilder.append("]}");
|
drilldownBuilder.append("]}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PieSlice {
|
||||||
|
private final String name;
|
||||||
|
final long y;
|
||||||
|
private final String color;
|
||||||
|
|
||||||
|
public PieSlice(String name, long y, String color) {
|
||||||
|
this.name = name;
|
||||||
|
this.y = y;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{name:'" + name + "'," +
|
||||||
|
"y:" + y + "," +
|
||||||
|
"color:" + color + "," +
|
||||||
|
"drilldown: '" + name + "'}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares PieSlices to descending Percentage order.
|
||||||
|
*/
|
||||||
|
class PieSliceComparator implements Comparator<PieSlice> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(PieSlice o1, PieSlice o2) {
|
||||||
|
return -Long.compare(o1.y, o2.y);
|
||||||
|
}
|
||||||
|
}
|
@ -73,6 +73,8 @@ Customization:
|
|||||||
UseServerTime: true
|
UseServerTime: true
|
||||||
Display:
|
Display:
|
||||||
SessionsAsTable: false
|
SessionsAsTable: false
|
||||||
|
# By Default WorldPie is ordered alphabetically, colors are still determined alphabetically.
|
||||||
|
OrderWorldPieByPercentage: false
|
||||||
MaxSessions: 50
|
MaxSessions: 50
|
||||||
MaxPlayers: 2500
|
MaxPlayers: 2500
|
||||||
MaxPlayersPlayersPage: 25000
|
MaxPlayersPlayersPage: 25000
|
||||||
|
Loading…
Reference in New Issue
Block a user