some refactoring

master
Armin Wolf 2 years ago
parent 219c0d92f4
commit b08291edbe
  1. 2
      .gitignore
  2. 1
      README.md
  3. 41
      build.gradle
  4. 1
      gradle.properties
  5. BIN
      gradle/wrapper/gradle-wrapper.jar
  6. 6
      gradle/wrapper/gradle-wrapper.properties
  7. 183
      gradlew
  8. 103
      gradlew.bat
  9. 4
      settings.gradle
  10. 61
      src/main/java/de/wwwu/awolf/App.java
  11. 79
      src/main/java/de/wwwu/awolf/model/Interval.java
  12. 297
      src/main/java/de/wwwu/awolf/model/Line.java
  13. 145
      src/main/java/de/wwwu/awolf/model/LineModel.java
  14. 54
      src/main/java/de/wwwu/awolf/model/Pair.java
  15. 119
      src/main/java/de/wwwu/awolf/model/Point.java
  16. 37
      src/main/java/de/wwwu/awolf/model/communication/AlgorithmData.java
  17. 8
      src/main/java/de/wwwu/awolf/model/communication/Data.java
  18. 77
      src/main/java/de/wwwu/awolf/model/communication/EvaluationData.java
  19. 43
      src/main/java/de/wwwu/awolf/model/communication/GeneratorData.java
  20. 34
      src/main/java/de/wwwu/awolf/model/communication/ImportData.java
  21. 13
      src/main/java/de/wwwu/awolf/model/communication/SubscriberType.java
  22. 16
      src/main/java/de/wwwu/awolf/model/communication/TypeData.java
  23. 24
      src/main/java/de/wwwu/awolf/model/evaluation/ComparisonResult.java
  24. 168
      src/main/java/de/wwwu/awolf/presenter/AbstractPresenter.java
  25. 134
      src/main/java/de/wwwu/awolf/presenter/Presenter.java
  26. 49
      src/main/java/de/wwwu/awolf/presenter/algorithms/Algorithm.java
  27. 97
      src/main/java/de/wwwu/awolf/presenter/algorithms/AlgorithmHandler.java
  28. 467
      src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimator.java
  29. 356
      src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/RepeatedMedianEstimator.java
  30. 248
      src/main/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimator.java
  31. 143
      src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivLeastMedianOfSquaresEstimator.java
  32. 165
      src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivRepeatedMedianEstimator.java
  33. 114
      src/main/java/de/wwwu/awolf/presenter/algorithms/naiv/NaivTheilSenEstimator.java
  34. 89
      src/main/java/de/wwwu/awolf/presenter/data/DataHandler.java
  35. 63
      src/main/java/de/wwwu/awolf/presenter/data/generator/CircleDatasetGenerator.java
  36. 53
      src/main/java/de/wwwu/awolf/presenter/data/generator/CloudDatasetGenerator.java
  37. 67
      src/main/java/de/wwwu/awolf/presenter/data/generator/DatasetGenerator.java
  38. 35
      src/main/java/de/wwwu/awolf/presenter/data/generator/LineDatasetGenerator.java
  39. 61
      src/main/java/de/wwwu/awolf/presenter/data/io/DataExporter.java
  40. 88
      src/main/java/de/wwwu/awolf/presenter/data/io/DataImporter.java
  41. 48
      src/main/java/de/wwwu/awolf/presenter/evaluation/AlgorithmComparison.java
  42. 282
      src/main/java/de/wwwu/awolf/presenter/evaluation/EvaluatationHandler.java
  43. 111
      src/main/java/de/wwwu/awolf/presenter/evaluation/measures/PercentageErrorBasedMeasure.java
  44. 90
      src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaleDependentMeasure.java
  45. 108
      src/main/java/de/wwwu/awolf/presenter/evaluation/measures/ScaledErrorBasedMeasure.java
  46. 33
      src/main/java/de/wwwu/awolf/presenter/util/BinomialCoeffizient.java
  47. 19
      src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorBegin.java
  48. 19
      src/main/java/de/wwwu/awolf/presenter/util/Comparators/YOrderLineComparatorEnd.java
  49. 95
      src/main/java/de/wwwu/awolf/presenter/util/FastElementSelector.java
  50. 173
      src/main/java/de/wwwu/awolf/presenter/util/IntersectionComputer.java
  51. 50
      src/main/java/de/wwwu/awolf/presenter/util/Logging.java
  52. 44
      src/main/java/de/wwwu/awolf/presenter/util/RandomSampler.java
  53. 213
      src/main/java/de/wwwu/awolf/view/ViewController.java
  54. 119
      src/main/java/de/wwwu/awolf/view/controller/AlgorithmTabController.java
  55. 39
      src/main/java/de/wwwu/awolf/view/services/ButtonClickService.java
  56. 51
      src/main/java/de/wwwu/awolf/view/services/DataService.java
  57. 28
      src/main/java/de/wwwu/awolf/view/services/GuiRegisterService.java
  58. 6
      src/main/resources/META-INF/services/de.wwwu.awolf.presenter.algorithms.Algorithm
  59. BIN
      src/main/resources/Thumbs.db
  60. BIN
      src/main/resources/icons/export.png
  61. BIN
      src/main/resources/icons/frame-2.png
  62. BIN
      src/main/resources/icons/frame.png
  63. BIN
      src/main/resources/icons/generate.png
  64. BIN
      src/main/resources/icons/import.png
  65. BIN
      src/main/resources/icons/plot.png
  66. BIN
      src/main/resources/icons/start.png
  67. BIN
      src/main/resources/icons/wwu.png
  68. 14
      src/main/resources/log4j.properties
  69. 340
      src/main/resources/style/style.css
  70. 64
      src/main/resources/views/AlgorithmTab.fxml
  71. 22
      src/main/resources/views/MainFrame.fxml
  72. 37
      src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimatorTest.java
  73. 31
      src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/TheilSenEstimatorTest.java
  74. 33
      src/test/java/de/wwwu/awolf/presenter/util/FastElementSelectorTest.java
  75. 40
      src/test/java/de/wwwu/awolf/presenter/util/IntersectionCounterTest.java

