Skip to content
Snippets Groups Projects
Commit 128f48c4 authored by Peter J's avatar Peter J
Browse files

Merge branch 'dev' into main

parents c47794c5 3e8f126a
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Service
@Slf4j
......@@ -51,13 +52,13 @@ public class ItemService {
return optionalItem.get();
}
public List<Question> getQuestionsWithGivenPointsFromSubtree(@NotNull final Category root, @NotNull final Integer points) {
public List<Question> getQuestionsWithGivenPointsFromSubtree(@NotNull final Category root, final Optional<Integer> points) {
List<Question> questions = new ArrayList<>();
for (var child : root.getChildren()) {
if (child instanceof Question) {
var question = (Question) child;
// add question if points ar unspecified (-1) or equal
if (points == -1 || question.getPoints().equals(points)) {
// add question if points or unspecified (-1) or equal
if (points.isEmpty() || points.get() == -1 || question.getPoints().equals(points.get())) {
questions.add((Question) child);
}
} else if (child instanceof Category) {
......
......@@ -28,7 +28,7 @@ public class TestVariantService {
private CompromiseGenerator compromiseGenerator;
public boolean checkSufficientQuestionCountInSubtree(@NotNull final Category root, final Integer points, final Integer count) throws Exception {
var questions = itemService.getQuestionsWithGivenPointsFromSubtree(root, points);
var questions = itemService.getQuestionsWithGivenPointsFromSubtree(root, Optional.ofNullable(points));
return questions.size() >= count;
}
......
......@@ -21,6 +21,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.util.ArrayList;
import java.util.Objects;
import static java.lang.Float.*;
......@@ -174,7 +175,8 @@ public class XMLService {
var penaltyEl = doc.createElement("penalty");
questionEl.appendChild(penaltyEl);
penaltyEl.setTextContent(question.getPenalty().toString());
var penalty = Objects.isNull(question.getPenalty()) ? 0 : question.getPenalty();
penaltyEl.setTextContent(String.valueOf(penalty));
var answerCount = question.getAnswers().size();
var correctCount = question.getAnswers().stream().filter(Answer::isCorrect).count();
......
......@@ -51,7 +51,10 @@ public class CompromiseGenerator implements Generator {
var availableQuestions = new ArrayList<Question>();
for (var category : searchedCategories) {
availableQuestions.addAll(itemService.getQuestionsWithGivenPointsFromSubtree(category, topic.getPoints()));
// TODO: get questions from all subtrees simultaneously
// having 3 categories specified for a topic means, that all of these categories COMBINED should
// have enough questions, NOT each of them
availableQuestions.addAll(itemService.getQuestionsWithGivenPointsFromSubtree(category, Optional.ofNullable(topic.getPoints())));
}
if (availableQuestions.size() < topic.getQuestionCount()) {
......
......@@ -9,9 +9,11 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.swing.text.html.Option;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Service
@AllArgsConstructor
......@@ -62,7 +64,7 @@ public class UniqueGenerator implements Generator {
var availableQuestions = new ArrayList<Question>();
for (var category : searchedCategories) {
availableQuestions.addAll(itemService.getQuestionsWithGivenPointsFromSubtree(category, topic.getPoints()));
availableQuestions.addAll(itemService.getQuestionsWithGivenPointsFromSubtree(category, Optional.ofNullable(topic.getPoints())));
}
if (availableQuestions.size() < topic.getQuestionCount()) {
......
......@@ -2,11 +2,15 @@ package cz.cvut.fel.pro.etmt.util;
import cz.cvut.fel.pro.etmt.model.library.Question;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.aggregation.DateOperators;
import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
@Slf4j
public class LatexStringBuilder {
......@@ -16,6 +20,7 @@ public class LatexStringBuilder {
public LatexStringBuilder() {
sb = new StringBuilder();
sdf.setTimeZone(TimeZone.getTimeZone("GMT+2"));
}
public LatexStringBuilder create(@NotNull final String title, final Date date) {
......
......@@ -23,8 +23,6 @@ async def read_root():
async def upload(request: Request):
data: bytes = await request.body()
print(data)
# create out folder in case it doesn't exist
pathlib.Path(OUT_PATH).mkdir(parents=True, exist_ok=True)
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment