Search in sources :

Example 6 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class VelocityPingCounter method run.

@Override
public void run() {
    long time = System.currentTimeMillis();
    Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
    while (starts.hasNext()) {
        Map.Entry<UUID, Long> start = starts.next();
        if (time >= start.getValue()) {
            addPlayer(start.getKey());
            starts.remove();
        }
    }
    Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
        UUID uuid = entry.getKey();
        List<DateObj<Integer>> history = entry.getValue();
        Player player = plugin.getProxy().getPlayer(uuid).orElse(null);
        if (player != null) {
            int ping = getPing(player);
            if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
                // Don't accept bad values
                continue;
            }
            history.add(new DateObj<>(time, ping));
            if (history.size() >= 30) {
                dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
                history.clear();
            }
        } else {
            iterator.remove();
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) DateObj(com.djrapitops.plan.delivery.domain.DateObj) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class GeolocationQueriesTest method pingIsGroupedByGeolocationAppropriately.

@Test
default void pingIsGroupedByGeolocationAppropriately() {
    UUID[] uuids = storeSpecificGeolocations();
    Database db = db();
    long time = System.currentTimeMillis();
    List<DateObj<Integer>> ping = Collections.singletonList(new DateObj<>(time, 5));
    for (UUID uuid : uuids) {
        db.executeTransaction(new PingStoreTransaction(uuid, serverUUID(), ping));
    }
    Map<String, Ping> got = db.query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID()));
    Map<String, Ping> expected = new HashMap<>();
    // first user has a more recent connection from Finland so their country should be counted as Finland.
    Ping expectedPing = new Ping(time, serverUUID(), 5, 5, 5);
    expected.put("Finland", expectedPing);
    expected.put("Sweden", expectedPing);
    expected.put("Not Known", expectedPing);
    expected.put("Local Machine", expectedPing);
    expected.put("Denmark", expectedPing);
    assertEquals(expected, got);
}
Also used : DateObj(com.djrapitops.plan.delivery.domain.DateObj) Ping(com.djrapitops.plan.gathering.domain.Ping) Database(com.djrapitops.plan.storage.database.Database) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 8 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class PingQueriesTest method singlePingIsStored.

@Test
default void singlePingIsStored() {
    DateObj<Integer> saved = RandomData.randomIntDateObject();
    int value = saved.getValue();
    db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), Collections.singletonList(saved)));
    Map<UUID, List<Ping>> expected = Collections.singletonMap(playerUUID, Collections.singletonList(new Ping(saved.getDate(), serverUUID(), value, value, value)));
    Map<UUID, List<Ping>> fetched = db().query(PingQueries.fetchAllPingData());
    assertEquals(expected, fetched);
}
Also used : Ping(com.djrapitops.plan.gathering.domain.Ping) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) List(java.util.List) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

PingStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction)8 DateObj (com.djrapitops.plan.delivery.domain.DateObj)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 Ping (com.djrapitops.plan.gathering.domain.Ping)2 Test (org.junit.jupiter.api.Test)2 Player (cn.nukkit.Player)1 Database (com.djrapitops.plan.storage.database.Database)1 Player (com.velocitypowered.api.proxy.Player)1 List (java.util.List)1 UUID (java.util.UUID)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 Player (org.bukkit.entity.Player)1 Player (org.spongepowered.api.entity.living.player.Player)1