mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 17:37:34 +01:00
New player retention 7d, 30d
This commit is contained in:
parent
3c421199ac
commit
417738c560
@ -225,4 +225,42 @@ public class PlayerCountQueries {
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Integer> retainedPlayerCount(long after, long before, UUID serverUUID) {
|
||||
String selectNewUUIDs = SELECT + UserInfoTable.USER_UUID +
|
||||
FROM + UserInfoTable.TABLE_NAME +
|
||||
WHERE + UserInfoTable.REGISTERED + "<=?" +
|
||||
AND + UserInfoTable.REGISTERED + ">=?" +
|
||||
AND + UserInfoTable.SERVER_UUID + "=?";
|
||||
|
||||
String selectUniqueUUIDs = SELECT + "DISTINCT " + SessionsTable.USER_UUID +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
WHERE + SessionsTable.SESSION_START + ">=?" +
|
||||
AND + SessionsTable.SESSION_END + "<=?" +
|
||||
AND + SessionsTable.SERVER_UUID + "=?";
|
||||
|
||||
String sql = SELECT + "COUNT(1) as player_count" +
|
||||
FROM + '(' + selectNewUUIDs + ") q1" +
|
||||
INNER_JOIN + '(' + selectUniqueUUIDs + ") q2 on q1." + SessionsTable.USER_UUID + "=q2." + SessionsTable.USER_UUID;
|
||||
|
||||
return new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, before);
|
||||
statement.setLong(2, after);
|
||||
statement.setString(3, serverUUID.toString());
|
||||
|
||||
// Have played in the last half of the time frame
|
||||
long half = before - (after - before) / 2;
|
||||
statement.setLong(4, half);
|
||||
statement.setLong(5, before);
|
||||
statement.setString(6, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getInt("player_count") : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -105,13 +105,15 @@ public class OnlineActivityOverviewJSONParser implements TabJSONParser<Map<Strin
|
||||
numbers.put("unique_players_7d_avg", db.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo, now, timeZoneOffset, serverUUID)));
|
||||
numbers.put("unique_players_24h_avg", db.query(PlayerCountQueries.averageUniquePlayerCount(dayAgo, now, timeZoneOffset, serverUUID)));
|
||||
|
||||
numbers.put("new_players_30d", db.query(PlayerCountQueries.newPlayerCount(monthAgo, now, serverUUID)));
|
||||
Integer new30d = db.query(PlayerCountQueries.newPlayerCount(monthAgo, now, serverUUID));
|
||||
Integer new7d = db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID));
|
||||
numbers.put("new_players_30d", new30d);
|
||||
numbers.put("new_players_30d_trend", new Trend(
|
||||
db.query(PlayerCountQueries.newPlayerCount(monthAgo, halfMonthAgo, serverUUID)),
|
||||
db.query(PlayerCountQueries.newPlayerCount(halfMonthAgo, now, serverUUID)),
|
||||
false
|
||||
));
|
||||
numbers.put("new_players_7d", db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID)));
|
||||
numbers.put("new_players_7d", new7d);
|
||||
numbers.put("new_players_24h", db.query(PlayerCountQueries.newPlayerCount(dayAgo, now, serverUUID)));
|
||||
|
||||
numbers.put("new_players_30d_avg", db.query(PlayerCountQueries.averageNewPlayerCount(monthAgo, now, timeZoneOffset, serverUUID)));
|
||||
@ -123,10 +125,14 @@ public class OnlineActivityOverviewJSONParser implements TabJSONParser<Map<Strin
|
||||
numbers.put("new_players_7d_avg", db.query(PlayerCountQueries.averageNewPlayerCount(weekAgo, now, timeZoneOffset, serverUUID)));
|
||||
numbers.put("new_players_24h_avg", db.query(PlayerCountQueries.averageNewPlayerCount(dayAgo, now, timeZoneOffset, serverUUID)));
|
||||
|
||||
numbers.put("new_players_retention_30d", 0); // TODO
|
||||
numbers.put("new_players_retention_30d_perc", percentageFormatter.apply(-1.0)); // TODO
|
||||
numbers.put("new_players_retention_7d", 0); // TODO
|
||||
numbers.put("new_players_retention_7d_perc", percentageFormatter.apply(-1.0)); // TODO
|
||||
int retained30d = db.query(PlayerCountQueries.retainedPlayerCount(monthAgo, now, serverUUID));
|
||||
int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
|
||||
double retentionPerc30d = new30d != 0 ? (double) retained30d / new30d : -1;
|
||||
double retentionPerc7d = new7d != 0 ? (double) retained7d / new7d : -1;
|
||||
numbers.put("new_players_retention_30d", retained30d);
|
||||
numbers.put("new_players_retention_30d_perc", percentageFormatter.apply(retentionPerc30d));
|
||||
numbers.put("new_players_retention_7d", retained7d);
|
||||
numbers.put("new_players_retention_7d_perc", percentageFormatter.apply(retentionPerc7d));
|
||||
numbers.put("new_players_retention_24h", 0); // TODO
|
||||
numbers.put("new_players_retention_24h_perc", percentageFormatter.apply(-1.0)); // TODO
|
||||
|
||||
|
@ -89,16 +89,21 @@ public class ServerOverviewJSONParser implements TabJSONParser<Map<String, Objec
|
||||
private Map<String, Object> createLast7DaysMap(UUID serverUUID) {
|
||||
Database db = dbSystem.getDatabase();
|
||||
long now = System.currentTimeMillis();
|
||||
long sevenDaysAgo = now - TimeUnit.DAYS.toMillis(7L);
|
||||
long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
|
||||
|
||||
Map<String, Object> sevenDays = new HashMap<>();
|
||||
|
||||
sevenDays.put("unique_players", db.query(PlayerCountQueries.uniquePlayerCount(sevenDaysAgo, now, serverUUID)));
|
||||
sevenDays.put("unique_players_day", db.query(PlayerCountQueries.averageUniquePlayerCount(sevenDaysAgo, now, timeZone.getOffset(now), serverUUID)));
|
||||
sevenDays.put("new_players", db.query(PlayerCountQueries.newPlayerCount(sevenDaysAgo, now, serverUUID)));
|
||||
sevenDays.put("new_players_retention", "!"); // TODO
|
||||
sevenDays.put("new_players_retention_perc", "!"); // TODO
|
||||
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(sevenDaysAgo, now, serverUUID)));
|
||||
sevenDays.put("unique_players", db.query(PlayerCountQueries.uniquePlayerCount(weekAgo, now, serverUUID)));
|
||||
sevenDays.put("unique_players_day", db.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo, now, timeZone.getOffset(now), serverUUID)));
|
||||
|
||||
int new7d = db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID));
|
||||
int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
|
||||
double retentionPerc7d = new7d != 0 ? (double) retained7d / new7d : -1;
|
||||
|
||||
sevenDays.put("new_players", new7d);
|
||||
sevenDays.put("new_players_retention", retained7d);
|
||||
sevenDays.put("new_players_retention_perc", percentage.apply(retentionPerc7d));
|
||||
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(weekAgo, now, serverUUID)));
|
||||
sevenDays.put("average_tps", decimals.apply(tpsMutator.averageTPS()));
|
||||
sevenDays.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.getNumber(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
|
||||
sevenDays.put("downtime", timeAmount.apply(tpsMutator.serverDownTime()));
|
||||
|
Loading…
Reference in New Issue
Block a user