changed assessment time limit
This commit is contained in:
parent
08544e1428
commit
d93fc9b139
@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -38,8 +39,14 @@ public class Assessment extends BaseEntity {
|
|||||||
.map(AssessmentEvent::getTimestamp)
|
.map(AssessmentEvent::getTimestamp)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
return started.map(instant -> 300L - (Instant.now().getEpochSecond() - instant.getEpochSecond()))
|
final Integer totalTimeMinutes = questions.stream()
|
||||||
.orElse(300L);
|
.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() {
|
public Instant getStartingTime() {
|
||||||
|
@ -18,4 +18,5 @@ public class Question extends BaseEntity{
|
|||||||
private String description;
|
private String description;
|
||||||
@Lob
|
@Lob
|
||||||
private String content;
|
private String content;
|
||||||
|
private Integer timeMinutes;
|
||||||
}
|
}
|
||||||
|
@ -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.Overflow;
|
||||||
import com.vaadin.flow.theme.lumo.LumoUtility.Padding;
|
import com.vaadin.flow.theme.lumo.LumoUtility.Padding;
|
||||||
import com.vaadin.flow.theme.lumo.LumoUtility.TextColor;
|
import com.vaadin.flow.theme.lumo.LumoUtility.TextColor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ import java.util.stream.Collectors;
|
|||||||
@Scope("prototype")
|
@Scope("prototype")
|
||||||
@Route(value = "/evaluation", layout = MainLayout.class)
|
@Route(value = "/evaluation", layout = MainLayout.class)
|
||||||
@AnonymousAllowed
|
@AnonymousAllowed
|
||||||
|
@Slf4j
|
||||||
public class EvaluationView extends Main implements HasUrlParameter<String> {
|
public class EvaluationView extends Main implements HasUrlParameter<String> {
|
||||||
|
|
||||||
final CompilerService compilerService;
|
final CompilerService compilerService;
|
||||||
@ -82,6 +84,8 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
Section startSection = null;
|
Section startSection = null;
|
||||||
|
|
||||||
Section completedSection = null;
|
Section completedSection = null;
|
||||||
|
private H3 questionTitle = null;
|
||||||
|
private Text questionDescription = null;
|
||||||
|
|
||||||
public EvaluationView(final CompilerService compilerService, final AssessmentService assessmentService) {
|
public EvaluationView(final CompilerService compilerService, final AssessmentService assessmentService) {
|
||||||
this.compilerService = compilerService;
|
this.compilerService = compilerService;
|
||||||
@ -170,6 +174,14 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
private void initEditorSection() {
|
private void initEditorSection() {
|
||||||
editorSection = new Section();
|
editorSection = new Section();
|
||||||
editorSection.addClassNames(Display.FLEX, FlexDirection.COLUMN, Flex.GROW, Height.FULL);
|
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();
|
questionEditor = getCodeEditor();
|
||||||
|
|
||||||
final MenuBar runMenuBar = new MenuBar();
|
final MenuBar runMenuBar = new MenuBar();
|
||||||
@ -186,7 +198,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
|
|
||||||
final MenuBar navMenuBar = new MenuBar();
|
final MenuBar navMenuBar = new MenuBar();
|
||||||
prev = navMenuBar.addItem("Anterior pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
prev = navMenuBar.addItem("Anterior pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
||||||
System.out.println(">>> prev");
|
log.info(">>> prev");
|
||||||
this.currSubmission.setResponse(this.questionEditor.getValue());
|
this.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
this.currSubmission = this.assessmentService.getPrevSubmission(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(runMenuBar);
|
||||||
setInlineBlock(navMenuBar);
|
setInlineBlock(navMenuBar);
|
||||||
|
|
||||||
editorSection.add(menuBar, questionEditor);
|
editorSection.add(header, menuBar, questionEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCompletedSection() {
|
private void initCompletedSection() {
|
||||||
@ -239,7 +251,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
start = new Button("Empezar");
|
start = new Button("Empezar");
|
||||||
start.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_SUCCESS);
|
start.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_SUCCESS);
|
||||||
start.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
start.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
System.out.println(">>> start");
|
log.info(">>> start");
|
||||||
this.assessment = this.assessmentService.startAssessment(this.assessment.getId());
|
this.assessment = this.assessmentService.startAssessment(this.assessment.getId());
|
||||||
|
|
||||||
if (tf.getValue().trim().equalsIgnoreCase(this.assessment.getAppUser().getEmail())) {
|
if (tf.getValue().trim().equalsIgnoreCase(this.assessment.getAppUser().getEmail())) {
|
||||||
@ -304,7 +316,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void goToNext() {
|
private void goToNext() {
|
||||||
System.out.println(">>> next");
|
log.info(">>> next");
|
||||||
Submission found = this.assessmentService.getNextSubmission(assessment.getId(), this.currSubmission.getId());
|
Submission found = this.assessmentService.getNextSubmission(assessment.getId(), this.currSubmission.getId());
|
||||||
|
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
@ -330,7 +342,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
timer = new SimpleTimer(0);
|
timer = new SimpleTimer(0);
|
||||||
timer.setMinutes(true);
|
timer.setMinutes(true);
|
||||||
timer.addTimerEndEvent((ComponentEventListener<SimpleTimer.TimerEndedEvent>) timerEndedEvent -> {
|
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.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
this.assessment = assessmentService.completeAssessment(assessment.getId());
|
this.assessment = assessmentService.completeAssessment(assessment.getId());
|
||||||
@ -357,6 +369,8 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
} else {
|
} else {
|
||||||
if (currSubmission != null) {
|
if (currSubmission != null) {
|
||||||
questionEditor.setValue(this.currSubmission.getResponse());
|
questionEditor.setValue(this.currSubmission.getResponse());
|
||||||
|
questionTitle.setText(this.currSubmission.getQuestion().getTitle());
|
||||||
|
questionDescription.setText(this.currSubmission.getQuestion().getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
editorSection.setVisible(true);
|
editorSection.setVisible(true);
|
||||||
@ -383,8 +397,9 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Long remainingTime = this.assessment.getRemainingTimeSeconds();
|
||||||
timer.pause();
|
timer.pause();
|
||||||
timer.setStartTime(this.assessment.getRemainingTimeSeconds());
|
timer.setStartTime(remainingTime > 0 ? remainingTime : 3);
|
||||||
timer.setMinutes(true);
|
timer.setMinutes(true);
|
||||||
timer.reset();
|
timer.reset();
|
||||||
timer.start();
|
timer.start();
|
||||||
|
@ -3,6 +3,7 @@ package com.primefactorsolutions.views;
|
|||||||
import com.primefactorsolutions.model.Question;
|
import com.primefactorsolutions.model.Question;
|
||||||
import com.primefactorsolutions.service.QuestionService;
|
import com.primefactorsolutions.service.QuestionService;
|
||||||
import com.vaadin.flow.component.Component;
|
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.TextArea;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
import com.vaadin.flow.router.BeforeEvent;
|
import com.vaadin.flow.router.BeforeEvent;
|
||||||
@ -29,6 +30,7 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
|
|||||||
private TextField title = null;
|
private TextField title = null;
|
||||||
private TextArea description = null;
|
private TextArea description = null;
|
||||||
private TextArea content = null;
|
private TextArea content = null;
|
||||||
|
private IntegerField timeMinutes = null;
|
||||||
|
|
||||||
public QuestionView(final QuestionService questionService) {
|
public QuestionView(final QuestionService questionService) {
|
||||||
super(Question.class);
|
super(Question.class);
|
||||||
@ -42,6 +44,9 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
|
|||||||
content = new TextArea();
|
content = new TextArea();
|
||||||
content.setLabel("Content");
|
content.setLabel("Content");
|
||||||
|
|
||||||
|
timeMinutes = new IntegerField();
|
||||||
|
timeMinutes.setLabel("TimeMinutes");
|
||||||
|
|
||||||
setSavedHandler((SavedHandler<Question>) questionService::createOrUpdate);
|
setSavedHandler((SavedHandler<Question>) questionService::createOrUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +63,6 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Component> getFormComponents() {
|
protected List<Component> getFormComponents() {
|
||||||
return List.of(title, description, content);
|
return List.of(title, description, timeMinutes, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user