Skip to content

Commit 1787175

Browse files
authored
Merge pull request #162 from correctexam/develop
add export service to get metadaata with image of a question
2 parents 8b7cf33 + e05ef2e commit 1787175

6 files changed

Lines changed: 340 additions & 25 deletions

File tree

src/main/java/fr/istic/service/QuestionService.java

Lines changed: 218 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
import io.quarkus.panache.common.Page;
44
import fr.istic.domain.Answer2HybridGradedComment;
5-
import fr.istic.domain.Exam;
5+
import fr.istic.domain.ExamSheet;
66
import fr.istic.domain.GradedComment;
77
import fr.istic.domain.HybridGradedComment;
88
import fr.istic.domain.Question;
99
import fr.istic.domain.StudentResponse;
1010
import fr.istic.domain.TextComment;
11-
import fr.istic.domain.Zone;
1211
import fr.istic.domain.enumeration.GradeType;
13-
import fr.istic.service.dto.ExamDTO;
12+
import fr.istic.service.customdto.exportcomments.Answer;
13+
import fr.istic.service.customdto.exportcomments.AnswersWithPredictionDto;
14+
import fr.istic.service.customdto.exportcomments.Comment;
15+
import fr.istic.service.customdto.exportcomments.Prediction;
1416
import fr.istic.service.dto.QuestionDTO;
1517
import fr.istic.service.mapper.ExamMapper;
1618
import fr.istic.service.mapper.QuestionMapper;
@@ -37,56 +39,54 @@ public class QuestionService {
3739
@Inject
3840
QuestionMapper questionMapper;
3941

40-
4142
@Inject
4243
ExamMapper examMapper;
4344

4445
@Inject
4546
ZoneService zoneService;
4647

47-
4848
@Transactional
4949
public QuestionDTO persistOrUpdate(QuestionDTO questionDTO) {
5050
log.debug("Request to save Question : {}", questionDTO);
5151
var question = questionMapper.toEntity(questionDTO);
5252

53-
if (question.id!= null){
53+
if (question.id != null) {
5454
Question q2 = Question.findById(question.id);
55-
if (q2 != null && question.gradeType == GradeType.HYBRID && (
56-
q2.gradeType != question.gradeType || q2.defaultpoint != question.defaultpoint || q2.quarterpoint != q2.quarterpoint
57-
) ){
55+
if (q2 != null && question.gradeType == GradeType.HYBRID && (q2.gradeType != question.gradeType
56+
|| q2.defaultpoint != question.defaultpoint || q2.quarterpoint != q2.quarterpoint)) {
5857

59-
List<StudentResponse> sts= StudentResponse.findAllByQuestionIdfetchAnswerfetchHybridCommand(question.id).list();
60-
for (StudentResponse st : sts ){
61-
var currentNote = 0.0;
58+
List<StudentResponse> sts = StudentResponse
59+
.findAllByQuestionIdfetchAnswerfetchHybridCommand(question.id).list();
60+
for (StudentResponse st : sts) {
61+
var currentNote = 0.0;
6262
var absoluteNote2Add = 0.0;
6363
double pourcentage = 0.0;
64-
if (question != null && question.defaultpoint != null){
65-
pourcentage = question.defaultpoint.doubleValue() *4;
64+
if (question != null && question.defaultpoint != null) {
65+
pourcentage = question.defaultpoint.doubleValue() * 4;
6666
}
6767

68-
for( Answer2HybridGradedComment an2 : st.hybridcommentsValues){
68+
for (Answer2HybridGradedComment an2 : st.hybridcommentsValues) {
6969
var stepValue = an2.stepValue.doubleValue();
7070
if (stepValue > 0) {
7171
var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative : false;
7272
var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() : 1.0;
7373
var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() : 0.0;
7474

7575
if (relative) {
76-
pourcentage = pourcentage + (stepValue / step) * grade;
76+
pourcentage = pourcentage + (stepValue / step) * grade;
7777
} else {
78-
absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade;
78+
absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade;
7979
}
80-
}
80+
}
8181
}
82-
var point = question.quarterpoint !=null ? question.quarterpoint.doubleValue(): 0.0;
82+
var point = question.quarterpoint != null ? question.quarterpoint.doubleValue() : 0.0;
8383
currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add;
8484
if (currentNote > point && !st.question.canExceedTheMax) {
8585
currentNote = point;
8686
} else if (currentNote < 0 && !st.question.canBeNegative) {
8787
currentNote = 0;
8888
}
89-
st.quarternote = Double.valueOf(currentNote*100).intValue();
89+
st.quarternote = Double.valueOf(currentNote * 100).intValue();
9090
st.persistOrUpdate();
9191
}
9292
}
@@ -103,13 +103,12 @@ public QuestionDTO cleanAllCorrectionAndComment(QuestionDTO questionDTO) {
103103
return questionMapper.toDto(cleanAllCorrectionAndComment(question));
104104
}
105105

106-
107106
public Question cleanAllCorrectionAndComment(Question question) {
108107
List<GradedComment> gradeComment = new ArrayList<GradedComment>();
109108
List<TextComment> textComments = new ArrayList<TextComment>();
110109
gradeComment.addAll(GradedComment.findByQuestionId(question.id).list());
111110
textComments.addAll(TextComment.findByQuestionId(question.id).list());
112-
Set<StudentResponse> srs= this.updateCorrectionAndAnswer(question, gradeComment, textComments);
111+
Set<StudentResponse> srs = this.updateCorrectionAndAnswer(question, gradeComment, textComments);
113112
List<Long> gradeCommentids = gradeComment.stream().map(gc -> gc.id).collect(Collectors.toList());
114113
List<Long> textCommentsids = textComments.stream().map(gc -> gc.id).collect(Collectors.toList());
115114

@@ -123,12 +122,9 @@ public Question cleanAllCorrectionAndComment(Question question) {
123122
qids.add(question.id);
124123
HybridGradedComment.deleteByQIds(qids);
125124

126-
127125
return question;
128126
}
129127

130-
131-
132128
public Set<StudentResponse> updateCorrectionAndAnswer(Question question, List<GradedComment> gradeComment,
133129
List<TextComment> textComments) {
134130
Set<StudentResponse> srs = new HashSet(StudentResponse.findAllByQuestionId(question.id).list());
@@ -225,5 +221,202 @@ public Paged<QuestionDTO> findQuestionbyZoneId(Page page, long zoneId) {
225221
.map(question -> questionMapper.toDto((Question) question));
226222
}
227223

224+
public AnswersWithPredictionDto getallcommentsandprediction4qId(long qId) {
225+
AnswersWithPredictionDto awp = new AnswersWithPredictionDto();
226+
Question q = Question.findById(qId);
227+
awp.setQid(qId);
228+
var point = q.quarterpoint != null ? q.quarterpoint.doubleValue() : 0.0;
229+
230+
awp.setMaxgrade(point / 4.0);
231+
List<StudentResponse> srs = StudentResponse.findAllByQuestionId(qId).list();
232+
List<fr.istic.domain.Prediction> predictions = fr.istic.domain.Prediction.findByQuestionId(qId).list();
233+
234+
for (StudentResponse sr : srs) {
235+
236+
ExamSheet sh = sr.getCSheet();
237+
238+
if (sh != null && sh.pagemin != -1 && sh.pagemax != -1) {
239+
240+
Answer answer = new Answer();
241+
awp.getAnswer().add(answer);
242+
answer.setPagemin(sh.pagemin);
243+
answer.setPagemax(sh.pagemax);
244+
answer.setSheetId(sh.id);
245+
answer.setSheetName(sh.name);
246+
predictions.stream().filter(pr -> pr.sheet.id == sh.id).findAny().ifPresent(p -> {
247+
Prediction p1 = new Prediction();
248+
p1.setPredictionconfidence(p.predictionconfidence);
249+
p1.setText(p.text);
250+
answer.setPrediction(p1);
251+
});
252+
answer.setGrade(this.computeNote(sr)/100.0);
253+
254+
for (TextComment t : sr.textcomments) {
255+
Comment comment = new Comment();
256+
comment.setText(t.text);
257+
comment.setDescription(t.description);
258+
answer.getComments().add(comment);
259+
}
260+
for (GradedComment t : sr.gradedcomments) {
261+
Comment comment = new Comment();
262+
comment.setText(t.text);
263+
comment.setDescription(t.description);
264+
if (!"QCM".equals(q.type.algoName) && q.step > 0) {
265+
if (q.gradeType == GradeType.POSITIVE) {
266+
comment.setNoteComments(t.gradequarter / 4.0 / q.step);
267+
} else if (q.gradeType == GradeType.NEGATIVE) {
268+
comment.setNoteComments(-1.0*t.gradequarter / 4.0 / q.step);
269+
}
270+
}
271+
answer.getComments().add(comment);
272+
}
273+
for (Answer2HybridGradedComment t : sr.hybridcommentsValues) {
274+
Comment comment = new Comment();
275+
comment.setText(t.hybridcomments.text);
276+
comment.setDescription(t.hybridcomments.description);
277+
comment.setNoteComments(computeNote4HybridComment(sr, t)/4.0);
278+
answer.getComments().add(comment);
279+
}
280+
}
281+
}
282+
return awp;
283+
284+
}
285+
286+
private double computeNote(StudentResponse resp){
287+
if (resp.question.gradeType == GradeType.DIRECT && !"QCM".equals(resp.question.type.algoName)) {
288+
if (resp.question.step > 0) {
289+
return ((resp.quarternote * 100 / 4) / resp.question.step);
290+
}else {
291+
return 0.0;
292+
}
293+
} else if (resp.question.gradeType == GradeType.POSITIVE
294+
&& !"QCM".equals(resp.question.type.algoName)) {
295+
int currentNote = 0;
296+
for (var g : resp.gradedcomments) {
297+
if (g.gradequarter != null) {
298+
currentNote = currentNote + g.gradequarter;
299+
}
300+
}
301+
302+
if (currentNote > (resp.question.quarterpoint) * resp.question.step) {
303+
currentNote = (resp.question.quarterpoint) * resp.question.step;
304+
}
305+
if (resp.question.step > 0) {
306+
return (currentNote * 100 / 4 / resp.question.step);
307+
} else {
308+
return 0.0;
309+
}
310+
311+
} else if (resp.question.gradeType == GradeType.NEGATIVE
312+
&& !"QCM".equals(resp.question.type.algoName)) {
313+
int currentNote = resp.question.quarterpoint * resp.question.step;
314+
for (var g : resp.gradedcomments) {
315+
if (g.gradequarter != null) {
316+
currentNote = currentNote - g.gradequarter;
317+
}
318+
}
319+
;
320+
if (currentNote < 0) {
321+
currentNote = 0;
322+
}
323+
if (resp.question.step > 0) {
324+
return (currentNote * 100 / 4 / resp.question.step);
325+
}
326+
else {
327+
return 0.0;
328+
}
329+
330+
} else if (resp.question.gradeType == GradeType.HYBRID
331+
&& !"QCM".equals(resp.question.type.algoName)) {
332+
return this.computeNote4Hybrid(resp)/4;
333+
334+
} else if ("QCM".equals(resp.question.type.algoName) && resp.question.step !=null && resp.question.step > 0) {
335+
int currentNote = 0;
336+
for (var g : resp.gradedcomments) {
337+
if (g.description.startsWith("correct")) {
338+
currentNote = currentNote + resp.question.quarterpoint * resp.question.step;
339+
} else if (g.description.startsWith("incorrect")) {
340+
currentNote = currentNote - resp.question.quarterpoint;
341+
}
342+
}
343+
return (currentNote * 100 / 4 / resp.question.step);
344+
} else if ("QCM".equals(resp.question.type.algoName) && resp.question.step <= 0) {
345+
int currentNote = 0;
346+
for (var g : resp.gradedcomments) {
347+
if (g.description.startsWith("correct")) {
348+
currentNote = currentNote + resp.question.quarterpoint;
349+
}
350+
}
351+
return (currentNote * 100 / 4);
352+
}
353+
else {
354+
return 0.0;
355+
}
356+
}
357+
358+
private double computeNote4Hybrid(StudentResponse resp) {
359+
var currentNote = 0.0;
360+
var absoluteNote2Add = 0.0;
361+
double pourcentage = 0.0;
362+
if (resp.question != null && resp.question.defaultpoint != null) {
363+
pourcentage = resp.question.defaultpoint.doubleValue() *4;
364+
}
365+
366+
for (Answer2HybridGradedComment an2 : resp.hybridcommentsValues) {
367+
var stepValue = an2.stepValue !=null ? an2.stepValue.doubleValue(): 0.0;
368+
if (stepValue > 0) {
369+
var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative : false;
370+
var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() : 1.0;
371+
var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() : 0.0;
372+
373+
if (relative) {
374+
pourcentage = pourcentage + ((stepValue / step) * grade);
375+
376+
} else {
377+
absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade;
378+
379+
}
380+
}
381+
}
382+
var point = resp.question.quarterpoint != null ? resp.question.quarterpoint.doubleValue() : 0.0;
383+
384+
currentNote = ((point * pourcentage) / 400.0) + absoluteNote2Add;
385+
386+
if (currentNote > point && !resp.question.canExceedTheMax) {
387+
currentNote = point;
388+
} else if (currentNote < 0 && !resp.question.canBeNegative) {
389+
currentNote = 0;
390+
}
391+
392+
return Double.valueOf(currentNote * 100);
393+
394+
}
395+
396+
397+
private double computeNote4HybridComment(StudentResponse resp, Answer2HybridGradedComment an2) {
398+
var absoluteNote2Add = 0.0;
399+
double pourcentage = 0.0;
400+
if (resp.question != null && resp.question.defaultpoint != null) {
401+
pourcentage = resp.question.defaultpoint.doubleValue() *4;
402+
}
403+
404+
var stepValue = an2.stepValue !=null ? an2.stepValue.doubleValue(): 0.0;
405+
if (stepValue > 0) {
406+
var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative : false;
407+
var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() : 1.0;
408+
var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() : 0.0;
409+
410+
if (relative) {
411+
pourcentage = pourcentage + ((stepValue / step) * grade);
412+
413+
} else {
414+
absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade;
415+
416+
}
417+
}
418+
419+
return absoluteNote2Add;
420+
}
228421

229422
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package fr.istic.service.customdto.exportcomments;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import io.quarkus.runtime.annotations.RegisterForReflection;
7+
@RegisterForReflection
8+
9+
public class Answer {
10+
private Long sheetId;
11+
private String sheetName;
12+
private Double grade;
13+
private Integer pagemin;
14+
private Integer pagemax;
15+
private List<Comment> comments = new ArrayList<>();
16+
private Prediction prediction;
17+
18+
public Long getSheetId() { return sheetId; }
19+
public void setSheetId(Long value) { this.sheetId = value; }
20+
21+
public String getSheetName() { return sheetName; }
22+
public void setSheetName(String value) { this.sheetName = value; }
23+
24+
public Double getGrade() { return grade; }
25+
public void setGrade(Double value) { this.grade = value; }
26+
27+
public Integer getPagemin() { return pagemin; }
28+
public void setPagemin(Integer value) { this.pagemin = value; }
29+
30+
public Integer getPagemax() { return pagemax; }
31+
public void setPagemax(Integer value) { this.pagemax = value; }
32+
33+
public List<Comment> getComments() { return comments; }
34+
public void setComments(List<Comment> value) { this.comments = value; }
35+
36+
public Prediction getPrediction() { return prediction; }
37+
public void setPrediction(Prediction value) { this.prediction = value; }
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package fr.istic.service.customdto.exportcomments;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import io.quarkus.runtime.annotations.RegisterForReflection;
7+
8+
@RegisterForReflection
9+
10+
public class AnswersWithPredictionDto {
11+
private Double maxgrade;
12+
private Long qid;
13+
private List<Answer> answer = new ArrayList<>();
14+
15+
public Double getMaxgrade() { return maxgrade; }
16+
public void setMaxgrade(Double value) { this.maxgrade = value; }
17+
18+
public Long getQid() { return qid; }
19+
public void setQid(Long value) { this.qid = value; }
20+
21+
public List<Answer> getAnswer() { return answer; }
22+
public void setAnswer(List<Answer> value) { this.answer = value; }
23+
}

0 commit comments

Comments
 (0)