Skip to content
Snippets Groups Projects
Commit d6364343 authored by Maxence Antoine's avatar Maxence Antoine
Browse files

Merge branch 'matiasmennecart' into 'master'

Matiasmennecart

See merge request sae302/2024/H4_SAE3.3!11
parents 0d5fcf3b 8a815671
No related branches found
No related tags found
No related merge requests found
Showing
with 141 additions and 53 deletions
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<children> <children>
<Button fx:id="loadData" mnemonicParsing="false" onAction="#openLoadData" prefHeight="27.0" prefWidth="185.0" text="Charger un jeu de données" /> <Button fx:id="loadData" mnemonicParsing="false" onAction="#openLoadData" prefHeight="27.0" prefWidth="185.0" text="Charger un jeu de données" />
<Button fx:id="addData" mnemonicParsing="false" onAction="#openAddData" prefHeight="26.0" prefWidth="141.0" text="Ajouter une donnée" /> <Button fx:id="addData" mnemonicParsing="false" onAction="#openAddData" prefHeight="26.0" prefWidth="141.0" text="Ajouter une donnée" />
<Button fx:id="classifyData" disable="true" mnemonicParsing="false" prefHeight="26.0" prefWidth="157.0" text="Classifier une donnée" /> <Button fx:id="classifyData" disable="true" mnemonicParsing="false" onAction="#classifyDatas" prefHeight="26.0" prefWidth="157.0" text="Classifier les données" />
</children> </children>
</HBox> </HBox>
</children> </children>
......
...@@ -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 {
...@@ -56,8 +54,10 @@ public class AddDataController { ...@@ -56,8 +54,10 @@ 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);
ClassificationModel.getClassificationModel().ajouterDonnee(sepalLengthSpinner.getValue(), sepalWidthSpinner.getValue(), petalLengthSpinner.getValue(), petalWidthSpinner.getValue()); ClassificationModel.getClassificationModel().ajouterDonnee(sepalLengthSpinner.getValue(), sepalWidthSpinner.getValue(), petalLengthSpinner.getValue(), petalWidthSpinner.getValue());
mainStageView.update(mainStageView.getModel(),new Iris(sepalWidthSpinner.getValue(),sepalLengthSpinner.getValue(),petalWidthSpinner.getValue(),petalLengthSpinner.getValue()));
stage.close(); stage.close();
} }
......
package fr.univlille.sae.classification.controller; package fr.univlille.sae.classification.controller;
import fr.univlille.sae.classification.model.ClassificationModel;
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.Button;
...@@ -41,7 +42,10 @@ public class AxesSettingsController{ ...@@ -41,7 +42,10 @@ 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.update(mainStageView.getModel()); mainStageView.getController().getScatterChart().getXAxis().setLabel(mainStageView.getActualX());
mainStageView.getController().getScatterChart().getYAxis().setLabel(mainStageView.getActualY());
mainStageView.update(ClassificationModel.getClassificationModel());
stage.close(); stage.close();
} }
} }
...@@ -2,6 +2,7 @@ package fr.univlille.sae.classification.controller; ...@@ -2,6 +2,7 @@ package fr.univlille.sae.classification.controller;
import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.model.ClassificationModel;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
...@@ -29,10 +30,6 @@ public class LoadDataController { ...@@ -29,10 +30,6 @@ public class LoadDataController {
File file; File file;
public void loadData() {
System.out.println("Loading data");
stage.close();
}
public void openFileChooser() { public void openFileChooser() {
...@@ -49,7 +46,14 @@ public class LoadDataController { ...@@ -49,7 +46,14 @@ public class LoadDataController {
public void validate() throws IOException { public void validate() throws IOException {
if (file == null) { if (file == null) {
stage.close(); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Erreur de chargement du fichier");
alert.setHeaderText(null);
alert.initOwner(stage);
alert.setContentText("Le chargement du fichier à echoué, veuillez reessayer !");
alert.showAndWait();
openFileChooser();
return;
//throw exception //throw exception
} }
ClassificationModel.getClassificationModel().loadData(file); ClassificationModel.getClassificationModel().loadData(file);
......
...@@ -81,6 +81,13 @@ public class MainStageController { ...@@ -81,6 +81,13 @@ public class MainStageController {
} }
public void classifyDatas() {
ClassificationModel.getClassificationModel().classifierDonnees();
classifyData.setDisable(true);
}
public ScatterChart getScatterChart() { public ScatterChart getScatterChart() {
return this.scatterChart; return this.scatterChart;
} }
...@@ -88,4 +95,8 @@ public class MainStageController { ...@@ -88,4 +95,8 @@ public class MainStageController {
public void setAxesSelected(String texte) { public void setAxesSelected(String texte) {
this.AxesSelected.setText(texte); this.AxesSelected.setText(texte);
} }
public Button getClassifyData() {
return this.classifyData;
}
} }
...@@ -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;
} }
...@@ -75,16 +77,22 @@ public class ClassificationModel extends Observable { ...@@ -75,16 +77,22 @@ public class ClassificationModel extends Observable {
notifyObservers(); notifyObservers();
} }
public void classifierDonnees() {
dataToClass.forEach(this::classifierDonnee);
}
/** /**
* TODO * TODO
* @param data * @param data
*/ */
public void classifierDonnee(LoadableData data) { private void classifierDonnee(LoadableData data) {
List<String> classes = new ArrayList<>(data.getClassificationTypes()); List<String> classes = new ArrayList<>(data.getClassificationTypes());
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,26 +7,37 @@ import java.util.Random; ...@@ -7,26 +7,37 @@ 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() {
// //
} }
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength, String variety) { @Override
public String getClassification() {
return variety;
}
@Override
public void setClassification(String classification) {
this.variety = classification;
}
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;
...@@ -51,9 +62,6 @@ public class Iris extends LoadableData{ ...@@ -51,9 +62,6 @@ public class Iris extends LoadableData{
return petalLength; return petalLength;
} }
public String getVariety() {
return variety;
}
public double getDataType(String axes){ public double getDataType(String axes){
switch (axes){ switch (axes){
...@@ -85,10 +93,10 @@ public class Iris extends LoadableData{ ...@@ -85,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;
} }
...@@ -96,10 +104,10 @@ public class Iris extends LoadableData{ ...@@ -96,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 +
'}'; '}';
} }
} }
...@@ -6,7 +6,8 @@ public abstract class LoadableData { ...@@ -6,7 +6,8 @@ public abstract class LoadableData {
private static Set<String> classificationTypes; private static Set<String> classificationTypes;
private String classification;
protected LoadableData() { protected LoadableData() {
...@@ -16,9 +17,7 @@ public abstract class LoadableData { ...@@ -16,9 +17,7 @@ public abstract class LoadableData {
this.classificationTypes.add(classificationType); this.classificationTypes.add(classificationType);
} }
public String getClassification() { public abstract String getClassification() ;
return this.classification;
}
public static Set<String> getClassificationTypes() { public static Set<String> getClassificationTypes() {
return classificationTypes; return classificationTypes;
...@@ -28,9 +27,7 @@ public abstract class LoadableData { ...@@ -28,9 +27,7 @@ public abstract class LoadableData {
LoadableData.classificationTypes = classificationTypes; LoadableData.classificationTypes = classificationTypes;
} }
public void setClassification(String classification) { public abstract void setClassification(String classification);
this.classification = classification;
}
public abstract String[] getAttributesName(); public abstract String[] getAttributesName();
......
...@@ -4,6 +4,7 @@ import fr.univlille.sae.classification.controller.AddDataController; ...@@ -4,6 +4,7 @@ import fr.univlille.sae.classification.controller.AddDataController;
import fr.univlille.sae.classification.controller.AxesSettingsController; import fr.univlille.sae.classification.controller.AxesSettingsController;
import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.model.ClassificationModel;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.control.Alert;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
...@@ -41,6 +42,17 @@ public class AddDataView { ...@@ -41,6 +42,17 @@ public class AddDataView {
controller.setMainStageView(mainStageView); controller.setMainStageView(mainStageView);
if(model.getDatas().isEmpty()) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Erreur");
alert.setHeaderText(null);
alert.setContentText("Veuillez d'abord charger les données avant pouvoir ajouter un point");
alert.showAndWait();
return;
}
root.setResizable(false); root.setResizable(false);
root.initOwner(owner); root.initOwner(owner);
root.initModality(Modality.APPLICATION_MODAL); root.initModality(Modality.APPLICATION_MODAL);
......
...@@ -5,6 +5,7 @@ import fr.univlille.sae.classification.controller.MainStageController; ...@@ -5,6 +5,7 @@ import fr.univlille.sae.classification.controller.MainStageController;
import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.model.LoadableData; import fr.univlille.sae.classification.model.LoadableData;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.control.Alert;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
...@@ -43,9 +44,19 @@ public class AxesSettingsView { ...@@ -43,9 +44,19 @@ public class AxesSettingsView {
root.setTitle("Configuration des axes"); root.setTitle("Configuration des axes");
AxesSettingsController controller = loader.getController(); AxesSettingsController controller = loader.getController();
controller.setMainStageView(mainStageView);
if(model.getDatas().isEmpty()) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Erreur");
alert.setHeaderText(null);
alert.setContentText("Veuillez d'abord charger les données avant de modifier les parametres");
alert.showAndWait();
return;
}
LoadableData dataType = model.getDatas().get(0); LoadableData dataType = model.getDatas().get(0);
controller.setMainStageView(mainStageView);
controller.setSelectAbs(dataType.getAttributesName()); controller.setSelectAbs(dataType.getAttributesName());
controller.setSelectOrd(dataType.getAttributesName()); controller.setSelectOrd(dataType.getAttributesName());
......
...@@ -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;
...@@ -20,9 +22,7 @@ import javafx.stage.Stage; ...@@ -20,9 +22,7 @@ import javafx.stage.Stage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Random;
public class MainStageView implements Observer { public class MainStageView implements Observer {
...@@ -32,6 +32,7 @@ public class MainStageView implements Observer { ...@@ -32,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;
...@@ -49,7 +50,7 @@ public class MainStageView implements Observer { ...@@ -49,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();
...@@ -58,36 +59,68 @@ public class MainStageView implements Observer { ...@@ -58,36 +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);
for(LoadableData i : model.getDatas()) {
//On recupere les données du model
List<LoadableData> points = new ArrayList<>(model.getDatas());
points.addAll(model.getDataToClass());
// on ajoute chaque point a la serie
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);
...@@ -128,7 +160,8 @@ public class MainStageView implements Observer { ...@@ -128,7 +160,8 @@ public class MainStageView implements Observer {
return actualY; return actualY;
} }
public Observable getModel() { public MainStageController getController() {
return this.model; return controller;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment