Exemplo n.º 1
0
 public static void updateLessonsDictated(Teacher teacher) {
   Date today = new Date();
   int lessonsDictated = 0;
   for (Lesson lesson : Lesson.list()) {
     if (Objects.equals(lesson.getTeacher().getId(), teacher.getId())
         && lesson.getLessonState() == 1
         && lesson.getDateTime().before(today)) {
       lessonsDictated++;
     }
   }
   teacher.setLessonsDictated(lessonsDictated);
   teacher.save();
 }
Exemplo n.º 2
0
 public static void updateRating(Teacher teacher) {
   float lessonsRated = 0;
   float totalScore = 0;
   for (Lesson lesson : Lesson.list()) {
     if (Objects.equals(lesson.getTeacher().getId(), teacher.getId())
         && lesson.getTeacherReview() != null) {
       lessonsRated++;
       totalScore += lesson.getTeacherReview().getStars();
     }
   }
   float temp =
       lessonsRated == 0
           ? 0
           : (((float) ((long) (((totalScore / lessonsRated) * 100) + 0.5))) / 100);
   teacher.setRanking(temp);
   teacher.save();
 }
Exemplo n.º 3
0
  public int getFitness() {
    int res = 0;
    ArrayList<Lesson> pre = new ArrayList<Lesson>();
    HashMap<Lesson, Integer> perWeek = new HashMap<Lesson, Integer>();
    for (int j = 0; j < slots.length; j++) {
      for (int k = 0; k < slots[j].length; k++) {
        try {
          if (slots[j][k].isFree()) {
            // System.out.println("bbooa");
          }
        } catch (Exception e) {
          System.out.println("buu");
        }
        if (k % 2 == 0) {
          pre = slots[j][k].getL();
        } else {
          if (slots[j][k].getL() == pre) {
            res += 5;
          }
        }
        String[] teachers = new String[slots[j][k].getL().size()];
        for (int i = 0; i < slots[j][k].getL().size(); i++) {
          teachers[i] = slots[j][k].getL().get(i).getTeacher();
        }
        res += (!repeat(teachers) ? 5 : 0);
        Integer[] rooms = new Integer[slots[j][k].getL().size()];
        for (int i = 0; i < slots[j][k].getL().size(); i++) {
          rooms[i] = slots[j][k].getL().get(i).getRoom();
        }
        res += (!repeat(rooms) ? 5 : 0);
        for (Lesson l : slots[j][k].getL()) {
          if (Const.teachersAndLessons.containsKey(l.getSubject())) {
            if (contains(Const.teachersAndLessons.get(l.getSubject()), l.getTeacher())) {
              res += 5;
            }
          }
          if (Const.roomSpecific.containsKey(l.getTeacher())) {
            if (Const.roomSpecific.get(l.getTeacher()) == l.getRoom()) {
              res++;
            }
          }
          if (perWeek.containsKey(l)) {
            int count = perWeek.get(l);
            perWeek.remove(l);
            perWeek.put(l, count + 1);

          } else {
            perWeek.put(l, 1);
          }
          if (teachersAndLessons.containsKey(l.getSubject())) {
            if (l.getTeacher() == teachersAndLessons.get(l.getSubject())) {
              res += 5;
            }
          } else {
            teachersAndLessons.put(l.getSubject(), l.getTeacher());
          }
        }
        if (slots[j][k] == after(j, k) && slots[j][k] != before(j, k)) {

          res += 10;
        }
      }
    }
    for (Entry<Lesson, Integer> entry : perWeek.entrySet()) {
      if (entry.getKey().getSubject() == "Homeroom" && entry.getValue() == 1) {
        res += 5;
      }
      if (entry.getKey().getSubject() != "Majors") {
        if (entry.getValue() == Const.perWeek.get(entry.getKey())) res += 5;
      } else {
        if (entry.getValue() == Const.majorsPerWeek.get(entry.getKey())) res += 10;
      }
    }
    if (lessonCount() == 44) {
      res += 10;
    }
    this.fitness = res;
    return res;
  }