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

Ajouts d'une premiere version du chargement des donnees test

parent b48bc489
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,9 @@
<HBox prefHeight="356.0" prefWidth="691.0">
<children>
<Region prefHeight="338.0" prefWidth="65.0" />
<ScatterChart prefHeight="342.0" prefWidth="609.0">
<ScatterChart fx:id="scatterChart" prefHeight="342.0" prefWidth="609.0">
<xAxis>
<CategoryAxis fx:id="absAxe" prefHeight="21.0" prefWidth="498.0" side="BOTTOM" />
<NumberAxis fx:id="absAxe" prefHeight="21.0" prefWidth="498.0" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis fx:id="ordAxe" side="LEFT" />
......
......@@ -11,7 +11,7 @@ public class Main extends Application {
public void start(Stage stage) throws IOException {
ClassificationModel model = new ClassificationModel();
ClassificationModel model = ClassificationModel.getClassificationModel();
MainStageView view = new MainStageView(model);
view.show();
......
package fr.univlille.sae.classification.controller;
import fr.univlille.sae.classification.model.ClassificationModel;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
......@@ -8,6 +9,7 @@ import javafx.stage.FileChooser;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
public class LoadDataController {
......@@ -42,19 +44,21 @@ public class LoadDataController {
this.file = fileChooser.showOpenDialog(stage);
if(file != null) {
filePath.setText(file.getName());
filePath.setText(file.getPath());
}
}
public void validate() {
public void validate() throws IOException {
if (file == null) {
stage.close();
//throw exception
}
loadData();
ClassificationModel.getClassificationModel().loadData(file);
stage.close();
}
......
package fr.univlille.sae.classification.controller;
import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.view.LoadDataView;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.chart.*;
......@@ -17,7 +19,7 @@ public class MainStageController {
Stage stage;
@FXML
CategoryAxis absAxe;
NumberAxis absAxe;
@FXML
NumberAxis ordAxe;
......@@ -34,6 +36,8 @@ public class MainStageController {
@FXML
Button classifyData;
@FXML
ScatterChart scatterChart;
Stage loadStage;
......@@ -43,24 +47,15 @@ public class MainStageController {
* @throws IOException
*/
public void openLoadData() throws IOException {
FXMLLoader loader = new FXMLLoader();
URL fxmlFileUrl = new File(System.getProperty("user.dir") + File.separator + "res" + File.separator + "stages" + File.separator + "load-data-stage.fxml").toURI().toURL();
if (fxmlFileUrl == null) {
System.out.println("Impossible de charger le fichier fxml");
System.exit(-1);
}
loader.setLocation(fxmlFileUrl);
loadStage = loader.load();
LoadDataView loadDataView = new LoadDataView(ClassificationModel.getClassificationModel(), stage);
loadDataView.show();
loadStage.setResizable(false);
loadStage.initOwner(stage);
loadStage.initModality(Modality.APPLICATION_MODAL);
loadStage.setTitle("Chargement des donées");
loadStage.showAndWait();
}
public ScatterChart getScatterChart() {
return this.scatterChart;
}
}
......@@ -10,6 +10,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
public class ClassificationModel extends Observable {
......@@ -18,11 +19,25 @@ public class ClassificationModel extends Observable {
private DataType type;
public ClassificationModel() {
private static ClassificationModel model;
/**
* Renvoie une instance unique du model. Par default le type de ce modele est Iris.
* Modifier en .setType(DataType).
* @return l'instance du model
*/
public static ClassificationModel getClassificationModel() {
if(model == null) model = new ClassificationModel();
return model;
}
private ClassificationModel() {
this(DataType.IRIS);
}
public ClassificationModel(DataType type) {
private ClassificationModel(DataType type) {
this.datas = new ArrayList<>();
this.dataToClass = new ArrayList<>();
this.type = type;
......@@ -34,7 +49,7 @@ public class ClassificationModel extends Observable {
* @param coords toutes les données du points
* @throws IllegalArgumentException Exception levée si le nombre de parametres est insuffisant pour creer un point du type du model
*/
private void ajouterDonnee(double... coords) {
public void ajouterDonnee(double... coords) {
LoadableData newData = PointFactory.createPoint(type, coords);
this.dataToClass.add(newData);
notifyObservers(newData);
......@@ -45,11 +60,12 @@ public class ClassificationModel extends Observable {
* TODO
* @param file
*/
private void loadData(File file) throws IOException {
public void loadData(File file) throws IOException {
this.datas = new CsvToBeanBuilder<LoadableData>(Files.newBufferedReader(file.toPath()))
.withSeparator(',')
.withType(Iris.class)
.build().parse();
Set<String> types = new HashSet<>();
for (LoadableData d : datas) {
types.add(d.getClassification());
......@@ -63,7 +79,7 @@ public class ClassificationModel extends Observable {
* TODO
* @param data
*/
private void classifierDonnee(LoadableData data) {
public void classifierDonnee(LoadableData data) {
List<String> classes = new ArrayList<>(data.getClassificationTypes());
Random rdm = new Random();
......@@ -71,4 +87,23 @@ public class ClassificationModel extends Observable {
notifyObservers(data);
}
public void setType(DataType type) {
this.type = type;
}
public List<LoadableData> getDatas() {
return datas;
}
public List<LoadableData> getDataToClass() {
return dataToClass;
}
public DataType getType() {
return type;
}
}
package fr.univlille.sae.classification.view;
import fr.univlille.sae.classification.model.ClassificationModel;
import javafx.fxml.FXMLLoader;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class LoadDataView {
private ClassificationModel model;
private Stage owner;
public LoadDataView(ClassificationModel model, Stage owner) {
this.model = model;
this.owner = owner;
}
public void show() throws IOException {
FXMLLoader loader = new FXMLLoader();
URL fxmlFileUrl = new File(System.getProperty("user.dir") + File.separator + "res" + File.separator + "stages" + File.separator + "load-data-stage.fxml").toURI().toURL();
if (fxmlFileUrl == null) {
System.out.println("Impossible de charger le fichier fxml");
System.exit(-1);
}
loader.setLocation(fxmlFileUrl);
Stage root = loader.load();
root.setResizable(false);
root.initOwner(owner);
root.initModality(Modality.APPLICATION_MODAL);
root.setTitle("Chargement des donées");
root.showAndWait();
}
}
package fr.univlille.sae.classification.view;
import fr.univlille.sae.classification.controller.LoadDataController;
import fr.univlille.sae.classification.controller.MainStageController;
import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.model.DataType;
import fr.univlille.sae.classification.model.Iris;
import fr.univlille.sae.classification.model.LoadableData;
import fr.univlille.sae.classification.utils.Observable;
import fr.univlille.sae.classification.utils.Observer;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import java.io.File;
......@@ -14,8 +22,12 @@ import java.net.URL;
public class MainStageView implements Observer {
private ClassificationModel model;
private ScatterChart scatterChart;
public MainStageView(ClassificationModel model) {
this.model = model;
model.attach(this);
......@@ -36,11 +48,28 @@ public class MainStageView implements Observer {
root.setResizable(false);
root.setTitle("SAE3.3 - Logiciel de classification");
root.show();
loader.getController();
MainStageController controller = loader.getController();
scatterChart = controller.getScatterChart();
}
@Override
public void update(Observable observable) {
if(scatterChart == null) throw new IllegalStateException();
if(!(observable instanceof ClassificationModel)) throw new IllegalStateException();
XYChart.Series series1 = new XYChart.Series();
series1.setName("Dice Launch");
scatterChart.getData().add(series1);
for(LoadableData i : model.getDatas()) {
if(model.getType() == DataType.IRIS) {
series1.getData().add(new XYChart.Data<>(((Iris)i).getPetalLength(),
((Iris)i).getPetalWidth()));
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment