Skip to content

Commit

Permalink
Merge pull request #16 from lrusso96/fix-duplicate
Browse files Browse the repository at this point in the history
OpenstudHelper: Fix duplicated code, some reformatting
  • Loading branch information
leosarra authored Oct 24, 2019
2 parents c440abf + 5b6b933 commit 8e84ca6
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions src/main/java/lithium/openstud/driver/core/OpenstudHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

public class OpenstudHelper {

public enum Mode {
MOBILE, WEB
}

public enum Provider {
SAPIENZA
}

public static boolean isValidUrl(String url) {
if (url == null) return false;
String[] schemes = {"http", "https"};
Expand All @@ -42,19 +34,19 @@ public static double computeWeightedAverage(List<ExamDone> list, int laude) {
}

public static int computeBaseGraduation(List<ExamDone> list, int laude, boolean removeMaxMin) {
if (list.size() == 0 || (removeMaxMin && list.size()<=2)) return -1;
if (list.size() == 0 || (removeMaxMin && list.size() <= 2)) return -1;
List<ExamDone> tmp = new LinkedList<>(list);
if (removeMaxMin) {
ExamDone max = null;
ExamDone min = null;
for (ExamDone exam:tmp) {
for (ExamDone exam : tmp) {
if (max == null) max = exam;
else if (exam.getResult()>max.getResult()) max = exam;
else if (exam.getResult() > max.getResult()) max = exam;
}
tmp.remove(max);
for (ExamDone exam:tmp) {
for (ExamDone exam : tmp) {
if (min == null) min = exam;
else if (exam.getResult()<min.getResult()) min = exam;
else if (exam.getResult() < min.getResult()) min = exam;
}
tmp.remove(min);
}
Expand Down Expand Up @@ -95,24 +87,15 @@ public static ExamDone createFakeExamDone(String description, int cfu, int grade
done.setCfu(cfu);
done.setDate(LocalDate.now());
done.setDescription(description);
if (grade >= 31) done.setResult(31);
else done.setResult(grade);
done.setResult(Math.min(grade, 31));
return done;
}

public static List<Event> generateEventsFromTimetable(Map<String, List<Lesson>> timetable) {
List<Event> events = new LinkedList<>();
for (String code : timetable.keySet()) {
List<Lesson> lessons = timetable.get(code);
for (Lesson lesson : lessons) {
Event ev = new Event(EventType.LESSON);
ev.setTitle(lesson.getName());
ev.setStart(lesson.getStart());
ev.setEnd(lesson.getEnd());
ev.setTeacher(lesson.getTeacher());
ev.setWhere(lesson.getWhere());
events.add(ev);
}
events.addAll(generateEventsFromTimetable(lessons));
}
return events;
}
Expand Down Expand Up @@ -218,4 +201,12 @@ public static List<ExamDone> sortExamByGrade(List<ExamDone> list, boolean ascend
return list;
}

public enum Mode {
MOBILE, WEB
}

public enum Provider {
SAPIENZA
}

}

0 comments on commit 8e84ca6

Please sign in to comment.