mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-29 04:27:53 +01:00
Merge pull request #206 from Fuzzlemann/master
PR for 3.6.0 (Fuzzlemann) (5)
This commit is contained in:
commit
aacbdc2d53
@ -132,6 +132,7 @@ public enum Html {
|
||||
|
||||
localeRows.add(line);
|
||||
}
|
||||
|
||||
for (String localeRow : localeRows) {
|
||||
try {
|
||||
String[] split = localeRow.split(" <> ");
|
||||
|
@ -24,15 +24,18 @@ public class RecentPlayersButtonsCreator {
|
||||
* @return html p-tag list of recent log-ins.
|
||||
*/
|
||||
public static String createRecentLoginsButtons(List<String> names, int limit) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
html.append("<p>");
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
if (i < limit) {
|
||||
String name = names.get(i);
|
||||
html.append(Html.BUTTON.parse(HtmlUtils.getRelativeInspectUrl(name), name));
|
||||
html.append(" ");
|
||||
StringBuilder html = new StringBuilder("<p>");
|
||||
|
||||
int i = 0;
|
||||
for (String name : names) {
|
||||
if (i >= limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
html.append(Html.BUTTON.parse(HtmlUtils.getRelativeInspectUrl(name), name)).append(" ");
|
||||
i++;
|
||||
}
|
||||
|
||||
html.append("</p>");
|
||||
return html.toString();
|
||||
}
|
||||
|
@ -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.MathUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -43,8 +44,7 @@ public class PunchCardGraphCreator {
|
||||
}
|
||||
|
||||
private static StringBuilder buildString(int[][] scaled) {
|
||||
StringBuilder arrayBuilder = new StringBuilder();
|
||||
arrayBuilder.append("[");
|
||||
StringBuilder arrayBuilder = new StringBuilder("[");
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 24; j++) {
|
||||
int value = scaled[i][j];
|
||||
@ -68,6 +68,7 @@ public class PunchCardGraphCreator {
|
||||
int h = dAndH[1];
|
||||
dataArray[d][h] = dataArray[d][h] + 1;
|
||||
}
|
||||
|
||||
if (Settings.ANALYSIS_REMOVE_OUTLIERS.isTrue()) {
|
||||
int avg = findAverage(dataArray);
|
||||
double standardDeviation = getStandardDeviation(dataArray, avg);
|
||||
@ -93,8 +94,8 @@ public class PunchCardGraphCreator {
|
||||
}
|
||||
}
|
||||
|
||||
int size = array.length * array[0].length;
|
||||
int sum = sum(valueMinusAvg);
|
||||
double size = array.length * array[0].length;
|
||||
double sum = sum(valueMinusAvg);
|
||||
return Math.sqrt(sum / size);
|
||||
}
|
||||
|
||||
@ -105,13 +106,7 @@ public class PunchCardGraphCreator {
|
||||
}
|
||||
|
||||
private static int sum(int[][] array) {
|
||||
int total = 0;
|
||||
for (int[] is : array) {
|
||||
for (int i : is) {
|
||||
total += i;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
return Arrays.stream(array).mapToInt(is -> is.length).sum();
|
||||
}
|
||||
|
||||
private static List<Long> getSessionStarts(Collection<SessionData> data) {
|
||||
|
@ -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.webserver.response.*;
|
||||
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.uuid.UUIDUtility;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -26,7 +25,9 @@ import java.security.cert.CertificateException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
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
|
||||
@ -75,7 +76,6 @@ public class WebServer {
|
||||
server.createContext("/", new HttpHandler() {
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException {
|
||||
OutputStream os = null;
|
||||
try {
|
||||
URI uri = exchange.getRequestURI();
|
||||
String target = uri.toString();
|
||||
@ -94,26 +94,25 @@ public class WebServer {
|
||||
Response response = getResponse(target, user);
|
||||
|
||||
String content = response.getContent();
|
||||
exchange.sendResponseHeaders(response.getCode(), content.length());
|
||||
try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody())) {
|
||||
try (ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
|
||||
try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
|
||||
byte[] buffer = new byte[2048];
|
||||
int count;
|
||||
while ((count = bis.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
throw e;
|
||||
} finally {
|
||||
MiscUtils.close(os);
|
||||
exchange.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
server.setExecutor(Executors.newSingleThreadExecutor());
|
||||
server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
|
||||
server.start();
|
||||
|
||||
enabled = true;
|
||||
|
@ -168,7 +168,7 @@ public class AnalysisUtils {
|
||||
.map(value -> (boolean) value)
|
||||
.collect(Collectors.toList());
|
||||
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) {
|
||||
return logPluginDataCausedError(source, e);
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package test.java.main.java.com.djrapitops.plan.ui.graphs;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -43,38 +41,4 @@ public class PlayerActivityGraphCreatorTest {
|
||||
@Before
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user