2
.gitignore vendored

@ -15,7 +15,7 @@
log/
target/
# Ignore Gradle project-specific cache directory
.gradle
.gradle/
# Ignore Gradle build output directory
build

@ -0,0 +1 @@
# README #

@ -0,0 +1,41 @@
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
id 'java'
id "org.sonarqube" version "2.7"
}
apply plugin: 'org.sonarqube'
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri('http://repo.maven.apache.org/maven2')
}
}
dependencies {
implementation 'junit:junit:4.12'
implementation 'commons-io:commons-io:2.5'
implementation 'log4j:log4j:1.2.17'
implementation 'org.apache.logging.log4j:log4j-core:2.13.1'
implementation 'com.opencsv:opencsv:5.1'
implementation 'com.google.guava:guava:28.2-jre'
implementation 'org.powermock:powermock-core:2.0.6'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
}
group = 'de.wwu.awolf'
version = '1.0.0'
sourceCompatibility = '11'
sonarqube {
properties {
property "sonar.projectName", "${rootProject.name}"
property "sonar.projectKey", "${project.group}:${rootProject.name}"
}
}

@ -0,0 +1 @@
systemProp.sonar.host.url=http://192.168.0.158:9000

Binary file not shown.

@ -0,0 +1,6 @@
#Wed Mar 25 19:04:29 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

183
gradlew vendored

@ -0,0 +1,183 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

103
gradlew.bat vendored

@ -0,0 +1,103 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

@ -0,0 +1,4 @@
/*
* This file was generated by the Gradle 'init' task.
*/
rootProject.name = 'linreg-tool'

@ -0,0 +1,61 @@
package de.wwwu.awolf;
import de.wwwu.awolf.presenter.util.Logging;
import de.wwwu.awolf.view.ViewController;
import de.wwwu.awolf.view.services.GuiRegisterService;
import java.io.IOException;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class App extends Application {
private static final String TITLE = "Algorithmen zur Berechnung von Ausgleichsgeraden";
/**
* Maim Methode
*
* @param argv
*/
public static void main(String[] argv) {
Logging.logDebug("Start ....");
Application.launch(App.class, argv);
}
@Override
public void start(Stage primaryStage) throws Exception {
Platform.runLater(() -> {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
ViewController.class.getResource("/views/MainFrame.fxml"));
Parent pane = fxmlLoader.load();
//register at presenter
new GuiRegisterService(fxmlLoader.getController()).start();
primaryStage.setTitle(TITLE);
Scene scene = new Scene(pane, 1200, 900);
scene.getStylesheets()
.add(ViewController.class.getResource("/style/style.css")
.toExternalForm());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(e -> {
Platform.exit();
System.exit(0);
});
primaryStage.show();
} catch (IOException e) {
Logging.logError("Error reading FXML file. ", e);
}
});
}
}

