mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
Inspect Requests Handled correctly, begun work on analysis
Added player.html template. Added analysis.html template
This commit is contained in:
parent
7fa2254dd2
commit
15078df7d3
40
Plan Advanced/src/analysis.html
Normal file
40
Plan Advanced/src/analysis.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>Plan | Server Analysis</title>
|
||||
<meta name="description" content="Server Analysis Window">
|
||||
<meta name="author" content="Rsl1122">
|
||||
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="line-height: 55%; font-family: Verdana, Geneva, sans-serif;">
|
||||
<h1 style="text-decoration: underline;">Plan | Server Analysis</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<td style="margin-left: 3px; margin-right: auto;
|
||||
border-style: groove; border-width: 3px; border-radius: 12px;
|
||||
box-shadow: 5px 5px 4px 0px #888888;">
|
||||
<p>%activitygraph%</p>
|
||||
</td>
|
||||
<td style="margin-left: 3px; margin-right: auto;
|
||||
border-style: groove; border-width: 3px; border-radius: 12px;
|
||||
box-shadow: 5px 5px 4px 0px #888888;">
|
||||
<p>%activitypiegraph%</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="margin-left: 3px; margin-right: auto;
|
||||
border-style: groove; border-width: 3px; border-radius: 12px;
|
||||
box-shadow: 5px 5px 4px 0px #888888;">
|
||||
<p>Averages</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
11
Plan Advanced/src/com/djrapitops/plan/data/AnalysisData.java
Normal file
11
Plan Advanced/src/com/djrapitops/plan/data/AnalysisData.java
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
package com.djrapitops.plan.data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AnalysisData {
|
||||
private long averagePlayTime;
|
||||
|
||||
}
|
@ -35,6 +35,8 @@ public class UserData {
|
||||
private boolean isOp;
|
||||
private boolean isBanned;
|
||||
private DemographicsData demData;
|
||||
|
||||
private String name;
|
||||
|
||||
public UserData(Player player, DemographicsData demData, Database db) {
|
||||
uuid = player.getUniqueId();
|
||||
@ -57,6 +59,7 @@ public class UserData {
|
||||
lastGamemode = player.getGameMode();
|
||||
this.demData = demData;
|
||||
isBanned = player.isBanned();
|
||||
name = player.getName();
|
||||
}
|
||||
|
||||
public UserData(OfflinePlayer player, DemographicsData demData, Database db) {
|
||||
@ -78,6 +81,7 @@ public class UserData {
|
||||
gmTimes.put(GameMode.SPECTATOR, zero);
|
||||
this.demData = demData;
|
||||
isBanned = player.isBanned();
|
||||
name = player.getName();
|
||||
}
|
||||
|
||||
public void addIpAddress(InetAddress ip) {
|
||||
@ -210,6 +214,10 @@ public class UserData {
|
||||
return demData;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// Setters -------------------------------------------------------------
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
@ -274,4 +282,8 @@ public class UserData {
|
||||
public void setDemData(DemographicsData demData) {
|
||||
this.demData = demData;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -31,7 +34,35 @@ public class DataRequestHandler {
|
||||
if (data == null) {
|
||||
return "<h1>404 Data was not found in cache</h1>";
|
||||
}
|
||||
return "Test Successful";
|
||||
Scanner scanner = new Scanner(plugin.getResource("player.html"));
|
||||
String html = "";
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
html += line + "\r\n";
|
||||
}
|
||||
HashMap<String, String> replaceMap = new HashMap<>();
|
||||
replaceMap.put("%uuid%", ""+data.getUuid());
|
||||
replaceMap.put("%logintimes%", ""+data.getLoginTimes());
|
||||
replaceMap.put("%bed%", FormatUtils.formatLocation(data.getBedLocation()));
|
||||
replaceMap.put("%geoloc%", data.getDemData().getGeoLocation());
|
||||
int age = data.getDemData().getAge();
|
||||
replaceMap.put("%age%", (age != -1) ? ""+age:"Not known");
|
||||
replaceMap.put("%gender%", ""+data.getDemData().getGender().name().toLowerCase());
|
||||
replaceMap.put("%gmpiechart%", "Piechart soon");
|
||||
replaceMap.put("%ips%", data.getIps().toString());
|
||||
replaceMap.put("%nicknames%", data.getNicknames().toString());
|
||||
replaceMap.put("%name%", data.getName());
|
||||
replaceMap.put("%registered%", FormatUtils.formatTimeStamp(""+data.getRegistered()));
|
||||
replaceMap.put("%timeskicked%", ""+data.getTimesKicked());
|
||||
replaceMap.put("%playtime%", FormatUtils.formatTimeAmount(""+data.getPlayTime()));
|
||||
replaceMap.put("%banned%", data.isBanned() ? "Banned":"Not Banned");
|
||||
replaceMap.put("%op%", data.isOp() ? ", Operator (Op)":"");
|
||||
|
||||
for (String key : replaceMap.keySet()) {
|
||||
html = html.replaceAll(key, replaceMap.get(key));
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
public String getAnalysisHtml() {
|
||||
|
@ -58,11 +58,11 @@ public class Response {
|
||||
}
|
||||
if (handler.checkIfCached(uuid)) {
|
||||
String dataHtml = handler.getDataHtml(uuid);
|
||||
String htmlDef = "HTTP/1.1 Analysis\r\n"
|
||||
String htmlDef = "HTTP/1.1 Inspect\r\n"
|
||||
+ "Content-Type: text/html\r\n"
|
||||
+ "Content-Length: " + dataHtml.length() + "\r\n"
|
||||
+ "\r\n";
|
||||
output.write((htmlDef + dataHtml).getBytes());
|
||||
output.write((htmlDef+dataHtml).getBytes());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,68 @@
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.AnalysisData;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class Analysis {
|
||||
|
||||
private Plan plugin;
|
||||
private AnalysisData data;
|
||||
private InspectCacheHandler inspectCache;
|
||||
private final List<UserData> rawData;
|
||||
private final List<UUID> added;
|
||||
|
||||
public Analysis(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
this.inspectCache = plugin.getInspectCache();
|
||||
rawData = new ArrayList<>();
|
||||
added = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void analyze() {
|
||||
rawData.clear();
|
||||
added.clear();
|
||||
plugin.log("Analysis | Beginning analysis of user data..");
|
||||
OfflinePlayer[] offlinePlayers = Bukkit.getServer().getOfflinePlayers();
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
for (OfflinePlayer p : offlinePlayers) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if (plugin.getDB().wasSeenBefore(uuid)) {
|
||||
uuids.add(uuid);
|
||||
}
|
||||
}
|
||||
(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
uuids.stream().forEach((uuid) -> {
|
||||
inspectCache.cache(uuid);
|
||||
});
|
||||
plugin.log("Analysis | Fetching Data..");
|
||||
while (rawData.size() != uuids.size()) {
|
||||
try {
|
||||
this.wait(1);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
uuids.stream()
|
||||
.filter((uuid) -> (!added.contains(uuid)))
|
||||
.forEach((uuid) -> {
|
||||
UserData userData = inspectCache.getFromCache(uuid);
|
||||
if (userData != null) {
|
||||
rawData.add(userData);
|
||||
added.add(uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
plugin.log("Analysis | Data Fetched, beginning Analysis of data..");
|
||||
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AnalysisUtils {
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ package com.djrapitops.plan.utilities;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -118,5 +119,9 @@ public class FormatUtils {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String formatLocation(Location loc) {
|
||||
return "x "+loc.getBlockX()+" z " + loc.getBlockZ() +" in "+loc.getWorld();
|
||||
}
|
||||
|
||||
}
|
||||
|
41
Plan Advanced/src/player.html
Normal file
41
Plan Advanced/src/player.html
Normal file
@ -0,0 +1,41 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>Plan | Inspect %name%</title>
|
||||
<meta name="description" content="Player inspect window">
|
||||
<meta name="author" content="Rsl1122">
|
||||
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="line-height: 55%; font-family: Verdana, Geneva, sans-serif;">
|
||||
<h1 style="text-decoration: underline;">Plan | Inspect Player %name%</h1>
|
||||
<h4>UUID: %uuid%</h4>
|
||||
<h4>Registered: %registered% - %banned%%op%</h4>
|
||||
<table>
|
||||
<tr>
|
||||
<td style="margin-left: 3px; margin-right: auto;
|
||||
border-style: groove; border-width: 3px; border-radius: 12px;
|
||||
box-shadow: 5px 5px 4px 0px #888888;">
|
||||
<p>Nicknames: %nicknames% | Has connected from ips: %ips%</p>
|
||||
<p>Geolocation: %geoloc%</p>
|
||||
<p>Playtime: %playtime%</p>
|
||||
<p>Has logged in %logintimes% times.</p>
|
||||
<p>Age: %age% | Gender: %gender%</p>
|
||||
</td>
|
||||
<td style="margin-left: 3px; margin-right: auto;
|
||||
border-style: groove; border-width: 3px; border-radius: 12px;
|
||||
box-shadow: 5px 5px 4px 0px #888888;">
|
||||
<p>%gmpiechart%</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user