2020-03-21 00:37:09 +00:00
|
|
|
package de.wwwu.awolf.presenter;
|
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
import de.wwwu.awolf.model.Line;
|
2020-03-21 00:37:09 +00:00
|
|
|
import de.wwwu.awolf.model.LineModel;
|
|
|
|
import de.wwwu.awolf.model.communication.Data;
|
2020-03-28 15:24:35 +00:00
|
|
|
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.evaluation.EvaluatationHandler;
|
2020-03-21 00:37:09 +00:00
|
|
|
import de.wwwu.awolf.presenter.util.Logging;
|
2020-03-28 15:24:35 +00:00
|
|
|
import de.wwwu.awolf.view.ViewController;
|
|
|
|
import javafx.application.Platform;
|
2020-03-21 00:37:09 +00:00
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Set;
|
2020-03-21 00:37:09 +00:00
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Flow;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
|
|
*
|
|
|
|
* @Author: Armin Wolf
|
|
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
|
|
* @Date: 10.09.2017.
|
|
|
|
*/
|
|
|
|
public abstract class AbstractPresenter implements Flow.Subscriber<Data> {
|
|
|
|
|
|
|
|
private final ExecutorService executor;
|
|
|
|
private LineModel model;
|
2020-03-28 15:24:35 +00:00
|
|
|
private ViewController view;
|
|
|
|
private EvaluatationHandler evaluatationHandler;
|
|
|
|
private DataHandler dataHandler;
|
|
|
|
private AlgorithmHandler algorithmHandler;
|
|
|
|
|
2020-03-21 00:37:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Konstruktor
|
|
|
|
*/
|
2020-03-23 20:58:39 +00:00
|
|
|
public AbstractPresenter() {
|
2020-03-28 15:24:35 +00:00
|
|
|
Logging.logDebug("Create instance of Presenter.");
|
|
|
|
this.executor = Executors.newCachedThreadPool();
|
|
|
|
this.dataHandler = new DataHandler(this);
|
|
|
|
this.algorithmHandler = AlgorithmHandler.getInstance();
|
|
|
|
//empty model
|
|
|
|
this.model = new LineModel();
|
|
|
|
//init values null
|
|
|
|
this.view = null;
|
2020-03-21 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSubscribe(Flow.Subscription subscription) {
|
|
|
|
Logging.logInfo("New Subscription: " + subscription.toString());
|
|
|
|
subscription.request(15);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNext(Data data) {
|
|
|
|
switch (data.getType()) {
|
2020-03-21 19:54:03 +00:00
|
|
|
case EVALUATION_TABLE_DATA:
|
2020-03-21 00:37:09 +00:00
|
|
|
evaluatedDatas(data);
|
|
|
|
break;
|
|
|
|
case LMS:
|
|
|
|
visualizeLmsAlgorithm(data);
|
|
|
|
break;
|
|
|
|
case RM:
|
|
|
|
visualizeRmAlgorithm(data);
|
|
|
|
break;
|
|
|
|
case TS:
|
|
|
|
visualizeTsAlgorithm(data);
|
|
|
|
break;
|
|
|
|
case GENERATOR:
|
|
|
|
Logging.logInfo("Generierung war Erfolgreich");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract void visualizeTsAlgorithm(Data data);
|
|
|
|
|
|
|
|
protected abstract void visualizeRmAlgorithm(Data data);
|
|
|
|
|
|
|
|
protected abstract void visualizeLmsAlgorithm(Data data);
|
|
|
|
|
|
|
|
protected abstract void evaluatedDatas(Data data);
|
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
|
2020-03-21 00:37:09 +00:00
|
|
|
@Override
|
|
|
|
public void onError(Throwable throwable) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onComplete() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-28 15:24:35 +00:00
|
|
|
* Execute an algorithm specified by a type
|
|
|
|
*
|
|
|
|
* @param type algorithm type
|
|
|
|
* @param lines set of lines
|
2020-03-21 00:37:09 +00:00
|
|
|
*/
|
2020-03-28 15:24:35 +00:00
|
|
|
public void executeAlgorithmByType(Algorithm.Type type, Set<Line> lines) {
|
|
|
|
this.algorithmHandler.runAlgorithmByType(type, lines);
|
2020-03-21 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-28 15:24:35 +00:00
|
|
|
* Execute an algorithm specified by a type
|
|
|
|
* (use the Lines from the LineModel)
|
|
|
|
*
|
|
|
|
* @param type algorithm type
|
|
|
|
*/
|
|
|
|
public void executeAlgorithmByType(Algorithm.Type type) {
|
|
|
|
if (getModel().getSize() == 0) {
|
|
|
|
Logging.logDebug("No lines in the Model. Nothing to calculate.");
|
|
|
|
} else {
|
|
|
|
Logging.logDebug("AlgorithmHandler will start " + type.getName() + ", with " + getModel().getSize());
|
|
|
|
this.algorithmHandler.runAlgorithmByType(type, getModel().getLines());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return das zu grunde legende Modell
|
2020-03-21 00:37:09 +00:00
|
|
|
*/
|
2020-03-28 15:24:35 +00:00
|
|
|
public LineModel getModel() {
|
|
|
|
return model;
|
2020-03-21 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return die zu grunde legende View
|
|
|
|
*/
|
2020-03-28 15:24:35 +00:00
|
|
|
public ViewController getView() {
|
2020-03-21 00:37:09 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param view die zu grunde legende View
|
|
|
|
*/
|
2020-03-28 15:24:35 +00:00
|
|
|
public void registerView(ViewController view) {
|
2020-03-21 00:37:09 +00:00
|
|
|
this.view = view;
|
2020-03-28 15:24:35 +00:00
|
|
|
Logging.enableGuiLogging();
|
|
|
|
Logging.logDebug("View has been set.");
|
2020-03-21 00:37:09 +00:00
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
|
|
|
|
//customize gui
|
|
|
|
Platform.runLater(() -> {
|
|
|
|
this.view.initGui();
|
|
|
|
});
|
2020-03-21 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-28 15:24:35 +00:00
|
|
|
* @return Evaluation
|
2020-03-21 00:37:09 +00:00
|
|
|
*/
|
2020-03-28 15:24:35 +00:00
|
|
|
EvaluatationHandler getEvaluatationHandler() {
|
|
|
|
return evaluatationHandler;
|
2020-03-21 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
DataHandler getDataHandler() {
|
|
|
|
return dataHandler;
|
2020-03-21 19:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
/**
|
|
|
|
* Returns the instance of the ExecutorService
|
|
|
|
*
|
|
|
|
* @return ExecutorService instance
|
|
|
|
*/
|
2020-03-21 00:37:09 +00:00
|
|
|
public ExecutorService getExecutor() {
|
2020-03-28 15:24:35 +00:00
|
|
|
return Objects.requireNonNullElseGet(executor, Executors::newCachedThreadPool);
|
2020-03-21 00:37:09 +00:00
|
|
|
}
|
|
|
|
}
|