Server calendar end point

This commit is contained in:
Rsl1122 2019-07-06 11:46:54 +03:00
parent 05a8668fbf
commit da3e5db913
3 changed files with 30 additions and 13 deletions

View File

@ -74,4 +74,19 @@ public class GraphJSONParser {
'}';
}
public String serverCalendarJSON(UUID serverUUID) {
Database db = dbSystem.getDatabase();
SessionsMutator sessionsMutator = new SessionsMutator(db.query(SessionQueries.fetchSessionsOfServerFlat(serverUUID)))
.filterSessionsBetween(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(730L), System.currentTimeMillis());
PlayersMutator playersMutator = new PlayersMutator(db.query(new ServerPlayerContainersQuery(serverUUID)))
.filterRegisteredBetween(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(730L), System.currentTimeMillis());
return "{\"data\":" +
graphs.calendar().serverCalendar(
playersMutator,
sessionsMutator.uniqueJoinsPerDay(timeZone),
playersMutator.newPerDay(timeZone)
).toCalendarSeries() +
",\"firstDay\":" + 1 + '}';
}
}

View File

@ -65,6 +65,8 @@ public class GraphsJSONHandler extends ServerParameterJSONHandler {
return graphJSON.performanceGraphJSON(serverUUID);
case "uniqueAndNew":
return graphJSON.uniqueAndNewGraphJSON(serverUUID);
case "serverCalendar":
return graphJSON.serverCalendarJSON(serverUUID);
default:
throw new BadRequestException("unknown 'type' parameter: " + type);
}

View File

@ -60,7 +60,7 @@ public class ServerCalendar {
public String toCalendarSeries() {
StringBuilder series = new StringBuilder("[");
series.append("{title: 'badcode',start:0}");
series.append("{\"title\": \"badcode\",\"start\":0}");
appendSessionRelatedData(series);
appendRegistered(series);
@ -78,9 +78,9 @@ public class ServerCalendar {
String day = entry.getKey();
series.append(",{title: 'New: ").append(newPlayers)
.append("',start:'").append(day)
.append("',color: '").append(theme.getValue(ThemeVal.LIGHT_GREEN)).append("'")
series.append(",{\"title\": \"New: ").append(newPlayers)
.append("\",\"start\":\"").append(day)
.append("\",\"color\": \"").append(theme.getValue(ThemeVal.LIGHT_GREEN)).append('"')
.append("}");
}
@ -106,19 +106,19 @@ public class ServerCalendar {
long playtime = dayMutator.toPlaytime();
long uniquePlayers = entry.getValue();
series.append(",{title: 'Playtime: ").append(timeAmountFormatter.apply(playtime))
.append("',start:'").append(day)
.append("',color: '").append(theme.getValue(ThemeVal.GREEN)).append("'")
series.append(",{\"title\": \"Playtime: ").append(timeAmountFormatter.apply(playtime))
.append("\",\"start\":\"").append(day)
.append("\",\"color\": \"").append(theme.getValue(ThemeVal.GREEN)).append('"')
.append("}");
series.append(",{title: 'Sessions: ").append(sessionCount)
.append("',start:'").append(day)
.append("',color: '").append(theme.getValue(ThemeVal.TEAL)).append("'")
series.append(",{\"title\": \"Sessions: ").append(sessionCount)
.append("\",\"start\":\"").append(day)
.append("\",\"color\": \"").append(theme.getValue(ThemeVal.TEAL)).append('"')
.append("}");
series.append(",{title: 'Unique: ").append(uniquePlayers)
.append("',start:'").append(day)
.append("'}");
series.append(",{\"title\": \"Unique: ").append(uniquePlayers)
.append("\",\"start\":\"").append(day)
.append("\"}");
}
}