mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-18 08:35:16 +01:00
Session tab insights for network page
This commit is contained in:
parent
f41a6fbbce
commit
d842fe7b49
@ -720,6 +720,25 @@ public class SessionQueries {
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> afkTime(long after, long before) {
|
||||
String sql = SELECT + "SUM(" + SessionsTable.AFK_TIME + ") as afk_time" +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.SESSION_END + ">=?" +
|
||||
AND + SessionsTable.SESSION_START + "<=?";
|
||||
return new QueryStatement<Long>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, after);
|
||||
statement.setLong(2, before);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getLong("afk_time") : 0L;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Map<String, Long>> playtimePerServer(long after, long before) {
|
||||
String sql = SELECT +
|
||||
"SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime," +
|
||||
|
@ -37,7 +37,7 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Parses JSON payload for /server-page Server Overview tab.
|
||||
* Parses JSON payload for /network-page Network Overview tab.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
@ -34,7 +34,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Parses JSON payload for /server-page Playerbase Overview tab.
|
||||
* Parses JSON payload for /network-page Playerbase Overview tab.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.system.json.network;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.queries.objects.SessionQueries;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Parses JSON payload for /network-page Sessions tab.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class NetworkSessionsOverviewJSONParser implements NetworkTabJSONParser<Map<String, Object>> {
|
||||
|
||||
private DBSystem dbSystem;
|
||||
|
||||
private Formatter<Long> timeAmount;
|
||||
private Formatter<Double> percentage;
|
||||
|
||||
@Inject
|
||||
public NetworkSessionsOverviewJSONParser(
|
||||
DBSystem dbSystem,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
|
||||
timeAmount = formatters.timeAmount();
|
||||
percentage = formatters.percentage();
|
||||
}
|
||||
|
||||
public Map<String, Object> createJSONAsMap() {
|
||||
return Collections.singletonMap("insights", createInsightsMap());
|
||||
}
|
||||
|
||||
private Map<String, Object> createInsightsMap() {
|
||||
Database db = dbSystem.getDatabase();
|
||||
long now = System.currentTimeMillis();
|
||||
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
|
||||
|
||||
Map<String, Object> insights = new HashMap<>();
|
||||
|
||||
Long playtime = db.query(SessionQueries.playtime(monthAgo, now));
|
||||
Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now));
|
||||
insights.put("total_playtime", timeAmount.apply(playtime));
|
||||
insights.put("afk_time", timeAmount.apply(afkTime));
|
||||
insights.put("afk_time_perc", playtime != 0 ? percentage.apply(1.0 * afkTime / playtime) : "-");
|
||||
|
||||
return insights;
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import com.djrapitops.plan.api.exceptions.WebUserAuthException;
|
||||
import com.djrapitops.plan.system.json.JSONFactory;
|
||||
import com.djrapitops.plan.system.json.network.NetworkOverviewJSONParser;
|
||||
import com.djrapitops.plan.system.json.network.NetworkPlayerBaseOverviewJSONParser;
|
||||
import com.djrapitops.plan.system.json.network.NetworkSessionsOverviewJSONParser;
|
||||
import com.djrapitops.plan.system.json.network.NetworkTabJSONParser;
|
||||
import com.djrapitops.plan.system.webserver.RequestTarget;
|
||||
import com.djrapitops.plan.system.webserver.auth.Authentication;
|
||||
@ -42,12 +43,14 @@ public class NetworkJSONHandler extends TreePageHandler {
|
||||
ResponseFactory responseFactory,
|
||||
JSONFactory jsonFactory,
|
||||
NetworkOverviewJSONParser networkOverviewJSONParser,
|
||||
NetworkPlayerBaseOverviewJSONParser playerBaseOverviewJSONParser
|
||||
NetworkPlayerBaseOverviewJSONParser playerBaseOverviewJSONParser,
|
||||
NetworkSessionsOverviewJSONParser sessionsOverviewJSONParser
|
||||
) {
|
||||
super(responseFactory);
|
||||
|
||||
registerPage("overview", networkOverviewJSONParser);
|
||||
registerPage("playerbaseOverview", playerBaseOverviewJSONParser);
|
||||
registerPage("sessionsOverview", sessionsOverviewJSONParser);
|
||||
registerPage("servers", jsonFactory::serversAsJSONMaps);
|
||||
registerPage("pingTable", jsonFactory::pingPerGeolocation);
|
||||
}
|
||||
|
@ -871,6 +871,7 @@
|
||||
setLoadingText('Calculating values..');
|
||||
jsonRequest("../v1/network/overview", loadNetworkOverviewValues);
|
||||
jsonRequest("../v1/network/servers", loadServerBoxes);
|
||||
jsonRequest("../v1/network/sessionsOverview", loadSessionValues);
|
||||
jsonRequest("../v1/network/playerbaseOverview", loadPlayerbaseOverviewValues);
|
||||
jsonRequest("../v1/sessions", loadSessionAccordion);
|
||||
setLoadingText('Rendering graphs..');
|
||||
|
Loading…
Reference in New Issue
Block a user