@ -0,0 +1,79 @@
package de.wwwu.awolf.model;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 16.06.2017.
*/
public class Interval {
private double upper;
private double lower;
private Boolean activity;
/**
* Konstruktor
*
* @param lower untere Schranke
* @param upper obere Schranke
*/
public Interval(double lower, double upper) {
this.upper = upper;
this.lower = lower;
this.activity = true;
}
/**
* @return <code>true</code> falls das Intervall aktiv ist
*/
public Boolean getActivity() {
return activity;
}
/**
* @param isActive <code>true</code> falls das Intervall als aktiv gesetzt werden soll
*/
public void setActivity(Boolean isActive) {
this.activity = isActive;
}
/**
* @return obere Schranke des Intervalls
*/
public double getUpper() {
return upper;
}
/**
* @param upper obere Schranke des Intervalls
*/
public void setUpper(double upper) {
this.upper = upper;
}
/**
* @return untere Schranke des Intervalls
*/
public double getLower() {
return lower;
}
/**
* @param lower untere Schranke des Intervalls
*/
public void setLower(double lower) {
this.lower = lower;
}
/**
* Berechnet die Distanz zwischen der oberen und unteren Schranke
*
* @return Distanz
*/
public Double getDistance() {
return Math.abs(this.upper - this.lower);
}
}

@ -0,0 +1,297 @@
package de.wwwu.awolf.model;
import java.util.Objects;
import org.apache.commons.math3.util.Precision;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 12.06.2017.
*/
public class Line implements Comparable<Line> {
private static final double EPSILON = 0.00001;
private static final double MIN = 9999d;
private static final double MAX = -9999d;
private Double m;
private Double b;
private Double x1;
private Double x2;
private Double y1;
private Double y2;
private String id;
/**
* Konstruktor
*
* @param m Steigung
* @param b y-Achsenabschnitt
* @param id id
*/
public Line(double m, double b, String id) {
this.m = m;
this.b = b;
this.x1 = MAX;
this.y1 = (MAX * m) + b;
this.x2 = MIN * 0.5;
this.y2 = ((MIN * 0.5) * m) + b;
this.id = id;
}
/**
* Konstruktor
*
* @param m Steigung
* @param b y-Achsenabschnitt
*/
public Line(double m, double b) {
this.m = m;
this.b = b;
this.x1 = calculateX1(MAX);
this.y1 = calculateY1(MAX);
this.x2 = calculateX2(MIN * 0.5);
this.y2 = calculateY2(MIN * 0.5);
}
/**
* Konstruktor
*
* @param x1 x-Koordiante des Startpunkts
* @param x2 x-Koordinate des Endpunkts
* @param y1 y-Koordinate des Startpunkts
* @param y2 y-Koordinate des Endpunkts
*/
public Line(double x1, double x2, double y1, double y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.m = (y2 - y1) / (x2 - x1);
this.b = y2 - (x2 * m);
}
public Double calculateX1(Double min) {
return min;
}
public Double calculateY1(Double min) {
return (min * (m * -1)) + b;
}
public Double calculateX2(Double max) {
return max;
}
public Double calculateY2(Double max) {
return (max * (m * -1)) + b;
}
/**
* @return Steigung der Gerade
*/
public Double getM() {
return m;
}
/**
* @param m Steigung der Gerade
*/
public void setM(double m) {
this.m = m;
}
/**
* @return y-Achsenabschnitt der Gerade
*/
public Double getB() {
return b;
}
/**
* @param b y-Achsenabschnitt der Gerade
*/
public void setB(double b) {
this.b = b;
}
/**
* @return id der Gerade
*/
public String getId() {
return id;
}
/**
* @param id id der Gerade
*/
public void setId(String id) {
this.id = id;
}
/**
* @return x-Koordiante des Startpunkts
*/
public Double getX1() {
return x1;
}
/**
* @return x-Koordiante des Endpunkts
*/
public Double getX2() {
return x2;
}
/**
* @return y-Koordiante des Startpunkts
*/
public Double getY1() {
return y1;
}
/**
* @return y-Koordiante des Endpunkts
*/
public Double getY2() {
return y2;
}
/**
* Setzt die Koordianten des Segments. Aus dem Segment wird eine Gerade berechnet.
*
* @param x1 x-Koordiante des Startpunkts
* @param y1 y-Koordiante des Endpunkts
* @param x2 x-Koordinate des Startpunkts
* @param y2 y-Koordinte des Endpunkts
*/
public void setEndPoints(double x1, double y1, double x2, double y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.m = (y2 - y1) / (x2 - x1);
this.b = y2 - (x2 * m);
}
/**
* Vergleich einzelner Geradern
*
* @param obj zu vergleichende Gerade
* @return <code>true</code> falls die Geraden Gleich sind
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof Line) {
Line other = (Line) obj;
return Precision.equals(other.getM(), this.getM(), EPSILON) && Precision
.equals(other.getB(), this.getB(), EPSILON);
} else {
return super.equals(obj);
}
}
@Override
public int hashCode() {
return Objects.hash(Precision.round(m, 5), Precision.round(b, 5));
}
@Override
public String toString() {
return "Line m: " + this.getM() + ", b: " + this.getB();
}
public Point intersect(Line line) {
double x = (line.b - this.b) / (this.m - line.m);
double y = this.m * x + this.b;
return new Point(x, y);
}
// Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
public boolean onSegment(Point p, Point q, Point r) {
return q.getX() <= Math.max(p.getX(), r.getX()) && q.getX() >= Math
.min(p.getX(), r.getX()) &&
q.getY() <= Math.max(p.getY(), r.getY()) && q.getY() >= Math
.min(p.getY(), r.getY());
}
// To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
public int orientation(Point p, Point q, Point r) {
// See https://www.geeksforgeeks.org/orientation-3-ordered-points/
// for details of below formula.
double val = (q.getY() - p.getY()) * (r.getX() - q.getX()) -
(q.getX() - p.getX()) * (r.getY() - q.getY());
if (val == 0) {
return 0; // colinear
}
return (val > 0) ? 1 : 2; // clock or counterclock wise
}
// The main function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
// Line A: y = mx + b -->
public boolean doIntersect(Line line, double lower, double upper) {
//this
Point p1 = new Point(calculateX1(lower), calculateY1(lower));
Point q1 = new Point(calculateX2(upper), calculateY2(upper));
Point p2 = new Point(line.calculateX1(lower), line.calculateY1(lower));
Point q2 = new Point(line.calculateX2(upper), line.calculateY2(upper));
// Find the four orientations needed for general and
// special cases
int o1 = orientation(p1, q1, p2);
int o2 = orientation(p1, q1, q2);
int o3 = orientation(p2, q2, p1);
int o4 = orientation(p2, q2, q1);
// General case
if (o1 != o2 && o3 != o4) {
return true;
}
// Special Cases
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
if (o1 == 0 && onSegment(p1, p2, q1)) {
return true;
}
// p1, q1 and q2 are colinear and q2 lies on segment p1q1
if (o2 == 0 && onSegment(p1, q2, q1)) {
return true;
}
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
if (o3 == 0 && onSegment(p2, p1, q2)) {
return true;
}
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
return o4 == 0 && onSegment(p2, q1, q2);// Doesn't fall in any of the above cases
}
@Override
public int compareTo(Line line) {
if (Precision.compareTo(this.getM(), line.getM(), EPSILON) == 0) {
return this.getB().compareTo(line.getB());
} else {
return this.getM().compareTo(line.getM());
}
}
}

@ -0,0 +1,145 @@
package de.wwwu.awolf.model;
import java.util.HashSet;
import java.util.Set;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class LineModel {
private Double max;
private Double min;
private Set<Line> lines;
private Double xMinimum;
private Double xMaximum;
private Double yMinimum;
private Double yMaximum;
private int size;
/**
* Konstruktor
*/
public LineModel() {
lines = new HashSet<>();
size = 0;
xMinimum = Double.MAX_VALUE;
xMaximum = Double.MIN_VALUE;
yMinimum = Double.MAX_VALUE;
yMaximum = Double.MIN_VALUE;
min = 0d;
max = 0d;
}
/**
* Fügt eine Gerade zu dem Modell hinzu
*
* @param line Gerade
*/
public void addLine(Line line) {
this.lines.add(line);
min = line.getM() <= min ? line.getM() : min;
max = line.getM() >= max ? line.getM() : max;
}
public Double getMin() {
return min;
}
public Double getMax() {
return max;
}
/**
* @return Liste der Geraden
*/
public Set<Line> getLines() {
return lines;
}
/**
* @param lines Liste der Geraden
*/
public void setLines(Set<Line> lines) {
lines.forEach(this::addLine);
this.size = lines.size();
}
/**
* @return Minimale x-Koordiante
*/
public Double getxMinimum() {
return xMinimum;
}
/**
* @param xMinimum Minimale x-Koordiante
*/
public void setxMinimum(Double xMinimum) {
this.xMinimum = xMinimum;
}
/**
* @return Maximale x-Koordiante
*/
public Double getxMaximum() {
return xMaximum;
}
/**
* @param xMaximum Maximale x-Koordiante
*/
public void setxMaximum(Double xMaximum) {
this.xMaximum = xMaximum;
}
/**
* @return Minimale y-Koordiante
*/
public Double getyMinimum() {
return yMinimum;
}
/**
* @param yMinimum Minimale y-Koordiante
*/
public void setyMinimum(Double yMinimum) {
this.yMinimum = yMinimum;
}
/**
* @return Maximale y-Koordiante
*/
public Double getyMaximum() {
return yMaximum;
}
/**
* @param yMaximum Maximale y-Koordiante
*/
public void setyMaximum(Double yMaximum) {
this.yMaximum = yMaximum;
}
/**
* Setzt die minimalen, maximalen x- und y-Koordinaten
*/
public void resetRanges() {
xMinimum = Double.MAX_VALUE;
xMaximum = Double.MIN_VALUE;
yMinimum = Double.MAX_VALUE;
yMaximum = Double.MIN_VALUE;
}
public int getSize() {
return size;
}
}

@ -0,0 +1,54 @@
package de.wwwu.awolf.model;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 19.06.2017.
*/
public class Pair {
private Integer p1;
private Integer p2;
/**
* Konstruktor
*
* @param p1 erstes Element des Tupels
* @param p2 zweites Element des Tupels
*/
public Pair(Integer p1, Integer p2) {
this.p1 = p1;
this.p2 = p2;
}
/**
* @return erstes Element des Tupels
*/
public Integer getP1() {
return p1;
}
/**
* @param p1 erstes Element des Tupels
*/
public void setP1(Integer p1) {
this.p1 = p1;
}
/**
* @return zweites Element des Tupels
*/
public Integer getP2() {
return p2;
}
/**
* @param p2 zweites Element des Tupels
*/
public void setP2(Integer p2) {
this.p2 = p2;
}
}

@ -0,0 +1,119 @@
package de.wwwu.awolf.model;
import java.util.Objects;
import org.apache.commons.math3.util.Precision;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class Point implements Comparable<Point> {
private static final double EPSILON = 0.00001;
private Double x;
private Double y;
private String id;
/**
* Konstruktor
*
* @param x x-Koordiante
* @param y y-Koordiante
*/
public Point(Double x, Double y) {
this.x = x;
this.y = y;
}
/**
* Konstruktor
*
* @param x x-Koordiante
* @param y y-Koordiante
* @param id id des Punkts
*/
public Point(Double x, Double y, String id) {
this.x = x;
this.y = y;
this.id = id;
}
/**
* @return x-Koordinate des Punkts
*/
public Double getX() {
return x;
}
/**
* @param x x-Koordinate des Punkts
*/
public void setX(Double x) {
this.x = x;
}
/**
* @return y-Koordinate des Punkts
*/
public Double getY() {
return y;
}
/**
* @param y y-Koordinate des Punkts
*/
public void setY(Double y) {
this.y = y;
}
@Override
public int compareTo(Point o) {
if (Precision.compareTo(this.getX(), o.getX(), EPSILON) == 0) {
return this.getY().compareTo(o.getY());
} else {
return this.getX().compareTo(o.getX());
}
}
/**
* Vergleich zweier Punkte
*
* @param obj zu vergleichernder Punkt
* @return <code>true</code> falls die Punkte gleich sind
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof Point) {
Point other = (Point) obj;
return Precision.equals(other.getX(), this.getX(), EPSILON) && Precision
.equals(other.getY(), this.getY(), EPSILON);
} else {
return super.equals(obj);
}
}
@Override
public int hashCode() {
return Objects.hash(Precision.round(x, 5), Precision.round(y, 5));
}
/**
* @return id des Punkts
*/
public String getId() {
return id;
}
/**
* @param id id des Punkts
*/
public void setId(String id) {
this.id = id;
}
}

@ -0,0 +1,37 @@
package de.wwwu.awolf.model.communication;
import de.wwwu.awolf.model.Line;
import de.wwwu.awolf.presenter.algorithms.Algorithm;
public class AlgorithmData implements Data {
private SubscriberType type;
private Algorithm.Type algorithmType;
private Line lineData;
public Algorithm.Type getAlgorithmType() {
return algorithmType;
}
public void setAlgorithmType(Algorithm.Type algorithmType) {
this.algorithmType = algorithmType;
}
@Override
public SubscriberType getType() {
return type;
}
@Override
public void setType(SubscriberType type) {
this.type = type;
}
public Line getLineData() {
return lineData;
}
public void setLineData(Line lineData) {
this.lineData = lineData;
}
}

@ -0,0 +1,8 @@
package de.wwwu.awolf.model.communication;
public interface Data {
SubscriberType getType();
void setType(SubscriberType type);
}

@ -0,0 +1,77 @@
package de.wwwu.awolf.model.communication;
import de.wwwu.awolf.presenter.algorithms.Algorithm;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public class EvaluationData implements Data {
private SubscriberType type;
private List<Algorithm.Type> algorithmtypes;
private List<Serializable> oneColumnresult;
private Map<Algorithm.Type, Map<String, String>> multipleColumnResult;
private int rowsPerColumn;
private int column;
private List<String> labels;
public int getRowsPerColumn() {
return rowsPerColumn;
}
public void setRowsPerColumn(int rowsPerColumn) {
this.rowsPerColumn = rowsPerColumn;
}
public int getColumn() {
return column;
}
public void setColumn(int col) {
this.column = col;
}
public List<String> getLabels() {
return labels;
}
public void setLabels(List<String> tableInput) {
this.labels = tableInput;
}
public List<Algorithm.Type> getAlgorithmtypes() {
return algorithmtypes;
}
public void setAlgorithmtypes(List<Algorithm.Type> algorithmtype) {
this.algorithmtypes = algorithmtype;
}
public List<Serializable> getOneColumnresult() {
return oneColumnresult;
}
public void setOneColumnresult(List<Serializable> oneColumnresult) {
this.oneColumnresult = oneColumnresult;
}
public Map<Algorithm.Type, Map<String, String>> getMultipleColumnResult() {
return multipleColumnResult;
}
public void setMultipleColumnResult(
Map<Algorithm.Type, Map<String, String>> multipleColumnResult) {
this.multipleColumnResult = multipleColumnResult;
}
@Override
public SubscriberType getType() {
return type;
}
@Override
public void setType(SubscriberType type) {
this.type = type;
}
}

@ -0,0 +1,43 @@
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;
}
}

@ -0,0 +1,34 @@
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;
}
}

@ -0,0 +1,13 @@
package de.wwwu.awolf.model.communication;
public enum SubscriberType {
EVAL_D,
EVALUATION_TABLE_DATA,
EVAL_T,
LINES_RES,
LINES_RES_MULT,
ALGORITHM,
PICTURE,
GENERATOR
}

@ -0,0 +1,16 @@
package de.wwwu.awolf.model.communication;
public class TypeData implements Data {
private SubscriberType type;
@Override
public SubscriberType getType() {
return type;
}
@Override
public void setType(SubscriberType type) {
this.type = type;
}
}

@ -0,0 +1,24 @@
package de.wwwu.awolf.model.evaluation;
import de.wwwu.awolf.model.Line;
import de.wwwu.awolf.presenter.algorithms.Algorithm;
import java.util.EnumMap;
import java.util.Map;
public class ComparisonResult {
private final Map<Algorithm.Type, Line> resultMapping;
public ComparisonResult() {
this.resultMapping = new EnumMap<>(Algorithm.Type.class);
}
public void put(final Algorithm.Type type, final Line lineResult) {
this.resultMapping.put(type, lineResult);
}
public Line get(final Algorithm.Type type) {
return this.resultMapping.get(type);
}
}

@ -0,0 +1,168 @@
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.presenter.algorithms.Algorithm;
import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler;
import de.wwwu.awolf.presenter.data.DataHandler;
import de.wwwu.awolf.presenter.evaluation.EvaluatationHandler;
import de.wwwu.awolf.presenter.util.Logging;
import de.wwwu.awolf.view.ViewController;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
/**
* 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;
private ViewController view;
private EvaluatationHandler evaluatationHandler;
private DataHandler dataHandler;
private AlgorithmHandler algorithmHandler;
/**
* Konstruktor
*/
public AbstractPresenter() {