mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-29 12:37:40 +01:00
ServerProfile get method to database, deprecated old analysis part system
This commit is contained in:
parent
32fd2dc5aa
commit
c4963c117a
@ -52,6 +52,13 @@ public class ServerProfile {
|
||||
players = new ArrayList<>();
|
||||
tps = new ArrayList<>();
|
||||
commandUsage = new HashMap<>();
|
||||
|
||||
allTimePeak = -1;
|
||||
allTimePeakPlayers = -1;
|
||||
lastPeakDate = -1;
|
||||
lastPeakPlayers = -1;
|
||||
playersOnline = -1;
|
||||
playersMax = -1;
|
||||
}
|
||||
|
||||
public List<PlayerProfile> getPlayers() {
|
||||
|
@ -38,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class ActivityPart extends RawData {
|
||||
|
||||
private final PlayerCountPart playerCount;
|
||||
|
@ -24,6 +24,7 @@ import java.util.Map;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class CommandUsagePart extends RawData {
|
||||
|
||||
private Map<String, Integer> commandUsage;
|
||||
|
@ -20,6 +20,7 @@ import java.util.stream.Collectors;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class GeolocationPart extends RawData {
|
||||
|
||||
private final Map<UUID, String> mostCommonGeolocations;
|
||||
|
@ -36,6 +36,7 @@ import java.util.stream.Collectors;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class JoinInfoPart extends RawData {
|
||||
|
||||
private final Map<UUID, Session> activeSessions;
|
||||
|
@ -21,6 +21,7 @@ import java.util.UUID;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class KillPart extends RawData {
|
||||
|
||||
private final JoinInfoPart joinInfoPart;
|
||||
|
@ -18,6 +18,7 @@ import java.util.UUID;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class PlayerCountPart extends RawData {
|
||||
|
||||
private final Set<UUID> uuids;
|
||||
|
@ -13,6 +13,7 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class PlaytimePart extends RawData {
|
||||
|
||||
private long totalPlaytime;
|
||||
|
@ -49,6 +49,7 @@ import java.util.List;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class TPSPart extends RawData {
|
||||
|
||||
private final List<TPS> tpsData;
|
||||
|
@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||
* @author Rsl1122
|
||||
* @since 3.6.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class WorldPart extends RawData {
|
||||
|
||||
private WorldTimes worldTimes;
|
||||
|
@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.database;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.data.PlayerProfile;
|
||||
import main.java.com.djrapitops.plan.data.ServerProfile;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@ -268,4 +269,6 @@ public abstract class Database {
|
||||
}
|
||||
|
||||
public abstract PlayerProfile getPlayerProfile(UUID uuid) throws SQLException;
|
||||
|
||||
public abstract ServerProfile getServerProfile(UUID serverUUID) throws SQLException;
|
||||
}
|
||||
|
@ -8,20 +8,16 @@ import com.djrapitops.plugin.task.ITask;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.data.PlayerProfile;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.data.*;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.database.tables.move.Version8TransferTable;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class containing main logic for different data related save and load functionality.
|
||||
@ -278,6 +274,59 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerProfile getServerProfile(UUID serverUUID) throws SQLException {
|
||||
ServerProfile profile = new ServerProfile(serverUUID);
|
||||
|
||||
profile.setPlayers(getPlayers(serverUUID));
|
||||
profile.setTps(tpsTable.getTPSData(serverUUID));
|
||||
Optional<TPS> allTimePeak = tpsTable.getAllTimePeak(serverUUID);
|
||||
if (allTimePeak.isPresent()) {
|
||||
TPS peak = allTimePeak.get();
|
||||
profile.setAllTimePeak(peak.getDate());
|
||||
profile.setAllTimePeakPlayers(peak.getPlayers());
|
||||
}
|
||||
Optional<TPS> lastPeak = tpsTable.getPeakPlayerCount(serverUUID, MiscUtils.getTime() - (TimeAmount.DAY.ms() * 2L));
|
||||
if (lastPeak.isPresent()) {
|
||||
TPS peak = lastPeak.get();
|
||||
profile.setLastPeakDate(peak.getDate());
|
||||
profile.setLastPeakPlayers(peak.getPlayers());
|
||||
}
|
||||
|
||||
profile.setCommandUsage(commandUseTable.getCommandUse(serverUUID));
|
||||
profile.setServerWorldtimes(worldTimesTable.getWorldTimesOfServer(serverUUID));
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
private List<PlayerProfile> getPlayers(UUID serverUUID) throws SQLException {
|
||||
List<UserInfo> serverUserInfo = userInfoTable.getServerUserInfo(serverUUID);
|
||||
Map<UUID, Integer> timesKicked = usersTable.getAllTimesKicked();
|
||||
Map<UUID, List<Action>> actions = actionsTable.getServerActions(serverUUID);
|
||||
Map<UUID, List<GeoInfo>> geoInfo = ipsTable.getAllGeoInfo();
|
||||
Map<UUID, List<Session>> sessions = sessionsTable.getSessionInfoOfServer(serverUUID);
|
||||
|
||||
List<PlayerProfile> players = new ArrayList<>();
|
||||
|
||||
for (UserInfo userInfo : serverUserInfo) {
|
||||
UUID uuid = userInfo.getUuid();
|
||||
PlayerProfile profile = new PlayerProfile(uuid, userInfo.getName(), userInfo.getRegistered());
|
||||
profile.setTimesKicked(timesKicked.getOrDefault(uuid, 0));
|
||||
if (userInfo.isBanned()) {
|
||||
profile.bannedOnServer(serverUUID);
|
||||
}
|
||||
if (userInfo.isOpped()) {
|
||||
profile.oppedOnServer(serverUUID);
|
||||
}
|
||||
profile.setActions(actions.getOrDefault(uuid, new ArrayList<>()));
|
||||
profile.setGeoInformation(geoInfo.getOrDefault(uuid, new ArrayList<>()));
|
||||
profile.setSessions(serverUUID, sessions.getOrDefault(uuid, new ArrayList<>()));
|
||||
|
||||
players.add(profile);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasSeenBefore(UUID uuid) {
|
||||
if (uuid == null) {
|
||||
|
@ -193,4 +193,43 @@ public class ActionsTable extends UserIDTable {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Map<UUID, List<Action>> getServerActions(UUID serverUUID) throws SQLException {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
String sql = "SELECT " +
|
||||
columnActionID + ", " +
|
||||
columnDate + ", " +
|
||||
columnAdditionalInfo + ", " +
|
||||
usersUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID +
|
||||
" WHERE " + serverTable.statementSelectServerID + "=" + columnServerID;
|
||||
|
||||
return query(new QueryStatement<Map<UUID, List<Action>>>(sql, 20000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, List<Action>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<Action>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
|
||||
List<Action> actions = map.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
long date = set.getLong(columnDate);
|
||||
Actions doneAction = Actions.getById(set.getInt(columnActionID));
|
||||
String additionalInfo = set.getString(columnAdditionalInfo);
|
||||
|
||||
actions.add(new Action(date, doneAction, additionalInfo, -1));
|
||||
|
||||
map.put(uuid, actions);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -234,4 +234,5 @@ public class NicknamesTable extends UserIDTable {
|
||||
public String getColumnUserID() {
|
||||
return columnUserID;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,6 +76,10 @@ public class TPSTable extends Table {
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public List<TPS> getTPSData() throws SQLException {
|
||||
return getTPSData(MiscUtils.getIPlan().getServerUuid());
|
||||
}
|
||||
|
||||
public List<TPS> getTPSData(UUID serverUUID) throws SQLException {
|
||||
String sql = Select.all(tableName)
|
||||
.where(columnServerID + "=" + serverTable.statementSelectServerID)
|
||||
.toString();
|
||||
@ -83,7 +87,7 @@ public class TPSTable extends Table {
|
||||
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, MiscUtils.getIPlan().getServerUuid().toString());
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user