mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 01:17:45 +01:00
Average Playtime / Player
This commit is contained in:
parent
272906e420
commit
a47ef57539
@ -495,6 +495,62 @@ public class SessionQueries {
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> averagePlaytimePerPlayer(long after, long before, UUID serverUUID) {
|
||||
return database -> {
|
||||
String selectPlaytimePerPlayer = SELECT +
|
||||
SessionsTable.USER_UUID + "," +
|
||||
"SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime" +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.SESSION_END + "<=?" +
|
||||
AND + SessionsTable.SESSION_START + ">=?" +
|
||||
AND + SessionsTable.SERVER_UUID + "=?" +
|
||||
GROUP_BY + SessionsTable.USER_UUID;
|
||||
String selectAverage = SELECT + "AVG(playtime) as average" + FROM + '(' + selectPlaytimePerPlayer + ") q1";
|
||||
|
||||
return database.query(new QueryStatement<Long>(selectAverage, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, before);
|
||||
statement.setLong(2, after);
|
||||
statement.setString(3, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getLong("average") : 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> averageAfkPerPlayer(long after, long before, UUID serverUUID) {
|
||||
return database -> {
|
||||
String selectAfkPerPlayer = SELECT +
|
||||
SessionsTable.USER_UUID + "," +
|
||||
"SUM(" + SessionsTable.AFK_TIME + ") as afk" +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.SESSION_END + "<=?" +
|
||||
AND + SessionsTable.SESSION_START + ">=?" +
|
||||
AND + SessionsTable.SERVER_UUID + "=?" +
|
||||
GROUP_BY + SessionsTable.USER_UUID;
|
||||
String selectAverage = SELECT + "AVG(afk) as average" + FROM + '(' + selectAfkPerPlayer + ") q1";
|
||||
|
||||
return database.query(new QueryStatement<Long>(selectAverage, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, before);
|
||||
statement.setLong(2, after);
|
||||
statement.setString(3, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getLong("average") : 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> afkTime(long after, long before, UUID serverUUID) {
|
||||
String sql = SELECT + "SUM(" + SessionsTable.AFK_TIME + ") as afk_time" +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
|
@ -44,8 +44,8 @@ public class PlayerBaseOverviewJSONParser implements TabJSONParser<Map<String, O
|
||||
private PlanConfig config;
|
||||
private DBSystem dbSystem;
|
||||
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
private Formatter<Double> percentageFormatter;
|
||||
private Formatter<Long> timeAmount;
|
||||
private Formatter<Double> percentage;
|
||||
|
||||
@Inject
|
||||
public PlayerBaseOverviewJSONParser(
|
||||
@ -56,8 +56,8 @@ public class PlayerBaseOverviewJSONParser implements TabJSONParser<Map<String, O
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
|
||||
timeAmountFormatter = formatters.timeAmount();
|
||||
percentageFormatter = formatters.percentage();
|
||||
timeAmount = formatters.timeAmount();
|
||||
percentage = formatters.percentage();
|
||||
}
|
||||
|
||||
public Map<String, Object> createJSONAsMap(UUID serverUUID) {
|
||||
@ -88,33 +88,32 @@ public class PlayerBaseOverviewJSONParser implements TabJSONParser<Map<String, O
|
||||
trends.put("regular_players_now", regularAfter);
|
||||
trends.put("regular_players_trend", new Trend(regularBefore, regularAfter, false));
|
||||
|
||||
// TODO
|
||||
trends.put("playtime_avg_then", "Not implemented");
|
||||
trends.put("playtime_avg_now", "Not implemented");
|
||||
trends.put("playtime_avg_trend", new Trend(0, 0, false, timeAmountFormatter));
|
||||
Long avgPlaytimeBefore = db.query(SessionQueries.averagePlaytimePerPlayer(twoMonthsAgo, monthAgo, serverUUID));
|
||||
Long avgPlaytimeAfter = db.query(SessionQueries.averagePlaytimePerPlayer(monthAgo, now, serverUUID));
|
||||
trends.put("playtime_avg_then", timeAmount.apply(avgPlaytimeBefore));
|
||||
trends.put("playtime_avg_now", timeAmount.apply(avgPlaytimeAfter));
|
||||
trends.put("playtime_avg_trend", new Trend(avgPlaytimeBefore, avgPlaytimeAfter, false, timeAmount));
|
||||
|
||||
Long playtimeBefore = db.query(SessionQueries.playtime(twoMonthsAgo, monthAgo, serverUUID));
|
||||
Long playtimeAfter = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
|
||||
Long afkBefore = db.query(SessionQueries.afkTime(twoMonthsAgo, monthAgo, serverUUID));
|
||||
Long afkAfter = db.query(SessionQueries.afkTime(monthAgo, now, serverUUID));
|
||||
double afkPercBefore = playersBefore != 0 ? (double) afkBefore / playtimeBefore : 0;
|
||||
double afkPercAfter = playersBefore != 0 ? (double) afkAfter / playtimeAfter : 0;
|
||||
trends.put("afk_then", percentageFormatter.apply(afkPercBefore));
|
||||
trends.put("afk_now", percentageFormatter.apply(afkPercAfter));
|
||||
trends.put("afk_trend", new Trend(afkPercBefore, afkPercAfter, Trend.REVERSED, percentageFormatter));
|
||||
Long avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo, serverUUID));
|
||||
Long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now, serverUUID));
|
||||
double afkPercBefore = avgPlaytimeBefore != 0 ? (double) avgAfkBefore / avgPlaytimeBefore : 0;
|
||||
double afkPercAfter = avgPlaytimeAfter != 0 ? (double) avgAfkAfter / avgPlaytimeAfter : 0;
|
||||
trends.put("afk_then", percentage.apply(afkPercBefore));
|
||||
trends.put("afk_now", percentage.apply(afkPercAfter));
|
||||
trends.put("afk_trend", new Trend(afkPercBefore, afkPercAfter, Trend.REVERSED, percentage));
|
||||
|
||||
// TODO
|
||||
trends.put("regular_playtime_avg_then", "Not implemented");
|
||||
trends.put("regular_playtime_avg_now", "Not implemented");
|
||||
trends.put("regular_playtime_avg_trend", new Trend(0, 0, false, timeAmountFormatter));
|
||||
trends.put("regular_playtime_avg_trend", new Trend(0, 0, false, timeAmount));
|
||||
// TODO
|
||||
trends.put("regular_session_avg_then", "Not implemented");
|
||||
trends.put("regular_session_avg_now", "Not implemented");
|
||||
trends.put("regular_session_avg_trend", new Trend(0, 0, false, timeAmountFormatter));
|
||||
trends.put("regular_session_avg_trend", new Trend(0, 0, false, timeAmount));
|
||||
// TODO
|
||||
trends.put("regular_afk_avg_then", "Not implemented");
|
||||
trends.put("regular_afk_avg_now", "Not implemented");
|
||||
trends.put("regular_afk_avg_trend", new Trend(0, 0, Trend.REVERSED, percentageFormatter));
|
||||
trends.put("regular_afk_avg_trend", new Trend(0, 0, Trend.REVERSED, percentage));
|
||||
|
||||
return trends;
|
||||
}
|
||||
|
@ -277,9 +277,9 @@ function loadPlayerbaseOverviewValues(json, error) {
|
||||
$(element).find('#data_regular_session_avg_then').text(data.regular_session_avg_then);
|
||||
$(element).find('#data_regular_session_avg_now').text(data.regular_session_avg_now);
|
||||
$(element).find('#data_regular_session_avg_trend').replaceWith(trend(data.regular_session_avg_trend));
|
||||
$(element).find('#data_regular_afk_then').text(data.regular_afk_then);
|
||||
$(element).find('#data_regular_afk_now').text(data.regular_afk_now);
|
||||
$(element).find('#data_regular_afk_trend').replaceWith(trend(data.regular_afk_trend));
|
||||
$(element).find('#data_regular_afk_then').text(data.regular_afk_avg_then);
|
||||
$(element).find('#data_regular_afk_now').text(data.regular_afk_avg_now);
|
||||
$(element).find('#data_regular_afk_trend').replaceWith(trend(data.regular_afk_avg_trend));
|
||||
|
||||
// Insights
|
||||
data = json.insights;
|
||||
|
@ -766,7 +766,7 @@
|
||||
<thead>
|
||||
<th><i class="text-success fa fa-caret-up"></i><i
|
||||
class="text-danger fa fa-caret-down"></i>
|
||||
<small>Comparing 15 days</small>
|
||||
<small>Comparing 30d ago to Now</small>
|
||||
</th>
|
||||
<th>30 days ago</th>
|
||||
<th>Now</th>
|
||||
|
Loading…
Reference in New Issue
Block a user