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() {
addValue("commandUniqueCount", String.valueOf(getUniqueCommands()));
addValue("commandCount", String.valueOf(getCommandTotal()));
String commandUsageTable = CommandUseTableCreator.createSortedCommandUseTable(commandUsage);
String commandUsageTable = CommandUseTableCreator.createTable(commandUsage);
addValue("tableBodyCommands", HtmlUtils.removeXSS(commandUsageTable));
}

View File

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

View File

@ -57,12 +57,13 @@ public class Version8TransferTable extends Table {
execute(dropTableSql("plan_sessions"));
db.getSessionsTable().createTable();
execute(dropTableSql("plan_worldtimes"));
execute(dropTableSql("plan_world_times"));
execute(dropTableSql("plan_worlds"));
db.getWorldTable().createTable();
db.getWorldTimesTable().createTable();
execute(dropTableSql("plan_gamemodetimes"));
execute(dropTableSql("plan_kills"));
db.getKillsTable().createTable();
execute(dropTableSql("plan_sessions"));
db.getSessionsTable().createTable();
db.setVersion(10);
Benchmark.stop("Schema copy from 8 to 10");
@ -71,32 +72,55 @@ public class Version8TransferTable extends Table {
private void copyUsers() throws SQLException, DBCreateTableException {
String tempTableName = "temp_users";
UsersTable usersTable = db.getUsersTable();
UserInfoTable userInfoTable = db.getUserInfoTable();
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();
killsTable.createTable();
UserInfoTable userInfoTable = db.getUserInfoTable();
userInfoTable.createTable();
String statement = "INSERT INTO plan_users " +
"(" +
"uuid, registered, name" +
"id, uuid, registered, name" +
") SELECT " +
"uuid, registered, name" +
"id, uuid, registered, name" +
" FROM " + tempTableName;
execute(statement);
statement = "(SELECT plan_users.id as a FROM plan_users JOIN temp_users on temp_users.uuid=plan_users.uuid" +
" WHERE plan_users.uuid=temp_users.uuid); INSERT INTO plan_user_info " +
statement = "INSERT INTO plan_user_info " +
"(" +
"user_id, registered, opped, banned, server_id" +
") SELECT " +
"a, registered, opped, banned, '" + serverID + "'" +
"id, registered, opped, banned, '" + serverID + "'" +
" FROM " + tempTableName;
execute(statement);
copyNicknames();
statement = "INSERT INTO plan_nicknames " +
"(" +
"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(tempNickTableName));
execute(dropTableSql(tempKillsTableName));
}
private void copyCommandUsage() throws SQLException, DBCreateTableException {
@ -118,26 +142,6 @@ public class Version8TransferTable extends Table {
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 {
String tempTableName = "temp_tps";
TPSTable tpsTable = db.getTpsTable();

View File

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

View File

@ -286,7 +286,7 @@ public class Analysis {
joinInfo.addActiveSessions(activeSessions);
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();
killPart.addKills(playerKills);

View File

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

View File

@ -22,7 +22,7 @@ public class ActionsTableCreator {
throw new IllegalStateException("Utility class");
}
public static String createTableContent(List<Action> actions) {
public static String createTable(List<Action> actions) {
StringBuilder html = new StringBuilder();
if (actions.isEmpty()) {
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
* @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);
StringBuilder html = new StringBuilder();

View File

@ -26,7 +26,7 @@ public class PlayersTableCreator {
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()) {
return Html.TABLELINE_PLAYERS.parse("<b>No Players</b>", "", "", "", "", "", "", "", "", "");
}
@ -74,7 +74,7 @@ public class PlayersTableCreator {
String.valueOf(playtime), FormatUtils.formatTimeAmount(playtime),
String.valueOf(loginTimes),
String.valueOf(registered), FormatUtils.formatTimeStampYear(registered),
String.valueOf(lastSeen), FormatUtils.formatTimeStamp(lastSeen),
String.valueOf(lastSeen), lastSeen != 0 ? FormatUtils.formatTimeStamp(lastSeen) : "-",
String.valueOf(geoLocation)
));
} 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.HtmlUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
/**
* //TODO Class Javadoc Comment
@ -23,7 +20,7 @@ import java.util.UUID;
*/
public class SessionsTableCreator {
public static String createTable(JoinInfoPart joinInfoPart) {
public static String[] createTables(JoinInfoPart joinInfoPart) {
Map<Integer, UUID> uuidByID = new HashMap<>();
for (Map.Entry<UUID, List<Session>> entry : joinInfoPart.getSessions().entrySet()) {
List<Session> sessions = entry.getValue();
@ -34,14 +31,17 @@ public class SessionsTableCreator {
List<Session> allSessions = joinInfoPart.getAllSessions();
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());
StringBuilder html = new StringBuilder();
StringBuilder sessionTableBuilder = new StringBuilder();
StringBuilder recentLoginsBuilder = new StringBuilder();
int i = 0;
Set<String> recentLoginsNames = new HashSet<>();
for (Session session : allSessions) {
if (i >= 50) {
break;
@ -54,15 +54,19 @@ public class SessionsTableCreator {
String length = session.getSessionEnd() != -1 ? FormatUtils.formatTimeAmount(session.getLength()) : "Online";
// getLongestWorldPlayed()
html.append(Html.TABLELINE_4.parse(
HtmlUtils.getRelativeInspectUrl(name)
String inspectUrl = 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++;
}
return html.toString();
return new String[]{sessionTableBuilder.toString(), recentLoginsBuilder.toString()};
}
}

View File

@ -71,7 +71,7 @@
<div class="box" style="margin-bottom: 5px;">
<div class="row">
<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>
${playersActive} Active Players<br>
${playersTotal} Total Players<br>
@ -106,7 +106,7 @@
<thead>
<tr>
<th>Player</th>
<th>Seen</th>
<th>Session Started</th>
</tr>
</thead>
<tbody>
@ -288,7 +288,7 @@
<th><i class="fa fa-user"></i> Player</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-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-calendar-check-o"></i> Last seen</th>
<th><i class="fa fa-globe"></i> Geolocation</th>