analyseWriter/src/app/evaluate.java

467 lines
19 KiB
Java
Raw Normal View History

2022-05-24 18:25:41 +02:00
package app;
import java.awt.BorderLayout;
2022-05-25 09:30:49 +02:00
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
2022-05-24 18:25:41 +02:00
2022-05-25 09:30:49 +02:00
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
2022-05-24 18:25:41 +02:00
import javax.swing.JFrame;
2022-05-25 09:30:49 +02:00
import javax.swing.JLabel;
2022-05-24 18:25:41 +02:00
import javax.swing.JPanel;
2022-05-25 09:30:49 +02:00
import javax.swing.JTextPane;
import javax.swing.JToolBar;
2022-05-24 18:25:41 +02:00
import javax.swing.border.EmptyBorder;
2022-05-25 21:22:38 +02:00
import javax.swing.filechooser.FileNameExtensionFilter;
2022-05-24 18:25:41 +02:00
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import MEPTL.commandes;
import MEPTL.feedbacks;
import MEPTL.meptl;
import cXML.Run;
import cXML.node;
import net.lingala.zip4j.exception.ZipException;
2022-05-25 15:28:58 +02:00
import javax.swing.SwingConstants;
2022-05-25 18:21:23 +02:00
import javax.swing.Timer;
2022-05-25 15:28:58 +02:00
import java.awt.GridLayout;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.Component;
import javax.swing.Box;
2022-05-25 18:21:23 +02:00
import javax.swing.JEditorPane;
import javax.swing.JProgressBar;
2022-05-24 18:25:41 +02:00
public class evaluate extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JLabel lblPath = new JLabel();
2022-05-25 15:28:58 +02:00
private JLabel lblFileAnalyse = new JLabel();
2022-05-25 21:22:38 +02:00
private JLabel lblFichierCSV = new JLabel();
2022-05-24 18:25:41 +02:00
private JCheckBox chckbxfichiersEtudaints = new JCheckBox();
private JCheckBox chckbxZipfeedback = new JCheckBox();
private JCheckBox chckbxnoFeedback = new JCheckBox();
private JCheckBox chckbxNoNote = new JCheckBox();
2022-05-25 18:21:23 +02:00
private JCheckBox chckCSVNotes = new JCheckBox();
private JTextPane txtpnmessages = new JTextPane();
private JProgressBar progressBar = new JProgressBar();
private JButton btnSelectFileAnalyse = new JButton();
private JButton btnSelectFolder = new JButton();
private JButton btnEvaluerLesFichiers = new JButton();
2022-05-25 21:22:38 +02:00
private JButton btnFichierCSV = new JButton();
2022-05-25 18:21:23 +02:00
2022-05-24 18:25:41 +02:00
/**
* Create the frame.
*/
public evaluate() {
setIconImage(Toolkit.getDefaultToolkit().getImage(evaluate.class.getResource("/resources/evalwriter.ico")));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2022-05-25 15:28:58 +02:00
setBounds(100, 100, 960, 677);
2022-05-24 18:25:41 +02:00
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JToolBar toolBar = new JToolBar();
contentPane.add(toolBar, BorderLayout.NORTH);
2022-05-25 18:21:23 +02:00
btnSelectFolder = new JButton("Selection dossier d'analyse");
2022-05-25 15:28:58 +02:00
btnSelectFolder.setIcon(new ImageIcon(evaluate.class.getResource("/resources/open2.png")));
2022-05-24 18:25:41 +02:00
btnSelectFolder.setSelectedIcon(new ImageIcon(evaluate.class.getResource("/resources/evalwriter.png")));
2022-05-25 15:28:58 +02:00
btnSelectFolder.setToolTipText("Sélectionner le dossier d'analyse (CTRL+O)");
2022-05-24 18:25:41 +02:00
toolBar.add(btnSelectFolder);
2022-05-25 18:21:23 +02:00
btnEvaluerLesFichiers = new JButton("Evaluer les fichiers des étudiants");
btnSelectFileAnalyse = new JButton("Selection fichier analyse");
2022-05-25 15:28:58 +02:00
btnSelectFileAnalyse.setToolTipText("Sélection du fichier d'analyse");
btnSelectFileAnalyse.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierAnalyse.png")));
toolBar.add(btnSelectFileAnalyse);
2022-05-25 21:22:38 +02:00
btnFichierCSV = new JButton("Sélection fichier CSV");
btnFichierCSV.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierCSV.png")));
toolBar.add(btnFichierCSV);
2022-05-25 18:21:23 +02:00
btnEvaluerLesFichiers.setIcon(new ImageIcon(evaluate.class.getResource("/resources/evaluate.png")));
toolBar.add(btnEvaluerLesFichiers);
2022-05-24 18:25:41 +02:00
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.WEST);
2022-05-25 15:28:58 +02:00
panel.setLayout(new GridLayout(0, 1, 0, 0));
lblFileAnalyse = new JLabel("<HTML><B><U>Fichier de l'analyse</U></B> : </HTML>");
lblFileAnalyse.setHorizontalAlignment(SwingConstants.LEFT);
2022-05-25 21:22:38 +02:00
lblFileAnalyse.setFont(new Font("Tahoma", Font.BOLD, 14));
2022-05-25 15:28:58 +02:00
panel.add(lblFileAnalyse);
lblPath.setHorizontalAlignment(SwingConstants.LEFT);
2022-05-25 21:22:38 +02:00
lblPath.setFont(new Font("Tahoma", Font.BOLD, 14));
2022-05-24 18:25:41 +02:00
lblPath.setText("<HTML><B><U>Dossier de l'analyse</U></B> : " + commandes.path.substring(commandes.path.lastIndexOf("\\")+1,commandes.path.length()) + "</HTML>");
2022-05-25 15:28:58 +02:00
panel.add(lblPath);
2022-05-24 18:25:41 +02:00
2022-05-25 21:22:38 +02:00
lblFichierCSV = new JLabel("<HTML><B><U>Fichier CSV liste des étudiants</U></B></HTML> :");
lblFichierCSV.setFont(new Font("Tahoma", Font.BOLD, 14));
panel.add(lblFichierCSV);
2022-05-24 18:25:41 +02:00
chckbxfichiersEtudaints = new JCheckBox("Les fichiers ne sont pas dans des dossiers nominatifs");
chckbxfichiersEtudaints.setFont(new Font("Tahoma", Font.PLAIN, 12));
chckbxfichiersEtudaints.setToolTipText("Cochez si les fichiers des étudiants ne sont pas dans des dossier nominatifs");
2022-05-25 15:28:58 +02:00
panel.add(chckbxfichiersEtudaints);
2022-05-24 18:25:41 +02:00
chckbxnoFeedback = new JCheckBox("Pas de feedback");
chckbxnoFeedback.setFont(new Font("Tahoma", Font.PLAIN, 12));
2022-05-25 15:28:58 +02:00
panel.add(chckbxnoFeedback);
2022-05-24 18:25:41 +02:00
chckbxZipfeedback = new JCheckBox("Zip les feedbacks");
chckbxZipfeedback.setFont(new Font("Tahoma", Font.PLAIN, 12));
2022-05-25 15:28:58 +02:00
panel.add(chckbxZipfeedback);
2022-05-24 18:25:41 +02:00
chckbxNoNote = new JCheckBox("Pas de note dans les feedbacks");
chckbxNoNote.setFont(new Font("Tahoma", Font.PLAIN, 12));
2022-05-25 15:28:58 +02:00
panel.add(chckbxNoNote);
2022-05-25 18:21:23 +02:00
chckCSVNotes = new JCheckBox("Créer un fichier CSV des notes");
panel.add(chckCSVNotes);
2022-05-24 18:25:41 +02:00
JPanel panel_1 = new JPanel();
contentPane.add(panel_1, BorderLayout.CENTER);
2022-05-25 15:28:58 +02:00
panel_1.setLayout(new GridLayout(1, 0, 0, 0));
2022-05-24 18:25:41 +02:00
2022-05-25 15:28:58 +02:00
JScrollPane scrollPane = new JScrollPane();
panel_1.add(scrollPane);
2022-05-25 18:21:23 +02:00
progressBar = new JProgressBar();
progressBar.setEnabled(false);
scrollPane.setColumnHeaderView(progressBar);
2022-05-24 18:25:41 +02:00
2022-05-25 18:21:23 +02:00
txtpnmessages = new JTextPane();
txtpnmessages.setText("Messages");
scrollPane.setViewportView(txtpnmessages);
2022-05-24 18:25:41 +02:00
2022-05-25 18:21:23 +02:00
CommandeListener();
2022-05-24 18:25:41 +02:00
refreshLabel();
setVisible(true);
}
2022-05-25 18:21:23 +02:00
/**
* Raffraichi les informations
*/
2022-05-24 18:25:41 +02:00
private void refreshLabel() {
if(!commandes.fichierAnalyseValide) {
2022-05-25 18:21:23 +02:00
txtpnmessages.setText(MEPTL.verificationFichierAnalyse.messageErreur.toString());
2022-05-24 18:25:41 +02:00
chckbxfichiersEtudaints.setEnabled(false);
chckbxZipfeedback.setEnabled(false);
chckbxnoFeedback.setEnabled(false);
chckbxNoNote.setEnabled(false);
2022-05-25 18:21:23 +02:00
chckCSVNotes.setEnabled(false);
2022-05-25 15:28:58 +02:00
}else {
chckbxfichiersEtudaints.setEnabled(true);
chckbxZipfeedback.setEnabled(true);
chckbxnoFeedback.setEnabled(true);
chckbxNoNote.setEnabled(true);
2022-05-25 18:21:23 +02:00
chckCSVNotes.setEnabled(true);
2022-05-25 15:28:58 +02:00
StringBuilder text = new StringBuilder();
2022-05-25 21:22:38 +02:00
text.append("\n***********************************************");
text.append("\n** INFORMATIONS **");
text.append("\n***********************************************");
text.append("\nLe titre de l'exercice est : " + commandes.analyse_titre);
2022-05-25 15:28:58 +02:00
text.append("\n");
2022-05-25 21:22:38 +02:00
text.append("\nLe sujet (metaSujet) est : " + commandes.analyse_metaSujet);
2022-05-25 15:28:58 +02:00
text.append("\n");
2022-05-25 21:22:38 +02:00
text.append("\nL'auteur de l'exercice est : " + commandes.analyse_auteur);
2022-05-25 15:28:58 +02:00
text.append("\n");
2022-05-25 21:22:38 +02:00
2022-05-25 15:28:58 +02:00
if(commandes.analyse_baremeABC==true) {
2022-05-25 21:22:38 +02:00
text.append("\nLa notation est sous la forme d'un barème alphabétique ABCDE.");
text.append("\n\tLa progression est de " + String.valueOf(commandes.analyse_progression));
2022-05-25 15:28:58 +02:00
}else {
2022-05-25 21:22:38 +02:00
text.append("\nLa notation est sous la forme d'une note numérique.");
text.append("\n\tLe barème est sur " + String.valueOf(commandes.analyse_notefrom));
text.append("\n\tLa progression est de " + String.valueOf(commandes.analyse_progression));
2022-05-25 15:28:58 +02:00
}
2022-05-25 18:21:23 +02:00
text.append("\n");
2022-05-25 21:22:38 +02:00
text.append("\nLe hash de l'évaluation est : " + commandes.hash);
text.append("\n");
text.append("\n***********************************************");
2022-05-25 18:21:23 +02:00
progressBar.setVisible(false);
txtpnmessages.setText(text.toString());
2022-05-25 15:28:58 +02:00
2022-05-24 18:25:41 +02:00
}
lblPath.setText("<HTML><B><U>Dossier de l'analyse</U></B> : " + commandes.path.substring(commandes.path.lastIndexOf("\\")+1,commandes.path.length()) + "</HTML>");
2022-05-25 15:28:58 +02:00
lblFileAnalyse.setText("<HTML><B><U>Fichier de l'analyse</U></B> : " + commandes.filename + "</HTML>");
2022-05-25 21:22:38 +02:00
lblFichierCSV.setText("<HTML><B><U>Fichier CSV liste des étudiants</U></B> :" + commandes.nameCSV.substring(commandes.nameCSV.lastIndexOf("\\")+1,commandes.nameCSV.length()) + "</HTML>");
2022-05-24 18:25:41 +02:00
}
2022-05-25 18:21:23 +02:00
/**
* Les actionListener
*/
private void CommandeListener() {
2022-05-24 18:25:41 +02:00
2022-05-25 18:21:23 +02:00
// Sélectionne un dossier pour analyser le contenu
btnSelectFolder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
2022-05-24 18:25:41 +02:00
2022-05-25 18:21:23 +02:00
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File(commandes.path));
2022-05-25 21:22:38 +02:00
chooser.setDialogTitle("Sélectionner le dossier contenant les fichiers des étudiants.");
2022-05-25 18:21:23 +02:00
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
2022-05-24 18:25:41 +02:00
2022-05-25 18:21:23 +02:00
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath());
commandes.path = chooser.getSelectedFile().getAbsolutePath();
} else {
System.out.println("No Selection ");
}
refreshLabel();
2022-05-24 18:25:41 +02:00
}
2022-05-25 18:21:23 +02:00
});
2022-05-24 18:25:41 +02:00
2022-05-25 18:21:23 +02:00
// Sélectionne un fichier d'analyse
btnSelectFileAnalyse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new filechooserXML();
refreshLabel();
2022-05-24 18:25:41 +02:00
}
2022-05-25 18:21:23 +02:00
});
// Analyse le contenu du dossier
btnEvaluerLesFichiers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
evaluerLesFichiersEtudiants();
} catch (ParserConfigurationException | SAXException | IOException | CloneNotSupportedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
2022-05-24 18:25:41 +02:00
}
2022-05-25 18:21:23 +02:00
});
2022-05-25 21:22:38 +02:00
// Sélectionne un fichier CSV
btnFichierCSV.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Choisir un fichier CSV");
chooser.setCurrentDirectory(new java.io.File(commandes.path));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Format CSV", "csv");
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(true);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath());
commandes.nameCSV = chooser.getSelectedFile().getAbsolutePath();
commandes.fourniCSV=true;
} else {
commandes.nameCSV = "";
commandes.fourniCSV=false;
System.out.println("No Selection ");
}
refreshLabel();
}
});
2022-05-25 18:21:23 +02:00
}
private void evaluerLesFichiersEtudiants() throws ParserConfigurationException, SAXException, IOException, CloneNotSupportedException {
commandes.analyse=true;
progressBar.setVisible(true);
if(chckbxfichiersEtudaints.isSelected()) commandes.fichierStudentMoodle=true;
if(chckbxZipfeedback.isSelected()) commandes.zipfeedback=true;
if(chckbxnoFeedback.isSelected()) commandes.sansFeeback=true;
if(chckbxNoNote.isSelected()) commandes.noNote=true;
if(chckCSVNotes.isSelected()) commandes.ecritNoteCSV=true;
meptl.analyseVerifieHistoriqueLesFichiersEtudiantsEtExportNoteCSV();
txtpnmessages.setText(commandes.message.toString());
progressBar.setVisible(false);
// Run a = new Run(commandes.path,commandes.Profil, commandes.fichierStudentMoodle);
//
// //** Nouveau node qui permet de convertir le fichier contenant la liste des étudiants en node.
// node nodeCSV = null;
//
// //*****************************************
// //** Nombre de fichier writer à analyser **
// //*****************************************
// int nbFichierWriter = a.getLectDossiers().getEC().getListeContentWriter().size();
//
//
//
// //***************************************
// //** -verif ou -use file.xml -verifcsv **
// //***************************************
// node verif = new node();
// if(commandes.verifHisto || commandes.verifHisto2) {
// node verification = new node();
// verification.setNomElt("verification");
// verification.getAttributs().put("nombre_fichier", String.valueOf(a.getLectDossiers().getEC().getListeFichierodt().size()));
// for(int i = 0 ; i < nbFichierWriter ; i++) {
// node nod = Run.XMLContent(a.getLectDossiers().getEC().getListeContentWriter().get(i));
// node nodStudent = meptl.LectureFichierEtudiantPourVerification(nod,a,i);
// verification.getNodes().add(nodStudent);
2022-05-24 18:25:41 +02:00
// }
2022-05-25 18:21:23 +02:00
// //a.ecritureNodeEnXML(verification, "VerificationHistorique","",false); //écriture du node de l'étudiant
// verif = meptl.verificationHistorique(verification, a); // vérification des correspondances entre les fichiers
//
// //********************************
// //** Ecriture du node verif.xml **
// //********************************
// Run.ecritureNodeEnXML(verif, "Verif",commandes.pathDestination,commandes.fourniDossierDestination, "Verif"); //écriture du node de vérification
// if(!commandes.analyse) {
// //** bye bye analyseWriter
// commandes.clotureApplication();
// }
// }
//
//
//
// System.getProperty("file.encoding","UTF-8");
//
// //*********************************************************
// //** Node contenant l'ensemble des analyses des étudiants **
// //*********************************************************
// node ensembleanalyse = new node();
// ensembleanalyse.setNomElt("analyses");
//
//
// StringBuilder textMessage = new StringBuilder();
//
// //*****************************************************
// //** Parcours l'ensemble des fichiers des étudiants ***
// //*****************************************************
// for(int i = 0 ; i < nbFichierWriter ; i++) {
//
// //** Ne prends pas en compte le dossier destination créé par la commande -dest
// //** Si pas d'analyse alors le nom doit contenir le caractère $ dans le nom du dossier.
// if(commandes.fourniDossierDestination)if(a.getLectDossiers().getEC().getListeNomDossier().get(i).equals(commandes.pathDestination)) continue;
//
// //***********************************************************
// //** Lecture et transformation en node du fichier étudiant **
// //***********************************************************
// node nod = Run.XMLContent(a.getLectDossiers().getEC().getListeContentWriter().get(i));
// node nodStudent = meptl.LectureFichierEtudiantSousFormeDeNode(nod,a,i);
// //a.ecritureNodeEnXML(nodStudent, a.getLectDossiers().getEC().getListeNomDossier().get(i),"",false,""); //écriture du node de l'étudiant
//
// //**********************************
// //** Analyse des fichiers student **
// //**********************************
// if(commandes.analyse||commandes.ecritNodeAnalyse) {
//
//// Run.ecritureNodeEnXML(nodStudent, "fichier student","",false,""); //écriture du node nodStudent de l'étudiant
// node ana = meptl.analyse(nodStudent, commandes.sujet, i, a);
//
// //**************************************************
// //** Ecriture des fichiers d'analyse des students **
// //**************************************************
// if(commandes.ecritNodeAnalyse) {
// Run.ecritureNodeEnXML(ana, "nodana"+ana.retourneFirstEnfantsByName("ouverture").getAttributs().get("dossier"),"",false,""); //écriture du node analyse de l'étudiant
// }
//
// //****************************
// //** Création des feedbacks **
// //****************************
// if(!commandes.sansFeeback&&!commandes.ecritNodeAnalyse) {
// if(!commandes.zipfeedback) {
// //feedback(ana, verif); //classique directement dans le répertoire
// feedbacks.feedback(ana,verif, false);
// }
// if(commandes.zipfeedback) { // Dans une archive pour Moodle
// try {
// a.AddStreamToZip(feedbacks.feedback(ana, verif, true), meptl.retourneLeNomDuFeedback(a.getLectDossiers().getEC().getListeNomFichierFeedBack().get(i),ana, verif),commandes.analyse_size,commandes.analyse_nameZip);
// } catch (ZipException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
//
// //********************************************************************************
// //** Ajoute au node ensembleanalyse lorsque -csv file.csv ou -verifcsv file.scv **
// //********************************************************************************
// if(commandes.ecritNoteCSV) ensembleanalyse.addNode(ana);
//
// //*********************************************************
// //** Message dans la console sur l'analyse de l'étudiant **
// //*********************************************************
// textMessage.append(meptl.messageSystem(ana).toString());
// textAreaMessage.setText(textMessage.toString());
//
// }
// }
// if(commandes.sujet!=null) {
// //*****************************************************
// //** Exportation au format CSV si -csv ou -verifcsv **
// //*****************************************************
// if(commandes.ecritNoteCSV && !commandes.fourniCSV) {
// if(!commandes.verifHisto2) meptl.ecritureCSV(ensembleanalyse);
// if(commandes.verifHisto2) meptl.ecritureCSV(ensembleanalyse,verif,a,commandes.sujet.retourneFirstEnfantsByName("setting"));
// //a.ecritureNodeEnXML(ensembleanalyse, "ensembleAnalyse"); //écriture du node de l'étudiant
// }
//
// //***********************************************************************
// //** Exportation au format CSV si -csv file.csv ou -verifcsv file.csv **
// //***********************************************************************
// if(commandes.ecritNoteCSV && commandes.fourniCSV) {
// meptl.ecritureCSV(ensembleanalyse,verif,a,nodeCSV, commandes.sujet.retourneFirstEnfantsByName("setting"));
// //a.ecritureNodeEnXML(ensembleanalyse, "ensembleAnalyse"); //écriture du node de l'étudiant
// }
//
// //**************************************
// //** Mise à jour du fichier d'analyse **
// //**************************************
//// if(commandes.MAJFichierAnalyse||commandes.MAJnameAnalysisFile) {
//// verificationFichierAnalyse.MiseAJourFichierAnalyse();
//// verificationFichierAnalyse.messagMiseAJourFichierAnalyseAprèsAnalyse();
//// }
// }
2022-05-24 18:25:41 +02:00
}
2022-05-25 09:30:49 +02:00
2022-05-24 18:25:41 +02:00
}