예제 #1
0
 /** Connect the vector of QV's into the main View */
 public void installQVs() {
   Exam thisExam = theTD.curX;
   Vector qv = thisExam.getListData();
   for (int i = 0; i < qv.size(); i++) {
     // Use question number (1-origin) as string name.
     // System.out.println("Add question " +i +" to " + questionsPanel);
     questionsPanel.add(Integer.toString(i + 1), new QView((Q) qv.elementAt(i)));
   }
   myCardLayout.first(questionsPanel);
 }
 /**
  * Compute conflicts -- there is a conflict if the other variable is assigned and {@link
  * ExamDistributionConstraint#check(ExamPlacement, ExamPlacement)} is false
  */
 @Override
 public void computeConflicts(ExamPlacement givenPlacement, Set<ExamPlacement> conflicts) {
   boolean before = true;
   for (Exam exam : variables()) {
     if (exam.equals(givenPlacement.variable())) {
       before = false;
       continue;
     }
     ExamPlacement placement = exam.getAssignment();
     if (placement == null) continue;
     if (!check(before ? placement : givenPlacement, before ? givenPlacement : placement))
       conflicts.add(placement);
   }
 }
예제 #3
0
  /**
   * Create a new object of type cls from a resultset row starting from a specified offset. This is
   * done so that you can select other rows than just those needed for this object. You may for
   * example want to create two objects from the same row.
   *
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  public static Exam row2Object(Record row, int offset, Class cls) throws TorqueException {
    try {
      Exam obj = (Exam) cls.newInstance();
      ExamPeer.populateObject(row, offset, obj);
      obj.setModified(false);
      obj.setNew(false);

      return obj;
    } catch (InstantiationException e) {
      throw new TorqueException(e);
    } catch (IllegalAccessException e) {
      throw new TorqueException(e);
    }
  }
 /**
  * Check for conflict -- there is a conflict if the other variable is assigned and {@link
  * ExamDistributionConstraint#check(ExamPlacement, ExamPlacement)} is false
  */
 @Override
 public boolean inConflict(ExamPlacement givenPlacement) {
   boolean before = true;
   for (Exam exam : variables()) {
     if (exam.equals(givenPlacement.variable())) {
       before = false;
       continue;
     }
     ExamPlacement placement = exam.getAssignment();
     if (placement == null) continue;
     if (!check(before ? placement : givenPlacement, before ? givenPlacement : placement))
       return true;
   }
   return false;
 }
  /**
   * Approve Exam.
   *
   * @param examId
   * @return
   */
  public boolean approveExam(String examId) {
    // Upon Approved, Generate Time Slots
    Exam examToApproved = examDao.findByExamId(examId);

    List<TestingCenterTimeSlots> timeSlots = generateTimeSlots(examToApproved);

    tctsDao.insertTimeSlots(timeSlots);

    examToApproved.setStatusType(ExamStatusType.APROVED);
    if (examDao.updateExam(examToApproved)) {
      return true;
    } else {
      return false;
    }
  }
  // Schedule an Exam
  public boolean addExam(Exam newExam, String userId) {
    ExamType examType = newExam.getExamType();
    boolean result = true;
    if (examType.equals(ExamType.REGULAR)) {
      // If Regular Exam
      result = examDao.addExam(newExam);

      // If
    } else {
      result = adhocExamDao.addAdhocExam((AdhocExam) newExam);
    }
    if (result) {
      User user = userDao.getUserById(userId);
      String emailAddress = user.getEmail();
      try {
        emailService.sendEmail(
            StringResources.EMAIL_HOST,
            StringResources.EMAIL_PORT,
            StringResources.EMAIL_LOGIN,
            StringResources.EMAIL_PASSWORD,
            emailAddress,
            "Exam Request Notification",
            "You successfully send a exam request");
      } catch (MessagingException e) {
        // Do nothing
      }
    }
    return result;
  }
예제 #7
0
 public void editExam(Exam exam) {
   for (int i = 0; i < exams.size(); i++) {
     if (exams.get(i).getId() == exam.getId()) {
       exams.set(i, exam);
     }
   }
 }
예제 #8
0
 /** Build a Criteria object from the data object for this peer */
 public static Criteria buildCriteria(Exam obj) {
   Criteria criteria = new Criteria(DATABASE_NAME);
   if (!obj.isNew()) criteria.add(EXAM_ID, obj.getExamId());
   criteria.add(TITLE, obj.getTitle());
   criteria.add(TIME_OF_EXAM, obj.getTimeOfExam());
   criteria.add(UPLOADED_BY, obj.getUploadedBy());
   criteria.add(DATE_UPLOADED, obj.getDateUploaded());
   criteria.add(INSTRUCTIONS, obj.getInstructions());
   return criteria;
 }
