diff --git "a/C:\\Users\\Xxsafirex\\Desktop\\Image\\sortie.jpg" "b/C:\\Users\\Xxsafirex\\Desktop\\Image\\sortie.jpg" new file mode 100644 index 0000000..238559c Binary files /dev/null and "b/C:\\Users\\Xxsafirex\\Desktop\\Image\\sortie.jpg" differ diff --git a/Tess4J/src/net/sourceforge/tess4j/util/ImageIOHelper.java b/Tess4J/src/net/sourceforge/tess4j/util/ImageIOHelper.java index c4bf186..e6bb7cc 100644 --- a/Tess4J/src/net/sourceforge/tess4j/util/ImageIOHelper.java +++ b/Tess4J/src/net/sourceforge/tess4j/util/ImageIOHelper.java @@ -16,6 +16,7 @@ package net.sourceforge.tess4j.util; import java.io.*; + import java.util.*; import javax.imageio.*; import javax.imageio.stream.*; diff --git a/launcher.sh b/launcher.sh index 3c0d771..de4706f 100644 --- a/launcher.sh +++ b/launcher.sh @@ -4,4 +4,4 @@ mkdir bin javac -cp ".:jar/*" -d bin src/*/*.java src/Exec.java; -java -Dfile.encoding=UTF-8 -classpath ./bin:./jar/commons-beanutils-1.9.2.jar:./jar/commons-io-2.6.jar:./jar/commons-logging-1.2-javadoc.jar:./jar/commons-logging-1.2.jar:./jar/fontbox-2.0.16.jar:./jar/fontbox-2.0.9.jar:./jar/ghost4j-1.0.1.jar:./jar/hamcrest-core-1.3.jar:./jar/itext-2.1.7.jar:./jar/jai-imageio-core-1.4.0.jar:./jar/jbig2-imageio-3.0.0.jar:./jar/jboss-vfs-3.2.12.Final.jar:./jar/jcl-over-slf4j-1.7.25.jar:./jar/jna-4.1.0.jar:./jar/jul-to-slf4j-1.7.25.jar:./jar/junit-4.12.jar:./jar/lept4j-1.6.4.jar:./jar/log4j-api-2.12.1.jar:./jar/log4j-core-2.12.1.jar:./jar/log4j-over-slf4j-1.7.25.jar:./jar/logback-classic-1.2.3.jar:./jar/logback-core-1.2.3.jar:./jar/pdfbox-2.0.16.jar:./jar/pdfbox-2.0.9.jar:./jar/pdfbox-app-2.0.16.jar:./jar/pdfbox-debugger-2.0.16.jar:./jar/pdfbox-tools-2.0.16.jar:./jar/pdfbox-tools-2.0.9.jar:./jar/preflight-2.0.16.jar:./jar/preflight-app-2.0.16.jar:./jar/slf4j-api-1.7.25.jar:./jar/tess4j-3.4.8.jar:./jar/xmlgraphics-commons-1.5.jar:./jar/xmpbox-2.0.16.jar:/LIB/junit-platform-console-standalone-1.5.1.jar Exec \ No newline at end of file +java -Dfile.encoding=UTF-8 -classpath ./bin:./resources:./jar/commons-beanutils-1.9.2.jar:./jar/commons-io-2.6.jar:./jar/commons-logging-1.2-javadoc.jar:./jar/commons-logging-1.2.jar:./jar/fontbox-2.0.16.jar:./jar/fontbox-2.0.9.jar:./jar/ghost4j-1.0.1.jar:./jar/hamcrest-core-1.3.jar:./jar/itext-2.1.7.jar:./jar/jai-imageio-core-1.4.0.jar:./jar/jbig2-imageio-3.0.0.jar:./jar/jboss-vfs-3.2.12.Final.jar:./jar/jcl-over-slf4j-1.7.25.jar:./jar/jna-4.1.0.jar:./jar/jul-to-slf4j-1.7.25.jar:./jar/junit-4.12.jar:./jar/lept4j-1.6.4.jar:./jar/log4j-api-2.12.1.jar:./jar/log4j-core-2.12.1.jar:./jar/log4j-over-slf4j-1.7.25.jar:./jar/logback-classic-1.2.3.jar:./jar/logback-core-1.2.3.jar:./jar/pdfbox-2.0.16.jar:./jar/pdfbox-2.0.9.jar:./jar/pdfbox-app-2.0.16.jar:./jar/pdfbox-debugger-2.0.16.jar:./jar/pdfbox-tools-2.0.16.jar:./jar/pdfbox-tools-2.0.9.jar:./jar/preflight-2.0.16.jar:./jar/preflight-app-2.0.16.jar:./jar/slf4j-api-1.7.25.jar:./jar/tess4j-3.4.8.jar:./jar/xmlgraphics-commons-1.5.jar:./jar/xmpbox-2.0.16.jar:/LIB/junit-platform-console-standalone-1.5.1.jar Exec -r -help #-r -d pdf -o result.csv config.txt \ No newline at end of file diff --git a/pdf/TestDecale.pdf b/pdf/TestDecale.pdf index 2ad698e..fd201f4 100644 Binary files a/pdf/TestDecale.pdf and b/pdf/TestDecale.pdf differ diff --git a/resources/log4j2.properties b/resources/log4j2.properties index 29862d4..1840751 100644 --- a/resources/log4j2.properties +++ b/resources/log4j2.properties @@ -2,7 +2,6 @@ name=PropertiesConfig property.filename = logs appenders = console, file - # Création des appenders (interfaces) pour les sorties fichier et console appender.console.type = Console appender.console.name = STDOUT diff --git a/src/Exec.java b/src/Exec.java index 07c5f54..3a02c79 100644 --- a/src/Exec.java +++ b/src/Exec.java @@ -42,7 +42,7 @@ public class Exec implements Callable { public static void main(String[] args) throws InterruptedException { // Système de subcommand semblable Ă  celui de git permettant d'appeler les classes relatives - String[] t = {"-r","-v9","-d","pdf","config.txt"}; + CommandLine cmd = new CommandLine (new Exec()) .addSubcommand("-r", new Read(System.out)) // nom commande, objet commande .addSubcommand("-b", new Build(System.out)) @@ -52,7 +52,7 @@ public class Exec implements Callable { .addSubcommand("-e", new Evaluate(System.out)) .addSubcommand("help", new HelpCommand()); // Aide gĂ©nĂ©rĂ©e automatiquement par l'API - cmd.execute(t); //t + cmd.execute(args); //t } diff --git a/src/commands/Read.java b/src/commands/Read.java index d0e5709..215f892 100644 --- a/src/commands/Read.java +++ b/src/commands/Read.java @@ -2,7 +2,6 @@ package commands; import picocli.CommandLine; - import picocli.CommandLine.*; import progressbar.ProgressBar; @@ -156,7 +155,7 @@ public class Read implements Callable { logger.debug("CSV initialized with : "+ocr.createHashMapforCSV()+" , "+config.getParam().get("Code")+" , "+result_name); - GenerateCSV csv = new GenerateCSV(ocr.createHashMapforCSV(),config.getParam().get("Code"), result_name); + GenerateCSV csv = new GenerateCSV(ocr.createHashMapforCSV(),config.getParam().get("Code"),config.getParam().get("MarkFormat"), result_name); csv.createFile(); //GĂ©nère le fichier csv Ă  partir de la HMap retournĂ©e par l'OCR diff --git a/src/config/Config.java b/src/config/Config.java index aae4321..1fe0dd9 100644 --- a/src/config/Config.java +++ b/src/config/Config.java @@ -49,7 +49,7 @@ public class Config { param.put("ShuffleQuestions", "1"); // 1 = qt mĂ©langĂ©es, 0 = non mĂ©l param.put("ShuffleAnswers", "1"); // 1= proposition rĂ©p mĂ©langĂ©es, 0= non param.put("Code", "8"); // code Ă©tudiant = 8 chiffres (entre 1 et 16) - param.put("MarkFormat", "20/4"); // expl "20/4" pour des notes entre 0 et 20 notĂ©es Ă© 0.25 points + param.put("MarkFormat", "20"); // expl "20" pour des notes entre 0 et 20 notĂ©es Ă© 0.25 points param.put("NameField", "Nom et PrĂ©nom"); // remplace le texte param.put("StudentField", "Veuillez coder votre numĂ©ro\r\n d'Ă©tudiant ci-contre et Ă©crire votre nom \r\n dans la case ci-dessous"); diff --git a/src/csv/GenerateCSV.java b/src/csv/GenerateCSV.java index 07a1df5..5c3aec9 100644 --- a/src/csv/GenerateCSV.java +++ b/src/csv/GenerateCSV.java @@ -13,13 +13,15 @@ import org.apache.logging.log4j.Logger; public class GenerateCSV { Map etudiants; - int numLength; + int nLength; + double mType; String path = "export"; Logger logger = LogManager.getLogger(GenerateCSV.class); - public GenerateCSV(Map map, String length, String pth) { + public GenerateCSV(Map map, String numLength,String markType, String pth) { this.etudiants = map; - this.numLength = Integer.parseInt(length); + this.nLength = Integer.parseInt(numLength); + this.mType = Integer.parseInt(markType); this.path = path + "/" + pth; } @@ -28,10 +30,10 @@ public class GenerateCSV { // Teste validitĂ© du numero etudiant (selon param de la config passĂ© : // numLength) - public boolean isValid(String s) { + public boolean isNumValid(String s) { int i = 0; logger.debug("Checking string validity"); - if (s.length() == this.numLength) { + if (s.length() == this.nLength) { while (i < s.length()) { int nb = Character.getNumericValue(s.charAt(i)); @@ -59,6 +61,27 @@ public class GenerateCSV { return false; } } + + + public boolean isMarkValid(String s) { + logger.debug("Checking mark validity"); + if(s.contains(",")) { + s = s.replace(",","."); + System.out.println(s); + } + + double nb = Double.parseDouble(s); + + if (nb>= 0 && nb <=this.mType) { + logger.debug("Mark format ok"); + return true; + } + else { + logger.fatal("Mark format is not correct"); + return false; + } + + } public void createFile() { try (PrintWriter writer = new PrintWriter(new File(this.path))) { @@ -79,12 +102,12 @@ public class GenerateCSV { // Si etudiant HashMap est null, pas ecrit if (etud != null) { - if (this.isValid(etud)) { + if (this.isNumValid(etud) && this.isMarkValid(etudiants.get(etud))) { writer.write(etud + ";" + etudiants.get(etud) + System.getProperty("line.separator")); logger.debug("Added "+etud+" to csv"); } else { - logger.debug("Invalid id for "+etud+" not added to csv"); + logger.debug("Invalid pair for "+etud+" and "+etudiants.get(etud)+" not added to csv"); } } else { diff --git a/tests/csv/TestCSV.java b/tests/csv/TestCSV.java index d03f5dc..0038e2d 100644 --- a/tests/csv/TestCSV.java +++ b/tests/csv/TestCSV.java @@ -13,8 +13,9 @@ public class TestCSV { Map map = new HashMap(); String length = "8"; + String format = "20"; String path = "../export/result.csv"; - GenerateCSV csv = new GenerateCSV(map,length,path); + GenerateCSV csv = new GenerateCSV(map,length,format,path); @BeforeEach void setUp() { @@ -27,7 +28,7 @@ public class TestCSV { void testNotNull() { map.put("21705239", "17"); - csv = new GenerateCSV(map,length,path); + csv = new GenerateCSV(map,length,format,path); assertFalse(csv == null); } @@ -37,10 +38,10 @@ public class TestCSV { map.put("21435712", "9"); map.put("21705239", "17"); - csv = new GenerateCSV(map,length,path); + csv = new GenerateCSV(map,length,format,path); for (String etud : csv.etudiants.keySet()) { - assertTrue(csv.isValid(etud)); + assertTrue(csv.isNumValid(etud)); } } @@ -51,10 +52,10 @@ public class TestCSV { map.put("21435", "9"); map.put("1705239", "17"); - csv = new GenerateCSV(map,length,path); + csv = new GenerateCSV(map,length,format,path); for (String etud : csv.etudiants.keySet()) { - assertFalse(csv.isValid(etud)); + assertFalse(csv.isNumValid(etud)); } }