Search in sources :

Example 6 with FinishedSession

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

the class JoinAddressQueriesTest method joinAddressCanBeUnknown.

@Test
default void joinAddressCanBeUnknown() {
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
    db().executeTransaction(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, TestConstants.PLAYER_ONE_NAME));
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    session.getExtraData().remove(JoinAddress.class);
    db().executeTransaction(new StoreSessionTransaction(session));
    Set<Integer> expected = Set.of(db().query(BaseUserQueries.fetchUserId(playerUUID)).orElseThrow(AssertionError::new));
    Set<Integer> result = db().query(JoinAddressQueries.userIdsOfPlayersWithJoinAddresses(List.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP)));
    assertEquals(expected, result);
    Map<String, Integer> expectedAddressCounts = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1);
    Map<String, Integer> resultAddressCounts = db().query(JoinAddressQueries.latestJoinAddresses());
    assertEquals(expectedAddressCounts, resultAddressCounts);
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) Test(org.junit.jupiter.api.Test)

Example 7 with FinishedSession

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

the class JoinAddressQueriesTest method joinAddressQueryHasDistinctPlayers.

@Test
default void joinAddressQueryHasDistinctPlayers() {
    joinAddressCanBeUnknown();
    db().executeTransaction(TestData.storeServers());
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, player2UUID, playerUUID);
    String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
    session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
    db().executeTransaction(new StoreSessionTransaction(session));
    Map<String, Integer> expected = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1, expectedAddress, 1);
    Map<String, Integer> result = db().query(JoinAddressQueries.latestJoinAddresses());
    assertEquals(expected, result);
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) Test(org.junit.jupiter.api.Test)

Example 8 with FinishedSession

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

the class PerServerContainerQuery method executeQuery.

@Override
public PerServerContainer executeQuery(SQLDB db) {
    PerServerContainer perServerContainer = new PerServerContainer();
    userInformation(db, perServerContainer);
    lastSeen(db, perServerContainer);
    playerKillCount(db, perServerContainer);
    mobKillCount(db, perServerContainer);
    totalDeathCount(db, perServerContainer);
    worldTimes(db, perServerContainer);
    Map<ServerUUID, List<FinishedSession>> sessions = db.query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
    for (Map.Entry<ServerUUID, List<FinishedSession>> entry : sessions.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        List<FinishedSession> serverSessions = entry.getValue();
        if (!serverSessions.isEmpty()) {
            serverSessions.get(0).getExtraData().get(JoinAddress.class).map(JoinAddress::getAddress).ifPresent(address -> perServerContainer.putToContainerOfServer(serverUUID, PerServerKeys.JOIN_ADDRESS, address));
        }
        DataContainer serverContainer = perServerContainer.getOrDefault(serverUUID, new SupplierDataContainer());
        serverContainer.putRawData(PerServerKeys.SESSIONS, serverSessions);
        perServerContainer.put(serverUUID, serverContainer);
    }
    return perServerContainer;
}
Also used : PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) SupplierDataContainer(com.djrapitops.plan.delivery.domain.container.SupplierDataContainer) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) List(java.util.List) Map(java.util.Map) SupplierDataContainer(com.djrapitops.plan.delivery.domain.container.SupplierDataContainer)

Example 9 with FinishedSession

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

the class PingMutator method addPingToSessions.

public void addPingToSessions(List<FinishedSession> sessions) {
    if (sessions.isEmpty())
        return;
    Comparator<DateHolder> comparator = new DateHolderOldestComparator();
    sessions.sort(comparator);
    pings.sort(comparator);
    Map<ServerUUID, SortedMap<Long, Ping>> pingByServer = sortByServers(pings);
    Map<ServerUUID, List<FinishedSession>> sessionsByServer = SessionsMutator.sortByServers(sessions);
    for (Map.Entry<ServerUUID, SortedMap<Long, Ping>> entry : pingByServer.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        SortedMap<Long, Ping> pingOfServer = entry.getValue();
        if (pingOfServer.isEmpty())
            continue;
        List<FinishedSession> sessionsOfServer = sessionsByServer.getOrDefault(serverUUID, Collections.emptyList());
        double pingCount = 0.0;
        int pingEntries = 0;
        for (FinishedSession session : sessionsOfServer) {
            long start = session.getDate();
            long end = session.getEnd();
            if (end < start)
                continue;
            // Calculate average ping for each session with a section of the Ping map
            SortedMap<Long, Ping> duringSession = pingOfServer.subMap(start, end);
            for (Ping ping : duringSession.values()) {
                pingCount += ping.getAverage();
                pingEntries++;
            }
            if (pingEntries != 0) {
                session.getExtraData().put(AveragePing.class, new AveragePing(pingCount / pingEntries));
            }
            pingCount = 0.0;
            pingEntries = 0;
        }
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) DateHolder(com.djrapitops.plan.delivery.domain.DateHolder) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Ping(com.djrapitops.plan.gathering.domain.Ping) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) DateHolderOldestComparator(com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)

Example 10 with FinishedSession

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

the class TimeSegmentsMutator method sessionClockSegments.

public static TimeSegmentsMutator<Integer> sessionClockSegments(List<FinishedSession> sessions) {
    List<DateObj<Integer>> changes = new ArrayList<>();
    for (FinishedSession session : sessions) {
        long startTime = (session.getStart()) % TimeUnit.DAYS.toMillis(1);
        long endTime = (session.getEnd()) % TimeUnit.DAYS.toMillis(1);
        changes.add(new DateObj<>(startTime, 1));
        changes.add(new DateObj<>(endTime, -1));
    }
    changes.sort(new DateHolderOldestComparator());
    int count = 0;
    long previousTime = 0L;
    List<TimeSegment<Integer>> segments = new ArrayList<>();
    for (DateObj<Integer> change : changes) {
        segments.add(new TimeSegment<>(previousTime, change.getDate(), count));
        count += change.getValue();
        previousTime = change.getDate();
    }
    return new TimeSegmentsMutator<>(segments);
}
Also used : TimeSegment(com.djrapitops.plan.delivery.domain.TimeSegment) ArrayList(java.util.ArrayList) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) DateObj(com.djrapitops.plan.delivery.domain.DateObj) DateHolderOldestComparator(com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)

Aggregations

FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)32 Test (org.junit.jupiter.api.Test)22 ServerUUID (com.djrapitops.plan.identification.ServerUUID)13 RepeatedTest (org.junit.jupiter.api.RepeatedTest)11 StoreSessionTransaction (com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction)10 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)8 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 RandomData (utilities.RandomData)6 TestConstants (utilities.TestConstants)6 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)5 List (java.util.List)5 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)4 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)4 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)4 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)4 UsersTable (com.djrapitops.plan.storage.database.sql.tables.UsersTable)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Collection (java.util.Collection)4 TimeUnit (java.util.concurrent.TimeUnit)4