mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 11:37:41 +01:00
Removed rest of ManageUtils combineSessions
This commit is contained in:
parent
8fe7de9bb6
commit
f986f24d12
@ -199,5 +199,6 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<sonar.language>java</sonar.language>
|
||||
</properties>
|
||||
</project>
|
@ -5,8 +5,6 @@ import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -257,56 +255,6 @@ public class SessionsTable extends Table {
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clean() throws SQLException {
|
||||
Map<Integer, Integer> loginTimes = db.getUsersTable().getLoginTimes();
|
||||
Map<Integer, List<SessionData>> allSessions = getSessionData(loginTimes.keySet());
|
||||
|
||||
Benchmark.start("Database: Combine Sessions");
|
||||
|
||||
int before = MathUtils.sumInt(allSessions.values().stream().map(List::size));
|
||||
|
||||
Log.debug("Sessions before: " + before);
|
||||
|
||||
Map<Integer, Integer> beforeM = new HashMap<>();
|
||||
Map<Integer, Integer> afterM = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Integer, List<SessionData>> entrySet : allSessions.entrySet()) {
|
||||
Integer id = entrySet.getKey();
|
||||
List<SessionData> sessions = entrySet.getValue();
|
||||
|
||||
beforeM.put(id, sessions.size());
|
||||
if (sessions.isEmpty()) {
|
||||
afterM.put(id, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer times = loginTimes.get(id);
|
||||
if (sessions.size() == times) {
|
||||
afterM.put(id, times);
|
||||
continue;
|
||||
}
|
||||
|
||||
List<SessionData> combined = ManageUtils.combineSessions(sessions, times);
|
||||
afterM.put(id, combined.size());
|
||||
allSessions.put(id, combined);
|
||||
}
|
||||
|
||||
int after = MathUtils.sumInt(allSessions.values().stream().map(List::size));
|
||||
Log.debug("Sessions after: " + after);
|
||||
|
||||
if (before - after > 50) {
|
||||
Benchmark.start("Database: Save combined sessions");
|
||||
for (Integer id : new HashSet<>(allSessions.keySet())) {
|
||||
if (afterM.get(id) < beforeM.get(id)) {
|
||||
removeUserSessions(id);
|
||||
} else {
|
||||
allSessions.remove(id);
|
||||
}
|
||||
}
|
||||
saveSessionData(allSessions);
|
||||
Benchmark.stop("Database: Save combined sessions");
|
||||
}
|
||||
|
||||
Benchmark.stop("Database: Combine Sessions");
|
||||
Log.info("Combined " + (before - after) + " sessions.");
|
||||
// TODO Clean sessions before Configurable time span
|
||||
}
|
||||
}
|
||||
|
@ -1,175 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({JavaPlugin.class})
|
||||
public class ManageUtilsTest {
|
||||
|
||||
private final int threshold = 5000;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ManageUtilsTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsCombinable() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold - 100, threshold * 2));
|
||||
data.add(new SessionData(threshold * 2 + 100, threshold * 3));
|
||||
assertTrue(ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsCombinableFalse() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, threshold));
|
||||
data.add(new SessionData(threshold * 3, threshold * 4));
|
||||
assertTrue(!ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsCombinableFalse2() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3, threshold * 4));
|
||||
assertTrue(!ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsCombinableFalse3() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
assertTrue(!ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCombineSessions() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 2 + 100, threshold * 3));
|
||||
SessionData get = ManageUtils.combineSessions(data, 1).get(0);
|
||||
SessionData exp = new SessionData(0, threshold * 3);
|
||||
assertEquals(exp, get);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCombineSessions2() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 2 + 100, threshold * 3));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
SessionData get = ManageUtils.combineSessions(data, 1).get(0);
|
||||
SessionData exp = new SessionData(0, threshold * 4);
|
||||
assertEquals(exp, get);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCombineSessions3() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
List<SessionData> result = ManageUtils.combineSessions(data, 2);
|
||||
SessionData exp = new SessionData(0, threshold * 2);
|
||||
assertEquals(exp, result.get(0));
|
||||
SessionData exp2 = new SessionData(threshold * 3 + 200, threshold * 4);
|
||||
assertEquals(exp2, result.get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCombineSessions4() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
data.add(new SessionData(threshold * 5 - 200, threshold * 5));
|
||||
List<SessionData> result = ManageUtils.combineSessions(data, 2);
|
||||
SessionData exp = new SessionData(0, threshold * 2);
|
||||
assertEquals(exp, result.get(0));
|
||||
SessionData exp2 = new SessionData(threshold * 3 + 200, threshold * 5);
|
||||
assertEquals(exp2, result.get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCombineSessions5() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 5, threshold * 5 + 100));
|
||||
data.add(new SessionData(threshold * 8, threshold * 8 + 200));
|
||||
data.add(new SessionData(threshold * 9 - 200, threshold * 10));
|
||||
List<SessionData> result = ManageUtils.combineSessions(data, 3);
|
||||
SessionData exp = new SessionData(0, threshold * 2);
|
||||
assertEquals(exp, result.get(0));
|
||||
SessionData exp2 = new SessionData(threshold * 5, threshold * 5 + 100);
|
||||
assertEquals(exp2, result.get(1));
|
||||
SessionData exp3 = new SessionData(threshold * 8, threshold * 10);
|
||||
assertEquals(exp3, result.get(2));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user