Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit e9b978c9 authored by hvernier's avatar hvernier
Browse files

Ajout lib Python pour traitement

parent 554a2181
......@@ -77,8 +77,7 @@ public class DataSession {
this.data = data;
this.mTitle = "Data - "+data.getDataName();
this.dataPanel = new DataPanel(data);
this.dataPanel = new DataPanel(data,this);
this.mWorskSpace.addTab(dataPanel.getDataTabPanel());
this.mWorskSpace.addTabListener(new TabListener() {
......@@ -248,6 +247,10 @@ public class DataSession {
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public void setTile(String title) {
this.mTitle = title;
......
This diff is collapsed.
......@@ -11,6 +11,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFileChooser;
......@@ -147,22 +148,129 @@ public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
try {
List<DataObject> result = new ArrayList<DataObject>();
Data data = null;
boolean noDataNull = true;
CSVUtils reader = null;
try {
ArrayList<double[]> dimValue = new ArrayList<double[]>();
ArrayList<String>attributeNames = new ArrayList<String>();
boolean haveDate = true;
DataObject object = null;
int id,tmp,conteur,conteurInit;
double[] tabValue = null ;
id = -1;
conteurInit = 0;
try (Scanner scanner = new Scanner(new File(this.textFile.getText()));) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
try (Scanner rowScanner = new Scanner(line)) {
rowScanner.useDelimiter(this.textSeparator.getText());
conteur = 0;
if(conteurInit == 1) {
/*if(attributeNames.get(1) != "date" && attributeNames.get(1) != "Date") {
haveDate = false;
}*/
if(haveDate) {
tabValue = new double[attributeNames.size()-2];
}else {
tabValue = new double[attributeNames.size()-1];
}
}
while (rowScanner.hasNext()) {
if(conteurInit == 0) {
attributeNames.add(rowScanner.next());
}else {
if(conteur ==0) {
if(id != -1) {
dimValue.add(tabValue);
if(haveDate) {
tabValue = new double[attributeNames.size()-2];
}else {
tabValue = new double[attributeNames.size()-1];
}
}
tmp = Integer.parseInt(rowScanner.next());
if(tmp != id) {
if(id != -1) {
double[][] valueObject = new double[dimValue.size()][11];
for(int j =0 ; j<valueObject.length ; j++) {
valueObject[j] = dimValue.get(j);
}
object.setAttribute(0,new AttributeMultiDimSequence(valueObject));
dimValue.removeAll(dimValue);
result.add(object);
}
object = new DataObject(1);
id = tmp;
object.setId(id);
}
conteur++;
}
else if(conteur == 1) {
/*
if( attributeNames.get(1).equalsIgnoreCase("date") && attributeNames.get(1).equalsIgnoreCase("Date")) {
String tmpS = rowScanner.next();
if(tmpS.length()!=0) {
tabValue[conteur-1] = Double.parseDouble(tmpS);
}
}*/
rowScanner.next();
conteur++;
}
else {
String tmpS = rowScanner.next();
if(tmpS.length()!=0) {
tabValue[conteur-2] = Double.parseDouble(tmpS);
}else {
double test = Double.NaN;
tabValue[conteur-2] = test;
noDataNull = false;
}
conteur++;
}
}
}
conteurInit++;
}
}
}
/*try {
File file = new File(this.textFile.getText());
reader = new CSVUtils(file, this.textSeparator.getText().charAt(0));
List<String> line;
while((line = reader.readNext()) != null) {
extractObjectFromLine(result, line);
//extractObjectFromLine(result, line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
result = null;
}
}*/
if(result != null) {
data = new SimpleData(result, null, null);
data.setNoDataNull(noDataNull);
data.initSequenceMax();
if(haveDate) {
String[] attrNames = new String[attributeNames.size()-2];
for(int i=2 ; i<attributeNames.size();i++) {
attrNames[i-2] = attributeNames.get(i);
System.out.println(attrNames[i-2]);
}
data.setAttributesNames(attrNames);
data.setSubAttributesNames(attrNames);
}else {
String[] attrNames = new String[attributeNames.size()-1];
for(int i=1 ; i<attributeNames.size();i++) {
attrNames[i-1] = attributeNames.get(i);
}
data.setAttributesNames(attrNames);
data.setSubAttributesNames(attrNames);
}
DistanceModel model = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, data);
......@@ -209,6 +317,7 @@ public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
double[][] seq = new double[line.size()][];
for (int i = 0 ; i < line.size() ; i++) {
seq[i] = new double[1];
System.out.println(line.get(i));
seq[i][0] = Double.parseDouble(line.get(i));
}
......
......@@ -131,7 +131,7 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject {
@Override
public void run() {
ImageData data = null;
System.out.println("============>>> "+sample.getDataObjects().size());
if (sourcePanel.isSequenceMaskSelected() && sample instanceof ImageSampler
&& imageSessions != null) {
List<Mask> maskSequence = new ArrayList<Mask>();
......@@ -147,20 +147,19 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject {
((ImageSampler) sample).setMaskSequence(maskSequence);
}
}
System.out.println(filesPaths);
if (filesPaths.size() > 1) {
data = new ImageData(sample, filesPaths, null, null, null);
} else {
data = new ImageData(sample, filesPaths.get(0), null, null);
}
DistanceModel distModel = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distParameters = DistanceModel
.generateDefaultDistanceParameters(1, distModel, data);
data.setDistanceModel(distModel, distParameters);
MainFrame.getInstance().createDataSession(data);
DataConstructFrame.getInstance().updateDataConstructPanel();
DataConstructFrame.getInstance().dispose();
}
......
......@@ -6,6 +6,7 @@ import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
......@@ -29,9 +30,11 @@ import javax.swing.event.ListSelectionListener;
import jcl.data.Data;
import jcl.utils.Histogram;
import mustic.gui.ClassificationFrame;
import mustic.gui.DataSession;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.ImageSession;
import mustic.gui.MainFrame;
import mustic.gui.PythonProcessing;
import mustic.gui.dialog.classifier.ConstraintsSelectionFrame;
import mustic.io.ImageData;
import mustic.io.RawImage;
......@@ -89,6 +92,8 @@ public class DataPanel extends JPanel implements ChangeListener {
/** Reference vers les donnees */
Data data = null;
DataSession dataSession = null;
JButton deleteAttributeButton = new JButton("Delete Attribute");
......@@ -108,7 +113,11 @@ public class DataPanel extends JPanel implements ChangeListener {
JButton viewCommentsButton = new JButton("View Comments");
JButton viewDataButton = new JButton("View Data (text)");
JButton viewDataButton = new JButton("View Data");
JButton pretraitementButton = new JButton("Preprocessing");
JButton deleteButton = new JButton("Delete Panel");
/** Boutons de choix */
JButton visualizeDataButton = new JButton("Visualize Data (chart)");
......@@ -119,6 +128,8 @@ public class DataPanel extends JPanel implements ChangeListener {
/** Button to classify the Data */
JButton constraintButton = new JButton(Messages.getString("DataPanel.01"));
PythonProcessing pythonProcessing = new PythonProcessing();
/** La liste des onglets */
private TitledTab tabPanel = null;
......@@ -131,9 +142,10 @@ public class DataPanel extends JPanel implements ChangeListener {
* @param _data
* donnees a afficher
*/
public DataPanel(Data _data) {
public DataPanel(Data _data, DataSession dataSession) {
super(new BorderLayout());
this.dataSession = dataSession;
/* On garde une trace des donnees */
this.data = _data;
this.classifyButton.setFont(classifyButton.getFont().deriveFont(Font.BOLD));
......@@ -156,8 +168,46 @@ public class DataPanel extends JPanel implements ChangeListener {
/* Selectionne par defaut le premier attribut */
this.attrTable.getSelectionModel().setLeadSelectionIndex(0);
}
public DataPanel(Data _data) {
super(new BorderLayout());
/* On garde une trace des donnees */
this.data = _data;
this.classifyButton.setFont(classifyButton.getFont().deriveFont(Font.BOLD));
JPanel container = buildBody();
// JScrollPane sp = new JScrollPane(container);
JPanel sp = container;//no scroll bars for better visibility
JPanel dataPane = new JPanel(new BorderLayout());
// dataPane.setSize(700, 500);
dataPane.setPreferredSize(new Dimension(700,500));
dataPane.add(sp, BorderLayout.CENTER);
/* Panel des donnees */
tabPanel = TabFactory.createTitledTab(
"Data",
new ImageIcon(getClass().getResource(
"/icons/actions/document-open-arff.png")),
dataPane);
tabPanel.setFocusableComponent(null);
/* Selectionne par defaut le premier attribut */
this.attrTable.getSelectionModel().setLeadSelectionIndex(0);
}
public Data getData() {
return data;
}
public void setData(Data data) {
data.testNanValue();
this.dataSession.setData(data);
this.data = data;
pythonProcessing.updateButton(data.noHaveDataNull());
}
/**
* Build all the elements of the Data tab
......@@ -267,7 +317,7 @@ public class DataPanel extends JPanel implements ChangeListener {
/* Bouttons pour modifier les attributs */
JPanel buttonTablePanel = new JPanel();
buttonTablePanel.add(this.deleteAttributeButton);
//buttonTablePanel.add(this.deleteAttributeButton);
tablePanel.add(buttonTablePanel, BorderLayout.SOUTH);
......@@ -305,12 +355,16 @@ public class DataPanel extends JPanel implements ChangeListener {
/** South : boutons de config */
JPanel buttonPanel = new JPanel();
buttonPanel.add(this.viewDataButton);
buttonPanel.add(this.visualizeDataButton);
buttonPanel.add(this.pretraitementButton);
buttonPanel.add(this.deleteButton);
buttonPanel.add(this.viewCommentsButton);
buttonPanel.add(this.filterButton);
//buttonPanel.add(this.filterButton);
buttonPanel.add(this.classifyButton);
buttonPanel.add(this.constraintButton);
// buttonPanel.add(doOp);
container.add(buttonPanel, BorderLayout.SOUTH);
......@@ -319,46 +373,103 @@ public class DataPanel extends JPanel implements ChangeListener {
}
private void initializeButtonsListeners() {
DataPanel dataPanel = this;
/* Efface un Attribut */
this.deleteAttributeButton.addActionListener(new ActionListener() {
/*this.deleteAttributeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int rows = DataPanel.this.attrTable.getRowCount();
/* Si on a plus que 1 attribut et qu'on en a un de selectionne */
// Si on a plus que 1 attribut et qu'on en a un de selectionne
if (rows > 1
&& (DataPanel.this.attrTable.getSelectedRow() != -1)) {
int selectedRow = DataPanel.this.attrTable.getSelectedRow();
System.out.println(selectedRow);
/* On efface l'attribut dans les donnees */
// On efface l'attribut dans les donnees
DataPanel.this.data.removeAttribute(selectedRow);
/* On met a jour la JTable */
// On met a jour la JTable
updateAttrTable();
/* On met a jour la selection dans la JTable */
// On met a jour la selection dans la JTable
if (selectedRow == DataPanel.this.attrTable.getRowCount())
selectedRow--;
DataPanel.this.attrTable.getSelectionModel()
.setLeadSelectionIndex(selectedRow);
/* On met a jour le nombre d'attribut */
// On met a jour le nombre d'attribut
DataPanel.this.nbattrLabel.setText("Attributes : "
+ DataPanel.this.data.getOneDataObject()
.getNbAttributes());
}
}
});
});*/
/* Affichage d'une fenetre de dialogue avec la liste des donnees */
this.viewDataButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ClarffxDialog viewDataDialog = new ClarffxDialog(
JPanel test = new JPanel();
pythonProcessing.initOngletVisualisation(test, dataPanel);
ClarffxDialog viewDataDialog = new ClarffxDialog(test
,
ClarffxDialog.CLOSE_BUTTONS);
// viewDataDialog.setSize(700, 500);
viewDataDialog.setPreferredSize(new Dimension(700,500));
RefineryUtilities.centerFrameOnScreen(viewDataDialog);
// @todo
viewDataDialog.setTitle("Data View");
viewDataDialog.setVisible(true);
/*ClarffxDialog viewDataDialog = new ClarffxDialog(
new DataViewPanel(DataPanel.this.data,
DataPanel.this.nbobjLabel),
ClarffxDialog.CLOSE_BUTTONS);
// viewDataDialog.setSize(700, 500);
viewDataDialog.setPreferredSize(new Dimension(700,500));
RefineryUtilities.centerFrameOnScreen(viewDataDialog);
/** @todo */
// @todo
viewDataDialog.setTitle("Data View");
viewDataDialog.setVisible(true);*/
}
});
this.pretraitementButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPanel test = new JPanel();
pythonProcessing.initOngletPretraitement(test, dataPanel);
ClarffxDialog viewDataDialog = new ClarffxDialog(test
,
ClarffxDialog.CLOSE_BUTTONS);
// viewDataDialog.setSize(700, 500);
viewDataDialog.setPreferredSize(new Dimension(700,500));
RefineryUtilities.centerFrameOnScreen(viewDataDialog);
// @todo
viewDataDialog.setTitle("Data Preprocessing");
viewDataDialog.setVisible(true);
/*ClarffxDialog viewDataDialog = new ClarffxDialog(
new DataViewPanel(DataPanel.this.data,
DataPanel.this.nbobjLabel),
ClarffxDialog.CLOSE_BUTTONS);
// viewDataDialog.setSize(700, 500);
viewDataDialog.setPreferredSize(new Dimension(700,500));
RefineryUtilities.centerFrameOnScreen(viewDataDialog);
// @todo
viewDataDialog.setTitle("Data View");
viewDataDialog.setVisible(true);*/
}
});
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPanel test = new JPanel();
pythonProcessing.initOngletSupp(test, dataPanel);
ClarffxDialog viewDataDialog = new ClarffxDialog(test
,
ClarffxDialog.CLOSE_BUTTONS);
viewDataDialog.setPreferredSize(new Dimension(700,500));
RefineryUtilities.centerFrameOnScreen(viewDataDialog);
// @todo
viewDataDialog.setTitle("Delete Panel");
viewDataDialog.setVisible(true);
}
});
......
......@@ -250,7 +250,6 @@ public class ImageData extends SimpleData implements Serializable {
}
this.rawImages.add(path);
long startTime = System.currentTimeMillis();
// we create the band names
......
package mustic.io;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
//import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.io.File;
import java.io.Serializable;
import java.util.Vector;
import java.util.Observable;
......
......@@ -164,7 +164,7 @@ public class AttributeSelectionPanel extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
new SubWeightFrame(AttributeSelectionPanel.this, indice,
data.getOneDataObject().getAttribute(indice));
data.getOneDataObject().getAttribute(indice),data);
}
});
JPanel subWeightPane = new JPanel();
......@@ -243,14 +243,16 @@ public class AttributeSelectionPanel extends JPanel {
private AttributeSelectionPanel attrPanel = null;
private int id;
private Data data;
private JCheckBox[] bandCheckBoxes = null;
private JTextField[] bandWeigths = null;
public SubWeightFrame(AttributeSelectionPanel attrPanel, int id, Attribute attribute) {
public SubWeightFrame(AttributeSelectionPanel attrPanel, int id, Attribute attribute,Data data) {
super();
this.attrPanel = attrPanel;
this.id = id;
this.data = data;
// get the dimensionality of the Attribute
final int size = getDimensionNumber(attribute);
......@@ -301,8 +303,11 @@ public class AttributeSelectionPanel extends JPanel {
int compteur = 0; // Compte le nombre d'element placés
for (int i = 0; i < size; i++) {
this.bandCheckBoxes[i] = new JCheckBox("dim " + (i+1), true);
if(data.getAttributesNames()!= null) {
this.bandCheckBoxes[i] = new JCheckBox(data.getAttributeName(i), true);
}else {
this.bandCheckBoxes[i] = new JCheckBox("dim " + (i+1), true);
}
this.bandWeigths[i] = new JTextField("" + 1, 4); //$NON-NLS-1$
final int indice = i;
this.bandCheckBoxes[i]
......
......@@ -5,15 +5,29 @@ import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import org.jfree.ui.RefineryUtilities;
import jcl.Classification;
import jcl.clustering.ClusteringResult;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.attribute.AttributeMultiDimSequence;
import mustic.gui.PythonProcessing;
import mustic.models.gui.charts.CentroidsChart;
import mustic.models.gui.widgets.ClarffxDialog;
import jep.Jep;
import jep.JepConfig;
import jep.JepException;
public class CentroidsPanel extends JPanel {
/** serialVersionUID */
......@@ -24,11 +38,25 @@ public class CentroidsPanel extends JPanel {
/** Attribut des Y */
JComboBox coord2Combo = new JComboBox();
/** Button see graph in Python **/
JButton pythonButton = new JButton();
/** Button edit cluster centers **/
JButton genClustersCenters = new JButton();
ArrayList<double[][]> dataTendence = new ArrayList<double[][]>();
/** Le graphique */
CentroidsChart dataChart;
private JLabel lblX;
private Jep jep = null;
private String[] complementGraph;
private Classification classif;
private JLabel lblY;
......@@ -43,7 +71,9 @@ public class CentroidsPanel extends JPanel {
} else {
subConstrStd(classification);
}
this.classif = classification;
complementGraph = new String[classification.getNbClusters()];
//initComplementGraph();
}
/**
......@@ -68,6 +98,97 @@ public class CentroidsPanel extends JPanel {
* } catch (Exception e) { e.printStackTrace(); System.exit(1); }
*/
}
/*private void initComplementGraph() {
int[] clusterMap = classif.getClusteringResult().getClusterMap();
DecimalFormat df = new DecimalFormat("0.00");
Data allData = classif.getData();
boolean existe = false;
String complementTmp;
float total = 0;
int lengthSeq = ((AttributeMultiDimSequence)(allData.getOneDataObject().getAttributes()[0])).getSequence()[0].length;
int cell = 0;
for(int i=0 ; i<classif.getNbClusters();i++) {
ArrayList<int[]> tmp = new ArrayList<int[]>();
complementTmp = "";
for(int j=0 ; j<clusterMap.length ; j++) {
if(clusterMap[j] == i) {