diff --git a/src/main/java/de/wwwu/awolf/model/communication/AlgorithmData.java b/src/main/java/de/wwwu/awolf/model/communication/AlgorithmMessage.java similarity index 89% rename from src/main/java/de/wwwu/awolf/model/communication/AlgorithmData.java rename to src/main/java/de/wwwu/awolf/model/communication/AlgorithmMessage.java index 18456dc..329de9e 100644 --- a/src/main/java/de/wwwu/awolf/model/communication/AlgorithmData.java +++ b/src/main/java/de/wwwu/awolf/model/communication/AlgorithmMessage.java @@ -1,9 +1,9 @@ package de.wwwu.awolf.model.communication; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.algorithms.Algorithm; -public class AlgorithmData implements Data { +public class AlgorithmMessage implements Message { private SubscriberType type; private Algorithm.Type algorithmType; diff --git a/src/main/java/de/wwwu/awolf/model/communication/TypeData.java b/src/main/java/de/wwwu/awolf/model/communication/DataProviderMessage.java similarity index 74% rename from src/main/java/de/wwwu/awolf/model/communication/TypeData.java rename to src/main/java/de/wwwu/awolf/model/communication/DataProviderMessage.java index 9740ed5..edb4181 100644 --- a/src/main/java/de/wwwu/awolf/model/communication/TypeData.java +++ b/src/main/java/de/wwwu/awolf/model/communication/DataProviderMessage.java @@ -1,12 +1,12 @@ package de.wwwu.awolf.model.communication; -public class TypeData implements Data { +public class DataProviderMessage implements Message { private SubscriberType type; @Override public SubscriberType getType() { - return type; + return this.type; } @Override diff --git a/src/main/java/de/wwwu/awolf/model/communication/EvaluationData.java b/src/main/java/de/wwwu/awolf/model/communication/EvaluationMessage.java similarity index 97% rename from src/main/java/de/wwwu/awolf/model/communication/EvaluationData.java rename to src/main/java/de/wwwu/awolf/model/communication/EvaluationMessage.java index c23bfda..5b967f9 100644 --- a/src/main/java/de/wwwu/awolf/model/communication/EvaluationData.java +++ b/src/main/java/de/wwwu/awolf/model/communication/EvaluationMessage.java @@ -5,7 +5,7 @@ import java.io.Serializable; import java.util.List; import java.util.Map; -public class EvaluationData implements Data { +public class EvaluationMessage implements Message { private SubscriberType type; private List algorithmtypes; diff --git a/src/main/java/de/wwwu/awolf/model/communication/GeneratorData.java b/src/main/java/de/wwwu/awolf/model/communication/GeneratorData.java deleted file mode 100644 index 436a7c6..0000000 --- a/src/main/java/de/wwwu/awolf/model/communication/GeneratorData.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.wwwu.awolf.model.communication; - -public class GeneratorData implements Data { - - private SubscriberType type; - private String message; - private double m; - private double b; - - public double getM() { - return m; - } - - public void setM(double m) { - this.m = m; - } - - public double getB() { - return b; - } - - public void setB(double b) { - this.b = b; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Override - public SubscriberType getType() { - return type; - } - - @Override - public void setType(SubscriberType type) { - this.type = type; - } -} diff --git a/src/main/java/de/wwwu/awolf/model/communication/ImportData.java b/src/main/java/de/wwwu/awolf/model/communication/ImportData.java deleted file mode 100644 index 2da1b90..0000000 --- a/src/main/java/de/wwwu/awolf/model/communication/ImportData.java +++ /dev/null @@ -1,34 +0,0 @@ -package de.wwwu.awolf.model.communication; - -public class ImportData implements Data { - - private SubscriberType type; - private int numberOfLines; - private int current; - - @Override - public SubscriberType getType() { - return type; - } - - @Override - public void setType(SubscriberType type) { - this.type = type; - } - - public int getNumberOfLines() { - return numberOfLines; - } - - public void setNumberOfLines(int numberOfLines) { - this.numberOfLines = numberOfLines; - } - - public int getCurrent() { - return current; - } - - public void setCurrent(int current) { - this.current = current; - } -} diff --git a/src/main/java/de/wwwu/awolf/model/communication/Data.java b/src/main/java/de/wwwu/awolf/model/communication/Message.java similarity index 81% rename from src/main/java/de/wwwu/awolf/model/communication/Data.java rename to src/main/java/de/wwwu/awolf/model/communication/Message.java index 1042caf..bd89fd7 100644 --- a/src/main/java/de/wwwu/awolf/model/communication/Data.java +++ b/src/main/java/de/wwwu/awolf/model/communication/Message.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.model.communication; -public interface Data { +public interface Message { SubscriberType getType(); diff --git a/src/main/java/de/wwwu/awolf/model/communication/SubscriberType.java b/src/main/java/de/wwwu/awolf/model/communication/SubscriberType.java index 31056e9..b98f91e 100644 --- a/src/main/java/de/wwwu/awolf/model/communication/SubscriberType.java +++ b/src/main/java/de/wwwu/awolf/model/communication/SubscriberType.java @@ -2,12 +2,7 @@ package de.wwwu.awolf.model.communication; public enum SubscriberType { - EVAL_D, - EVALUATION_TABLE_DATA, - EVAL_T, - LINES_RES, - LINES_RES_MULT, + EVALUATION, ALGORITHM, - PICTURE, - GENERATOR + DATA_PROVIDER } diff --git a/src/main/java/de/wwwu/awolf/model/Interval.java b/src/main/java/de/wwwu/awolf/model/dao/Interval.java similarity index 97% rename from src/main/java/de/wwwu/awolf/model/Interval.java rename to src/main/java/de/wwwu/awolf/model/dao/Interval.java index d8ab46e..220b0df 100644 --- a/src/main/java/de/wwwu/awolf/model/Interval.java +++ b/src/main/java/de/wwwu/awolf/model/dao/Interval.java @@ -1,4 +1,4 @@ -package de.wwwu.awolf.model; +package de.wwwu.awolf.model.dao; /** * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden. diff --git a/src/main/java/de/wwwu/awolf/model/Line.java b/src/main/java/de/wwwu/awolf/model/dao/Line.java similarity index 99% rename from src/main/java/de/wwwu/awolf/model/Line.java rename to src/main/java/de/wwwu/awolf/model/dao/Line.java index 82dd234..e612dd1 100644 --- a/src/main/java/de/wwwu/awolf/model/Line.java +++ b/src/main/java/de/wwwu/awolf/model/dao/Line.java @@ -1,4 +1,4 @@ -package de.wwwu.awolf.model; +package de.wwwu.awolf.model.dao; import java.util.Objects; import org.apache.commons.math3.util.Precision; diff --git a/src/main/java/de/wwwu/awolf/model/LineModel.java b/src/main/java/de/wwwu/awolf/model/dao/LineModel.java similarity index 98% rename from src/main/java/de/wwwu/awolf/model/LineModel.java rename to src/main/java/de/wwwu/awolf/model/dao/LineModel.java index 9da5c1c..5b3dff6 100644 --- a/src/main/java/de/wwwu/awolf/model/LineModel.java +++ b/src/main/java/de/wwwu/awolf/model/dao/LineModel.java @@ -1,4 +1,4 @@ -package de.wwwu.awolf.model; +package de.wwwu.awolf.model.dao; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/de/wwwu/awolf/model/Pair.java b/src/main/java/de/wwwu/awolf/model/dao/Pair.java similarity index 96% rename from src/main/java/de/wwwu/awolf/model/Pair.java rename to src/main/java/de/wwwu/awolf/model/dao/Pair.java index 50786c9..d510af8 100644 --- a/src/main/java/de/wwwu/awolf/model/Pair.java +++ b/src/main/java/de/wwwu/awolf/model/dao/Pair.java @@ -1,4 +1,4 @@ -package de.wwwu.awolf.model; +package de.wwwu.awolf.model.dao; /** * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden. diff --git a/src/main/java/de/wwwu/awolf/model/Point.java b/src/main/java/de/wwwu/awolf/model/dao/Point.java similarity index 98% rename from src/main/java/de/wwwu/awolf/model/Point.java rename to src/main/java/de/wwwu/awolf/model/dao/Point.java index 40467b2..b680938 100644 --- a/src/main/java/de/wwwu/awolf/model/Point.java +++ b/src/main/java/de/wwwu/awolf/model/dao/Point.java @@ -1,4 +1,4 @@ -package de.wwwu.awolf.model; +package de.wwwu.awolf.model.dao; import java.util.Objects; import org.apache.commons.math3.util.Precision; diff --git a/src/main/java/de/wwwu/awolf/model/evaluation/ComparisonResult.java b/src/main/java/de/wwwu/awolf/model/evaluation/ComparisonResult.java index 5872427..c125b21 100644 --- a/src/main/java/de/wwwu/awolf/model/evaluation/ComparisonResult.java +++ b/src/main/java/de/wwwu/awolf/model/evaluation/ComparisonResult.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.model.evaluation; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.algorithms.Algorithm; import java.util.EnumMap; import java.util.Map; diff --git a/src/main/java/de/wwwu/awolf/presenter/AbstractPresenter.java b/src/main/java/de/wwwu/awolf/presenter/AbstractPresenter.java index 4f6542a..1be9835 100644 --- a/src/main/java/de/wwwu/awolf/presenter/AbstractPresenter.java +++ b/src/main/java/de/wwwu/awolf/presenter/AbstractPresenter.java @@ -1,8 +1,8 @@ package de.wwwu.awolf.presenter; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.LineModel; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.LineModel; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.presenter.algorithms.Algorithm; import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler; import de.wwwu.awolf.presenter.data.DataHandler; @@ -24,7 +24,7 @@ import javafx.beans.property.BooleanProperty; * @Email: a_wolf28@uni-muenster.de * @Date: 10.09.2017. */ -public abstract class AbstractPresenter implements Flow.Subscriber { +public abstract class AbstractPresenter implements Flow.Subscriber { private final ExecutorService executor; private LineModel model; @@ -56,25 +56,23 @@ public abstract class AbstractPresenter implements Flow.Subscriber { @Override - public void onNext(Data data) { - Logging.logDebug("Presenter received message. Type: " + data.getType()); - switch (data.getType()) { - case EVALUATION_TABLE_DATA: - evaluatedDatas(data); + public void onNext(Message message) { + Logging.logDebug("Presenter received message. Type: " + message.getType()); + switch (message.getType()) { + case EVALUATION: + evaluatedDatas(message); break; case ALGORITHM: - visualizeAlgorithm(data); + visualizeAlgorithm(message); + break; + case DATA_PROVIDER: + enableStartAlgorithmButton(); break; default: break; } } - protected abstract void visualizeAlgorithm(Data data); - - protected abstract void evaluatedDatas(Data data); - - @Override public void onError(Throwable throwable) { @@ -121,23 +119,14 @@ public abstract class AbstractPresenter implements Flow.Subscriber { } } - /** - * @return das zu grunde legende Modell - */ public LineModel getModel() { return model; } - /** - * @return die zu grunde legende View - */ public ViewController getView() { return view; } - /** - * @param view die zu grunde legende View - */ public void registerView(ViewController view) { this.view = view; Logging.logDebug("View has been set."); @@ -146,9 +135,6 @@ public abstract class AbstractPresenter implements Flow.Subscriber { Platform.runLater(() -> this.view.initGui()); } - /** - * @return Evaluation - */ EvaluatationHandler getEvaluatationHandler() { return evaluatationHandler; } @@ -157,12 +143,17 @@ public abstract class AbstractPresenter implements Flow.Subscriber { return dataHandler; } - /** - * Returns the instance of the ExecutorService - * - * @return ExecutorService instance - */ public ExecutorService getExecutor() { return Objects.requireNonNullElseGet(executor, Executors::newCachedThreadPool); } + + public AlgorithmHandler getAlgorithmHandler() { + return algorithmHandler; + } + + protected abstract void enableStartAlgorithmButton(); + + protected abstract void visualizeAlgorithm(Message message); + + protected abstract void evaluatedDatas(Message message); } diff --git a/src/main/java/de/wwwu/awolf/presenter/Presenter.java b/src/main/java/de/wwwu/awolf/presenter/Presenter.java index 9b89857..c982a1e 100644 --- a/src/main/java/de/wwwu/awolf/presenter/Presenter.java +++ b/src/main/java/de/wwwu/awolf/presenter/Presenter.java @@ -1,16 +1,14 @@ package de.wwwu.awolf.presenter; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; -import de.wwwu.awolf.model.communication.EvaluationData; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.data.DataHandler; import de.wwwu.awolf.presenter.evaluation.EvaluatationHandler; import de.wwwu.awolf.presenter.util.Logging; import java.io.File; import java.util.Set; import javafx.application.Platform; -import javax.swing.SwingUtilities; /** @@ -28,6 +26,11 @@ public class Presenter extends AbstractPresenter { super(); } + /** + * Singleton access method + * + * @return instance + */ public static Presenter getInstance() { if (instance == null) { instance = new Presenter(); @@ -37,26 +40,25 @@ public class Presenter extends AbstractPresenter { } @Override - protected void visualizeAlgorithm(Data data) { - AlgorithmData algorithmData = (AlgorithmData) data; - - Platform.runLater(() -> getView().getAlgorithmTabControllers().get(algorithmData.getAlgorithmType()).updatePlot(getModel(), algorithmData.getLineData()) - ); - Logging.logInfo("Type: " + algorithmData.getType() + ". Result: " + algorithmData.getLineData().toString()); + protected void enableStartAlgorithmButton() { + Platform.runLater(() -> getView().getAlgorithmTabControllers().values().forEach(tab -> tab.getStartButton().setDisable(false))); } @Override - protected void evaluatedDatas(Data data) { - EvaluationData evaluationData = (EvaluationData) data; - SwingUtilities - .invokeLater( - () -> getView().appendEvalResults(evaluationData.getMultipleColumnResult())); + protected void visualizeAlgorithm(Message message) { + AlgorithmMessage algorithmMessage = (AlgorithmMessage) message; + Platform.runLater(() -> getView().getAlgorithmTabControllers().get(algorithmMessage.getAlgorithmType()).updatePlot(getModel(), algorithmMessage.getLineData())); + Logging.logInfo("Type: " + algorithmMessage.getType() + ". Result: " + algorithmMessage.getLineData().toString()); } - /*************************************************************************************************************************** - * Hilfsmethoden - ***************************************************************************************************************************/ - + @Override + protected void evaluatedDatas(Message message) { + //TODO +// EvaluationData evaluationData = (EvaluationData) data; +// SwingUtilities +// .invokeLater( +// () -> getView().appendEvalResults(evaluationData.getMultipleColumnResult())); + } /** * Startet den Export des akteullen Datensatzes (nur der Geraden) @@ -87,8 +89,7 @@ public class Presenter extends AbstractPresenter { getModel().setLines(data); //Berechnung der Schnittpunkte und vis. der Ergebnisse (anz. Geraden, anz. Schnittpunkte) Logging.logInfo("Import was successful! "); - Platform.runLater(() -> getView().getAlgorithmTabControllers().values().forEach(e -> e.updatePlot(getModel(), null)) - ); + Platform.runLater(() -> getView().getAlgorithmTabControllers().values().forEach(e -> e.updatePlot(getModel(), null))); return data; } @@ -102,8 +103,7 @@ public class Presenter extends AbstractPresenter { Set data = getDataHandler().getData(type, n); getModel().setLines(data); Logging.logInfo("Generate was successful!"); - Platform.runLater(() -> getView().getAlgorithmTabControllers().values().forEach(e -> e.updatePlot(getModel(), null)) - ); + Platform.runLater(() -> getView().getAlgorithmTabControllers().values().forEach(e -> e.updatePlot(getModel(), null))); return data; } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/Algorithm.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/Algorithm.java index 176f29f..97dec47 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/Algorithm.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/Algorithm.java @@ -1,8 +1,9 @@ package de.wwwu.awolf.presenter.algorithms; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.communication.Message; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.AbstractPresenter; +import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.Flow; @@ -14,7 +15,7 @@ import java.util.concurrent.Flow; * @Email: a_wolf28@uni-muenster.de * @Date: 28.05.2017. */ -public interface Algorithm extends Callable, Flow.Publisher { +public interface Algorithm extends Callable, Flow.Publisher { /** * Startet die Berechnung des jeweiligen Algorithmus. @@ -28,6 +29,10 @@ public interface Algorithm extends Callable, Flow.Publisher { void setPresenter(AbstractPresenter presenter); + Map getParameter(); + + void setParameter(Map parameter); + enum Type { LMS("Least Median of Squares"), RM("Repeated Median"), diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/AlgorithmHandler.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/AlgorithmHandler.java index 3a542c8..6ea0791 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/AlgorithmHandler.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/AlgorithmHandler.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.algorithms; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.Presenter; import de.wwwu.awolf.presenter.util.Logging; import java.util.EnumMap; @@ -17,6 +17,7 @@ public class AlgorithmHandler { private static AlgorithmHandler instance; private Map algorithmMapping; + private Map> algorithmParameters; private AlgorithmHandler() { @@ -88,10 +89,15 @@ public class AlgorithmHandler { ServiceLoader load = ServiceLoader.load(Algorithm.class); load.reload(); algorithmMapping = new EnumMap<>(Algorithm.Type.class); + algorithmParameters = new EnumMap<>(Algorithm.Type.class); load.forEach(algorithm -> { algorithmMapping.put(algorithm.getType(), algorithm); + algorithmParameters.put(algorithm.getType(), algorithm.getParameter()); Logging.logDebug("Found: " + algorithm.getClass().getSimpleName()); }); } + public Map getAlgorithmParametersByType(Algorithm.Type type) { + return algorithmParameters.get(type); + } } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimator.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimator.java index feb9ed5..d8b13c4 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimator.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimator.java @@ -1,10 +1,10 @@ package de.wwwu.awolf.presenter.algorithms.advanced; -import de.wwwu.awolf.model.Interval; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.Point; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Interval; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.Point; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; @@ -14,8 +14,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Set; @@ -43,11 +45,21 @@ public class LeastMedianOfSquaresEstimator implements Algorithm { private Line sigmaMin; private double heightsigmaMin; private double intersectionsPoint; - private double constant = 0.5; + private double constant; private double slope; private double yInterception; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; + private Map parameter; + + public LeastMedianOfSquaresEstimator() { + quantileError = 0.1; + constant = 0.5; + + parameter = new HashMap<>(); + parameter.put("Quantile Error", quantileError); + parameter.put("Constant", constant); + } /** * Algorithmus zum berechnen des LMS-Schätzers @@ -57,9 +69,9 @@ public class LeastMedianOfSquaresEstimator implements Algorithm { */ @Override public Line call() { + this.n = setOfLines.size(); double qPlus = 0.5; - quantileError = 0.1; double qMinus = qPlus * (1 - quantileError); kMinus = (int) Math.ceil(n * qMinus); kPlus = (int) Math.ceil(n * qPlus); @@ -155,6 +167,16 @@ public class LeastMedianOfSquaresEstimator implements Algorithm { subscribe(presenter); } + @Override + public Map getParameter() { + return this.parameter; + } + + @Override + public void setParameter(Map parameter) { + this.parameter = parameter; + } + /** * Liefert die Anzahl der Schnittpunkte in einem Intervall @@ -373,7 +395,7 @@ public class LeastMedianOfSquaresEstimator implements Algorithm { slope = m; yInterception = b; - AlgorithmData data = new AlgorithmData(); + AlgorithmMessage data = new AlgorithmMessage(); data.setAlgorithmType(getType()); data.setType(SubscriberType.ALGORITHM); data.setLineData(new Line(m, b)); @@ -460,7 +482,7 @@ public class LeastMedianOfSquaresEstimator implements Algorithm { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/RepeatedMedianEstimator.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/RepeatedMedianEstimator.java index a31f992..9a5c829 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/RepeatedMedianEstimator.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/RepeatedMedianEstimator.java @@ -1,10 +1,10 @@ package de.wwwu.awolf.presenter.algorithms.advanced; -import de.wwwu.awolf.model.Interval; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.Point; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Interval; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.Point; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; @@ -14,9 +14,11 @@ import de.wwwu.awolf.presenter.util.Logging; import de.wwwu.awolf.presenter.util.RandomSampler; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.Flow; @@ -57,8 +59,15 @@ public class RepeatedMedianEstimator implements Algorithm { private double slope; private double yInterception; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; + private Map parameter; + public RepeatedMedianEstimator() { + beta = 0.5; + + parameter = new HashMap<>(); + parameter.put("Beta", beta); + } /** * Führt den Algortihmus zur Berechnung des RM-Schätzers durch. @@ -70,7 +79,7 @@ public class RepeatedMedianEstimator implements Algorithm { n = setOfLines.size(); interval = new Interval(-10000, 10000); original = new Interval(-10000, 10000); - beta = 0.5; + intersectionsInLeftSlab = new HashSet<>(); intersectionsInCenterSlab = new HashSet<>(); @@ -253,7 +262,7 @@ public class RepeatedMedianEstimator implements Algorithm { Math.floor(potentialYInterceptions.size() * 0.5)); if (this.subscriber != null) { - AlgorithmData data = new AlgorithmData(); + AlgorithmMessage data = new AlgorithmMessage(); data.setAlgorithmType(getType()); data.setType(SubscriberType.ALGORITHM); data.setLineData(new Line(getSlope(), getyInterception())); @@ -348,9 +357,19 @@ public class RepeatedMedianEstimator implements Algorithm { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } + + @Override + public Map getParameter() { + return this.parameter; + } + + @Override + public void setParameter(Map parameter) { + this.parameter = parameter; + } } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimator.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimator.java index 477a4b2..f71c2c4 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimator.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimator.java @@ -1,10 +1,10 @@ package de.wwwu.awolf.presenter.algorithms.advanced; -import de.wwwu.awolf.model.Interval; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.Point; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Interval; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.Point; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.Flow; @@ -50,8 +51,9 @@ public class TheilSenEstimator implements Algorithm { private double bVariant; private double slope; private double yInterception; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; private AbstractPresenter presenter; + private Map parameter; /** @@ -217,7 +219,7 @@ public class TheilSenEstimator implements Algorithm { yInterception = b; if (this.subscriber != null) { - AlgorithmData data = new AlgorithmData(); + AlgorithmMessage data = new AlgorithmMessage(); data.setAlgorithmType(getType()); data.setType(SubscriberType.ALGORITHM); data.setLineData(new Line(m, b)); @@ -242,7 +244,17 @@ public class TheilSenEstimator implements Algorithm { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } + + @Override + public Map getParameter() { + return this.parameter; + } + + @Override + public void setParameter(Map parameter) { + this.parameter = parameter; + } } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivLeastMedianOfSquaresEstimator.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveLeastMedianOfSquaresEstimator.java similarity index 81% rename from src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivLeastMedianOfSquaresEstimator.java rename to src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveLeastMedianOfSquaresEstimator.java index 4efcfb7..4267dd4 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivLeastMedianOfSquaresEstimator.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveLeastMedianOfSquaresEstimator.java @@ -1,8 +1,8 @@ -package de.wwwu.awolf.presenter.algorithms.naiv; +package de.wwwu.awolf.presenter.algorithms.naive; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; @@ -10,8 +10,10 @@ import de.wwwu.awolf.presenter.util.FastElementSelector; import de.wwwu.awolf.presenter.util.Logging; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.Flow; @@ -22,16 +24,20 @@ import java.util.concurrent.Flow; * @Email: a_wolf28@uni-muenster.de * @Date: 15.09.2017. */ -public class NaivLeastMedianOfSquaresEstimator implements Algorithm { +public class NaiveLeastMedianOfSquaresEstimator implements Algorithm { private static final Algorithm.Type type = Type.NAIVE_LMS; private List setOfLines = new ArrayList<>(); private int n; private double ds, b, m; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; private AbstractPresenter presenter; + private Map parameter; + public NaiveLeastMedianOfSquaresEstimator() { + parameter = new HashMap<>(); + } /** * Crude Algorithmus zum berechnen des LSM-Schätzers. @@ -77,7 +83,7 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm { Logging.logInfo("=== E N D - naiv L M S ==="); Logging.logInfo("Slope: " + getSlope() + ", y-Interception: " + getYInterception()); - AlgorithmData data = new AlgorithmData(); + AlgorithmMessage data = new AlgorithmMessage(); data.setAlgorithmType(getType()); data.setType(SubscriberType.ALGORITHM); data.setLineData(new Line(getSlope(), getYInterception())); @@ -137,7 +143,17 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } + + @Override + public Map getParameter() { + return this.parameter; + } + + @Override + public void setParameter(Map parameter) { + this.parameter = parameter; + } } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivRepeatedMedianEstimator.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveRepeatedMedianEstimator.java similarity index 85% rename from src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivRepeatedMedianEstimator.java rename to src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveRepeatedMedianEstimator.java index 578ddce..3c348a6 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivRepeatedMedianEstimator.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveRepeatedMedianEstimator.java @@ -1,9 +1,9 @@ -package de.wwwu.awolf.presenter.algorithms.naiv; +package de.wwwu.awolf.presenter.algorithms.naive; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.Point; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.Point; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; @@ -23,7 +23,7 @@ import java.util.concurrent.Flow; * @Email: a_wolf28@uni-muenster.de * @Date: 15.09.2017. */ -public class NaivRepeatedMedianEstimator implements Algorithm { +public class NaiveRepeatedMedianEstimator implements Algorithm { private static final Algorithm.Type type = Type.NAIVE_RM; @@ -34,8 +34,13 @@ public class NaivRepeatedMedianEstimator implements Algorithm { private List yMedians; private double medianX; private double medianY; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; private AbstractPresenter presenter; + private Map parameter; + + public NaiveRepeatedMedianEstimator() { + parameter = new HashMap<>(); + } @Override public Line call() { @@ -90,7 +95,7 @@ public class NaivRepeatedMedianEstimator implements Algorithm { end = System.currentTimeMillis(); Logging.logInfo("=== E N D - naiv R M ==="); Logging.logInfo("Slope: " + getSlope() + ", y-Interception: " + getYInterception()); - AlgorithmData data = new AlgorithmData(); + AlgorithmMessage data = new AlgorithmMessage(); data.setAlgorithmType(getType()); data.setType(SubscriberType.ALGORITHM); data.setLineData(new Line(getSlope(), getYInterception())); @@ -144,6 +149,16 @@ public class NaivRepeatedMedianEstimator implements Algorithm { return new Point(m, b); } + @Override + public Map getParameter() { + return this.parameter; + } + + @Override + public void setParameter(Map parameter) { + this.parameter = parameter; + } + /** * @return Steigung */ @@ -159,7 +174,7 @@ public class NaivRepeatedMedianEstimator implements Algorithm { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } } diff --git a/src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivTheilSenEstimator.java b/src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveTheilSenEstimator.java similarity index 79% rename from src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivTheilSenEstimator.java rename to src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveTheilSenEstimator.java index ad44db7..e7b6ce8 100644 --- a/src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivTheilSenEstimator.java +++ b/src/main/java/de/wwwu/awolf/presenter/algorithms/naive/NaiveTheilSenEstimator.java @@ -1,15 +1,17 @@ -package de.wwwu.awolf.presenter.algorithms.naiv; +package de.wwwu.awolf.presenter.algorithms.naive; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.communication.AlgorithmData; -import de.wwwu.awolf.model.communication.Data; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.communication.AlgorithmMessage; +import de.wwwu.awolf.model.communication.Message; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; import de.wwwu.awolf.presenter.util.FastElementSelector; import de.wwwu.awolf.presenter.util.Logging; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.Flow; @@ -20,15 +22,20 @@ import java.util.concurrent.Flow; * @Email: a_wolf28@uni-muenster.de * @Date: 15.09.2017. */ -public class NaivTheilSenEstimator implements Algorithm { +public class NaiveTheilSenEstimator implements Algorithm { private static final Algorithm.Type type = Type.NAIVE_TS; private List setOfLines; private double slope; private double yInterception; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; private AbstractPresenter presenter; + private Map parameter; + + public NaiveTheilSenEstimator() { + parameter = new HashMap<>(); + } @Override public Line call() { @@ -68,7 +75,7 @@ public class NaivTheilSenEstimator implements Algorithm { end = System.currentTimeMillis(); Logging.logInfo("=== E N D - naiv T S ==="); Logging.logInfo("Slope: " + getSlope() + ", y-Interception: " + getYInterception()); - AlgorithmData data = new AlgorithmData(); + AlgorithmMessage data = new AlgorithmMessage(); data.setAlgorithmType(getType()); data.setType(SubscriberType.ALGORITHM); data.setLineData(new Line(getSlope(), getYInterception())); @@ -92,6 +99,16 @@ public class NaivTheilSenEstimator implements Algorithm { subscribe(presenter); } + @Override + public Map getParameter() { + return this.parameter; + } + + @Override + public void setParameter(Map parameter) { + this.parameter = parameter; + } + /** * @return Steigung @@ -108,7 +125,7 @@ public class NaivTheilSenEstimator implements Algorithm { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } } diff --git a/src/main/java/de/wwwu/awolf/presenter/data/DataHandler.java b/src/main/java/de/wwwu/awolf/presenter/data/DataHandler.java index 66a7048..03b586c 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/DataHandler.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/DataHandler.java @@ -1,6 +1,9 @@ package de.wwwu.awolf.presenter.data; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.communication.DataProviderMessage; +import de.wwwu.awolf.model.communication.Message; +import de.wwwu.awolf.model.communication.SubscriberType; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.AbstractPresenter; import de.wwwu.awolf.presenter.data.generator.CircleDatasetGenerator; import de.wwwu.awolf.presenter.data.generator.CloudDatasetGenerator; @@ -13,19 +16,22 @@ import java.util.Collections; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.Flow; +import java.util.concurrent.Flow.Subscriber; -public class DataHandler { +public class DataHandler implements Flow.Publisher { private final AbstractPresenter presenter; + private Subscriber subscriber; public DataHandler(AbstractPresenter presenter) { this.presenter = presenter; + subscribe(presenter); } public Set getData(final File file) { //Presenter soll die Klasse überwachen - ExecutorCompletionService> completionService = new ExecutorCompletionService<>( - this.presenter.getExecutor()); + ExecutorCompletionService> completionService = new ExecutorCompletionService<>(this.presenter.getExecutor()); Logging.logDebug("Importing Data: " + file.getAbsolutePath()); completionService.submit(new DataImporter(file)); //wait until future is ready @@ -35,14 +41,17 @@ public class DataHandler { Logging.logError("Interrupted while importing... ", e); Thread.currentThread().interrupt(); return Collections.emptySet(); + } finally { + DataProviderMessage message = new DataProviderMessage(); + message.setType(SubscriberType.DATA_PROVIDER); + this.subscriber.onNext(message); } } public Set getData(final DataType type, final int dataSize) { //Presenter soll die Klasse überwachen - ExecutorCompletionService> completionService = new ExecutorCompletionService<>( - this.presenter.getExecutor()); + ExecutorCompletionService> completionService = new ExecutorCompletionService<>(this.presenter.getExecutor()); Logging.logDebug("Generating Data: Size: " + dataSize + ", dataType: " + type.name()); switch (type) { @@ -65,6 +74,10 @@ public class DataHandler { Logging.logError("Interrupted while generating... ", e); Thread.currentThread().interrupt(); return Collections.emptySet(); + } finally { + DataProviderMessage message = new DataProviderMessage(); + message.setType(SubscriberType.DATA_PROVIDER); + this.subscriber.onNext(message); } } @@ -72,6 +85,11 @@ public class DataHandler { this.presenter.getExecutor().submit(new DataExporter(lines, file)); } + @Override + public void subscribe(Subscriber subscriber) { + this.subscriber = subscriber; + } + public enum DataType { CLOUD, diff --git a/src/main/java/de/wwwu/awolf/presenter/data/generator/CircleDatasetGenerator.java b/src/main/java/de/wwwu/awolf/presenter/data/generator/CircleDatasetGenerator.java index e5e28ce..269b1ee 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/generator/CircleDatasetGenerator.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/generator/CircleDatasetGenerator.java @@ -2,7 +2,7 @@ package de.wwwu.awolf.presenter.data.generator; import static de.wwwu.awolf.presenter.data.generator.DatasetGenerator.generateDataLines; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.util.HashSet; import java.util.Set; import java.util.concurrent.Callable; diff --git a/src/main/java/de/wwwu/awolf/presenter/data/generator/CloudDatasetGenerator.java b/src/main/java/de/wwwu/awolf/presenter/data/generator/CloudDatasetGenerator.java index dbfe53d..56786c4 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/generator/CloudDatasetGenerator.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/generator/CloudDatasetGenerator.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.data.generator; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.security.SecureRandom; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/de/wwwu/awolf/presenter/data/generator/DatasetGenerator.java b/src/main/java/de/wwwu/awolf/presenter/data/generator/DatasetGenerator.java index 801879a..acfe325 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/generator/DatasetGenerator.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/generator/DatasetGenerator.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.data.generator; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.security.SecureRandom; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/wwwu/awolf/presenter/data/generator/LineDatasetGenerator.java b/src/main/java/de/wwwu/awolf/presenter/data/generator/LineDatasetGenerator.java index 2464807..a97d1cf 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/generator/LineDatasetGenerator.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/generator/LineDatasetGenerator.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.data.generator; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.util.HashSet; import java.util.Set; import java.util.concurrent.Callable; diff --git a/src/main/java/de/wwwu/awolf/presenter/data/io/DataExporter.java b/src/main/java/de/wwwu/awolf/presenter/data/io/DataExporter.java index f66328b..fbd5f69 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/io/DataExporter.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/io/DataExporter.java @@ -1,7 +1,7 @@ package de.wwwu.awolf.presenter.data.io; import com.opencsv.CSVWriter; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.util.Logging; import java.io.File; import java.io.FileWriter; diff --git a/src/main/java/de/wwwu/awolf/presenter/data/io/DataImporter.java b/src/main/java/de/wwwu/awolf/presenter/data/io/DataImporter.java index a5c0bd5..ae83ad4 100644 --- a/src/main/java/de/wwwu/awolf/presenter/data/io/DataImporter.java +++ b/src/main/java/de/wwwu/awolf/presenter/data/io/DataImporter.java @@ -1,7 +1,7 @@ package de.wwwu.awolf.presenter.data.io; import com.opencsv.CSVReader; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.util.Logging; import java.io.File; import java.io.FileNotFoundException; diff --git a/src/main/java/de/wwwu/awolf/presenter/evaluation/AlgorithmComparison.java b/src/main/java/de/wwwu/awolf/presenter/evaluation/AlgorithmComparison.java index 5381268..8821418 100644 --- a/src/main/java/de/wwwu/awolf/presenter/evaluation/AlgorithmComparison.java +++ b/src/main/java/de/wwwu/awolf/presenter/evaluation/AlgorithmComparison.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.evaluation; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.model.evaluation.ComparisonResult; import de.wwwu.awolf.presenter.algorithms.Algorithm; import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler; diff --git a/src/main/java/de/wwwu/awolf/presenter/evaluation/EvaluatationHandler.java b/src/main/java/de/wwwu/awolf/presenter/evaluation/EvaluatationHandler.java index 5f52508..0710f2d 100644 --- a/src/main/java/de/wwwu/awolf/presenter/evaluation/EvaluatationHandler.java +++ b/src/main/java/de/wwwu/awolf/presenter/evaluation/EvaluatationHandler.java @@ -1,9 +1,9 @@ package de.wwwu.awolf.presenter.evaluation; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.LineModel; -import de.wwwu.awolf.model.communication.Data; -import de.wwwu.awolf.model.communication.EvaluationData; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.LineModel; +import de.wwwu.awolf.model.communication.Message; +import de.wwwu.awolf.model.communication.EvaluationMessage; import de.wwwu.awolf.model.communication.SubscriberType; import de.wwwu.awolf.model.evaluation.ComparisonResult; import de.wwwu.awolf.presenter.Presenter; @@ -31,7 +31,7 @@ import java.util.concurrent.Flow; * @Email: a_wolf28@uni-muenster.de * @Date: 01.08.2017. */ -public class EvaluatationHandler implements Runnable, Flow.Publisher { +public class EvaluatationHandler implements Runnable, Flow.Publisher { private LineModel arrangement; private DatasetGenerator generator; @@ -40,7 +40,7 @@ public class EvaluatationHandler implements Runnable, Flow.Publisher { private int type; private int iterations; private int alg; - private Flow.Subscriber subscriber; + private Flow.Subscriber subscriber; private Map> resultMapping; /** @@ -173,8 +173,8 @@ public class EvaluatationHandler implements Runnable, Flow.Publisher { */ private void sendTableApproximationData(Map> result) { - EvaluationData data = new EvaluationData(); - data.setType(SubscriberType.EVALUATION_TABLE_DATA); + EvaluationMessage data = new EvaluationMessage(); + data.setType(SubscriberType.EVALUATION); data.setMultipleColumnResult(result); data.setRowsPerColumn(result.keySet().size()); this.subscriber.onNext(data); @@ -276,7 +276,7 @@ public class EvaluatationHandler implements Runnable, Flow.Publisher { } @Override - public void subscribe(Flow.Subscriber subscriber) { + public void subscribe(Flow.Subscriber subscriber) { this.subscriber = subscriber; } } diff --git a/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/PercentageErrorBasedMeasure.java b/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/PercentageErrorBasedMeasure.java index 349adc1..0060f3b 100644 --- a/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/PercentageErrorBasedMeasure.java +++ b/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/PercentageErrorBasedMeasure.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.evaluation.measures; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.util.FastElementSelector; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaleDependentMeasure.java b/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaleDependentMeasure.java index 89b677a..ba30fae 100644 --- a/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaleDependentMeasure.java +++ b/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaleDependentMeasure.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.evaluation.measures; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.util.FastElementSelector; import java.util.ArrayList; import java.util.HashSet; diff --git a/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaledErrorBasedMeasure.java b/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaledErrorBasedMeasure.java index 7b3f6e3..6364e30 100644 --- a/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaledErrorBasedMeasure.java +++ b/src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaledErrorBasedMeasure.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.evaluation.measures; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.util.FastElementSelector; import java.util.ArrayList; import java.util.Set; diff --git a/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorBegin.java b/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorBegin.java index aaf7b44..469280d 100644 --- a/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorBegin.java +++ b/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorBegin.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.util.Comparators; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.util.Comparator; /** diff --git a/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorEnd.java b/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorEnd.java index fc2b94f..b50414f 100644 --- a/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorEnd.java +++ b/src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorEnd.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.util.Comparators; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.util.Comparator; /** diff --git a/src/main/java/de/wwwu/awolf/presenter/util/IntersectionComputer.java b/src/main/java/de/wwwu/awolf/presenter/util/IntersectionComputer.java index 686108a..94f9e5e 100644 --- a/src/main/java/de/wwwu/awolf/presenter/util/IntersectionComputer.java +++ b/src/main/java/de/wwwu/awolf/presenter/util/IntersectionComputer.java @@ -1,8 +1,8 @@ package de.wwwu.awolf.presenter.util; import com.google.common.collect.Lists; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.Point; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.Point; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/de/wwwu/awolf/view/ViewController.java b/src/main/java/de/wwwu/awolf/view/ViewController.java index 84c8913..93703ae 100644 --- a/src/main/java/de/wwwu/awolf/view/ViewController.java +++ b/src/main/java/de/wwwu/awolf/view/ViewController.java @@ -1,8 +1,9 @@ package de.wwwu.awolf.view; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.Presenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; +import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler; import de.wwwu.awolf.presenter.data.DataHandler; import de.wwwu.awolf.presenter.util.Logging; import de.wwwu.awolf.view.controller.AlgorithmTabController; @@ -10,7 +11,6 @@ import de.wwwu.awolf.view.services.DataService; import java.io.File; import java.io.IOException; import java.util.EnumMap; -import java.util.HashMap; import java.util.Map; import javafx.application.Platform; import javafx.fxml.FXML; @@ -56,22 +56,15 @@ public class ViewController { } private void initTabbedPane() { - //TODO - Map props = new HashMap<>(); - props.put("sfsdf", "dsadasd"); - props.put("dfd", "dsadasd"); - props.put("sdfdsfg", "dsadasd"); - props.put("dsfsdfsdf", "dsadasd"); - + AlgorithmHandler algorithmHandler = Presenter.getInstance().getAlgorithmHandler(); try { for (Algorithm.Type value : Algorithm.Type.values()) { FXMLLoader loader = new FXMLLoader(); - loader.setLocation( - AlgorithmTabController.class.getResource("/views/AlgorithmTab.fxml")); + loader.setLocation(AlgorithmTabController.class.getResource("/views/AlgorithmTab.fxml")); Parent parent = loader.load(); AlgorithmTabController controller = loader.getController(); controller.setAlgorithmType(value); - controller.setProperties(props); + controller.setProperties(algorithmHandler.getAlgorithmParametersByType(value)); controller.setModel(Presenter.getInstance().getModel()); controller.init(); this.algorithmTabControllers.put(value, controller); diff --git a/src/main/java/de/wwwu/awolf/view/controller/AlgorithmTabController.java b/src/main/java/de/wwwu/awolf/view/controller/AlgorithmTabController.java index 1985a09..c7b79de 100644 --- a/src/main/java/de/wwwu/awolf/view/controller/AlgorithmTabController.java +++ b/src/main/java/de/wwwu/awolf/view/controller/AlgorithmTabController.java @@ -1,7 +1,7 @@ package de.wwwu.awolf.view.controller; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.LineModel; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.LineModel; import de.wwwu.awolf.presenter.algorithms.Algorithm; import de.wwwu.awolf.view.services.ButtonClickService; import java.util.Map; @@ -22,13 +22,14 @@ public class AlgorithmTabController { private final XYChart.Series dataSerie; private final XYChart.Series lineSerie; @FXML - public LineChart chart; + private LineChart chart; @FXML - public VBox vBox; + private VBox vBox; @FXML - public Button startButton; + private Button startButton; + private Algorithm.Type algorithmType; - private Map properties; + private Map properties; private LineModel model; public AlgorithmTabController() { @@ -48,25 +49,27 @@ public class AlgorithmTabController { public void init() { // add GUI elements to maintain the parameters - properties.forEach((key, value) -> { - //Pane component for the layout - BorderPane borderPane = new BorderPane(); - borderPane.setPadding(new Insets(10, 0, 10, 0)); + if (properties != null) { + properties.forEach((key, value) -> { + //Pane component for the layout + BorderPane borderPane = new BorderPane(); + borderPane.setPadding(new Insets(10, 0, 10, 0)); - //text field for the input - TextField textField = new TextField(value); + //text field for the input + TextField textField = new TextField(String.valueOf(value)); - //label - Label label = new Label(key); - label.setAlignment(Pos.BASELINE_LEFT); - label.setLabelFor(textField); - label.setPadding(new Insets(2, 10, 0, 0)); + //label + Label label = new Label(key); + label.setAlignment(Pos.BASELINE_LEFT); + label.setLabelFor(textField); + label.setPadding(new Insets(2, 10, 0, 0)); - //add components - borderPane.setLeft(label); - borderPane.setRight(textField); - vBox.getChildren().add(borderPane); - }); + //add components + borderPane.setLeft(label); + borderPane.setRight(textField); + vBox.getChildren().add(borderPane); + }); + } BooleanProperty booleanProperty = startButton.disableProperty(); startButton.setOnAction(event -> { @@ -107,13 +110,15 @@ public class AlgorithmTabController { this.algorithmType = algorithmType; } - public Map getProperties() { + public Map getProperties() { return properties; } - public void setProperties(Map properties) { + public void setProperties(Map properties) { this.properties = properties; } - + public Button getStartButton() { + return startButton; + } } diff --git a/src/main/java/de/wwwu/awolf/view/services/ButtonClickService.java b/src/main/java/de/wwwu/awolf/view/services/ButtonClickService.java index eb55b1d..00e1929 100644 --- a/src/main/java/de/wwwu/awolf/view/services/ButtonClickService.java +++ b/src/main/java/de/wwwu/awolf/view/services/ButtonClickService.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.view.services; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.Presenter; import de.wwwu.awolf.presenter.algorithms.Algorithm; import javafx.beans.property.BooleanProperty; @@ -12,7 +12,7 @@ public class ButtonClickService extends Service { private final BooleanProperty startButtonDisabled; private Algorithm.Type type; - public ButtonClickService(Algorithm.Type algorithmType, BooleanProperty startButtonDisabled) { + public ButtonClickService(final Algorithm.Type algorithmType, final BooleanProperty startButtonDisabled) { this.startButtonDisabled = startButtonDisabled; this.type = algorithmType; } diff --git a/src/main/java/de/wwwu/awolf/view/services/DataService.java b/src/main/java/de/wwwu/awolf/view/services/DataService.java index c6fe277..7486b52 100644 --- a/src/main/java/de/wwwu/awolf/view/services/DataService.java +++ b/src/main/java/de/wwwu/awolf/view/services/DataService.java @@ -13,8 +13,7 @@ public class DataService extends Service { private DataHandler.ActionType actionType; private int n; - public DataService(final DataHandler.ActionType actionType, final DataHandler.DataType type, - final int n) { + public DataService(final DataHandler.ActionType actionType, final DataHandler.DataType type, final int n) { this.type = type; this.actionType = actionType; this.n = n; diff --git a/src/main/resources/META-INF/services/de.wwwu.awolf.presenter.algorithms.Algorithm b/src/main/resources/META-INF/services/de.wwwu.awolf.presenter.algorithms.Algorithm index 0ac6867..4689741 100644 --- a/src/main/resources/META-INF/services/de.wwwu.awolf.presenter.algorithms.Algorithm +++ b/src/main/resources/META-INF/services/de.wwwu.awolf.presenter.algorithms.Algorithm @@ -1,6 +1,6 @@ de.wwwu.awolf.presenter.algorithms.advanced.LeastMedianOfSquaresEstimator de.wwwu.awolf.presenter.algorithms.advanced.RepeatedMedianEstimator de.wwwu.awolf.presenter.algorithms.advanced.TheilSenEstimator -de.wwwu.awolf.presenter.algorithms.naiv.NaivLeastMedianOfSquaresEstimator -de.wwwu.awolf.presenter.algorithms.naiv.NaivRepeatedMedianEstimator -de.wwwu.awolf.presenter.algorithms.naiv.NaivTheilSenEstimator \ No newline at end of file +de.wwwu.awolf.presenter.algorithms.naive.NaiveLeastMedianOfSquaresEstimator +de.wwwu.awolf.presenter.algorithms.naive.NaiveRepeatedMedianEstimator +de.wwwu.awolf.presenter.algorithms.naive.NaiveTheilSenEstimator \ No newline at end of file diff --git a/src/main/resources/views/AlgorithmTab.fxml b/src/main/resources/views/AlgorithmTab.fxml index d179ffb..265e38c 100644 --- a/src/main/resources/views/AlgorithmTab.fxml +++ b/src/main/resources/views/AlgorithmTab.fxml @@ -1,61 +1,54 @@ - - - - - - - - - + + + + + + +
- + - + - +
- + - + - + - + - + - + - diff --git a/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimatorTest.java b/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimatorTest.java index 44468aa..bc0908a 100644 --- a/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimatorTest.java +++ b/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimatorTest.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.algorithms.advanced; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import de.wwwu.awolf.presenter.algorithms.Algorithm; import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler; import java.util.HashSet; diff --git a/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimatorTest.java b/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimatorTest.java index b68b8aa..f785e0d 100644 --- a/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimatorTest.java +++ b/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimatorTest.java @@ -1,6 +1,6 @@ package de.wwwu.awolf.presenter.algorithms.advanced; -import de.wwwu.awolf.model.Line; +import de.wwwu.awolf.model.dao.Line; import java.util.LinkedList; import java.util.List; import org.junit.Before; diff --git a/src/test/java/de/wwwu/awolf/presenter/util/IntersectionCounterTest.java b/src/test/java/de/wwwu/awolf/presenter/util/IntersectionCounterTest.java index ebbea50..ee04834 100644 --- a/src/test/java/de/wwwu/awolf/presenter/util/IntersectionCounterTest.java +++ b/src/test/java/de/wwwu/awolf/presenter/util/IntersectionCounterTest.java @@ -2,8 +2,8 @@ package de.wwwu.awolf.presenter.util; import static org.junit.Assert.assertEquals; -import de.wwwu.awolf.model.Line; -import de.wwwu.awolf.model.LineModel; +import de.wwwu.awolf.model.dao.Line; +import de.wwwu.awolf.model.dao.LineModel; import java.util.ArrayList; import org.junit.Before; import org.junit.Test;