mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-07 04:18:26 +02: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) {
|
public static Query<Long> afkTime(long after, long before, UUID serverUUID) {
|
||||||
String sql = SELECT + "SUM(" + SessionsTable.AFK_TIME + ") as afk_time" +
|
String sql = SELECT + "SUM(" + SessionsTable.AFK_TIME + ") as afk_time" +
|
||||||
FROM + SessionsTable.TABLE_NAME +
|
FROM + SessionsTable.TABLE_NAME +
|
||||||
|
@ -44,8 +44,8 @@ public class PlayerBaseOverviewJSONParser implements TabJSONParser<Map<String, O
|
|||||||
private PlanConfig config;
|
private PlanConfig config;
|
||||||
private DBSystem dbSystem;
|
private DBSystem dbSystem;
|
||||||
|
|
||||||
private Formatter<Long> timeAmountFormatter;
|
private Formatter<Long> timeAmount;
|
||||||
private Formatter<Double> percentageFormatter;
|
private Formatter<Double> percentage;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PlayerBaseOverviewJSONParser(
|
public PlayerBaseOverviewJSONParser(
|
||||||
@ -56,8 +56,8 @@ public class PlayerBaseOverviewJSONParser implements TabJSONParser<Map<String, O
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
|
|
||||||
timeAmountFormatter = formatters.timeAmount();
|
timeAmount = formatters.timeAmount();
|
||||||
percentageFormatter = formatters.percentage();
|
percentage = formatters.percentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> createJSONAsMap(UUID serverUUID) {
|
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_now", regularAfter);
|
||||||
trends.put("regular_players_trend", new Trend(regularBefore, regularAfter, false));
|
trends.put("regular_players_trend", new Trend(regularBefore, regularAfter, false));
|
||||||
|
|
||||||
// TODO
|
Long avgPlaytimeBefore = db.query(SessionQueries.averagePlaytimePerPlayer(twoMonthsAgo, monthAgo, serverUUID));
|
||||||
trends.put("playtime_avg_then", "Not implemented");
|
Long avgPlaytimeAfter = db.query(SessionQueries.averagePlaytimePerPlayer(monthAgo, now, serverUUID));
|
||||||
trends.put("playtime_avg_now", "Not implemented");
|
trends.put("playtime_avg_then", timeAmount.apply(avgPlaytimeBefore));
|
||||||
trends.put("playtime_avg_trend", new Trend(0, 0, false, timeAmountFormatter));
|
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 avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo, serverUUID));
|
||||||
Long playtimeAfter = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
|
Long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now, serverUUID));
|
||||||
Long afkBefore = db.query(SessionQueries.afkTime(twoMonthsAgo, monthAgo, serverUUID));
|
double afkPercBefore = avgPlaytimeBefore != 0 ? (double) avgAfkBefore / avgPlaytimeBefore : 0;
|
||||||
Long afkAfter = db.query(SessionQueries.afkTime(monthAgo, now, serverUUID));
|
double afkPercAfter = avgPlaytimeAfter != 0 ? (double) avgAfkAfter / avgPlaytimeAfter : 0;
|
||||||
double afkPercBefore = playersBefore != 0 ? (double) afkBefore / playtimeBefore : 0;
|
trends.put("afk_then", percentage.apply(afkPercBefore));
|
||||||
double afkPercAfter = playersBefore != 0 ? (double) afkAfter / playtimeAfter : 0;
|
trends.put("afk_now", percentage.apply(afkPercAfter));
|
||||||
trends.put("afk_then", percentageFormatter.apply(afkPercBefore));
|
trends.put("afk_trend", new Trend(afkPercBefore, afkPercAfter, Trend.REVERSED, percentage));
|
||||||
trends.put("afk_now", percentageFormatter.apply(afkPercAfter));
|
|
||||||
trends.put("afk_trend", new Trend(afkPercBefore, afkPercAfter, Trend.REVERSED, percentageFormatter));
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
trends.put("regular_playtime_avg_then", "Not implemented");
|
trends.put("regular_playtime_avg_then", "Not implemented");
|
||||||
trends.put("regular_playtime_avg_now", "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
|
// TODO
|
||||||
trends.put("regular_session_avg_then", "Not implemented");
|
trends.put("regular_session_avg_then", "Not implemented");
|
||||||
trends.put("regular_session_avg_now", "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
|
// TODO
|
||||||
trends.put("regular_afk_avg_then", "Not implemented");
|
trends.put("regular_afk_avg_then", "Not implemented");
|
||||||
trends.put("regular_afk_avg_now", "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;
|
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_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_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_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_then').text(data.regular_afk_avg_then);
|
||||||
$(element).find('#data_regular_afk_now').text(data.regular_afk_now);
|
$(element).find('#data_regular_afk_now').text(data.regular_afk_avg_now);
|
||||||
$(element).find('#data_regular_afk_trend').replaceWith(trend(data.regular_afk_trend));
|
$(element).find('#data_regular_afk_trend').replaceWith(trend(data.regular_afk_avg_trend));
|
||||||
|
|
||||||
// Insights
|
// Insights
|
||||||
data = json.insights;
|
data = json.insights;
|
||||||
|
@ -766,7 +766,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<th><i class="text-success fa fa-caret-up"></i><i
|
<th><i class="text-success fa fa-caret-up"></i><i
|
||||||
class="text-danger fa fa-caret-down"></i>
|
class="text-danger fa fa-caret-down"></i>
|
||||||
<small>Comparing 15 days</small>
|
<small>Comparing 30d ago to Now</small>
|
||||||
</th>
|
</th>
|
||||||
<th>30 days ago</th>
|
<th>30 days ago</th>
|
||||||
<th>Now</th>
|
<th>Now</th>
|
||||||
|
Loading…
Reference in New Issue
Block a user