VersionTransferTable now works for SQLite, fixed some Html issues.

This commit is contained in:
Rsl1122 2017-09-05 12:02:17 +03:00
parent 3386255627
commit 864f50df62
11 changed files with 70 additions and 57 deletions

View File

@ -36,7 +36,7 @@ public class CommandUsagePart extends RawData {
public void analyse() { public void analyse() {
addValue("commandUniqueCount", String.valueOf(getUniqueCommands())); addValue("commandUniqueCount", String.valueOf(getUniqueCommands()));
addValue("commandCount", String.valueOf(getCommandTotal())); addValue("commandCount", String.valueOf(getCommandTotal()));
String commandUsageTable = CommandUseTableCreator.createSortedCommandUseTable(commandUsage); String commandUsageTable = CommandUseTableCreator.createTable(commandUsage);
addValue("tableBodyCommands", HtmlUtils.removeXSS(commandUsageTable)); addValue("tableBodyCommands", HtmlUtils.removeXSS(commandUsageTable));
} }

View File

@ -62,7 +62,9 @@ public class JoinInfoPart extends RawData {
} }
private void sessionTables() { private void sessionTables() {
addValue("tableBodyRecentLogins", SessionsTableCreator.createTable(this)); String[] tables = SessionsTableCreator.createTables(this);
addValue("tableBodySessions", tables[0]);
addValue("tableBodyRecentLogins", tables[1]);
} }
private void uniquePlayers() { private void uniquePlayers() {

View File

@ -57,12 +57,13 @@ public class Version8TransferTable extends Table {
execute(dropTableSql("plan_sessions")); execute(dropTableSql("plan_sessions"));
db.getSessionsTable().createTable(); db.getSessionsTable().createTable();
execute(dropTableSql("plan_worldtimes")); execute(dropTableSql("plan_world_times"));
execute(dropTableSql("plan_worlds"));
db.getWorldTable().createTable();
db.getWorldTimesTable().createTable(); db.getWorldTimesTable().createTable();
execute(dropTableSql("plan_gamemodetimes")); execute(dropTableSql("plan_gamemodetimes"));
execute(dropTableSql("plan_sessions"));
execute(dropTableSql("plan_kills")); db.getSessionsTable().createTable();
db.getKillsTable().createTable();
db.setVersion(10); db.setVersion(10);
Benchmark.stop("Schema copy from 8 to 10"); Benchmark.stop("Schema copy from 8 to 10");
@ -71,32 +72,55 @@ public class Version8TransferTable extends Table {
private void copyUsers() throws SQLException, DBCreateTableException { private void copyUsers() throws SQLException, DBCreateTableException {
String tempTableName = "temp_users"; String tempTableName = "temp_users";
UsersTable usersTable = db.getUsersTable(); UsersTable usersTable = db.getUsersTable();
UserInfoTable userInfoTable = db.getUserInfoTable();
execute(tableRenameSql("plan_users", tempTableName)); execute(tableRenameSql("plan_users", tempTableName));
String tempNickTableName = "temp_nicks";
NicknamesTable nicknamesTable = db.getNicknamesTable();
execute(tableRenameSql(nicknamesTable.toString(), tempNickTableName));
String tempKillsTableName = "temp_kills";
KillsTable killsTable = db.getKillsTable();
execute(tableRenameSql(killsTable.toString(), tempKillsTableName));
nicknamesTable.createTable();
usersTable.createTable(); usersTable.createTable();
killsTable.createTable();
UserInfoTable userInfoTable = db.getUserInfoTable();
userInfoTable.createTable(); userInfoTable.createTable();
String statement = "INSERT INTO plan_users " + String statement = "INSERT INTO plan_users " +
"(" + "(" +
"uuid, registered, name" + "id, uuid, registered, name" +
") SELECT " + ") SELECT " +
"uuid, registered, name" + "id, uuid, registered, name" +
" FROM " + tempTableName; " FROM " + tempTableName;
execute(statement); execute(statement);
statement = "(SELECT plan_users.id as a FROM plan_users JOIN temp_users on temp_users.uuid=plan_users.uuid" + statement = "INSERT INTO plan_user_info " +
" WHERE plan_users.uuid=temp_users.uuid); INSERT INTO plan_user_info " +
"(" + "(" +
"user_id, registered, opped, banned, server_id" + "user_id, registered, opped, banned, server_id" +
") SELECT " + ") SELECT " +
"a, registered, opped, banned, '" + serverID + "'" + "id, registered, opped, banned, '" + serverID + "'" +
" FROM " + tempTableName; " FROM " + tempTableName;
execute(statement); execute(statement);
statement = "INSERT INTO plan_nicknames " +
copyNicknames(); "(" +
"user_id, nickname, server_id" +
") SELECT " +
"user_id, nickname, '" + serverID + "'" +
" FROM " + tempNickTableName;
execute(statement);
statement = "INSERT INTO plan_kills " +
"(" +
"killer_id, victim_id, weapon, date, session_id" +
") SELECT " +
"killer_id, victim_id, weapon, date, '0'" +
" FROM " + tempKillsTableName;
execute(statement);
execute(dropTableSql(tempTableName)); execute(dropTableSql(tempTableName));
execute(dropTableSql(tempNickTableName));
execute(dropTableSql(tempKillsTableName));
} }
private void copyCommandUsage() throws SQLException, DBCreateTableException { private void copyCommandUsage() throws SQLException, DBCreateTableException {
@ -118,26 +142,6 @@ public class Version8TransferTable extends Table {
execute(dropTableSql(tempTableName)); execute(dropTableSql(tempTableName));
} }
private void copyNicknames() throws SQLException, DBCreateTableException {
String tempTableName = "temp_nicks";
NicknamesTable nicknamesTable = db.getNicknamesTable();
execute(tableRenameSql(nicknamesTable.toString(), tempTableName));
nicknamesTable.createTable();
// TODO ID Of user
String statement = "INSERT INTO plan_nicknames " +
"(" +
"user_id, nickname" +
") SELECT " +
"(SELECT plan_users.id FROM plan_users JOIN temp_users on temp_users.uuid=plan_users.uuid" +
" WHERE plan_users.uuid=temp_users.uuid), " +
"nickname" +
" FROM " + tempTableName;
execute(statement);
}
private void copyTPS() throws SQLException, DBCreateTableException { private void copyTPS() throws SQLException, DBCreateTableException {
String tempTableName = "temp_tps"; String tempTableName = "temp_tps";
TPSTable tpsTable = db.getTpsTable(); TPSTable tpsTable = db.getTpsTable();

View File

@ -126,7 +126,7 @@ public class InspectPageParser extends PageParser {
.collect(Collectors.toList())); .collect(Collectors.toList()));
actions.sort(new ActionComparator()); actions.sort(new ActionComparator());
addValue("tableBodyActions", ActionsTableCreator.createTableContent(actions)); addValue("tableBodyActions", ActionsTableCreator.createTable(actions));
Benchmark.stop("Inspect Parse, Fetch"); Benchmark.stop("Inspect Parse, Fetch");

View File

@ -286,7 +286,7 @@ public class Analysis {
joinInfo.addActiveSessions(activeSessions); joinInfo.addActiveSessions(activeSessions);
joinInfo.addSessions(sessions); joinInfo.addSessions(sessions);
analysisData.setPlayersTable(PlayersTableCreator.createSortablePlayersTable(userInfo, joinInfo, geolocPart)); analysisData.setPlayersTable(PlayersTableCreator.createTable(userInfo, joinInfo, geolocPart));
Map<UUID, List<PlayerKill>> playerKills = db.getKillsTable().getPlayerKills(); Map<UUID, List<PlayerKill>> playerKills = db.getKillsTable().getPlayerKills();
killPart.addKills(playerKills); killPart.addKills(playerKills);

View File

@ -51,6 +51,9 @@ public class WorldPieCreator {
int i = 0; int i = 0;
Map<String, GMTimes> gmTimesMap = worldTimes.getWorldTimes(); Map<String, GMTimes> gmTimesMap = worldTimes.getWorldTimes();
if (gmTimesMap.isEmpty()) {
return "{[]}";
}
int size = gmTimesMap.size(); int size = gmTimesMap.size();
for (Map.Entry<String, GMTimes> world : gmTimesMap.entrySet()) { for (Map.Entry<String, GMTimes> world : gmTimesMap.entrySet()) {
drilldownBuilder.append("{name:'").append(world.getKey()) drilldownBuilder.append("{name:'").append(world.getKey())

View File

@ -22,7 +22,7 @@ public class ActionsTableCreator {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
public static String createTableContent(List<Action> actions) { public static String createTable(List<Action> actions) {
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
if (actions.isEmpty()) { if (actions.isEmpty()) {
html.append(Html.TABLELINE_3.parse("", "", "")); html.append(Html.TABLELINE_3.parse("", "", ""));

View File

@ -24,7 +24,7 @@ public class CommandUseTableCreator {
* @param commandUse The commands and the amount of times casted * @param commandUse The commands and the amount of times casted
* @return The created command use table * @return The created command use table
*/ */
public static String createSortedCommandUseTable(Map<String, Integer> commandUse) { public static String createTable(Map<String, Integer> commandUse) {
List<String[]> sorted = MapComparator.sortByValue(commandUse); List<String[]> sorted = MapComparator.sortByValue(commandUse);
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();

View File

@ -26,7 +26,7 @@ public class PlayersTableCreator {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
public static String createSortablePlayersTable(List<UserInfo> userInfo, JoinInfoPart joinInfoPart, GeolocationPart geolocationPart) { public static String createTable(List<UserInfo> userInfo, JoinInfoPart joinInfoPart, GeolocationPart geolocationPart) {
if (userInfo.isEmpty()) { if (userInfo.isEmpty()) {
return Html.TABLELINE_PLAYERS.parse("<b>No Players</b>", "", "", "", "", "", "", "", "", ""); return Html.TABLELINE_PLAYERS.parse("<b>No Players</b>", "", "", "", "", "", "", "", "", "");
} }
@ -74,7 +74,7 @@ public class PlayersTableCreator {
String.valueOf(playtime), FormatUtils.formatTimeAmount(playtime), String.valueOf(playtime), FormatUtils.formatTimeAmount(playtime),
String.valueOf(loginTimes), String.valueOf(loginTimes),
String.valueOf(registered), FormatUtils.formatTimeStampYear(registered), String.valueOf(registered), FormatUtils.formatTimeStampYear(registered),
String.valueOf(lastSeen), FormatUtils.formatTimeStamp(lastSeen), String.valueOf(lastSeen), lastSeen != 0 ? FormatUtils.formatTimeStamp(lastSeen) : "-",
String.valueOf(geoLocation) String.valueOf(geoLocation)
)); ));
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) {

View File

@ -11,10 +11,7 @@ import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparato
import main.java.com.djrapitops.plan.utilities.html.Html; import main.java.com.djrapitops.plan.utilities.html.Html;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* //TODO Class Javadoc Comment * //TODO Class Javadoc Comment
@ -23,7 +20,7 @@ import java.util.UUID;
*/ */
public class SessionsTableCreator { public class SessionsTableCreator {
public static String createTable(JoinInfoPart joinInfoPart) { public static String[] createTables(JoinInfoPart joinInfoPart) {
Map<Integer, UUID> uuidByID = new HashMap<>(); Map<Integer, UUID> uuidByID = new HashMap<>();
for (Map.Entry<UUID, List<Session>> entry : joinInfoPart.getSessions().entrySet()) { for (Map.Entry<UUID, List<Session>> entry : joinInfoPart.getSessions().entrySet()) {
List<Session> sessions = entry.getValue(); List<Session> sessions = entry.getValue();
@ -34,14 +31,17 @@ public class SessionsTableCreator {
List<Session> allSessions = joinInfoPart.getAllSessions(); List<Session> allSessions = joinInfoPart.getAllSessions();
if (allSessions.isEmpty()) { if (allSessions.isEmpty()) {
return Html.TABLELINE_4.parse("<b>No Sessions</b>", "", "", ""); return new String[]{Html.TABLELINE_4.parse("<b>No Sessions</b>", "", "", ""),
Html.TABLELINE_2.parse("<b>No Sessions</b>", "")};
} }
allSessions.sort(new SessionStartComparator()); allSessions.sort(new SessionStartComparator());
StringBuilder html = new StringBuilder(); StringBuilder sessionTableBuilder = new StringBuilder();
StringBuilder recentLoginsBuilder = new StringBuilder();
int i = 0; int i = 0;
Set<String> recentLoginsNames = new HashSet<>();
for (Session session : allSessions) { for (Session session : allSessions) {
if (i >= 50) { if (i >= 50) {
break; break;
@ -54,15 +54,19 @@ public class SessionsTableCreator {
String length = session.getSessionEnd() != -1 ? FormatUtils.formatTimeAmount(session.getLength()) : "Online"; String length = session.getSessionEnd() != -1 ? FormatUtils.formatTimeAmount(session.getLength()) : "Online";
// getLongestWorldPlayed() // getLongestWorldPlayed()
html.append(Html.TABLELINE_4.parse( String inspectUrl = HtmlUtils.getRelativeInspectUrl(name);
HtmlUtils.getRelativeInspectUrl(name) sessionTableBuilder.append(Html.TABLELINE_4.parse(
inspectUrl
)); ));
if (recentLoginsNames.size() < 20 && !recentLoginsNames.contains(name)) {
recentLoginsBuilder.append(Html.TABLELINE_2.parse(inspectUrl, start));
recentLoginsNames.add(name);
}
i++; i++;
} }
return new String[]{sessionTableBuilder.toString(), recentLoginsBuilder.toString()};
return html.toString();
} }
} }

View File

@ -71,7 +71,7 @@
<div class="box" style="margin-bottom: 5px;"> <div class="box" style="margin-bottom: 5px;">
<div class="row"> <div class="row">
<div class="column"> <div class="column">
<p>${playersOnline}/${playersMax} Players Online<br>43 New Players Today<br> <p>${playersOnline}/${playersMax} Players Online<br>${playersNewDay} New Players Today<br>
<br> <br>
${playersActive} Active Players<br> ${playersActive} Active Players<br>
${playersTotal} Total Players<br> ${playersTotal} Total Players<br>
@ -106,7 +106,7 @@
<thead> <thead>
<tr> <tr>
<th>Player</th> <th>Player</th>
<th>Seen</th> <th>Session Started</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -288,7 +288,7 @@
<th><i class="fa fa-user"></i> Player</th> <th><i class="fa fa-user"></i> Player</th>
<th><i class="fa fa-check"></i> Active</th> <th><i class="fa fa-check"></i> Active</th>
<th><i class="fa fa-clock-o"></i> Playtime</th> <th><i class="fa fa-clock-o"></i> Playtime</th>
<th><i class="fa fa-calendar-plus-o"></i> Login times</th> <th><i class="fa fa-calendar-plus-o"></i> Sessions</th>
<th><i class="fa fa-user-plus"></i> Registered</th> <th><i class="fa fa-user-plus"></i> Registered</th>
<th><i class="fa fa-calendar-check-o"></i> Last seen</th> <th><i class="fa fa-calendar-check-o"></i> Last seen</th>
<th><i class="fa fa-globe"></i> Geolocation</th> <th><i class="fa fa-globe"></i> Geolocation</th>