package MEPTL; import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.DateFormat; import java.text.ParseException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.Enumeration; import java.util.regex.Matcher; import java.util.regex.Pattern; import cXML.node; import calcul.formatDateWriter; public class feedbacks { public feedbacks() { } /** * Ecriture du fichier feedback.
* Si zip = true alors pour archive.
* Si zip = false alors pour fichier html.
*
* @param nodana : node de l'analyse de l'étudiant. * @param verif : node de vérification (ensemble des vérifications des historiques) * @parame zip : Pour créer un fichier html ou une archive zip. * @return * @throws IOException * @throws ParseException */ public static StringBuilder feedback(node nodana, node verif, Boolean zip, Boolean TestFichierAnalyse) throws IOException, ParseException { System.getProperty("file.encoding","UTF-8"); Date aujourdhui = new Date(); int number_match = 2; int mini_modification = 0; boolean plagiat = false; boolean dateModificationAnterieur = false; boolean copiercoller = false; boolean pasAssezDeModification =false; boolean baremeABC = false; boolean producteur =false; String SuiteBureautique=""; String VersionLibreOffice=""; String SystemeStudent=""; node verifStudent = null; if((commandes.verifHisto||commandes.verifHisto2)) { //&&commandes.ecritNoteCSV&&commandes.fourniCSV if(verif.getAttributs().get("number_match") != null) number_match = Integer.valueOf(verif.getAttributs().get("number_match")); if(verif.getAttributs().get("mini_number_modification") != null) mini_modification = Integer.valueOf(verif.getAttributs().get("mini_number_modification")); //verification du plagiat verifStudent = verif.retourneFirstNodeByNameAndAttributValue("fichier", "dossier", nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("dossier")); if(verifStudent != null) { if(verifStudent.getAttributs().get("filename").equals(nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("filename"))) { if(Integer.valueOf(verifStudent.getAttributs().get("nombre_correspondances_consecutives"))>number_match) plagiat=true; if(!verifStudent.getAttributs().get("first_modification_identique").equals("null") && Integer.valueOf(verifStudent.getAttributs().get("nombre_correspondances_consecutives"))>=number_match) plagiat=true; if(verifStudent.getAttributs().get("copier_coller")!=null) copiercoller=true; if(Integer.valueOf(verifStudent.getAttributs().get("nombre_modification"))<=mini_modification) pasAssezDeModification=true; if(verifStudent.getAttributs().get("first_date_modification_anterieur_date_du_controle").equals("true")) dateModificationAnterieur=true; } } } if(nodana.retourneFirstEnfantsByName("bodyetnotation").getAttributs().get("baremeABC")!=null) { try { baremeABC= Boolean.valueOf(nodana.retourneFirstEnfantsByName("bodyetnotation").getAttributs().get("baremeABC")); }catch (Exception e) { System.out.println("Problème avec la valeur binaire de l'attribut baremeABC."); } } StringBuilder fichier = new StringBuilder(); //ajoute le chemin vers le feedback dans le node d'analyse //nodana.retourneFirstEnfantsByName("ouverture").getAttributs().put("feedback", patch + "/" + cheminFeedBack); // auteur du sujet String auteurSujet = nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("auteur"); //création du feedback fichier.append("\r" + "\r" + "\r" + "\r" + "Fichier généré par AnalyseWriter - Développeur : Pablo Rodriguez\r"); fichier.append("\r" + "\r" + "\r"); fichier.append(HTML.getStyleCSS()); fichier.append("\r\r"); fichier.append("\r"); fichier.append("
"); if(!commandes.noLogo) { if(!commandes.newLogo) { fichier.append("

\r\n" + "Feedback - AnalyseWriter - format ODF 1.2
"+HTML.imgLogos()+"

\r"); }else { fichier.append("

\r\n" + "Feedback - AnalyseWriter - format ODF 1.2
"+commandes.contenuFichierSVG+"

\r"); } }else { fichier.append("

\r\n" + "Feedback - AnalyseWriter - format ODF 1.2

\r"); } //********** //** Note ** //********** node ouvre = nodana.retourneFirstEnfantsByName("ouverture"); String noteFrom = ouvre.getAttributs().get("notefrom"); node notation = nodana.retourneFirstEnfantsByName("bodyetnotation"); if(!baremeABC) { if(noteFrom ==null) noteFrom="20"; if(!commandes.noNote) if(!plagiat&&!copiercoller&&!pasAssezDeModification&&!dateModificationAnterieur) fichier.append("

" + notation.getAttributs().get("note") + " / " + noteFrom +"
"+ ouvre.getAttributs().get("metaSujet") +"

\r"); if(plagiat || copiercoller || pasAssezDeModification || dateModificationAnterieur) { notation.getAttributs().put("note","0"); String AffichageNote = ""; if(plagiat) AffichageNote = " Plagiat "; if(copiercoller) AffichageNote = AffichageNote + " Copier Coller "; if(pasAssezDeModification) AffichageNote = AffichageNote + " Pas assez de modification "; if(dateModificationAnterieur) AffichageNote = AffichageNote + " Réalisation avant le contrôle "; if(!commandes.noNote) fichier.append("

" + AffichageNote + " / " + noteFrom +"
"+ ouvre.getAttributs().get("metaSujet") +"

\r"); } }else { String imageNote = ""; switch (notation.getAttributs().get("noteABC")) { case "A": imageNote = HTML.NoteA(); break; case "B": imageNote = HTML.NoteB(); break; case "C": imageNote = HTML.NoteC(); break; case "D": imageNote = HTML.NoteD(); break; case "E": imageNote = HTML.NoteE(); break; default: imageNote = ""; break; } if(!commandes.noNote) if(!plagiat&& !copiercoller &&!pasAssezDeModification) fichier.append("

" + imageNote +"
"+ ouvre.getAttributs().get("metaSujet") +"

\r"); if(plagiat || copiercoller || pasAssezDeModification || dateModificationAnterieur) { notation.getAttributs().put("note","0"); notation.getAttributs().put("noteABC","E"); String AffichageNote = ""; if(plagiat) AffichageNote = " Plagiat "; if(copiercoller) AffichageNote = AffichageNote + " Copier Coller "; if(pasAssezDeModification) AffichageNote = AffichageNote + " Pas assez de modification "; if(dateModificationAnterieur) AffichageNote = AffichageNote + " Réalisation avant le controle "; if(!commandes.noNote) fichier.append("

" + AffichageNote + " / " + "
"+ ouvre.getAttributs().get("metaSujet") +"

\r"); } } //producteur if(ouvre.getAttributs().get("producteur")!=null) { try { producteur= true; String[] decompose = ouvre.getAttributs().get("producteur").split("/"); SuiteBureautique=decompose[0]; VersionLibreOffice=decompose[1].substring(0, decompose[1].lastIndexOf("$")); SystemeStudent=decompose[1].substring(decompose[1].lastIndexOf("$")+1, decompose[1].lastIndexOf(" ")); }catch (Exception e) { System.out.println("Problème avec l'attribut producteur."); }finally { } } //********************** //** Les informations ** //********************** // date d'analyse, dossier étudiant, auteur sujet, date de la dernière modificatio, lien, algorithme DateFormat mediumDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM); LocalDateTime dateTimeModif = null; String dateModif=""; if(!ouvre.getAttributs().get("dateModification").isEmpty()) { try { dateTimeModif = LocalDateTime.parse(ouvre.getAttributs().get("dateModification")); dateModif = dateTimeModif.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)); }catch (Exception e) { System.out.println(e.toString()); } } fichier.append("

Date d'analyse : "+ mediumDateFormat.format(aujourdhui) + "
"); fichier.append("Dossier étudiant : "+ ouvre.getAttributs().get("dossier") + "
"); fichier.append("Nom du fichier : "+ ouvre.getAttributs().get("filename") + "
"); fichier.append("Date de la dernière modification du fichier analysé : "+ dateModif + "
"); fichier.append("Durée d'édition du fichier analysé : "+ meptl.traitementDureeEdition(ouvre.getAttributs().get("dureeEdition") + "
")); if(producteur) { fichier.append("Suite de bureautique de l'étudiant : "+ SuiteBureautique + ""); fichier.append(" - Version : "+ VersionLibreOffice + ""); fichier.append(" - Système : "+ SystemeStudent + "
"); } fichier.append("
"); if(!auteurSujet.isEmpty()) {fichier.append("Sujet créé par : "+ auteurSujet + "
");} fichier.append("Hash du fichier analyse : "+ ouvre.getAttributs().get("hash") + "
"); fichier.append("Nom du fichier analyse : "+ commandes.nameSujet + "
"); fichier.append("Titre de l'exercice : "+ ouvre.getAttributs().get("titre") + "
"); fichier.append("Distance minimale de Levenshtein : "+ ouvre.getAttributs().get("tolerance_text") + "
"); if(!commandes.noNote) { if(!plagiat&&!copiercoller&&!pasAssezDeModification) fichier.append("Méthode :
Progression " + ouvre.getAttributs().get("progression") + "Explication
"+ HTML.imgProgression() +"
- Pourcentage correcte : " + nodana.retourneFirstEnfantsByName("bodyetnotation").getAttributs().get("proportioncorrect") +"
"); if(plagiat || copiercoller || pasAssezDeModification || dateModificationAnterieur) { String AffichageNote = ""; if(plagiat) AffichageNote = " Plagiat "; if(copiercoller) AffichageNote = AffichageNote + " Copier Coller "; if(pasAssezDeModification) AffichageNote = AffichageNote + " Pas assez de modification "; if(dateModificationAnterieur) AffichageNote = AffichageNote + " Réalisation avant le contrôle "; fichier.append("Méthode :
Progression " + ouvre.getAttributs().get("progression") + "Explication
"+ HTML.imgProgression() +"
- Pourcentage correcte : "+ AffichageNote +"
"); } if(baremeABC) { fichier.append("Barème :
0% → E → " + Math.round(Double.valueOf(notation.getAttributs().get("BorneE"))*100) + "% → D → " + Math.round(Double.valueOf(notation.getAttributs().get("BorneD"))*100) + "% → C → " + Math.round(Double.valueOf(notation.getAttributs().get("BorneC"))*100) + "% → B → " + Math.round(Double.valueOf(notation.getAttributs().get("BorneB"))*100) + "% → A → 100%Prendre en compte le coefficient de progression.
"); } } if(ouvre.getAttributs().get("link_sujet")!=null) { String linkSujet= ouvre.getAttributs().get("link_sujet"); Matcher m = Pattern.compile("^https://.{1,}|^http://.{1,}").matcher(linkSujet); if(m.find()) {fichier.append("
Lien vers le sujet
");} } if(ouvre.getAttributs().get("link_help")!=null) { String linkSujet= ouvre.getAttributs().get("link_help"); Matcher m = Pattern.compile("^https://.{1,}|^http://.{1,}").matcher(linkSujet); if(m.find()) {fichier.append("
Lien vers le support
");} } fichier.append("
Analysé avec la version : " + commandes.version + "

"); fichier.append(HTML.SautLigne()); fichier.append("
"); //ajoute le menu si pas de détails if(!commandes.noDetail) { fichier.append(HTML.getHTMLmenu(nodana.retourneFirstEnfantsByName("menu").getNodes())); } //Les erreurs node errors = nodana.retourneFirstEnfantsByName("erreurs"); if(Boolean.valueOf(errors.getAttributs().get("oneError"))) { fichier.append(HTML.SautLigne()); if(Boolean.valueOf(errors.getAttributs().get("manqueHistorique"))) fichier.append(HTML.Paragraph_classp5("ERREUR : Il n'y a pas d'historique des modifications dans ce fichier. Le fichier n'a pas été modifié ou il a été réïnitialisé.
L'analyse de l'historique n'a pas pu se faire.")); if(Boolean.valueOf(errors.getAttributs().get("manqueCreationDate"))) fichier.append(HTML.Paragraph_classp5("ERREUR : La date de création du fichier a été supprimée. Le fichier a été réïnitialisé ou ce n'est pas le fichier du sujet.")); if(Boolean.valueOf(errors.getAttributs().get("manqueValeurCreationDate"))) fichier.append(HTML.Paragraph_classp5("ERREUR : Ce n'est pas la bonne date de création du fichier. Le fichier a été réïnitialisé ou ce n'est pas le fichier du sujet.")); if(Boolean.valueOf(errors.getAttributs().get("manqueMetaSujet"))) fichier.append(HTML.Paragraph_classp5("ERREUR : La méta donnée \"Sujet\" dans les propriétés du fichier a été supprimée ou renommée.")); if(Boolean.valueOf(errors.getAttributs().get("manqueValeurMetaSujet"))) fichier.append(HTML.Paragraph_classp5("ERREUR : La valeur de la méta donnée \"Sujet\" dans les propriétés du fichier n'est pas \"" + nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("metaSujet"))+".\""); if(Boolean.valueOf(errors.getAttributs().get("manqueInitialCreator"))) fichier.append(HTML.Paragraph_classp5("ERREUR : La valeur de la méta donnée \"initial-creator\" dans les propriétés du fichier n'est pas \"" + nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("Initial_Creator"))+".\""); } //Affichage du feedback pour le plagiat if(plagiat) if(verifStudent!=null){ fichier.append(HTML.SautLigne()); ArrayList correspondance = verifStudent.retourneEnfantsByName("correspondance", new ArrayList()); for(int j = 0 ; j < correspondance.size();j++) { fichier.append(HTML.Paragraph_classp5("Correspondance à la date=" + correspondance.get(j).getAttributs().get("date") + " avec l'étudiant " + correspondance.get(j).getAttributs().get("Avec_etudiant"))); } } //Affichage du feedback pour la late de la première modification antérieure à la date du controle if(dateModificationAnterieur) if(verifStudent!=null){ fichier.append(HTML.SautLigne()); fichier.append(HTML.Paragraph_classp5("La date du début du contrôle est le :" + formatDateWriter.DateLibreOffice(commandes.analyse_modificationDateMini) + " et la première date de modification dans le fichier est :" + verifStudent.getAttributs().get("first_modification_date"))); } fichier.append(HTML.SautLigne()); //Affichage du feedback if(!plagiat && !copiercoller && !pasAssezDeModification && !dateModificationAnterieur) { //Ajoute de commentaire de l'exercice fichier.append(HTML.H3(nodana.getContenu().get(0)).replace("-NewLine-", "
")); fichier.append(HTML.SautLigne()); //************************************** //** Table de synthèse avec les liens ** //*************************************** fichier.append(HTML.H2("Synthèse")); fichier.append(HTML.TableEnteteTableurSynthese()); fichier = SyntheseTable(nodana.retourneFirstEnfantsByName("evaluation"),fichier); if(!commandes.noDetail) { //Ecriture des détails de l'évaluation Enumeration EnuNod = Collections.enumeration(nodana.retourneFirstEnfantsByName("evaluation").getNodes()); while(EnuNod.hasMoreElements()) { node nod = EnuNod.nextElement(); if(nod.isClose()) { fichier.append(HTML.Table(nod)); } } } fichier.append("



