Skip to content

Commit

Permalink
Merge pull request #388 from mp-access/improvement/rounding-384
Browse files Browse the repository at this point in the history
Improvement/rounding 384
  • Loading branch information
a-a-hofmann authored Nov 6, 2019
2 parents 7cc03ed + ac27927 commit 8007fff
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ExerciseMetadataDTO {
private ExerciseType type;
private String language;
private Boolean isGraded;
private int maxScore;
private double maxScore;

public ExerciseMetadataDTO(Exercise exercise) {
this.id = exercise.getId();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/uzh/ifi/access/course/model/Assignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public Optional<Exercise> findExerciseById(String id) {
return exercises.stream().filter(e -> e.getId().equals(id)).findFirst();
}

public int getMaxScore() {
return exercises.stream().mapToInt(e -> e.getMaxScore()).sum();
public double getMaxScore() {
return exercises.stream().mapToDouble(ExerciseConfig::getMaxScore).sum();
}


Expand Down
6 changes: 4 additions & 2 deletions src/main/java/ch/uzh/ifi/access/course/model/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Exercise extends ExerciseConfig implements Indexed<Exercise>, HasBr
@ToString.Exclude
private String question;


@JsonIgnore
@ToString.Exclude
private List<VirtualFile> private_files;
Expand All @@ -51,8 +52,8 @@ public Exercise(String name) {
}

@Builder
private Exercise(ExerciseType type, String language, Boolean isGraded, int maxScore, int maxSubmits, String gradingSetup, List<String> options, List<String> solutions, List<String> hints, String id, int index, String gitHash, Assignment assignment, String question, List<VirtualFile> private_files, List<VirtualFile> solution_files, List<VirtualFile> resource_files, List<VirtualFile> public_files, CodeExecutionLimits executionLimits, String title, String longTitle) {
super(title, longTitle, type, language, isGraded, maxScore, maxSubmits, gradingSetup, options, solutions, hints, executionLimits);
private Exercise(ExerciseType type, String language, Boolean isGraded, int maxScore, int maxSubmits, String gradingSetup, List<String> options, List<String> solutions, List<String> hints, String id, int index, String gitHash, Assignment assignment, String question, List<VirtualFile> private_files, List<VirtualFile> solution_files, List<VirtualFile> resource_files, List<VirtualFile> public_files, CodeExecutionLimits executionLimits, String title, String longTitle, Rounding rounding) {
super(title, longTitle, type, language, isGraded, maxScore, maxSubmits, gradingSetup, rounding, options, solutions, hints, executionLimits);
this.id = id;
this.index = index;
this.gitHash = gitHash;
Expand Down Expand Up @@ -82,6 +83,7 @@ public void set(ExerciseConfig other) {
this.solutions = other.getSolutions();
this.hints = other.getHints();
this.executionLimits = other.getExecutionLimits();
this.rounding = other.getRounding();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ public class ExerciseConfig implements Serializable {
protected ExerciseType type;
protected String language;
protected Boolean isGraded;
protected int maxScore;
protected double maxScore;
protected int maxSubmits;
protected String gradingSetup;
protected Rounding rounding;

protected List<String> options;
protected List<String> solutions;
protected List<String> hints;

protected CodeExecutionLimits executionLimits;


public ExerciseConfig() {
this.isGraded = true;
this.maxSubmits = 1;
this.maxScore = 1;
this.executionLimits = CodeExecutionLimits.DEFAULTS;
this.rounding = Rounding.DEFAULT;
}

}
58 changes: 58 additions & 0 deletions src/main/java/ch/uzh/ifi/access/course/model/Rounding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ch.uzh.ifi.access.course.model;

import lombok.Data;

import java.io.Serializable;
import java.util.function.BiFunction;

@Data
public class Rounding implements Serializable {

public static final Rounding DEFAULT = new Rounding(Strategy.ROUND, 4);

private Strategy strategy;
private int steps;

public Rounding() {
}

public Rounding(Strategy strategy, int steps) {
this.strategy = strategy;
this.steps = steps;
}

public double round(double value) {
return strategy.round(value, steps);
}

public enum Strategy {

CEILING(Strategy::ceil),
FLOOR(Strategy::floor),
ROUND(Strategy::roundUp);

private BiFunction<Double, Integer, Double> algorithm;

Strategy(BiFunction<Double, Integer, Double> algorithm) {
this.algorithm = algorithm;
}

double round(double unroundedValue, int steps) {
return algorithm.apply(unroundedValue, steps);
}

static double ceil(Double unroundedValue, Integer steps) {
return Math.ceil( unroundedValue*steps)/steps;
}

static double floor(Double unroundedValue, Integer steps) {
return Math.floor(unroundedValue * steps)/steps;
}

static double roundUp(double unroundedValue, Integer steps) {
return (double) Math.round(unroundedValue * steps) / steps;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AssignmentResults {

private String userId;
private String assignmentId;
private int maxScore;
private double maxScore;
private List<StudentSubmission> gradedSubmissions;

public double getStudentScore() {
Expand Down
Loading

0 comments on commit 8007fff

Please sign in to comment.