Search in sources :

Example 1 with GeoInfo

use of com.djrapitops.plan.gathering.domain.GeoInfo in project Plan by plan-player-analytics.

the class PlayersMutator method getPingPerCountry.

public Map<String, List<Ping>> getPingPerCountry(ServerUUID serverUUID) {
    Map<String, List<Ping>> pingPerCountry = new HashMap<>();
    for (PlayerContainer player : players) {
        Optional<GeoInfo> mostRecent = GeoInfoMutator.forContainer(player).mostRecent();
        if (!mostRecent.isPresent()) {
            continue;
        }
        List<Ping> pings = player.getValue(PlayerKeys.PING).orElse(new ArrayList<>());
        String country = mostRecent.get().getGeolocation();
        List<Ping> countryPings = pingPerCountry.computeIfAbsent(country, Lists::create);
        countryPings.addAll(new PingMutator(pings).filterByServer(serverUUID).all());
    }
    return pingPerCountry;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Lists(com.djrapitops.plan.utilities.java.Lists) Ping(com.djrapitops.plan.gathering.domain.Ping) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo)

Example 2 with GeoInfo

use of com.djrapitops.plan.gathering.domain.GeoInfo in project Plan by plan-player-analytics.

the class PlayersMutator method getGeolocations.

public List<String> getGeolocations() {
    List<String> geolocations = new ArrayList<>();
    for (PlayerContainer player : players) {
        Optional<GeoInfo> mostRecent = GeoInfoMutator.forContainer(player).mostRecent();
        geolocations.add(mostRecent.map(GeoInfo::getGeolocation).orElse("Unknown"));
    }
    return geolocations;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo)

Example 3 with GeoInfo

use of com.djrapitops.plan.gathering.domain.GeoInfo in project Plan by plan-player-analytics.

the class DatabaseTest method testRemovalSingleUser.

@Test
default void testRemovalSingleUser() {
    saveUserTwo();
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    saveTwoWorlds();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", RandomData.randomTime(), serverUUID()), (uuid, name) -> false));
    db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
    assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    db().executeTransaction(new RemovePlayerTransaction(playerUUID));
    assertFalse(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    assertFalse(db().query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID())));
    assertTrue(db().query(NicknameQueries.fetchNicknameDataOfPlayer(playerUUID)).isEmpty());
    assertTrue(db().query(GeoInfoQueries.fetchPlayerGeoInformation(playerUUID)).isEmpty());
    assertQueryIsEmpty(db(), SessionQueries.fetchSessionsOfPlayer(playerUUID));
}
Also used : SELECT(com.djrapitops.plan.storage.database.sql.building.Sql.SELECT) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) UserInfoTable(com.djrapitops.plan.storage.database.sql.tables.UserInfoTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) Disabled(org.junit.jupiter.api.Disabled) utilities(utilities) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) com.djrapitops.plan.storage.database.queries(com.djrapitops.plan.storage.database.queries) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ContainerFetchQueries(com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WHERE(com.djrapitops.plan.storage.database.sql.building.Sql.WHERE) ServerPlayerContainersQuery(com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery) QuerySvc(com.djrapitops.plan.query.QuerySvc) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Key(com.djrapitops.plan.delivery.domain.keys.Key) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) Assertions(org.junit.jupiter.api.Assertions) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Config(com.djrapitops.plan.settings.config.Config) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Example 4 with GeoInfo

use of com.djrapitops.plan.gathering.domain.GeoInfo in project Plan by plan-player-analytics.

the class DatabaseBackupTest method saveDataForBackup.

default void saveDataForBackup() {
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
    db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
    List<TPS> expected = RandomData.randomTPS();
    for (TPS tps : expected) {
        execute(DataStoreQueries.storeTPS(serverUUID(), tps));
    }
    db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), Collections.singletonList(new DateObj<>(System.currentTimeMillis(), RandomData.randomInt(-1, 40)))));
    User user = new User("test", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
    db().executeTransaction(new RegisterWebUserTransaction(user));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Files(java.nio.file.Files) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) File(java.io.File) Database(com.djrapitops.plan.storage.database.Database) Test(org.junit.jupiter.api.Test) List(java.util.List) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) DateObj(com.djrapitops.plan.delivery.domain.DateObj) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) BackupCopyTransaction(com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction) User(com.djrapitops.plan.delivery.domain.auth.User) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) TPS(com.djrapitops.plan.gathering.domain.TPS) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) RandomData(utilities.RandomData) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestConstants(utilities.TestConstants) Collections(java.util.Collections) User(com.djrapitops.plan.delivery.domain.auth.User) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) TPS(com.djrapitops.plan.gathering.domain.TPS)

Example 5 with GeoInfo

use of com.djrapitops.plan.gathering.domain.GeoInfo in project Plan by plan-player-analytics.

the class GeolocationQueriesTest method geolocationFilterResultsGetThePlayer.

@Test
default void geolocationFilterResultsGetThePlayer() {
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    List<GeoInfo> savedData = RandomData.randomGeoInfo();
    for (GeoInfo geoInfo : savedData) {
        save(playerUUID, geoInfo);
    }
    Set<UUID> expected = Collections.singleton(playerUUID);
    Set<UUID> result = db().query(GeoInfoQueries.uuidsOfPlayersWithGeolocations(Collections.singletonList(savedData.get(0).getGeolocation())));
    assertEquals(expected, result);
}
Also used : PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) Test(org.junit.jupiter.api.Test)

Aggregations

GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)12 Test (org.junit.jupiter.api.Test)6 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)4 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)4 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 com.djrapitops.plan.storage.database.queries.objects (com.djrapitops.plan.storage.database.queries.objects)3 com.djrapitops.plan.storage.database.transactions.events (com.djrapitops.plan.storage.database.transactions.events)3 Nickname (com.djrapitops.plan.delivery.domain.Nickname)2 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)2 Key (com.djrapitops.plan.delivery.domain.keys.Key)2 PlayerKeys (com.djrapitops.plan.delivery.domain.keys.PlayerKeys)2 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)2 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)2 QuerySvc (com.djrapitops.plan.query.QuerySvc)2 Config (com.djrapitops.plan.settings.config.Config)2 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)2 Locale (com.djrapitops.plan.settings.locale.Locale)2 Database (com.djrapitops.plan.storage.database.Database)2 com.djrapitops.plan.storage.database.queries (com.djrapitops.plan.storage.database.queries)2