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

Début d'implémentation: affichage dynamique des attributs dans l'ajout de données

parent 0646b56d
No related branches found
No related tags found
No related merge requests found
Showing with 83 additions and 86 deletions
......@@ -6,42 +6,19 @@
<?import javafx.scene.text.*?>
<?import javafx.stage.*?>
<Stage fx:id="stage" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.AddDataController">
<Stage fx:id="stage" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.AddDataController">
<scene>
<Scene>
<AnchorPane prefHeight="200" prefWidth="200">
<AnchorPane prefHeight="406.0" prefWidth="385.0">
<children>
<VBox alignment="CENTER" prefHeight="279.0" prefWidth="384.0" spacing="20.0">
<VBox alignment="CENTER" layoutY="385.0" prefHeight="38.0" prefWidth="384.0" spacing="20.0">
<children>
<HBox alignment="CENTER" layoutX="10.0" layoutY="109.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
<children>
<Label text="Sepal Length" />
<Spinner fx:id="sepalLengthSpinner" />
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="102.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
<children>
<Label text="Sepal Width" />
<Spinner fx:id="sepalWidthSpinner" />
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="102.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
<children>
<Label text="Petal Length" />
<Spinner fx:id="petalLengthSpinner" />
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="17.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
<children>
<Label text="Petal Width" />
<Spinner fx:id="petalWidthSpinner" />
</children>
</HBox>
<Button fx:id="confirmAdd" mnemonicParsing="false" onAction="#validate" stylesheets="@../css/style.css" text="Valider" textFill="WHITE">
<font>
<Font name="System Bold" size="13.0" />
</font></Button>
</children></VBox>
<VBox fx:id="entries" layoutY="16.0" prefHeight="366.0" prefWidth="385.0" spacing="10.0" />
</children></AnchorPane>
</Scene>
</scene>
......
package fr.univlille.sae.classification.controller;
import com.sun.scenario.effect.impl.state.HVSeparableKernel;
import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.view.MainStageView;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Controlleur pour le FXML add-data-stage, pour ajouter une nouvelle donnée
......@@ -19,39 +28,44 @@ public class AddDataController {
private Stage stage;
@FXML
private Spinner<Double> sepalLengthSpinner;
@FXML
private Spinner<Double> sepalWidthSpinner;
@FXML
private Spinner<Double> petalLengthSpinner;
@FXML
private Spinner<Double> petalWidthSpinner;
private VBox entries;
/**
* MainStageView associé au controlleur
*/
MainStageView mainStageView;
private List<Spinner<Double>> spinners;
/**
* Méthode d'intitialisation du controlleur
*/
@FXML
public void initialize() {
sepalLengthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0,0.1));
sepalWidthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0, 0.1));
petalLengthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0, 0.1));
petalWidthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0, 0.1));
// Permet d'écrire dans la case du spinners
sepalLengthSpinner.setEditable(true);
sepalWidthSpinner.setEditable(true);
petalLengthSpinner.setEditable(true);
petalWidthSpinner.setEditable(true);
this.spinners = new ArrayList<>();
ClassificationModel model = ClassificationModel.getClassificationModel();
if (!model.getDatas().isEmpty()) {
String[] attributes = model.getDatas().get(0).getAttributesNames().keySet().toArray(new String[0]);
for (String attribute : attributes) {
Label label = new Label(attribute);
Spinner<Double> spinner = new Spinner<>();
spinner.setEditable(true);
SpinnerValueFactory<Double> valueFactory =
new SpinnerValueFactory.DoubleSpinnerValueFactory(
0,
Double.POSITIVE_INFINITY,
0.0,
0.1
);
spinner.setValueFactory(valueFactory);
HBox hbox = new HBox(10, label, spinner);
hbox.setAlignment(Pos.CENTER);
hbox.setSpacing(10.0);
entries.getChildren().addAll(hbox);
spinners.add(spinner);
}
}
}
/**
......@@ -69,7 +83,8 @@ public class AddDataController {
mainStageView.getController().getClassifyData().setDisable(false);
try {
ClassificationModel.getClassificationModel().ajouterDonnee(sepalLengthSpinner.getValue(), sepalWidthSpinner.getValue(), petalLengthSpinner.getValue(), petalWidthSpinner.getValue());
Double[] values = spinners.stream().map(Spinner::getValue).toArray(Double[]::new);
ClassificationModel.getClassificationModel().ajouterDonnee((Object[]) values);
}catch (IllegalArgumentException e){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Erreur");
......
......@@ -13,7 +13,7 @@ public class DistanceManhattanNormalisée implements Distance{
for(int i = 0 ;i<l1.getAttributes().length; i++){
double dPoids = (Math.abs(l1.getAttributes()[i]- l2.getAttributes()[i])- MethodeKnn.minData[i])/MethodeKnn.amplitude[i];
double dPoids = (Math.abs(l1.getAttributes()[i]- l2.getAttributes()[i])- MethodKNN.minData[i])/MethodKNN.amplitude[i];
distance = distance + dPoids;
}
......
......@@ -3,6 +3,9 @@ package fr.univlille.sae.classification.model;
import com.opencsv.bean.CsvBindByName;
import javafx.scene.paint.Color;
import java.util.HashMap;
import java.util.Map;
/**
* Représente un point Iris.
* Contient des informations sur les dimensions des sépales et des pétales et sur la variété de la fleur.
......@@ -159,14 +162,15 @@ public class Iris extends LoadableData {
* Renvoie les noms des attributs de l'Iris.
* @return tableau de chaînes contenant les noms des attributs.
*/
@Override
public String[] getAttributesName() {
return new String[]{
"sepalLength",
"sepalWidth",
"petalLength",
"petalWidth"
};
public Map<String, Double> getAttributesNames() {
Map<String, Double> attrNames = new HashMap<>();
attrNames.put("Longueur des sépales", sepalLength);
attrNames.put("Largeur des sépales", sepalWidth);
attrNames.put("Longueur des pétales", petalLength);
attrNames.put("Largeur des pétales", petalWidth);
return attrNames;
}
/**
......
......@@ -2,6 +2,7 @@ package fr.univlille.sae.classification.model;
import javafx.scene.paint.Color;
import java.util.Map;
import java.util.Set;
/**
......@@ -45,11 +46,7 @@ public abstract class LoadableData {
*/
public abstract void setClassification(String classification);
/**
* Renvoie les noms des attributs de l'objet.
* @return tableau de chaînes contenant les noms des attributs.
*/
public abstract String[] getAttributesName();
public abstract Map<String, Double> getAttributesNames();
/**
* Renvoie la couleur associée à l'objet.
......
......@@ -3,6 +3,9 @@ package fr.univlille.sae.classification.model;
import com.opencsv.bean.CsvBindByName;
import javafx.scene.paint.Color;
import java.util.HashMap;
import java.util.Map;
public class Pokemon extends LoadableData {
// name,attack,base_egg_steps,capture_rate,defense,experience_growth,hp,sp_attack,sp_defense,type1,type2,speed,is_legendary
......@@ -90,20 +93,21 @@ public class Pokemon extends LoadableData{
*
* @return tableau de chaînes contenant les noms des attributs.
*/
@Override
public String[] getAttributesName() {
return new String[]{
"attack",
"base_egg_steps",
"capture_rate",
"defense",
"experience_growth",
"hp",
"sp_attack",
"sp_defense",
"speed",
"is_legendary"
};
public Map<String, Double> getAttributesNames() {
Map<String, Double> attrNames = new HashMap<>();
attrNames.put("Attaque", (double) attack);
attrNames.put("Base egg steps", (double) baseEggSteps);
attrNames.put("Capture rate", captureRate);
attrNames.put("Defense", (double) defense);
attrNames.put("Experience growth", (double) experienceGrowth);
attrNames.put("HP", (double) hp);
attrNames.put("Special attack", (double) spAttack);
attrNames.put("Special defense", (double) spDefense);
attrNames.put("Speed", speed);
attrNames.put("Is legendary", isLegendary ? 1.0 : 0.0);
return attrNames;
}
/**
......
......@@ -67,8 +67,8 @@ public class AxesSettingsView {
}
LoadableData dataType = model.getDatas().get(0);
controller.setSelectAbs(dataType.getAttributesName());
controller.setSelectOrd(dataType.getAttributesName());
controller.setSelectAbs(dataType.getAttributesNames().keySet().toArray(new String[0]));
controller.setSelectOrd(dataType.getAttributesNames().keySet().toArray(new String[0]));
root.showAndWait();
} catch (IOException e) {
......
......@@ -115,7 +115,7 @@ public class DataStageView extends DataVisualizationView implements Observer {
List<LoadableData> points = new ArrayList<>(model.getDatas());
points.addAll(model.getDataToClass().keySet());
for (LoadableData data : points) {
ScatterChart.Data<Double, Double> dataPoint = new ScatterChart.Data<>(data.getDataType(actualX), data.getDataType(actualY));
ScatterChart.Data<Double, Double> dataPoint = new ScatterChart.Data<>(data.getAttributesNames().get(actualX), data.getAttributesNames().get(actualY));
Node nodePoint = ViewUtil.getForm(data, new Circle(5), controller);
......@@ -157,8 +157,8 @@ public class DataStageView extends DataVisualizationView implements Observer {
return;
}
XYChart.Data<Double, Double> dataPoint = new XYChart.Data<>(
newData.getDataType(actualX),
newData.getDataType(actualY)
newData.getAttributesNames().get(actualX),
newData.getAttributesNames().get(actualY)
);
dataPoint.setNode(ViewUtil.getForm(newData, new Rectangle(10, 10), controller));
......
......@@ -120,7 +120,7 @@ public class MainStageView extends DataVisualizationView implements Observer {
List<LoadableData> points = new ArrayList<>(model.getDatas());
points.addAll(model.getDataToClass().keySet());
for (LoadableData data : points) {
ScatterChart.Data<Double, Double> dataPoint = new ScatterChart.Data<>(data.getDataType(actualX), data.getDataType(actualY));
ScatterChart.Data<Double, Double> dataPoint = new ScatterChart.Data<>(data.getAttributesNames().get(actualX), data.getAttributesNames().get(actualY));
Node nodePoint = ViewUtil.getForm(data, new Circle(5), controller);
......@@ -157,8 +157,8 @@ public class MainStageView extends DataVisualizationView implements Observer {
return;
}
XYChart.Data<Double, Double> dataPoint = new XYChart.Data<>(
newData.getDataType(actualX),
newData.getDataType(actualY)
newData.getAttributesNames().get(actualX),
newData.getAttributesNames().get(actualY)
);
dataPoint.setNode(ViewUtil.getForm(newData, new Rectangle(10, 10), controller));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment