TPS table, fixes

Fixed #135
Added process info for db
New batch split method
Craftbukkit no longer needs a local install (added spigot repo)
This commit is contained in:
Rsl1122 2017-06-20 13:57:44 +03:00
parent 754d437fd9
commit 18a0d26fc5
23 changed files with 240 additions and 42 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>Plan</artifactId>
<version>3.4.3</version>
<version>3.5.0</version>
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<defaultGoal>clean package install</defaultGoal>
@ -98,11 +98,17 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -3,26 +3,33 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>Plan</artifactId>
<version>3.4.3</version>
<version>3.5.0</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- SoftDepended Plugins-->
<!-- Library for easier plugin development-->
<dependency>
<groupId>com.djrapitops</groupId>
<artifactId>BukkitPluginDependency</artifactId>
<version>1.1.0</version>
<scope>compile</scope>
</dependency>
<!-- SoftDepended Plugins-->
<dependency>
<groupId>com.djrapitops</groupId>
<artifactId>PlanPluginBridge</artifactId>
<version>3.4.3</version>
<version>3.5.0</version>
<scope>compile</scope>
</dependency>
<!-- -->

View File

@ -19,7 +19,7 @@
*/
package main.java.com.djrapitops.plan;
import com.djrapitops.javaplugin.ColorScheme;
import com.djrapitops.javaplugin.api.ColorScheme;
import com.djrapitops.javaplugin.RslPlugin;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslTask;
@ -93,7 +93,7 @@ public class Plan extends RslPlugin<Plan> {
variable = new ServerVariableHolder(server);
Log.debug("-------------------------------------");
Log.debug("Debug log: Plan v." + getDescription().getVersion());
Log.debug("Debug log: Plan v." + getVersion());
Log.debug("Implements RslPlugin v." + getRslVersion());
Log.debug("Server: " + server.getBukkitVersion());
Log.debug("Version: " + server.getVersion());

View File

@ -7,7 +7,7 @@ package main.java.com.djrapitops.plan.command;
/**
*
* @author Risto
* @author Rsl1122
*/
public class Condition {
final private String failMsg;

View File

@ -0,0 +1,36 @@
/*
* 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 main.java.com.djrapitops.plan.data;
/**
* Class containing single datapoint of TPS/players online.
*
* @author Rsl1122
* @since 3.5.0
*/
public class TPS {
private final long date;
private final double tps;
private final int players;
public TPS(long date, double tps, int players) {
this.date = date;
this.tps = tps;
this.players = players;
}
public long getDate() {
return date;
}
public double getTps() {
return tps;
}
public int getPlayers() {
return players;
}
}

View File

@ -10,7 +10,7 @@ import static org.bukkit.Bukkit.getPluginManager;
/**
* This class is responsible for static utility methods used for importing.
*
* @author Risto
* @author Rsl1122
* @since 3.2.0
*/
public class ImportUtils {

View File

@ -6,6 +6,7 @@
package main.java.com.djrapitops.plan.database;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -17,8 +18,28 @@ import java.util.Map.Entry;
*/
public class DBUtils {
public static <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
int batchSize = 2048;
private static final int BATCH_SIZE = 2048;
public static <T> List<List<T>> splitIntoBatches(Collection<T> objects) {
List<List<T>> batches = new ArrayList<>();
int i = 0;
int j = 0;
for (T obj : objects) {
if (batches.size() - 1 <= j) {
batches.add(new ArrayList<>());
}
batches.get(j).add(obj);
i++;
if (i % BATCH_SIZE == 0) {
j++;
}
}
return batches;
}
public static <T> List<List<Container<T>>> splitIntoBatchesId(Map<Integer, List<T>> objects) {
List<List<Container<T>>> wrappedBatches = new ArrayList<>();
int i = 0;
@ -30,8 +51,8 @@ public class DBUtils {
wrappedBatches.add(new ArrayList<>());
}
wrappedBatches.get(j).add(new Container<>(object, entry.getKey()));
i++;
if (i % batchSize == 0) {
i++;
if (i % BATCH_SIZE == 0) {
j++;
}
}

View File

@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.database.tables.KillsTable;
import main.java.com.djrapitops.plan.database.tables.LocationsTable;
import main.java.com.djrapitops.plan.database.tables.NicknamesTable;
import main.java.com.djrapitops.plan.database.tables.SessionsTable;
import main.java.com.djrapitops.plan.database.tables.TPSTable;
import main.java.com.djrapitops.plan.database.tables.UsersTable;
import main.java.com.djrapitops.plan.database.tables.VersionTable;
@ -70,6 +71,13 @@ public abstract class Database {
*/
protected CommandUseTable commandUseTable;
/**
* Table representing plan_tps in the database.
*
* @since 3.5.0
*/
protected TPSTable tpsTable;
/**
* Table representing plan_version in the database.
*/
@ -327,4 +335,8 @@ public abstract class Database {
public CommandUseTable getCommandUseTable() {
return commandUseTable;
}
public TPSTable getTpsTable() {
return tpsTable;
}
}

View File

@ -62,7 +62,7 @@ public class CommandUseTable extends Table {
statement = prepareStatement("SELECT * FROM " + tableName);
set = statement.executeQuery();
while (set.next()) {
String cmd = set.getString(columnCommand);
String cmd = set.getString(columnCommand).toLowerCase();
int amountUsed = set.getInt(columnTimesUsed);
Integer get = commandUse.get(cmd);
if (get != null && get > amountUsed) {
@ -157,11 +157,4 @@ public class CommandUseTable extends Table {
close(statement);
}
}
public void clean() throws SQLException {
Map<String, Integer> commandUse = getCommandUse();
removeAllData();
saveCommandUse(commandUse);
Plan.getInstance().getHandler().getCommandUseFromDb();
}
}

View File

@ -0,0 +1,118 @@
package main.java.com.djrapitops.plan.database.tables;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.data.TPS;
import main.java.com.djrapitops.plan.database.DBUtils;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
/**
* Class representing database table plan_tps
*
* @author Rsl1122
* @since 3.5.0
*/
public class TPSTable extends Table {
private final String columnDate;
private final String columnTPS;
private final String columnPlayers;
public TPSTable(SQLDB db, boolean usingMySQL) {
super("plan_tps", db, usingMySQL);
columnDate = "date";
columnTPS = "tps";
columnPlayers = "players_online";
}
@Override
public boolean createTable() {
try {
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnDate + " bigint NOT NULL, "
+ columnTPS + " double NOT NULL, "
+ columnPlayers + " integer NOT NULL"
+ ")"
);
return true;
} catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex);
return false;
}
}
public List<TPS> getTPSData() throws SQLException {
Benchmark.start("Get TPS");
List<TPS> data = new ArrayList<>();
PreparedStatement statement = null;
ResultSet set = null;
try {
statement = prepareStatement("SELECT * FROM " + tableName);
set = statement.executeQuery();
while (set.next()) {
long date = set.getLong(columnDate);
double tps = set.getDouble(columnTPS);
int players = set.getInt(columnPlayers);
data.add(new TPS(date, tps, players));
}
return data;
} finally {
close(set);
close(statement);
Benchmark.stop("Get TPS");
}
}
public void saveTPSData(List<TPS> data) throws SQLException {
List<List<TPS>> batches = DBUtils.splitIntoBatches(data);
for (List<TPS> batch : batches) {
saveTPSBatch(batch);
}
}
private void saveTPSBatch(List<TPS> batch) throws SQLException {
PreparedStatement statement = null;
try {
statement = prepareStatement("INSERT INTO " + tableName + " ("
+ columnDate + ", "
+ columnTPS + ", "
+ columnPlayers
+ ") VALUES (?, ?, ?)");
boolean commitRequired = false;
int i = 0;
for (TPS tps : batch) {
statement.setLong(1, tps.getDate());
statement.setDouble(2, tps.getTps());
statement.setInt(3, tps.getPlayers());
statement.addBatch();
commitRequired = true;
i++;
}
if (commitRequired) {
Log.debug("Executing tps batch: " + i);
statement.executeBatch();
}
} finally {
close(statement);
}
}
public void clean() throws SQLException {
PreparedStatement statement = null;
try {
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnDate + "<?)");
// More than 8 days ago.
statement.setLong(1, MiscUtils.getTime()-((691200) * 1000));
statement.execute();
} finally {
close(statement);
}
}
}

View File

@ -129,6 +129,6 @@ public abstract class Table {
}
protected <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
return DBUtils.splitIntoBatches(objects);
return DBUtils.splitIntoBatchesId(objects);
}
}

View File

@ -18,7 +18,7 @@ import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
/**
*
* @author Risto
* @author Rsl1122
*/
public class SessionLengthDistributionGraphCreator {

View File

@ -44,18 +44,20 @@ public class ExportUtility {
if (!Settings.ANALYSIS_EXPORT.isTrue()) {
return;
}
Benchmark.start("Exporting Html pages");
String processName = "Exporting Html pages";
plugin.processStatus().startExecution(processName);
try {
File folder = getFolder();
writeAnalysisHtml(analysisData, new File(folder, "server"));
File playersFolder = getPlayersFolder(folder);
plugin.processStatus().setStatus(processName, "Player html files.");
for (UserData userData : rawData) {
writeInspectHtml(userData, playersFolder);
}
} catch (IOException ex) {
Log.toLog("ExportUtils.export", ex);
} finally {
Benchmark.stop("Exporting Html pages");
plugin.processStatus().finishExecution(processName);
}
}

View File

@ -7,7 +7,7 @@ package main.java.com.djrapitops.plan.utilities.analysis.locations;
/**
*
* @author Risto
* @author Rsl1122
*/
public class Point {

View File

@ -14,7 +14,7 @@ import main.java.com.djrapitops.plan.database.Database;
/**
*
* @author Risto
* @author Rsl1122
*/
public class UUIDUtility {

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: main.java.com.djrapitops.plan.Plan
version: 3.4.3
version: 3.5.0
softdepend:
- OnTime

View File

@ -12,7 +12,7 @@ import test.java.utils.MockUtils;
/**
*
* @author Risto
* @author Rsl1122
*/
public class PermissionsTest {

View File

@ -11,7 +11,7 @@ import static org.junit.Assert.*;
/**
*
* @author Risto
* @author Rsl1122
*/
public class AnalysisTypeTest {

View File

@ -22,7 +22,7 @@ import test.java.utils.TestInit;
/**
*
* @author Risto
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class})

View File

@ -15,7 +15,7 @@ import org.junit.Test;
/**
*
* @author Risto
* @author Rsl1122
*/
public class MathUtilsTest {

View File

@ -5,7 +5,8 @@
*/
package test.java.utils;
import com.djrapitops.javaplugin.utilities.PluginLog;
import com.djrapitops.javaplugin.status.ProcessStatus;
import com.djrapitops.javaplugin.utilities.log.BukkitLog;
import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files;
@ -67,8 +68,10 @@ public class TestInit {
when(planMock.getLogger()).thenReturn(Logger.getGlobal());
ServerVariableHolder serverVariableHolder = new ServerVariableHolder(mockServer);
when(planMock.getVariable()).thenReturn(serverVariableHolder);
PluginLog<Plan> log = new PluginLog(planMock, "console", "");
BukkitLog<Plan> log = new BukkitLog(planMock, "console", "");
when(planMock.getPluginLogger()).thenReturn(log);
ProcessStatus<Plan> process = new ProcessStatus(planMock);
when(planMock.processStatus()).thenReturn(process);
Plan.setInstance(planMock);
// Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp();
Settings.DEBUG.setValue(true);

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>PlanPluginBridge</artifactId>
<version>3.4.3</version>
<version>3.5.0</version>
<packaging>jar</packaging>
<repositories>
<repository>
@ -15,7 +15,7 @@
<dependency>
<groupId>com.djrapitops</groupId>
<artifactId>Plan</artifactId>
<version>3.4.3</version>
<version>3.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -19,7 +19,7 @@ import main.java.com.djrapitops.plan.data.additional.HookHandler;
/**
*
* @author Risto
* @author Rsl1122
*/
public class Bridge {
public static void hook(HookHandler handler) {