예제 #9
0
 public int getAwardLevel() {
   int passingExams = 0;
   double examAverage = 0;
   for (Exam exam : exams) {
     examAverage += exam.getGrade();
     if (exam.getGrade() >= 3) {
       passingExams++;
     }
   }
   examAverage = examAverage / exams.size();
   if (passingExams == 3) {
     return 1;
   } else if (passingExams > 3 && examAverage < 3.25) {
     return 1;
   } else if (passingExams == 4) {
     return 2;
   } else if (passingExams == 5) {
     return 3;
   } else {
     return 0;
   }
 }
예제 #10
0
 /**
  * Populates an object from a resultset row starting from a specified offset. This is done so that
  * you can select other rows than just those needed for this object. You may for example want to
  * create two objects from the same row.
  *
  * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
  *     TorqueException.
  */
 public static void populateObject(Record row, int offset, Exam obj) throws TorqueException {
   try {
     obj.setExamId(row.getValue(offset + 0).asInt());
     obj.setTitle(row.getValue(offset + 1).asString());
     obj.setTimeOfExam(row.getValue(offset + 2).asUtilDate());
     obj.setUploadedBy(row.getValue(offset + 3).asString());
     obj.setDateUploaded(row.getValue(offset + 4).asUtilDate());
     obj.setInstructions(row.getValue(offset + 5).asString());
   } catch (DataSetException e) {
     throw new TorqueException(e);
   }
 }
예제 #11
0
 public static void m2(Exam exam) {
   exam.w();
 }
예제 #12
0
 /**
  * Method to do update. This method is to be used during a transaction, otherwise use the
  * doUpdate(Exam) method. It will take care of the connection details internally.
  *
  * @param obj the data object to update in the database.
  * @param con the connection to use
  * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
  *     TorqueException.
  */
 public static void doUpdate(Exam obj, Connection con) throws TorqueException {
   doUpdate(buildCriteria(obj), con);
   obj.setModified(false);
 }
