mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-04 01:39:35 +01:00
Outsourced the reduce gap triangle algorithm
This commit is contained in:
parent
28489f07c1
commit
bb9fbaa76e
@ -93,14 +93,14 @@ public class CommandUseTable extends Table {
|
||||
Map<String, Integer> updateData = new HashMap<>(data);
|
||||
updateData.keySet().removeAll(newData.keySet());
|
||||
|
||||
for (String cmd : saved.keySet()) {
|
||||
for (Map.Entry<String, Integer> entrySet : saved.entrySet()) {
|
||||
String cmd = entrySet.getKey();
|
||||
// IMPORTANT - not using saved as value
|
||||
Integer toSave = updateData.get(cmd);
|
||||
|
||||
if (toSave == null || toSave > saved.get(cmd)) {
|
||||
continue;
|
||||
if (toSave != null && toSave <= entrySet.getValue()) {
|
||||
updateData.remove(cmd);
|
||||
}
|
||||
updateData.remove(cmd);
|
||||
}
|
||||
|
||||
updateCommands(updateData);
|
||||
|
@ -5,15 +5,11 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.ui.html.graphs;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.DouglasPeuckerAlgorithm;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.PointComparator;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.ReduceGapTriangles;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract scatter graph creator used by other graph creators.
|
||||
@ -42,26 +38,7 @@ public class ScatterGraphCreator {
|
||||
}
|
||||
|
||||
if (reduceGapTriangles) {
|
||||
Point lastPoint = null;
|
||||
|
||||
Set<Point> toAdd = new HashSet<>();
|
||||
for (Point point : points) {
|
||||
if (Verify.notNull(point, lastPoint)) {
|
||||
long date = (long) point.getX();
|
||||
long lastDate = (long) lastPoint.getX();
|
||||
double y = point.getY();
|
||||
double lastY = lastPoint.getY();
|
||||
if (Double.compare(y, lastY) != 0 && Math.abs(lastY - y) > 0.5) {
|
||||
if (lastDate < date - TimeAmount.MINUTE.ms() * 10L) {
|
||||
toAdd.add(new Point(lastDate + 1, lastY));
|
||||
toAdd.add(new Point(date - 1, lastY));
|
||||
}
|
||||
}
|
||||
}
|
||||
lastPoint = point;
|
||||
}
|
||||
points.addAll(toAdd);
|
||||
points.sort(new PointComparator());
|
||||
points = ReduceGapTriangles.reduce(points);
|
||||
}
|
||||
|
||||
int size = points.size();
|
||||
|
@ -5,15 +5,11 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.ui.html.graphs;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.DouglasPeuckerAlgorithm;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.PointComparator;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.ReduceGapTriangles;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract scatter graph creator used by other graph creators.
|
||||
@ -42,26 +38,7 @@ public class SeriesCreator {
|
||||
}
|
||||
|
||||
if (reduceGapTriangles) {
|
||||
Point lastPoint = null;
|
||||
|
||||
Set<Point> toAdd = new HashSet<>();
|
||||
for (Point point : points) {
|
||||
if (Verify.notNull(point, lastPoint)) {
|
||||
long date = (long) point.getX();
|
||||
long lastDate = (long) lastPoint.getX();
|
||||
double y = point.getY();
|
||||
double lastY = lastPoint.getY();
|
||||
if (Double.compare(y, lastY) != 0 && Math.abs(lastY - y) > 0.5) {
|
||||
if (lastDate < date - TimeAmount.MINUTE.ms() * 10L) {
|
||||
toAdd.add(new Point(lastDate + 1, lastY));
|
||||
toAdd.add(new Point(date - 1, lastY));
|
||||
}
|
||||
}
|
||||
}
|
||||
lastPoint = point;
|
||||
}
|
||||
points.addAll(toAdd);
|
||||
points.sort(new PointComparator());
|
||||
points = ReduceGapTriangles.reduce(points);
|
||||
}
|
||||
|
||||
int size = points.size();
|
||||
|
@ -24,9 +24,11 @@ public class DouglasPeuckerAlgorithm {
|
||||
if (points.isEmpty()) {
|
||||
return points;
|
||||
}
|
||||
|
||||
if (Double.compare(epsilon, -1) == 0) {
|
||||
epsilon = 0.002;
|
||||
}
|
||||
|
||||
int size = points.size();
|
||||
final int lastIndex = size - 1;
|
||||
final Point start = points.get(0);
|
||||
|
@ -0,0 +1,53 @@
|
||||
package main.java.com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.PointComparator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by Fuzzlemann on 30.07.2017.
|
||||
*/
|
||||
public class ReduceGapTriangles {
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
private ReduceGapTriangles() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static List<Point> reduce(List<Point> points) {
|
||||
Point lastPoint = null;
|
||||
|
||||
Set<Point> toAdd = new HashSet<>();
|
||||
for (Point point : points) {
|
||||
if (!Verify.notNull(point, lastPoint)) {
|
||||
lastPoint = point;
|
||||
continue;
|
||||
}
|
||||
|
||||
long date = (long) point.getX();
|
||||
long lastDate = (long) lastPoint.getX();
|
||||
double y = point.getY();
|
||||
double lastY = lastPoint.getY();
|
||||
|
||||
if (Double.compare(y, lastY) != 0
|
||||
&& Math.abs(lastY - y) > 0.5
|
||||
&& lastDate < date - TimeAmount.MINUTE.ms() * 10L) {
|
||||
toAdd.add(new Point(lastDate + 1, lastY));
|
||||
toAdd.add(new Point(date - 1, lastY));
|
||||
}
|
||||
|
||||
lastPoint = point;
|
||||
}
|
||||
|
||||
points.addAll(toAdd);
|
||||
points.sort(new PointComparator());
|
||||
|
||||
return points;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user