Add mark validity check
This commit is contained in:
parent
7426cdde82
commit
a068669a7a
BIN
C:\Users\Xxsafirex\Desktop\Image\sortie.jpg
Normal file
BIN
C:\Users\Xxsafirex\Desktop\Image\sortie.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 KiB |
@ -16,6 +16,7 @@
|
|||||||
package net.sourceforge.tess4j.util;
|
package net.sourceforge.tess4j.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.imageio.*;
|
import javax.imageio.*;
|
||||||
import javax.imageio.stream.*;
|
import javax.imageio.stream.*;
|
||||||
|
@ -4,4 +4,4 @@ mkdir bin
|
|||||||
|
|
||||||
javac -cp ".:jar/*" -d bin src/*/*.java src/Exec.java;
|
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
|
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
|
Binary file not shown.
@ -2,7 +2,6 @@ name=PropertiesConfig
|
|||||||
property.filename = logs
|
property.filename = logs
|
||||||
appenders = console, file
|
appenders = console, file
|
||||||
|
|
||||||
|
|
||||||
# Création des appenders (interfaces) pour les sorties fichier et console
|
# Création des appenders (interfaces) pour les sorties fichier et console
|
||||||
appender.console.type = Console
|
appender.console.type = Console
|
||||||
appender.console.name = STDOUT
|
appender.console.name = STDOUT
|
||||||
|
@ -42,7 +42,7 @@ public class Exec implements Callable <Void> {
|
|||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
// Système de subcommand semblable à celui de git permettant d'appeler les classes relatives
|
// 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())
|
CommandLine cmd = new CommandLine (new Exec())
|
||||||
.addSubcommand("-r", new Read(System.out)) // nom commande, objet commande
|
.addSubcommand("-r", new Read(System.out)) // nom commande, objet commande
|
||||||
.addSubcommand("-b", new Build(System.out))
|
.addSubcommand("-b", new Build(System.out))
|
||||||
@ -52,7 +52,7 @@ public class Exec implements Callable <Void> {
|
|||||||
.addSubcommand("-e", new Evaluate(System.out))
|
.addSubcommand("-e", new Evaluate(System.out))
|
||||||
.addSubcommand("help", new HelpCommand()); // Aide générée automatiquement par l'API
|
.addSubcommand("help", new HelpCommand()); // Aide générée automatiquement par l'API
|
||||||
|
|
||||||
cmd.execute(t); //t
|
cmd.execute(args); //t
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package commands;
|
|||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
|
|
||||||
import picocli.CommandLine.*;
|
import picocli.CommandLine.*;
|
||||||
import progressbar.ProgressBar;
|
import progressbar.ProgressBar;
|
||||||
|
|
||||||
@ -156,7 +155,7 @@ public class Read implements Callable <Void> {
|
|||||||
|
|
||||||
logger.debug("CSV initialized with : "+ocr.createHashMapforCSV()+" , "+config.getParam().get("Code")+" , "+result_name);
|
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
|
csv.createFile(); //Génère le fichier csv à partir de la HMap retournée par l'OCR
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class Config {
|
|||||||
param.put("ShuffleQuestions", "1"); // 1 = qt mélangées, 0 = non mél
|
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("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("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("NameField", "Nom et Prénom"); // remplace le texte
|
||||||
param.put("StudentField",
|
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");
|
"Veuillez coder votre numéro\r\n d'étudiant ci-contre et écrire votre nom \r\n dans la case ci-dessous");
|
||||||
|
@ -13,13 +13,15 @@ import org.apache.logging.log4j.Logger;
|
|||||||
public class GenerateCSV {
|
public class GenerateCSV {
|
||||||
|
|
||||||
Map<String, String> etudiants;
|
Map<String, String> etudiants;
|
||||||
int numLength;
|
int nLength;
|
||||||
|
double mType;
|
||||||
String path = "export";
|
String path = "export";
|
||||||
Logger logger = LogManager.getLogger(GenerateCSV.class);
|
Logger logger = LogManager.getLogger(GenerateCSV.class);
|
||||||
|
|
||||||
public GenerateCSV(Map<String, String> map, String length, String pth) {
|
public GenerateCSV(Map<String, String> map, String numLength,String markType, String pth) {
|
||||||
this.etudiants = map;
|
this.etudiants = map;
|
||||||
this.numLength = Integer.parseInt(length);
|
this.nLength = Integer.parseInt(numLength);
|
||||||
|
this.mType = Integer.parseInt(markType);
|
||||||
this.path = path + "/" + pth;
|
this.path = path + "/" + pth;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -28,10 +30,10 @@ public class GenerateCSV {
|
|||||||
// Teste validité du numero etudiant (selon param de la config passé :
|
// Teste validité du numero etudiant (selon param de la config passé :
|
||||||
// numLength)
|
// numLength)
|
||||||
|
|
||||||
public boolean isValid(String s) {
|
public boolean isNumValid(String s) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
logger.debug("Checking string validity");
|
logger.debug("Checking string validity");
|
||||||
if (s.length() == this.numLength) {
|
if (s.length() == this.nLength) {
|
||||||
while (i < s.length()) {
|
while (i < s.length()) {
|
||||||
|
|
||||||
int nb = Character.getNumericValue(s.charAt(i));
|
int nb = Character.getNumericValue(s.charAt(i));
|
||||||
@ -60,6 +62,27 @@ public class GenerateCSV {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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() {
|
public void createFile() {
|
||||||
try (PrintWriter writer = new PrintWriter(new File(this.path))) {
|
try (PrintWriter writer = new PrintWriter(new File(this.path))) {
|
||||||
|
|
||||||
@ -79,12 +102,12 @@ public class GenerateCSV {
|
|||||||
// Si etudiant HashMap est null, pas ecrit
|
// Si etudiant HashMap est null, pas ecrit
|
||||||
if (etud != null) {
|
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"));
|
writer.write(etud + ";" + etudiants.get(etud) + System.getProperty("line.separator"));
|
||||||
logger.debug("Added "+etud+" to csv");
|
logger.debug("Added "+etud+" to csv");
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
} else {
|
||||||
|
@ -13,8 +13,9 @@ public class TestCSV {
|
|||||||
|
|
||||||
Map<String,String> map = new HashMap<String,String>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
String length = "8";
|
String length = "8";
|
||||||
|
String format = "20";
|
||||||
String path = "../export/result.csv";
|
String path = "../export/result.csv";
|
||||||
GenerateCSV csv = new GenerateCSV(map,length,path);
|
GenerateCSV csv = new GenerateCSV(map,length,format,path);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
@ -27,7 +28,7 @@ public class TestCSV {
|
|||||||
void testNotNull() {
|
void testNotNull() {
|
||||||
|
|
||||||
map.put("21705239", "17");
|
map.put("21705239", "17");
|
||||||
csv = new GenerateCSV(map,length,path);
|
csv = new GenerateCSV(map,length,format,path);
|
||||||
|
|
||||||
assertFalse(csv == null);
|
assertFalse(csv == null);
|
||||||
}
|
}
|
||||||
@ -37,10 +38,10 @@ public class TestCSV {
|
|||||||
|
|
||||||
map.put("21435712", "9");
|
map.put("21435712", "9");
|
||||||
map.put("21705239", "17");
|
map.put("21705239", "17");
|
||||||
csv = new GenerateCSV(map,length,path);
|
csv = new GenerateCSV(map,length,format,path);
|
||||||
|
|
||||||
for (String etud : csv.etudiants.keySet()) {
|
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("21435", "9");
|
||||||
map.put("1705239", "17");
|
map.put("1705239", "17");
|
||||||
csv = new GenerateCSV(map,length,path);
|
csv = new GenerateCSV(map,length,format,path);
|
||||||
|
|
||||||
for (String etud : csv.etudiants.keySet()) {
|
for (String etud : csv.etudiants.keySet()) {
|
||||||
assertFalse(csv.isValid(etud));
|
assertFalse(csv.isNumValid(etud));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user