예제 #13
0
 /**
  * Method to do inserts. This method is to be used during a transaction, otherwise use the
  * doInsert(Exam) method. It will take care of the connection details internally.
  *
  * @param obj the data object to insert into the database.
  * @param con the connection to use
  * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
  *     TorqueException.
  */
 public static void doInsert(Exam obj, Connection con) throws TorqueException {
   obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
   obj.setNew(false);
   obj.setModified(false);
 }
  // Calculate How many time
  public List<TestingCenterTimeSlots> generateTimeSlots(Exam exam) {
    TestingCenterInfo tci = tcr.findByTerm(tcr.getCurrentTerm().getTermId());
    int gap = tci.getGap();
    int examDuration = exam.getDuration();
    int openMinutes = (int) ChronoUnit.MINUTES.between(tci.getOpen(), tci.getClose());

    // Ensure time chunk devides 30
    int timeChuck =
        (examDuration + gap) % 30 == 0 ? examDuration : 30 * ((examDuration + gap) / 30 + 1);

    LocalTime endTime = exam.getEndDateTime().toLocalTime();
    LocalTime beginTime = exam.getStartDateTime().toLocalTime();
    LocalTime openTime = tci.getOpen();
    LocalTime closeTime = tci.getClose();
    LocalDate beginDate = exam.getStartDateTime().toLocalDate();
    LocalDate endDate = exam.getEndDateTime().toLocalDate();

    beginTime = adjustTime(beginTime); // Exam Begin Time
    endTime = adjustTime(endTime); // Exam End Time

    // Calculate Duration According to different day.
    int startDayDuration = (int) ChronoUnit.MINUTES.between(beginTime, closeTime);
    int dayLast = (int) ChronoUnit.DAYS.between(beginDate, endDate) - 1;
    int endDayDuration = (int) ChronoUnit.MINUTES.between(openTime, endTime);

    int startDayChucks = startDayDuration / timeChuck;
    int endDayChucks = endDayDuration / timeChuck;
    int regularDayChuncks = dayLast >= 0 ? (dayLast * openMinutes) / timeChuck : 0;
    int dailyChuncks = openMinutes / timeChuck;

    LocalDate dateCursor = beginDate;
    LocalTime timeCursor = beginTime;
    List<TestingCenterTimeSlots> timeSlotses = new ArrayList<>();
    if (startDayChucks > 0) {
      for (int i = 0; i < startDayChucks; i++) {
        LocalDateTime slotsBegin = dateCursor.atTime(timeCursor);
        LocalDateTime slotsEnd = dateCursor.atTime(timeCursor.plusMinutes(examDuration));

        TestingCenterTimeSlots t =
            new TestingCenterTimeSlots(
                exam.getExamId(),
                slotsBegin,
                slotsEnd,
                tci.getNumSeats(),
                tci.getNumSetAsideSeats());
        timeSlotses.add(t);

        timeCursor = timeCursor.plusMinutes(timeChuck);
      }
    }
    if (regularDayChuncks > 0) {

      for (int i = 0; i < dayLast; i++) {
        dateCursor = dateCursor.plusDays(1);
        timeCursor = adjustTime(openTime);

        for (int j = 0; j < dailyChuncks; j++) {
          LocalDateTime slotsBegin = dateCursor.atTime(timeCursor);
          LocalDateTime slotsEnd = dateCursor.atTime(timeCursor.plusMinutes(examDuration));

          TestingCenterTimeSlots t =
              new TestingCenterTimeSlots(
                  exam.getExamId(),
                  slotsBegin,
                  slotsEnd,
                  tci.getNumSeats(),
                  tci.getNumSetAsideSeats());
          timeSlotses.add(t);

          timeCursor = timeCursor.plusMinutes(timeChuck);
        }
      }
    }
    if (endDayChucks > 0) {
      dateCursor = dateCursor.plusDays(1);
      timeCursor = adjustTime(openTime);

      for (int i = 0; i < endDayChucks; i++) {
        LocalDateTime slotsBegin = dateCursor.atTime(timeCursor);
        LocalDateTime slotsEnd = dateCursor.atTime(timeCursor.plusMinutes(examDuration));

        TestingCenterTimeSlots t =
            new TestingCenterTimeSlots(
                exam.getExamId(),
                slotsBegin,
                slotsEnd,
                tci.getNumSeats(),
                tci.getNumSetAsideSeats());
        timeSlotses.add(t);

        timeCursor = timeCursor.plusMinutes(timeChuck);
      }
    }
    return timeSlotses;
  }
 public static Exam getNewExam(boolean random) {
   return Exam.createExam(random, selectedDao);
 }
 public static Exam getNewExam(String name) {
   return Exam.createExam(name, selectedDao);
 }
 public static ArrayList<IExam> getExamList() {
   return Exam.getExams();
 }
 /**
  * Return true if this is hard constraint or this is a soft constraint without any violation
  *
  * @param p exam assignment to be made
  */
 public boolean isSatisfied(ExamPlacement p) {
   if (isHard()) return true;
   switch (getType()) {
     case sDistPrecedence:
       ExamPeriod last = null;
       for (Exam exam : variables()) {
         ExamPlacement placement =
             (p != null && exam.equals(p.variable()) ? p : exam.getAssignment());
         if (placement == null) continue;
         if (last == null || last.getIndex() < placement.getPeriod().getIndex())
           last = placement.getPeriod();
         else return false;
       }
       return true;
     case sDistPrecedenceRev:
       last = null;
       for (Exam exam : variables()) {
         ExamPlacement placement =
             (p != null && exam.equals(p.variable()) ? p : exam.getAssignment());
         if (placement == null) continue;
         if (last == null || last.getIndex() > placement.getPeriod().getIndex())
           last = placement.getPeriod();
         else return false;
       }
       return true;
     case sDistSamePeriod:
       ExamPeriod period = null;
       for (Exam exam : variables()) {
         ExamPlacement placement =
             (p != null && exam.equals(p.variable()) ? p : exam.getAssignment());
         if (placement == null) continue;
         if (period == null) period = placement.getPeriod();
         else if (period.getIndex() != placement.getPeriod().getIndex()) return false;
       }
       return true;
     case sDistDifferentPeriod:
       HashSet<ExamPeriod> periods = new HashSet<ExamPeriod>();
       for (Exam exam : variables()) {
         ExamPlacement placement =
             (p != null && exam.equals(p.variable()) ? p : exam.getAssignment());
         if (placement == null) continue;
         if (!periods.add(placement.getPeriod())) return false;
       }
       return true;
     case sDistSameRoom:
       Set<ExamRoomPlacement> rooms = null;
       for (Exam exam : variables()) {
         ExamPlacement placement =
             (p != null && exam.equals(p.variable()) ? p : exam.getAssignment());
         if (placement == null) continue;
         if (rooms == null) rooms = placement.getRoomPlacements();
         else if (!rooms.containsAll(placement.getRoomPlacements())
             || !placement.getRoomPlacements().containsAll(rooms)) return false;
       }
       return true;
     case sDistDifferentRoom:
       HashSet<ExamRoomPlacement> allRooms = new HashSet<ExamRoomPlacement>();
       for (Exam exam : variables()) {
         ExamPlacement placement =
             (p != null && exam.equals(p.variable()) ? p : exam.getAssignment());
         if (placement == null) continue;
         for (ExamRoomPlacement room : placement.getRoomPlacements()) {
           if (!allRooms.add(room)) return false;
         }
       }
       return true;
     default:
       return false;
   }
 }