changed assessment time limit

This commit is contained in:
alex 2024-08-07 07:39:48 -04:00
parent 08544e1428
commit d93fc9b139
4 changed files with 37 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Entity
@ -38,8 +39,14 @@ public class Assessment extends BaseEntity {
.map(AssessmentEvent::getTimestamp)
.findFirst();
return started.map(instant -> 300L - (Instant.now().getEpochSecond() - instant.getEpochSecond()))
.orElse(300L);
final Integer totalTimeMinutes = questions.stream()
.map(Question::getTimeMinutes)
.filter(Objects::nonNull)
.reduce(Integer::sum).orElse(30);
final long totalTimeSeconds = totalTimeMinutes * 60;
return started.map(instant -> totalTimeSeconds - (Instant.now().getEpochSecond() - instant.getEpochSecond()))
.orElse(totalTimeSeconds);
}
public Instant getStartingTime() {

View File

@ -18,4 +18,5 @@ public class Question extends BaseEntity{
private String description;
@Lob
private String content;
private Integer timeMinutes;
}

View File

@ -40,6 +40,7 @@ import com.vaadin.flow.theme.lumo.LumoUtility.Margin;
import com.vaadin.flow.theme.lumo.LumoUtility.Overflow;
import com.vaadin.flow.theme.lumo.LumoUtility.Padding;
import com.vaadin.flow.theme.lumo.LumoUtility.TextColor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Scope;
@ -55,6 +56,7 @@ import java.util.stream.Collectors;
@Scope("prototype")
@Route(value = "/evaluation", layout = MainLayout.class)
@AnonymousAllowed
@Slf4j
public class EvaluationView extends Main implements HasUrlParameter<String> {
final CompilerService compilerService;
@ -82,6 +84,8 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
Section startSection = null;
Section completedSection = null;
private H3 questionTitle = null;
private Text questionDescription = null;
public EvaluationView(final CompilerService compilerService, final AssessmentService assessmentService) {
this.compilerService = compilerService;
@ -170,6 +174,14 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
private void initEditorSection() {
editorSection = new Section();
editorSection.addClassNames(Display.FLEX, FlexDirection.COLUMN, Flex.GROW, Height.FULL);
VerticalLayout header = new VerticalLayout();
questionTitle = new H3("");
questionDescription = new Text("");
header.add(questionTitle);
header.add(questionDescription);
questionEditor = getCodeEditor();
final MenuBar runMenuBar = new MenuBar();
@ -186,7 +198,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
final MenuBar navMenuBar = new MenuBar();
prev = navMenuBar.addItem("Anterior pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
System.out.println(">>> prev");
log.info(">>> prev");
this.currSubmission.setResponse(this.questionEditor.getValue());
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
this.currSubmission = this.assessmentService.getPrevSubmission(assessment.getId(), this.currSubmission);
@ -208,7 +220,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
setInlineBlock(runMenuBar);
setInlineBlock(navMenuBar);
editorSection.add(menuBar, questionEditor);
editorSection.add(header, menuBar, questionEditor);
}
private void initCompletedSection() {
@ -239,7 +251,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
start = new Button("Empezar");
start.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_SUCCESS);
start.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
System.out.println(">>> start");
log.info(">>> start");
this.assessment = this.assessmentService.startAssessment(this.assessment.getId());
if (tf.getValue().trim().equalsIgnoreCase(this.assessment.getAppUser().getEmail())) {
@ -304,7 +316,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
}
private void goToNext() {
System.out.println(">>> next");
log.info(">>> next");
Submission found = this.assessmentService.getNextSubmission(assessment.getId(), this.currSubmission.getId());
if (found == null) {
@ -330,7 +342,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
timer = new SimpleTimer(0);
timer.setMinutes(true);
timer.addTimerEndEvent((ComponentEventListener<SimpleTimer.TimerEndedEvent>) timerEndedEvent -> {
Notification.show("Tiempo completado.", 5, Notification.Position.TOP_CENTER);
Notification.show("Tiempo completado.", 5_000, Notification.Position.TOP_CENTER);
this.currSubmission.setResponse(this.questionEditor.getValue());
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
this.assessment = assessmentService.completeAssessment(assessment.getId());
@ -357,6 +369,8 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
} else {
if (currSubmission != null) {
questionEditor.setValue(this.currSubmission.getResponse());
questionTitle.setText(this.currSubmission.getQuestion().getTitle());
questionDescription.setText(this.currSubmission.getQuestion().getDescription());
}
editorSection.setVisible(true);
@ -383,8 +397,9 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
);
}
final Long remainingTime = this.assessment.getRemainingTimeSeconds();
timer.pause();
timer.setStartTime(this.assessment.getRemainingTimeSeconds());
timer.setStartTime(remainingTime > 0 ? remainingTime : 3);
timer.setMinutes(true);
timer.reset();
timer.start();

View File

@ -3,6 +3,7 @@ package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Question;
import com.primefactorsolutions.service.QuestionService;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.TextArea;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.BeforeEvent;
@ -29,6 +30,7 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
private TextField title = null;
private TextArea description = null;
private TextArea content = null;
private IntegerField timeMinutes = null;
public QuestionView(final QuestionService questionService) {
super(Question.class);
@ -42,6 +44,9 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
content = new TextArea();
content.setLabel("Content");
timeMinutes = new IntegerField();
timeMinutes.setLabel("TimeMinutes");
setSavedHandler((SavedHandler<Question>) questionService::createOrUpdate);
}
@ -58,6 +63,6 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
@Override
protected List<Component> getFormComponents() {
return List.of(title, description, content);
return List.of(title, description, timeMinutes, content);
}
}