From a837be280d5f2db1e30335c67920d2cbb69d4b46 Mon Sep 17 00:00:00 2001 From: Olivier Barais Date: Thu, 21 Dec 2023 08:10:20 +0100 Subject: [PATCH 1/2] update JSON export to scale on big Exam --- .../java/fr/istic/web/rest/ExtendedAPI.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/istic/web/rest/ExtendedAPI.java b/src/main/java/fr/istic/web/rest/ExtendedAPI.java index 68493bb..c243f66 100644 --- a/src/main/java/fr/istic/web/rest/ExtendedAPI.java +++ b/src/main/java/fr/istic/web/rest/ExtendedAPI.java @@ -36,6 +36,7 @@ import org.apache.commons.io.IOUtils; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.hibernate.result.Output; import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; @@ -87,9 +88,11 @@ import javax.ws.rs.core.*; import java.io.ByteArrayInputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Base64; @@ -109,6 +112,7 @@ import org.slf4j.LoggerFactory; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import static javax.ws.rs.core.UriBuilder.fromPath; @@ -1297,24 +1301,17 @@ public Response exportExam(@PathParam("courseId") long courseId, @PathParam("exa } try { return Response.ok( + new StreamingOutput() { @Override public void write(OutputStream outputStream) throws IOException, WebApplicationException { - InputStream source = null; - try { - source = new ByteArrayInputStream( - new Gson().toJson(importExportService.export(courseId, true,examId)).getBytes()); - - } catch (Exception e) { - e.printStackTrace(); - return; - } - byte[] buf = new byte[8192]; - int length; - while ((length = source.read(buf)) != -1) { - outputStream.write(buf, 0, length); - } + OutputStreamWriter w = new OutputStreamWriter(outputStream); + Gson gson = new GsonBuilder().create(); + gson.toJson(importExportService.export(courseId, true,examId), w); + w.flush(); + w.close(); } + }, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment;filename=" + courseId + ".json") .build(); From 06ce758514a1b107bb4edfe8bfa59fe4822f6e9d Mon Sep 17 00:00:00 2001 From: Olivier Barais Date: Thu, 21 Dec 2023 10:44:09 +0100 Subject: [PATCH 2/2] fix #438 --- .../service/HybridGradedCommentService.java | 2 +- .../fr/istic/service/QuestionService.java | 2 +- .../java/fr/istic/web/rest/ExtendedAPI.java | 60 +++++++++++++++++-- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/istic/service/HybridGradedCommentService.java b/src/main/java/fr/istic/service/HybridGradedCommentService.java index 54ff02c..50569fe 100644 --- a/src/main/java/fr/istic/service/HybridGradedCommentService.java +++ b/src/main/java/fr/istic/service/HybridGradedCommentService.java @@ -75,7 +75,7 @@ public HybridGradedCommentDTO persistOrUpdate(HybridGradedCommentDTO hybridGrade } } var point = st.question.quarterpoint !=null ? st.question.quarterpoint.doubleValue(): 0.0; - currentNote = (point * pourcentage) / 100.0 + absoluteNote2Add; + currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add; if (currentNote > point) { currentNote = point; } else if (currentNote < 0) { diff --git a/src/main/java/fr/istic/service/QuestionService.java b/src/main/java/fr/istic/service/QuestionService.java index 2a38fa4..5383300 100644 --- a/src/main/java/fr/istic/service/QuestionService.java +++ b/src/main/java/fr/istic/service/QuestionService.java @@ -80,7 +80,7 @@ public QuestionDTO persistOrUpdate(QuestionDTO questionDTO) { } } var point = question.quarterpoint !=null ? question.quarterpoint.doubleValue(): 0.0; - currentNote = (point * pourcentage) / 100.0 + absoluteNote2Add; + currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add; if (currentNote > point) { currentNote = point; } else if (currentNote < 0) { diff --git a/src/main/java/fr/istic/web/rest/ExtendedAPI.java b/src/main/java/fr/istic/web/rest/ExtendedAPI.java index c243f66..7ff4c8b 100644 --- a/src/main/java/fr/istic/web/rest/ExtendedAPI.java +++ b/src/main/java/fr/istic/web/rest/ExtendedAPI.java @@ -11,6 +11,7 @@ import fr.istic.domain.GradedComment; import fr.istic.domain.HybridGradedComment; import fr.istic.domain.Question; +import fr.istic.domain.QuestionType; import fr.istic.domain.Scan; import fr.istic.domain.Student; import fr.istic.domain.StudentResponse; @@ -467,7 +468,10 @@ public Exam computeFinalNote(long examId, Map finalfinalResul } else if (resp.question.gradeType == GradeType.HYBRID && !"QCM".equals(resp.question.type.algoName)) { - // TODO + this.computeNote4Hybrid(resp); + + + // resp.persistOrUpdate(); finalnote = finalnote + (resp.quarternote / 4 ); } @@ -1310,7 +1314,7 @@ public void write(OutputStream outputStream) throws IOException, WebApplicationE gson.toJson(importExportService.export(courseId, true,examId), w); w.flush(); w.close(); - } + }; }, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment;filename=" + courseId + ".json") @@ -2080,6 +2084,44 @@ public Response getZone4GradedComment(@PathParam("examId") final long examId, } + private void computeNote4Hybrid(StudentResponse resp){ + var currentNote = 0.0; + var absoluteNote2Add = 0.0; + double pourcentage = 0.0; + if (resp.question != null && resp.question.defaultpoint != null){ + pourcentage = resp.question.defaultpoint.doubleValue(); + } + + for( Answer2HybridGradedComment an2 : resp.hybridcommentsValues){ + var stepValue = an2.stepValue.doubleValue(); + if (stepValue > 0) { + var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative : false; + var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() : 1.0; + var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() : 0.0; + + if (relative) { + pourcentage = pourcentage + ((stepValue / step) * grade); + } else { + absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade; + } + } + } + var point = resp.question.quarterpoint !=null ? resp.question.quarterpoint.doubleValue(): 0.0; + currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add; + + if (currentNote > point) { + currentNote = point; + } else if (currentNote < 0) { + currentNote = 0; + } + log.error("currentNote "+ Double.valueOf(currentNote*100).intValue()); + if (Double.valueOf(currentNote*100).intValue() != resp.quarternote) { + resp.quarternote = Double.valueOf(currentNote*100).intValue(); + StudentResponse.update(resp); + } + + } + @GET @Path("/getZone4HybridComment/{examId}/{hybridCommentId}/{stepValue}") @RolesAllowed({ AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN }) @@ -2132,6 +2174,8 @@ public Response getZone4HybridComment(@PathParam("examId") final long examId, Set processSt = new HashSet<>(); for (Answer2HybridGradedComment an : r) { StudentResponse studentResponse= an.studentResponse; + this.computeNote4Hybrid(studentResponse); + if (!processSt.contains(studentResponse)){ Answer4QuestionDTO answerdto = new Answer4QuestionDTO(); answerdto.setPagemin(studentResponse.sheet.pagemin); @@ -2280,13 +2324,13 @@ public Response getZone4Mark(@PathParam("examId") final long examId, @PathParam( List answers = new ArrayList<>(); Map textcomments = new HashMap<>(); Map gradedcomments = new HashMap<>(); - Map hybridcomments = new HashMap<>(); + Map hybridcomments = new HashMap<>(); if (r.size() > 0 && r.get(0).question != null) { int numero = r.get(0).question.numero; List hc= HybridGradedComment.findByQuestionId(r.get(0).question.id).list(); - hc.forEach(hc1 -> hybridcomments.put(hc1.id,hc1)); + hc.forEach(hc1 -> hybridcomments.put(hc1.id,this.hybridCommentMapper.toDto(hc1))); dto.setNumero(numero); List questions = Question.findQuestionbyExamIdandnumero(examId, numero).list(); @@ -2333,7 +2377,11 @@ public Response getZone4Mark(@PathParam("examId") final long examId, @PathParam( } answerdto.setStudentName(studentName); + if (studentResponse.question.gradeType == GradeType.HYBRID && !"QCM".equals(studentResponse.question.type.algoName)){ + this.computeNote4Hybrid(studentResponse); + } answerdto.setNote(Integer.valueOf(studentResponse.quarternote).doubleValue() / 4); + answerdto.setComments(commentsMapper.toDto(new ArrayList<>(studentResponse.comments))); answerdto.setTextComments( studentResponse.textcomments.stream().map(gc -> gc.id).collect(Collectors.toList())); @@ -2382,14 +2430,14 @@ public Response getZone4Question(@PathParam("examId") final long examId, @PathPa List answers = new ArrayList<>(); Map textcomments = new HashMap<>(); Map gradedcomments = new HashMap<>(); - Map hybridcomments = new HashMap<>(); + Map hybridcomments = new HashMap<>(); int numero = question.numero; dto.setNumero(numero); List questions = Question.findQuestionbyExamIdandnumero(examId, numero).list(); if (questions.size() > 0) { List hc= HybridGradedComment.findByQuestionId(questions.get(0).id).list(); - hc.forEach(hc1 -> hybridcomments.put(hc1.id,hc1)); + hc.forEach(hc1 -> hybridcomments.put(hc1.id,this.hybridCommentMapper.toDto(hc1))); dto.setZones(zoneMapper.toDto(questions.stream().map(q -> q.zone).collect(Collectors.toList()))); dto.setGradeType(questions.get(0).gradeType);