Skip to content
Snippets Groups Projects
Commit ec577d77 authored by Matisse DEKEISER's avatar Matisse DEKEISER
Browse files

Ajout chargement des données CSV

parent 4aa558bc
No related branches found
No related tags found
No related merge requests found
......@@ -67,5 +67,10 @@
<artifactId>javafx-fxml</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.9</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package fr.univlille.sae.classification.model;
import com.opencsv.bean.CsvToBeanBuilder;
import fr.univlille.sae.classification.utils.Observable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
......@@ -33,8 +37,11 @@ public class ClassificationModel extends Observable {
* TODO
* @param file
*/
private void loadData(File file) {
private void loadData(File file) throws IOException {
this.datas = new CsvToBeanBuilder<LoadableData>(Files.newBufferedReader(file.toPath()))
.withSeparator(',')
.withType(Iris.class)
.build().parse();
}
/**
......@@ -48,6 +55,4 @@ public class ClassificationModel extends Observable {
data.setClassification(classes.get(rdm.nextInt(classes.size())));
}
}
package fr.univlille.sae.classification.model;
import java.util.Set;
import com.opencsv.bean.*;
public class Iris extends LoadableData{
@CsvBindByName(column = "sepal.width")
private double sepalWidth;
@CsvBindByName(column = "sepal.length")
private double sepalLength;
@CsvBindByName(column = "petal.width")
private double petalWidth;
@CsvBindByName(column = "petal.length")
private double petalLength;
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength) {
this(sepalWidth, sepalLength, petalWidth, petalLength, "undefined");
}
public Iris() {
//
}
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength, String classification) {
super();
this.sepalWidth = sepalWidth;
......@@ -25,9 +30,6 @@ public class Iris extends LoadableData{
this.petalLength = petalLength;
}
public double getSepalWidth() {
return sepalWidth;
}
......@@ -43,4 +45,14 @@ public class Iris extends LoadableData{
public double getPetalLength() {
return petalLength;
}
@Override
public String toString() {
return "Iris{" +
"sepalWidth=" + sepalWidth +
", sepalLength=" + sepalLength +
", petalWidth=" + petalWidth +
", petalLength=" + petalLength +
'}';
}
}
File deleted
No preview for this file type
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment