Skip to content
Snippets Groups Projects
Commit 8a815671 authored by Matias Mennecart's avatar Matias Mennecart
Browse files

Ajouts selections des points et quelques améliorations

parent a8a96c3f
No related branches found
No related tags found
No related merge requests found
...@@ -4,13 +4,11 @@ import fr.univlille.sae.classification.model.ClassificationModel; ...@@ -4,13 +4,11 @@ import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.model.Iris; import fr.univlille.sae.classification.model.Iris;
import fr.univlille.sae.classification.view.MainStageView; import fr.univlille.sae.classification.view.MainStageView;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.*;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextFormatter;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
public class AddDataController { public class AddDataController {
...@@ -57,6 +55,8 @@ public class AddDataController { ...@@ -57,6 +55,8 @@ public class AddDataController {
public void validate() throws IOException { public void validate() throws IOException {
System.out.println("validé"); System.out.println("validé");
mainStageView.getController().getClassifyData().setDisable(false); mainStageView.getController().getClassifyData().setDisable(false);
ClassificationModel.getClassificationModel().ajouterDonnee(sepalLengthSpinner.getValue(), sepalWidthSpinner.getValue(), petalLengthSpinner.getValue(), petalWidthSpinner.getValue()); ClassificationModel.getClassificationModel().ajouterDonnee(sepalLengthSpinner.getValue(), sepalWidthSpinner.getValue(), petalLengthSpinner.getValue(), petalWidthSpinner.getValue());
stage.close(); stage.close();
} }
......
...@@ -42,6 +42,8 @@ public class AxesSettingsController{ ...@@ -42,6 +42,8 @@ public class AxesSettingsController{
public void validate(){ public void validate(){
mainStageView.setActualX(selectAbs.getValue().toString()); mainStageView.setActualX(selectAbs.getValue().toString());
mainStageView.setActualY(selectOrd.getValue().toString()); mainStageView.setActualY(selectOrd.getValue().toString());
mainStageView.getController().getScatterChart().getXAxis().setLabel(mainStageView.getActualX());
mainStageView.getController().getScatterChart().getYAxis().setLabel(mainStageView.getActualY());
mainStageView.update(ClassificationModel.getClassificationModel()); mainStageView.update(ClassificationModel.getClassificationModel());
stage.close(); stage.close();
......
...@@ -84,6 +84,7 @@ public class MainStageController { ...@@ -84,6 +84,7 @@ public class MainStageController {
public void classifyDatas() { public void classifyDatas() {
ClassificationModel.getClassificationModel().classifierDonnees(); ClassificationModel.getClassificationModel().classifierDonnees();
classifyData.setDisable(true);
} }
......
...@@ -9,6 +9,8 @@ import java.io.IOException; ...@@ -9,6 +9,8 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
public class ClassificationModel extends Observable { public class ClassificationModel extends Observable {
...@@ -39,7 +41,7 @@ public class ClassificationModel extends Observable { ...@@ -39,7 +41,7 @@ public class ClassificationModel extends Observable {
private ClassificationModel(DataType type) { private ClassificationModel(DataType type) {
this.datas = new ArrayList<>(); this.datas = new ArrayList<>();
this.dataToClass = new ArrayList<>(); this.dataToClass = new CopyOnWriteArrayList<>();
this.type = type; this.type = type;
} }
...@@ -90,6 +92,7 @@ public class ClassificationModel extends Observable { ...@@ -90,6 +92,7 @@ public class ClassificationModel extends Observable {
Random rdm = new Random(); Random rdm = new Random();
data.setClassification(classes.get(rdm.nextInt(classes.size()))); data.setClassification(classes.get(rdm.nextInt(classes.size())));
notifyObservers(data); notifyObservers(data);
dataToClass.remove(data);
} }
......
...@@ -7,19 +7,20 @@ import java.util.Random; ...@@ -7,19 +7,20 @@ import java.util.Random;
public class Iris extends LoadableData{ public class Iris extends LoadableData{
@CsvBindByName(column = "sepal.width")
private double sepalWidth;
@CsvBindByName(column = "sepal.length") @CsvBindByName(column = "sepal.length")
private double sepalLength; private double sepalLength;
@CsvBindByName(column = "petal.width") @CsvBindByName(column = "sepal.width")
private double petalWidth; private double sepalWidth;
@CsvBindByName(column = "petal.length") @CsvBindByName(column = "petal.length")
private double petalLength; private double petalLength;
@CsvBindByName(column = "petal.width")
private double petalWidth;
@CsvBindByName(column = "variety") @CsvBindByName(column = "variety")
private String variety; private String variety;
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength) { public Iris(double sepalLength, double sepalWidth, double petalLength, double petalWidth) {
this(sepalWidth, sepalLength, petalWidth, petalLength, "undefined"); this(sepalLength, sepalWidth, petalLength, petalWidth, "undefined");
} }
public Iris() { public Iris() {
...@@ -36,7 +37,7 @@ public class Iris extends LoadableData{ ...@@ -36,7 +37,7 @@ public class Iris extends LoadableData{
this.variety = classification; this.variety = classification;
} }
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength, String variety) { public Iris(double sepalLength, double sepalWidth, double petalLength, double petalWidth, String variety) {
super(); super();
this.sepalWidth = sepalWidth; this.sepalWidth = sepalWidth;
this.sepalLength = sepalLength; this.sepalLength = sepalLength;
...@@ -92,10 +93,10 @@ public class Iris extends LoadableData{ ...@@ -92,10 +93,10 @@ public class Iris extends LoadableData{
public String[] getAttributesName() { public String[] getAttributesName() {
String[] names = new String[]{ String[] names = new String[]{
"sepalWidth",
"sepalLength", "sepalLength",
"petalWidth", "sepalWidth",
"petalLength" "petalLength",
"petalWidth"
}; };
return names; return names;
} }
...@@ -103,10 +104,10 @@ public class Iris extends LoadableData{ ...@@ -103,10 +104,10 @@ public class Iris extends LoadableData{
@Override @Override
public String toString() { public String toString() {
return "Iris{" + return "Iris{" +
"sepalWidth=" + sepalWidth + "sepalLength=" + sepalLength +
", sepalLength=" + sepalLength + ", sepalWidth=" + sepalWidth +
", petalWidth=" + petalWidth +
", petalLength=" + petalLength + ", petalLength=" + petalLength +
", petalWidth=" + petalWidth +
'}'; '}';
} }
} }
...@@ -13,6 +13,8 @@ import javafx.fxml.FXML; ...@@ -13,6 +13,8 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.chart.ScatterChart; import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.stage.Stage; import javafx.stage.Stage;
...@@ -30,6 +32,7 @@ public class MainStageView implements Observer { ...@@ -30,6 +32,7 @@ public class MainStageView implements Observer {
private String actualX; private String actualX;
private String actualY; private String actualY;
private Stage root;
public MainStageView(ClassificationModel model) { public MainStageView(ClassificationModel model) {
this.model = model; this.model = model;
...@@ -47,7 +50,7 @@ public class MainStageView implements Observer { ...@@ -47,7 +50,7 @@ public class MainStageView implements Observer {
System.exit(-1); System.exit(-1);
} }
loader.setLocation(fxmlFileUrl); loader.setLocation(fxmlFileUrl);
Stage root = loader.load(); root = loader.load();
root.setResizable(false); root.setResizable(false);
root.setTitle("SAE3.3 - Logiciel de classification"); root.setTitle("SAE3.3 - Logiciel de classification");
root.show(); root.show();
...@@ -56,38 +59,68 @@ public class MainStageView implements Observer { ...@@ -56,38 +59,68 @@ public class MainStageView implements Observer {
controller.setMainStageView(this); controller.setMainStageView(this);
scatterChart = controller.getScatterChart(); scatterChart = controller.getScatterChart();
controller.setAxesSelected("Aucun fichier sélectionné"); controller.setAxesSelected("Aucun fichier sélectionné");
} }
@Override @Override
public void update(Observable observable) { public void update(Observable observable) {
if(scatterChart == null) throw new IllegalStateException(); if(scatterChart == null) throw new IllegalStateException();
scatterChart.getData().clear();
if(!(observable instanceof ClassificationModel)) throw new IllegalStateException(); if(!(observable instanceof ClassificationModel)) throw new IllegalStateException();
//on vide le nuage pour s'assurer que celui-ci est bien vide
scatterChart.getData().clear();
XYChart.Series series1 = new XYChart.Series(); XYChart.Series series1 = new XYChart.Series();
series1.setName("Iris"); series1.setName("Iris");
//Jalon 1: on verifie que le type de donnée est bien IRIS
if(model.getType() == DataType.IRIS) { if(model.getType() == DataType.IRIS) {
controller.setAxesSelected("");
if(actualX==null && actualY==null){ if(actualX==null && actualY==null){
controller.setAxesSelected("Aucuns axes sélectionnés"); controller.setAxesSelected("Aucuns axes sélectionnés");
} }
else{ else{
controller.setAxesSelected("");
// On ajoute la serie au nuage
scatterChart.getData().add(series1); scatterChart.getData().add(series1);
//On recupere les données du model
List<LoadableData> points = new ArrayList<>(model.getDatas()); List<LoadableData> points = new ArrayList<>(model.getDatas());
points.addAll(model.getDataToClass()); points.addAll(model.getDataToClass());
// on ajoute chaque point a la serie
for(LoadableData i : points) { for(LoadableData i : points) {
Iris iris = (Iris)i; Iris iris = (Iris)i;
XYChart.Data<Double, Double> dataPoint = new XYChart.Data<>(iris.getDataType(actualX), XYChart.Data<Double, Double> dataPoint = new XYChart.Data<>(iris.getDataType(actualX),
iris.getDataType(actualY)); iris.getDataType(actualY));
Circle circle = new Circle(5);
circle.setFill(iris.getColor()); dataPoint.setNode(getCircle(iris));
dataPoint.setNode(circle);
series1.getData().add(dataPoint); series1.getData().add(dataPoint);
} }
} }
} }
} }
private Circle getCircle(Iris iris) {
Circle circle = new Circle(5);
circle.setFill(iris.getColor());
circle.setOnMouseClicked(e -> {
ContextMenu contextMenu = new ContextMenu();
for(String attributes : iris.getAttributesName()) {
contextMenu.getItems().add(new MenuItem(attributes + " : " + iris.getDataType(attributes)));
}
contextMenu.show(root, e.getScreenX(), e.getScreenY());
});
return circle;
}
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
if(scatterChart == null) throw new IllegalStateException(); if(scatterChart == null) throw new IllegalStateException();
...@@ -102,9 +135,8 @@ public class MainStageView implements Observer { ...@@ -102,9 +135,8 @@ public class MainStageView implements Observer {
iris.getDataType(actualX), iris.getDataType(actualX),
iris.getDataType(actualY) iris.getDataType(actualY)
); );
Circle circle = new Circle(5);
circle.setFill(iris.getColor()); dataPoint.setNode(getCircle(iris));
dataPoint.setNode(circle);
if (!scatterChart.getData().isEmpty()) { if (!scatterChart.getData().isEmpty()) {
XYChart.Series series = (XYChart.Series) scatterChart.getData().get(0); XYChart.Series series = (XYChart.Series) scatterChart.getData().get(0);
series.getData().add(dataPoint); series.getData().add(dataPoint);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment