Fixed server preference pie for network page

- Flipped the dates in the query (ugh)
- Proper names for the servers in the pie

Affects issues:
- Fixed #1728
This commit is contained in:
Risto Lahtela 2021-01-29 11:01:08 +02:00
parent 60f6278352
commit b479753fc9
3 changed files with 13 additions and 3 deletions

View File

@ -362,7 +362,7 @@ public class GraphJSONCreator {
long now = System.currentTimeMillis();
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
Map<String, Long> playtimePerServer = dbSystem.getDatabase().query(SessionQueries.playtimePerServer(now, monthAgo));
Map<String, Long> playtimePerServer = dbSystem.getDatabase().query(SessionQueries.playtimePerServer(monthAgo, now));
return Maps.builder(String.class, Object.class)
.put("server_pie_colors", pieColors)

View File

@ -60,10 +60,14 @@ public class Server implements Comparable<Server> {
return name;
}
public String getIdentifiableName() {
public static String getIdentifiableName(String name, int id) {
return !"Plan".equalsIgnoreCase(name) ? name : "Server " + id;
}
public String getIdentifiableName() {
return getIdentifiableName(name, id);
}
public void setName(String name) {
this.name = name;
}

View File

@ -23,6 +23,7 @@ import com.djrapitops.plan.gathering.domain.GMTimes;
import com.djrapitops.plan.gathering.domain.PlayerKill;
import com.djrapitops.plan.gathering.domain.Session;
import com.djrapitops.plan.gathering.domain.WorldTimes;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.storage.database.queries.Query;
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
import com.djrapitops.plan.storage.database.queries.QueryStatement;
@ -743,6 +744,7 @@ public class SessionQueries {
public static Query<Map<String, Long>> playtimePerServer(long after, long before) {
String sql = SELECT +
"SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime," +
ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID + ',' +
ServerTable.NAME +
FROM + SessionsTable.TABLE_NAME +
INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.SERVER_UUID + '=' + SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID +
@ -760,7 +762,11 @@ public class SessionQueries {
public Map<String, Long> processResults(ResultSet set) throws SQLException {
Map<String, Long> playtimePerServer = new HashMap<>();
while (set.next()) {
playtimePerServer.put(set.getString(ServerTable.NAME), set.getLong("playtime"));
String name = Server.getIdentifiableName(
set.getString(ServerTable.NAME),
set.getInt(ServerTable.SERVER_ID)
);
playtimePerServer.put(name, set.getLong("playtime"));
}
return playtimePerServer;
}