Recodes the sum(int[][]) method

Adds one double cast to an Integer operand to prevent a rounded Integer from returning
Removes outdated test
Performance improvements
This commit is contained in:
Fuzzlemann 2017-07-29 17:23:52 +02:00
parent c1ba6a47ba
commit 505d2a9058
5 changed files with 19 additions and 56 deletions

View File

@ -115,7 +115,7 @@ public enum Html {
* @param 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<>();
boolean html = false;
@ -132,6 +132,7 @@ public enum Html {
localeRows.add(line);
}
for (String localeRow : localeRows) {
try {
String[] split = localeRow.split(" <> ");

View File

@ -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();
}

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.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) {

View File

@ -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);
}

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 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()));
}
}