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();
}
}
}
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);
}
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);
}
Aggregations