mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-23 00:21:43 +01:00
Trends for regular players' averages
This commit is contained in:
parent
a47ef57539
commit
4d09c51232
@ -213,6 +213,110 @@ public class ActivityIndexQueries {
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> averagePlaytimePerRegularPlayer(long after, long before, UUID serverUUID, Long threshold) {
|
||||
return database -> {
|
||||
// INNER JOIN limits the users to only those that are regular
|
||||
String selectPlaytimePerPlayer = SELECT +
|
||||
"p." + SessionsTable.USER_UUID + "," +
|
||||
"SUM(p." + SessionsTable.SESSION_END + "-p." + SessionsTable.SESSION_START + ") as playtime" +
|
||||
FROM + SessionsTable.TABLE_NAME + " p" +
|
||||
INNER_JOIN + '(' + selectActivityIndexSQL() + ") q2 on q2." + SessionsTable.USER_UUID + "=p." + SessionsTable.USER_UUID +
|
||||
WHERE + "p." + SessionsTable.SESSION_END + "<=?" +
|
||||
AND + "p." + SessionsTable.SESSION_START + ">=?" +
|
||||
AND + "p." + SessionsTable.SERVER_UUID + "=?" +
|
||||
AND + "q2.activity_index>=?" +
|
||||
AND + "q2.activity_index<?" +
|
||||
GROUP_BY + "p." + 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 {
|
||||
setSelectActivityIndexSQLParameters(statement, 1, threshold, serverUUID, before);
|
||||
statement.setLong(12, before);
|
||||
statement.setLong(13, after);
|
||||
statement.setString(14, serverUUID.toString());
|
||||
statement.setDouble(15, ActivityIndex.REGULAR);
|
||||
statement.setDouble(16, 5.1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getLong("average") : 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> averageSessionLengthPerRegularPlayer(long after, long before, UUID serverUUID, Long threshold) {
|
||||
return database -> {
|
||||
// INNER JOIN limits the users to only those that are regular
|
||||
String selectSessionLengthPerPlayer = SELECT +
|
||||
"p." + SessionsTable.USER_UUID + "," +
|
||||
"p." + SessionsTable.SESSION_END + "-p." + SessionsTable.SESSION_START + " as length" +
|
||||
FROM + SessionsTable.TABLE_NAME + " p" +
|
||||
INNER_JOIN + '(' + selectActivityIndexSQL() + ") q2 on q2." + SessionsTable.USER_UUID + "=p." + SessionsTable.USER_UUID +
|
||||
WHERE + "p." + SessionsTable.SESSION_END + "<=?" +
|
||||
AND + "p." + SessionsTable.SESSION_START + ">=?" +
|
||||
AND + "p." + SessionsTable.SERVER_UUID + "=?" +
|
||||
AND + "q2.activity_index>=?" +
|
||||
AND + "q2.activity_index<?";
|
||||
String selectAverage = SELECT + "AVG(length) as average" + FROM + '(' + selectSessionLengthPerPlayer + ") q1";
|
||||
|
||||
return database.query(new QueryStatement<Long>(selectAverage, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
setSelectActivityIndexSQLParameters(statement, 1, threshold, serverUUID, before);
|
||||
statement.setLong(12, before);
|
||||
statement.setLong(13, after);
|
||||
statement.setString(14, serverUUID.toString());
|
||||
statement.setDouble(15, ActivityIndex.REGULAR);
|
||||
statement.setDouble(16, 5.1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getLong("average") : 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Long> averageAFKPerRegularPlayer(long after, long before, UUID serverUUID, Long threshold) {
|
||||
return database -> {
|
||||
// INNER JOIN limits the users to only those that are regular
|
||||
String selectPlaytimePerPlayer = SELECT +
|
||||
"p." + SessionsTable.USER_UUID + "," +
|
||||
"SUM(p." + SessionsTable.AFK_TIME + ") as afk" +
|
||||
FROM + SessionsTable.TABLE_NAME + " p" +
|
||||
INNER_JOIN + '(' + selectActivityIndexSQL() + ") q2 on q2." + SessionsTable.USER_UUID + "=p." + SessionsTable.USER_UUID +
|
||||
WHERE + "p." + SessionsTable.SESSION_END + "<=?" +
|
||||
AND + "p." + SessionsTable.SESSION_START + ">=?" +
|
||||
AND + "p." + SessionsTable.SERVER_UUID + "=?" +
|
||||
AND + "q2.activity_index>=?" +
|
||||
AND + "q2.activity_index<?" +
|
||||
GROUP_BY + "p." + SessionsTable.USER_UUID;
|
||||
String selectAverage = SELECT + "AVG(afk) as average" + FROM + '(' + selectPlaytimePerPlayer + ") q1";
|
||||
|
||||
return database.query(new QueryStatement<Long>(selectAverage, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
setSelectActivityIndexSQLParameters(statement, 1, threshold, serverUUID, before);
|
||||
statement.setLong(12, before);
|
||||
statement.setLong(13, after);
|
||||
statement.setString(14, serverUUID.toString());
|
||||
statement.setDouble(15, ActivityIndex.REGULAR);
|
||||
statement.setDouble(16, 5.1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getLong("average") : 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Collection<ActivityIndex>> activityIndexForNewPlayers(long after, long before, UUID serverUUID, Long threshold) {
|
||||
String selectNewUUIDs = SELECT + UserInfoTable.USER_UUID +
|
||||
FROM + UserInfoTable.TABLE_NAME +
|
||||
|
@ -102,18 +102,25 @@ public class PlayerBaseOverviewJSONParser implements TabJSONParser<Map<String, O
|
||||
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, 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, 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, percentage));
|
||||
Long avgRegularPlaytimeBefore = db.query(ActivityIndexQueries.averagePlaytimePerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
|
||||
Long avgRegularPlaytimeAfter = db.query(ActivityIndexQueries.averagePlaytimePerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
|
||||
trends.put("regular_playtime_avg_then", timeAmount.apply(avgRegularPlaytimeBefore));
|
||||
trends.put("regular_playtime_avg_now", timeAmount.apply(avgRegularPlaytimeAfter));
|
||||
trends.put("regular_playtime_avg_trend", new Trend(avgRegularPlaytimeBefore, avgRegularPlaytimeAfter, false, timeAmount));
|
||||
|
||||
Long avgRegularSessionLengthBefore = db.query(ActivityIndexQueries.averageSessionLengthPerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
|
||||
Long avgRegularSessionLengthAfter = db.query(ActivityIndexQueries.averageSessionLengthPerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
|
||||
trends.put("regular_session_avg_then", timeAmount.apply(avgRegularSessionLengthBefore));
|
||||
trends.put("regular_session_avg_now", timeAmount.apply(avgRegularSessionLengthAfter));
|
||||
trends.put("regular_session_avg_trend", new Trend(avgRegularSessionLengthBefore, avgRegularSessionLengthAfter, false, timeAmount));
|
||||
|
||||
Long avgRegularAfkBefore = db.query(ActivityIndexQueries.averageAFKPerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
|
||||
Long avgRegularAfkAfter = db.query(ActivityIndexQueries.averageAFKPerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
|
||||
double afkRegularPercBefore = avgRegularPlaytimeBefore != 0 ? (double) avgRegularAfkBefore / avgRegularPlaytimeBefore : 0;
|
||||
double afkRegularPercAfter = avgRegularPlaytimeAfter != 0 ? (double) avgRegularAfkAfter / avgRegularPlaytimeAfter : 0;
|
||||
trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercBefore));
|
||||
trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercAfter));
|
||||
trends.put("regular_afk_avg_trend", new Trend(afkRegularPercBefore, afkRegularPercAfter, Trend.REVERSED, percentage));
|
||||
|
||||
return trends;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user