This commit is contained in:
Rsl1122 2017-10-02 16:33:25 +03:00
parent 394cd4474e
commit 66f879278b
8 changed files with 59 additions and 11 deletions

View File

@ -154,6 +154,7 @@ public class API {
* Check if the data is cached to AnalysisCache before calling this.
*
* @return server.html with all placeholders replaced.
* @throws NullPointerException if AnalysisData has not been cached.
*/
public String getAnalysisHtmlAsString() {
return plugin.getInfoManager().getAnalysisHtml();

View File

@ -144,7 +144,7 @@ public class ActivityPart extends RawData {
}
public Map<Long, Integer> getPlayersOnline() {
return tpsPart.getTpsData().stream().collect(Collectors.toMap(TPS::getDate, TPS::getPlayers));
return tpsPart.getTpsData().stream().distinct().collect(Collectors.toMap(TPS::getDate, TPS::getPlayers));
}
public List<String> getRecentPlayers() {

View File

@ -173,6 +173,9 @@ public class BukkitInformationManager extends InformationManager {
@Override
public boolean isAnalysisCached(UUID serverUUID) {
if (Plan.getServerUUID().equals(serverUUID)) {
return analysisData != null;
}
if (usingAnotherWebServer) {
try {
return getWebAPI().getAPI(IsCachedWebAPI.class).isAnalysisCached(webServerAddress, serverUUID);
@ -188,8 +191,17 @@ public class BukkitInformationManager extends InformationManager {
return plugin.getWebServer().getWebAPI();
}
/**
* Get the HTML for analysis page of this server.
*
* @return Html for Analysis page
* @throws NullPointerException if AnalysisData has not been cached.
*/
@Override
public String getAnalysisHtml() {
if (analysisData == null) {
throw new NullPointerException("Analysis Data has not been cached.");
}
try {
return Theme.replaceColors(new AnalysisPageParser(analysisData, plugin).parse());
} catch (ParseException e) {
@ -229,6 +241,10 @@ public class BukkitInformationManager extends InformationManager {
}
private void cacheAnalysisHtml() {
cacheAnalysisHtml(getAnalysisHtml());
}
public void cacheAnalysisHtml(String html) {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostHtmlWebAPI.class).sendAnalysisHtml(webServerAddress, getAnalysisHtml());
@ -237,7 +253,7 @@ public class BukkitInformationManager extends InformationManager {
cacheAnalysisHtml();
}
} else {
PageCache.cachePage("analysisPage:" + Plan.getServerUUID(), () -> new AnalysisPageResponse(this));
PageCache.cachePage("analysisPage:" + Plan.getServerUUID(), () -> new AnalysisPageResponse(html));
}
}

View File

@ -191,11 +191,6 @@ public class ResponseHandler extends APIResponseHandler {
}
private Response serverResponse(UUID serverUUID) {
if (!plugin.getInfoManager().isAnalysisCached(serverUUID)) {
String error = "Analysis Data was not cached.<br>Use /plan analyze to cache the Data.";
PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
}
return PageCache.loadPage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(plugin.getInfoManager()));
}

View File

@ -1,7 +1,10 @@
package main.java.com.djrapitops.plan.systems.webserver.response;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
/**
* @author Rsl1122
@ -9,13 +12,37 @@ import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
*/
public class AnalysisPageResponse extends Response {
/**
* @param informationManager
* @throws NullPointerException if AnalysisData has not been cached after 1 second.
*/
public AnalysisPageResponse(InformationManager informationManager) {
super.setHeader("HTTP/1.1 200 OK");
if (informationManager instanceof BukkitInformationManager) {
AnalysisData analysisData = ((BukkitInformationManager) informationManager).getAnalysisData();
if (analysisData == null) {
Plan.getInstance().getRunnableFactory().createNew("OnRequestAnalysisRefreshTask", new AbsRunnable() {
@Override
public void run() {
informationManager.refreshAnalysis(Plan.getServerUUID());
}
}).runTaskAsynchronously();
ErrorResponse analysisRefreshPage = new ErrorResponse();
analysisRefreshPage.setTitle("Analysis is being refreshed..");
analysisRefreshPage.setParagraph("<i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
analysisRefreshPage.replacePlaceholders();
super.setContent(analysisRefreshPage.getContent());
return;
}
}
super.setContent(informationManager.getAnalysisHtml());
}
public AnalysisPageResponse(String html) {
super.setHeader("HTTP/1.1 200 OK");
super.setContent(Theme.replaceColors(html));
super.setContent(html);
}
}

View File

@ -32,7 +32,7 @@ public class ErrorResponse extends Response {
}
}
protected void replacePlaceholders() {
public void replacePlaceholders() {
Map<String, String> placeHolders = new HashMap<>();
placeHolders.put("title", title);
placeHolders.put("paragraph", paragraph);

View File

@ -17,6 +17,8 @@ import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.response.ErrorResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.comparators.UserInfoLastPlayedComparator;
@ -63,6 +65,11 @@ public class Analysis {
plugin.getRunnableFactory().createNew(new AbsRunnable("AnalysisTask") {
@Override
public void run() {
ErrorResponse analysisRefreshPage = new ErrorResponse();
analysisRefreshPage.setTitle("Analysis is being refreshed..");
analysisRefreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"25\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
analysisRefreshPage.replacePlaceholders();
((BukkitInformationManager) plugin.getInfoManager()).cacheAnalysisHtml(analysisRefreshPage.getContent());
taskId = this.getTaskId();
analyze(infoManager, plugin.getDB());
taskId = -1;
@ -127,6 +134,7 @@ public class Analysis {
// ExportUtility.export(analysisData, rawData);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
((BukkitInformationManager) plugin.getInfoManager()).cacheAnalysisHtml(new InternalErrorResponse(e, "Analysis").getContent());
Log.debug("Analysis", "Error: " + e);
Log.logDebug("Analysis");
return false;
@ -238,7 +246,7 @@ public class Analysis {
tpsPart.addTpsData(tpsData);
Log.debug("Analysis", "TPS Data Size: " + tpsData.size());
List<UserInfo> userInfo = db.getUserInfoTable().getServerUserInfo();
List<UserInfo> userInfo = db.getUserInfoTable().getServerUserInfo().stream().distinct().collect(Collectors.toList());
for (UserInfo user : userInfo) {
if (user.isBanned()) {

View File

@ -21,6 +21,7 @@ public class WorldPieCreator {
public static String[] createSeriesData(WorldTimes worldTimes) {
StringBuilder seriesBuilder = new StringBuilder("[");
int i = 0;
// WorldTimes Map<String, GMTimes> (GMTimes.getTotal)
Map<String, Long> playtimePerWorld = worldTimes.getWorldTimes().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getTotal()));