"); } //************ //** footer ** //************ fichier.append("
"); fichier.append("analyseWriter - P. Rodriguez (université d'Artois) - Licence GPL v3.0 - analysé avec la version : " + commandes.version + " - "); fichier.append("Fichier d'analyse créé avec la version : " + ouvre.getAttributs().get("version") + ""); fichier.append("
"); fichier.append(""); fichier.append("\r"); fichier.append(""); if(!zip) { //nom du fichier feedback String metaS = nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("metaSujet"); if(metaS.equals("?")) metaS = "metaSujet-inconnu"; if(metaS.isEmpty()) metaS = "metaSujet-inconnu"; String cheminFeedBack = nodana.retourneFirstEnfantsByName("ouverture").getAttributs().get("dossier") + "-DateLong" + aujourdhui.getTime()+"-"+metaS; if(!commandes.noNote&&!baremeABC) { if(!plagiat&&!copiercoller)cheminFeedBack = cheminFeedBack + "-" + nodana.retourneFirstEnfantsByName("bodyetnotation").getAttributs().get("note") + ".html"; if(plagiat) cheminFeedBack = cheminFeedBack + "- plagiat"; if(copiercoller) cheminFeedBack = cheminFeedBack + "- copier-coller"; if(pasAssezDeModification) cheminFeedBack = cheminFeedBack + "- pas assez de modification"; if(dateModificationAnterieur) cheminFeedBack = cheminFeedBack + "- date modification antérieur au controle"; cheminFeedBack = cheminFeedBack + ".html"; } if(!commandes.noNote&&baremeABC) { if(!plagiat)cheminFeedBack = cheminFeedBack + "-" + nodana.retourneFirstEnfantsByName("bodyetnotation").getAttributs().get("noteABC") + ".html"; if(copiercoller) cheminFeedBack = cheminFeedBack + "- copier-coller"; if(plagiat) cheminFeedBack = cheminFeedBack + "- plagiat"; if(pasAssezDeModification) cheminFeedBack = cheminFeedBack + "- pas assez de modification"; if(dateModificationAnterieur) cheminFeedBack = cheminFeedBack + "- date modification antérieur au controle"; cheminFeedBack = cheminFeedBack + ".html"; } if(commandes.noNote) { cheminFeedBack = cheminFeedBack + ".html"; } // Chemin vers le dossier de destination Path outputFilePath = Paths.get(commandes.path + "/" + cheminFeedBack); if(commandes.fourniDossierDestination) outputFilePath = Paths.get(commandes.path + "/" + commandes.pathDestination+ "/" + cheminFeedBack); if(!TestFichierAnalyse) { BufferedWriter fichier1 = Files.newBufferedWriter(outputFilePath, StandardCharsets.UTF_8); //ajoute le chemin vers le feedback dans le node d'analyse nodana.retourneFirstEnfantsByName("ouverture").getAttributs().put("feedback", commandes.path + "/" + cheminFeedBack); fichier1.append(fichier.toString()); fichier1.close(); //affichage dans la console if(!commandes.fourniDossierDestination) System.out.println("\n\t The feedback file has been written.\n\t " + commandes.path + "\\" + cheminFeedBack); if(commandes.fourniDossierDestination) System.out.println("\n\t The feedback file has been written.\n\t " + commandes.path + "\\" + commandes.pathDestination + "\\" + cheminFeedBack); } } return fichier; } private static StringBuilder SyntheseTable(node nodana, StringBuilder fichier) { // String IdError = ""; // permet de récupérer les id des menu ou la proportioncorrect est NaN. (à cause de l'attribut analyseStyle=true) for(int k = 0 ; k < nodana.getNodes().size();k++) { if(nodana.getNodes().get(k).getAttributs().get("addmenu")!=null) { if(nodana.getNodes().get(k).getAttributs().get("addmenu").equals("true")) { node N = nodana.getNodes().get(k); if(N.getAttributs().get("proportioncorrect")!=null) { if(!N.getAttributs().get("proportioncorrect").equals("NaN")) { if(N.getAttributs().get("titre")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre"),Double.valueOf(N.getAttributs().get("proportioncorrect")),N.getAttributs().get("pointtotal") + " pt",N.getAttributs().get("pointgagner") + " pt", N.getAttributs().get("poids"),N.getAttributs().get("id"))); } if(N.getAttributs().get("titre1")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre1"),Double.valueOf(N.getAttributs().get("proportioncorrect")),N.getAttributs().get("pointtotal") + " pt",N.getAttributs().get("pointgagner") + " pt", N.getAttributs().get("poids"),N.getAttributs().get("id"))); } if(N.getAttributs().get("titre2")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre2"),Double.valueOf(N.getAttributs().get("proportioncorrect")),N.getAttributs().get("pointtotal") + " pt",N.getAttributs().get("pointgagner") + " pt", N.getAttributs().get("poids"),N.getAttributs().get("id"))); } if(N.getAttributs().get("titre3")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre3"),Double.valueOf(N.getAttributs().get("proportioncorrect")),N.getAttributs().get("pointtotal") + " pt",N.getAttributs().get("pointgagner") + " pt", N.getAttributs().get("poids"),N.getAttributs().get("id"))); } }else { // IdError = IdError + N.getAttributs().get("id"); // System.out.print("\t** Erreur menu, node : " + N.getNomElt()); } }else { if(N.getAttributs().get("titre")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre"),-1.0,"","", "",N.getAttributs().get("id"))); } if(N.getAttributs().get("titre1")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre1"),-1.0,"","", "",N.getAttributs().get("id"))); } if(N.getAttributs().get("titre2")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre2"),-1.0,"","", "",N.getAttributs().get("id"))); } if(N.getAttributs().get("titre3")!=null) { fichier.append(HTML.TablePointsSyntheseStyle(N.getAttributs().get("titre3"),-1.0,"","", "",N.getAttributs().get("id"))); } } } } } ArrayList LesPages = nodana.retourneFirstEnfantsByName("structurepage").retourneEnfantsByName("page", new ArrayList()); if(LesPages.size()>0) { fichier.append(HTML.SautLigne()); fichier.append(HTML.H2("Les points dans les pages")); fichier.append(HTML.SautLigne()); for(int k = 0 ; k < LesPages.size();k++) { if(LesPages.get(k).getNomElt().equals("page")) { if(LesPages.get(k).getAttributs().get("proportioncorrect")!=null) { if(!LesPages.get(k).getAttributs().get("proportioncorrect").equals("NaN")) { fichier.append(HTML.TablePointsSyntheseStyle2(" Page "+ LesPages.get(k).getAttributs().get("numeroabsolue"),Double.valueOf(LesPages.get(k).getAttributs().get("proportioncorrect")),LesPages.get(k).getAttributs().get("pointTotal") + " pt",LesPages.get(k).getAttributs().get("point") + " pt")); } } } } } return fichier; } }