mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 09:00:28 +08:00
Removed 3 SessionsTable methods - not used:
- getPlaytime, getPlaytimeOfServer, getSessionCount
This commit is contained in:
parent
57bc5b532e
commit
f4adf4a52c
@ -19,19 +19,16 @@ package com.djrapitops.plan.db.sql.tables;
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.patches.SessionAFKTimePatch;
|
||||
import com.djrapitops.plan.db.patches.SessionsOptimizationPatch;
|
||||
import com.djrapitops.plan.db.patches.Version10Patch;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
@ -91,105 +88,6 @@ public class SessionsTable extends Table {
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get Playtime after Epoch ms on a server.
|
||||
*
|
||||
* @param uuid UUID of the player.
|
||||
* @param serverUUID UUID of the server. @see ServerTable
|
||||
* @param afterDate Epoch ms (Playtime after this date is calculated)
|
||||
* @return Milliseconds played after given epoch ms on the server. 0 if player or server not found.
|
||||
*/
|
||||
public long getPlaytime(UUID uuid, UUID serverUUID, long afterDate) {
|
||||
String sql = SELECT +
|
||||
"(SUM(" + SESSION_END + ") - SUM(" + SESSION_START + ")) as playtime" +
|
||||
FROM + tableName +
|
||||
WHERE + SESSION_START + ">?" +
|
||||
AND + USER_UUID + "=?" +
|
||||
AND + SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<Long>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, afterDate);
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.setString(3, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return set.getLong("playtime");
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get Playtime after a date of a Server.
|
||||
*
|
||||
* @param serverUUID UUID of the server.
|
||||
* @param afterDate Epoch ms (Playtime after this date is calculated)
|
||||
* @return Milliseconds played after given epoch ms on the server. 0 if server not found.
|
||||
*/
|
||||
public long getPlaytimeOfServer(UUID serverUUID, long afterDate) {
|
||||
String sql = SELECT +
|
||||
"(SUM(" + SESSION_END + ") - SUM(" + SESSION_START + ")) as playtime" +
|
||||
FROM + tableName +
|
||||
WHERE + SESSION_START + ">?" +
|
||||
AND + SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<Long>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, afterDate);
|
||||
statement.setString(2, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return set.getLong("playtime");
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get total Session count of a Player on a server after a given epoch ms.
|
||||
*
|
||||
* @param uuid UUID of the player.
|
||||
* @param serverUUID UUID of the server.
|
||||
* @param afterDate Epoch ms (Session count after this date is calculated)
|
||||
* @return How many sessions player has. 0 if player or server not found.
|
||||
*/
|
||||
public int getSessionCount(UUID uuid, UUID serverUUID, long afterDate) {
|
||||
String sql = SELECT +
|
||||
"COUNT(*) as login_times" +
|
||||
FROM + tableName +
|
||||
WHERE + SESSION_START + " >= ?" +
|
||||
AND + USER_UUID + "=?" +
|
||||
AND + SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, afterDate);
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.setString(3, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return set.getInt("login_times");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getIDServerIDRelation() {
|
||||
String sql = SELECT +
|
||||
ID + ", " +
|
||||
|
@ -25,6 +25,7 @@ import com.djrapitops.plan.data.store.containers.NetworkContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.ServerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.*;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.data.store.objects.DateObj;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
@ -368,15 +369,17 @@ public abstract class CommonDBTest {
|
||||
|
||||
commitTest();
|
||||
|
||||
assertEquals(expectedLength, sessionsTable.getPlaytime(playerUUID, serverUUID, 0L));
|
||||
assertEquals(0L, sessionsTable.getPlaytime(playerUUID, serverUUID, 30000L));
|
||||
Map<UUID, List<Session>> sessions = db.query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
|
||||
assertTrue(sessions.containsKey(serverUUID));
|
||||
|
||||
long playtimeOfServer = sessionsTable.getPlaytimeOfServer(serverUUID, 0L);
|
||||
assertEquals(expectedLength, playtimeOfServer);
|
||||
assertEquals(0L, sessionsTable.getPlaytimeOfServer(serverUUID, 30000L));
|
||||
SessionsMutator sessionsMutator = new SessionsMutator(sessions.get(serverUUID));
|
||||
SessionsMutator afterTimeSessionsMutator = sessionsMutator.filterSessionsBetween(30000, System.currentTimeMillis());
|
||||
|
||||
assertEquals(1, sessionsTable.getSessionCount(playerUUID, serverUUID, 0L));
|
||||
assertEquals(0, sessionsTable.getSessionCount(playerUUID, serverUUID, 30000L));
|
||||
assertEquals(expectedLength, sessionsMutator.toPlaytime());
|
||||
assertEquals(0L, afterTimeSessionsMutator.toPlaytime());
|
||||
|
||||
assertEquals(1, sessionsMutator.count());
|
||||
assertEquals(0, afterTimeSessionsMutator.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user