Merge pull request #206 from Fuzzlemann/master

PR for 3.6.0 (Fuzzlemann) (5)
This commit is contained in:
Rsl1122 2017-07-29 23:52:12 +03:00 committed by GitHub
commit aacbdc2d53
6 changed files with 31 additions and 69 deletions

View File

@ -115,7 +115,7 @@ public enum Html {
* @param localeFile * @param localeFile
*/ */
public static void loadLocale(File localeFile) { public static void loadLocale(File localeFile) {
try (Scanner localeScanner = new Scanner(localeFile, "UTF-8")){ try (Scanner localeScanner = new Scanner(localeFile, "UTF-8")) {
List<String> localeRows = new ArrayList<>(); List<String> localeRows = new ArrayList<>();
boolean html = false; boolean html = false;
@ -132,6 +132,7 @@ public enum Html {
localeRows.add(line); localeRows.add(line);
} }
for (String localeRow : localeRows) { for (String localeRow : localeRows) {
try { try {
String[] split = localeRow.split(" <> "); String[] split = localeRow.split(" <> ");

View File

@ -24,15 +24,18 @@ public class RecentPlayersButtonsCreator {
* @return html p-tag list of recent log-ins. * @return html p-tag list of recent log-ins.
*/ */
public static String createRecentLoginsButtons(List<String> names, int limit) { public static String createRecentLoginsButtons(List<String> names, int limit) {
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder("<p>");
html.append("<p>");
for (int i = 0; i < names.size(); i++) { int i = 0;
if (i < limit) { for (String name : names) {
String name = names.get(i); if (i >= limit) {
html.append(Html.BUTTON.parse(HtmlUtils.getRelativeInspectUrl(name), name)); break;
html.append(" ");
} }
html.append(Html.BUTTON.parse(HtmlUtils.getRelativeInspectUrl(name), name)).append(" ");
i++;
} }
html.append("</p>"); html.append("</p>");
return html.toString(); return html.toString();
} }

View File

@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -43,8 +44,7 @@ public class PunchCardGraphCreator {
} }
private static StringBuilder buildString(int[][] scaled) { private static StringBuilder buildString(int[][] scaled) {
StringBuilder arrayBuilder = new StringBuilder(); StringBuilder arrayBuilder = new StringBuilder("[");
arrayBuilder.append("[");
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
for (int j = 0; j < 24; j++) { for (int j = 0; j < 24; j++) {
int value = scaled[i][j]; int value = scaled[i][j];
@ -68,6 +68,7 @@ public class PunchCardGraphCreator {
int h = dAndH[1]; int h = dAndH[1];
dataArray[d][h] = dataArray[d][h] + 1; dataArray[d][h] = dataArray[d][h] + 1;
} }
if (Settings.ANALYSIS_REMOVE_OUTLIERS.isTrue()) { if (Settings.ANALYSIS_REMOVE_OUTLIERS.isTrue()) {
int avg = findAverage(dataArray); int avg = findAverage(dataArray);
double standardDeviation = getStandardDeviation(dataArray, avg); double standardDeviation = getStandardDeviation(dataArray, avg);
@ -93,8 +94,8 @@ public class PunchCardGraphCreator {
} }
} }
int size = array.length * array[0].length; double size = array.length * array[0].length;
int sum = sum(valueMinusAvg); double sum = sum(valueMinusAvg);
return Math.sqrt(sum / size); return Math.sqrt(sum / size);
} }
@ -105,13 +106,7 @@ public class PunchCardGraphCreator {
} }
private static int sum(int[][] array) { private static int sum(int[][] array) {
int total = 0; return Arrays.stream(array).mapToInt(is -> is.length).sum();
for (int[] is : array) {
for (int i : is) {
total += i;
}
}
return total;
} }
private static List<Long> getSessionStarts(Collection<SessionData> data) { private static List<Long> getSessionStarts(Collection<SessionData> data) {

View File

@ -11,7 +11,6 @@ import main.java.com.djrapitops.plan.database.tables.SecurityTable;
import main.java.com.djrapitops.plan.ui.html.DataRequestHandler; import main.java.com.djrapitops.plan.ui.html.DataRequestHandler;
import main.java.com.djrapitops.plan.ui.webserver.response.*; import main.java.com.djrapitops.plan.ui.webserver.response.*;
import main.java.com.djrapitops.plan.utilities.HtmlUtils; import main.java.com.djrapitops.plan.utilities.HtmlUtils;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil; import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility; import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -26,7 +25,9 @@ import java.security.cert.CertificateException;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Executors; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* @author Rsl1122 * @author Rsl1122
@ -75,7 +76,6 @@ public class WebServer {
server.createContext("/", new HttpHandler() { server.createContext("/", new HttpHandler() {
@Override @Override
public void handle(HttpExchange exchange) throws IOException { public void handle(HttpExchange exchange) throws IOException {
OutputStream os = null;
try { try {
URI uri = exchange.getRequestURI(); URI uri = exchange.getRequestURI();
String target = uri.toString(); String target = uri.toString();
@ -94,26 +94,25 @@ public class WebServer {
Response response = getResponse(target, user); Response response = getResponse(target, user);
String content = response.getContent(); String content = response.getContent();
exchange.sendResponseHeaders(response.getCode(), content.length()); exchange.sendResponseHeaders(200, 0);
try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody())) {
try (ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) { try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody());
byte[] buffer = new byte[2048]; ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
int count; byte[] buffer = new byte[2048];
while ((count = bis.read(buffer)) != -1) { int count;
out.write(buffer, 0, count); while ((count = bis.read(buffer)) != -1) {
} out.write(buffer, 0, count);
} }
} }
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
throw e; throw e;
} finally { } finally {
MiscUtils.close(os);
exchange.close(); exchange.close();
} }
} }
}); });
server.setExecutor(Executors.newSingleThreadExecutor()); server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
server.start(); server.start();
enabled = true; enabled = true;

View File

@ -168,7 +168,7 @@ public class AnalysisUtils {
.map(value -> (boolean) value) .map(value -> (boolean) value)
.collect(Collectors.toList()); .collect(Collectors.toList());
long count = tempList.stream().filter(value -> value).count(); long count = tempList.stream().filter(value -> value).count();
return source.parseContainer(analysisType.getModifier(), ((double) (count / tempList.size()) * 100) + "%"); return source.parseContainer(analysisType.getModifier(), (((double) count / tempList.size()) * 100) + "%");
} catch (Exception | NoClassDefFoundError | NoSuchFieldError e) { } catch (Exception | NoClassDefFoundError | NoSuchFieldError e) {
return logPluginDataCausedError(source, e); return logPluginDataCausedError(source, e);
} }

View File

@ -2,8 +2,6 @@ package test.java.main.java.com.djrapitops.plan.ui.graphs;
import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.SessionData;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -43,38 +41,4 @@ public class PlayerActivityGraphCreatorTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
} }
/**
*
*/
@Test
@Ignore("Outdated")
public void testFilterSessions() {
List<SessionData> test = new ArrayList<>();
SessionData invalid = new SessionData(0);
test.add(invalid);
long now = 10000L;
long nowMinusScale = now - 3000L;
SessionData valid1 = new SessionData(9000L, 11000L);
test.add(valid1);
SessionData valid2 = new SessionData(8000L, 10000L);
test.add(valid2);
SessionData valid3 = new SessionData(7000L, 9000L);
test.add(valid3);
SessionData invalid2 = new SessionData(5000L, 5500L);
test.add(invalid2);
// List<List<Long>> result = PlayerActivityGraphCreator.filterAndTransformSessions(test, nowMinusScale);
// List<Long> starts = result.get(0);
// List<Long> ends = result.get(1);
// assertTrue("Contained invalid session" + starts, !starts.contains(invalid.getSessionStart()));
// assertTrue("Contained invalid session" + starts, !starts.contains(invalid2.getSessionStart()));
// assertTrue("Contained invalid session" + ends, !ends.contains(invalid2.getSessionEnd()));
// assertTrue("Contained invalid session" + ends, !ends.contains(invalid2.getSessionEnd()));
// assertTrue("Did not contain valid session" + starts, starts.contains(valid1.getSessionStart()));
// assertTrue("Did not contain valid session" + ends, ends.contains(valid1.getSessionEnd()));
// assertTrue("Did not contain valid session" + starts, starts.contains(valid2.getSessionStart()));
// assertTrue("Did not contain valid session" + ends, ends.contains(valid2.getSessionEnd()));
// assertTrue("Did not contain valid session" + starts, starts.contains(valid3.getSessionStart()));
// assertTrue("Did not contain valid session" + ends, ends.contains(valid3.getSessionEnd()));
}
} }