Allows admins to manage grading report templates #14
@ -1,5 +1,6 @@
|
|||||||
package se.su.dsv.scipro.report;
|
package se.su.dsv.scipro.report;
|
||||||
|
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import se.su.dsv.scipro.project.Project;
|
import se.su.dsv.scipro.project.Project;
|
||||||
import se.su.dsv.scipro.report.calculators.original.SupervisorBachelorGradeCalculator;
|
import se.su.dsv.scipro.report.calculators.original.SupervisorBachelorGradeCalculator;
|
||||||
import se.su.dsv.scipro.report.calculators.original.SupervisorMaster15GradeCalculator;
|
import se.su.dsv.scipro.report.calculators.original.SupervisorMaster15GradeCalculator;
|
||||||
@ -8,8 +9,21 @@ import se.su.dsv.scipro.system.DegreeType;
|
|||||||
import se.su.dsv.scipro.system.ProjectType;
|
import se.su.dsv.scipro.system.ProjectType;
|
||||||
|
|
||||||
public class GradeCalculatorServiceImpl implements GradeCalculatorService {
|
public class GradeCalculatorServiceImpl implements GradeCalculatorService {
|
||||||
|
|
||||||
|
private final GradingReportService gradingReportTemplateService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GradeCalculatorServiceImpl(GradingReportService gradingReportService) {
|
||||||
|
this.gradingReportTemplateService = gradingReportService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GradeCalculator getSupervisorCalculator(final Project project) {
|
public GradeCalculator getSupervisorCalculator(final Project project) {
|
||||||
|
GradingReportTemplate template = gradingReportTemplateService.getTemplate(project);
|
||||||
|
if (!template.getGradeLimits().isEmpty()) {
|
||||||
|
return new GradingReportTemplateGradeCalculator(template);
|
||||||
|
}
|
||||||
|
|
||||||
DegreeType degreeType = project.getProjectType().getDegreeType();
|
DegreeType degreeType = project.getProjectType().getDegreeType();
|
||||||
if (degreeType == DegreeType.BACHELOR) {
|
if (degreeType == DegreeType.BACHELOR) {
|
||||||
if (getYear(project) >= 2017) {
|
if (getYear(project) >= 2017) {
|
||||||
|
@ -15,8 +15,14 @@ import java.util.stream.Collectors;
|
|||||||
@Entity
|
@Entity
|
||||||
public abstract class GradingReport extends Report {
|
public abstract class GradingReport extends Report {
|
||||||
|
|
||||||
public enum Grade {
|
public record Grade(String name) {
|
||||||
A, B, C, D, E, F, FX
|
public static final Grade A = new Grade("A");
|
||||||
|
public static final Grade B = new Grade("B");
|
||||||
|
public static final Grade C = new Grade("C");
|
||||||
|
public static final Grade D = new Grade("D");
|
||||||
|
public static final Grade E = new Grade("E");
|
||||||
|
public static final Grade F = new Grade("F");
|
||||||
|
public static final Grade FX = new Grade("FX");
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum State { INITIAL, REVIEWING, FINALIZED }
|
public enum State { INITIAL, REVIEWING, FINALIZED }
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package se.su.dsv.scipro.report;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
class GradingReportTemplateGradeCalculator implements GradeCalculator {
|
||||||
|
private final GradingReportTemplate template;
|
||||||
|
|
||||||
|
GradingReportTemplateGradeCalculator(GradingReportTemplate template) {
|
||||||
|
this.template = template;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GradingReport.Grade getGrade(GradingReport gradingReport) {
|
||||||
|
for (GradingCriterion gradingCriterion : gradingReport.getGradingCriteria()) {
|
||||||
|
if (!gradingCriterion.meetsMinimumPointRequirement()) {
|
||||||
|
return new GradingReport.Grade(template.getFailingGrade());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long points = getPoints(gradingReport);
|
||||||
|
String textualGrade = template.getGradeLimits()
|
||||||
|
.stream()
|
||||||
|
.filter(gradeLimit -> points >= gradeLimit.getLowerLimit())
|
||||||
|
.max(Comparator.comparing(GradeLimit::getLowerLimit))
|
||||||
|
.map(GradeLimit::getGrade)
|
||||||
|
.orElseGet(template::getFailingGrade);
|
||||||
|
return new GradingReport.Grade(textualGrade);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPoints(GradingReport gradingReport) {
|
||||||
|
return gradingReport.getGradingCriteria()
|
||||||
|
.stream()
|
||||||
|
.map(GradingCriterion::getPoints)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.mapToInt(Integer::intValue)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ public class GradingReportPointsPanel extends Panel {
|
|||||||
return gradingReportIModel.getObject().getGrade(gradeCalculator);
|
return gradingReportIModel.getObject().getGrade(gradeCalculator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final Label grade = new Label(GRADE, gradeModel) {
|
final Label grade = new Label(GRADE, gradeModel.map(GradingReport.Grade::name)) {
|
||||||
@Override
|
@Override
|
||||||
protected void onConfigure() {
|
protected void onConfigure() {
|
||||||
super.onConfigure();
|
super.onConfigure();
|
||||||
|
@ -45,7 +45,7 @@ public class GradingReportPointsPanelTest extends SciProTest {
|
|||||||
when(gradeCalculator.getGrade(any(GradingReport.class))).thenReturn(grade);
|
when(gradeCalculator.getGrade(any(GradingReport.class))).thenReturn(grade);
|
||||||
startPanel();
|
startPanel();
|
||||||
|
|
||||||
tester.assertLabel(path(panel, GRADE), grade.toString());
|
tester.assertLabel(path(panel, GRADE), grade.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user