Ejemplo n.º 1
0
 public boolean isTimeslotFreeForCourse(Course c, Calendar time, int hours) {
   List<Room> rooms = findRoomsForCourse(c);
   Calendar end = (Calendar) time.clone();
   end.add(Calendar.HOUR_OF_DAY, hours);
   for (CurriculumSemester cs : c.getCurriculumSemesters()) {
     for (Course co : cs.getCourses()) {
       WeeklyEvent we = co.getWeeklyEvent();
       if (we != null
           && DateFunctions.doDateRangesOverlap(
               time, end, we.getStartTime(), we.getEndTime(), true)) {
         return false;
       }
     }
   }
   return true;
 }
Ejemplo n.º 2
0
 public boolean generateWeeklyEventForAllCourses() {
   HibernateSupport.beginTransaction();
   for (WeeklyEvent we : etm.getWeeklyEvents()) {
     we.deleteFromDB();
   }
   HibernateSupport.commitTransaction();
   etm.clearWeeklyEvents();
   List<Course> courses = bc.getCoc().getCourseTableModel().getAllCourses();
   boolean result = true;
   for (Course c : courses) {
     if (!generateWeeklyEventFor(c)) {
       LoggingFunctions.printError("Could not generate weekly event for " + c.getId(), "-");
       result = false;
     }
   }
   return result;
 }
Ejemplo n.º 3
0
 public List<Room> findRoomsForCourse(Course c) {
   List<Room> rooms = new ArrayList<>();
   for (Room r : bc.getRc().getRoomModel().getRooms()) {
     if (r.getRoomSize() >= c.getParticipants().size()) {
       rooms.add(r);
     }
   }
   return rooms;
 }
Ejemplo n.º 4
0
  public boolean generateWeeklyEventFor(Course c) {
    List<Room> rooms = findRoomsForCourse(c);
    Room r = null;
    if (rooms.size() < 1) {
      LoggingFunctions.printError(
          "Could not generate weekly event for course " + c.getId(), "No suitable rooms found");
      return false;
    }
    Calendar cal = DateFunctions.calculateNextValidStartTime();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    int hours = (int) c.getSemesterHours();

    // While there is another valid start time
    while (DateFunctions.calculateNextValidStartTime(cal, hours)) {
      // If the course can be done on that start time
      if (isTimeslotFreeForCourse(c, cal, hours)) {
        r = getFreeRoomForTimeslot(rooms, cal, hours);
        // If there is a free room at that time
        if (r != null) {
          WeeklyEvent we = new WeeklyEvent();
          we.setEvent(cal, hours, c, r);
          etm.addWeeklyEvent(we);
          we.saveToDB();
          System.out.println("");
          System.out.println("Saved new weekly event:");
          System.out.println("Course: " + c.getName());
          System.out.println(
              "From: " + cal.get(Calendar.HOUR_OF_DAY) + "" + DateFunctions.getDayOfWeek(cal));
          System.out.println(
              "To: "
                  + cal.get(Calendar.HOUR_OF_DAY)
                  + hours
                  + ""
                  + DateFunctions.getDayOfWeek(cal));
          System.out.println("Room: " + r.getRoomName());
          System.out.println("");
          return true;
        }
      }
    }

    return false;
  }