Exemplo n.º 1
1
    private void updateVelocity(float dt) {
      Vector prev = vel.copy();

      vel.add(acc.scale(dt, dt));
    }
Exemplo n.º 2
0
  /**
   * Query a quiz list from the database. If there is no student user name specified, the list will
   * contain all quizzes that are used in the instructor's courses. Otherwise, the list will contain
   * all quizzes that the student has taken and from the instructor's courses which the student is
   * registered. Throws InvalidDBRequestException if any error occured to the database connection.
   *
   * @param instructor instructor's user name
   * @param student student's user name. Can be empty to get a list of all quizzes in the
   *     instructor's courses.
   * @return a vector containing the list of quizzes
   * @throws InvalidDBRequestException
   */
  public Vector getQuizList(String instructor, String student) throws InvalidDBRequestException {
    Vector list = new Vector();

    try {
      Connection db;

      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      ResultSet rs;

      if (!student.equals("")) {
        // get the list that contains all quizzes that the student has taken and from the
        // instructor's courses which the student is registered
        rs =
            stmt.executeQuery(
                "select courseTest.test_name, scores.start_time from scores, courseTest, course "
                    + "where courseTest.test_name = scores.test_name "
                    + "and courseTest.course_id = course.course_id "
                    + "and instructor = '"
                    + instructor
                    + "' and user_login = '******' "
                    + "order by scores.start_time");

        while (rs.next()) {
          list.add(rs.getString(1) + " <" + rs.getString(2) + ">");
        }
      } else {
        // get the list that contains all quizzes that are used in the instructor's courses
        rs =
            stmt.executeQuery(
                "select test_name from courseTest, course "
                    + "where courseTest.course_id = course.course_id "
                    + "and instructor = '"
                    + instructor
                    + "' ");

        while (rs.next()) {
          list.add(rs.getString(1));
        }
      }

      rs.close();
      stmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in getQuizList: " + e.getMessage());
      throw new InvalidDBRequestException("???");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Internal Server Error");
    }

    return list;
  }
Exemplo n.º 3
0
  /**
   * Gets a list of courses that belongs to an instructor. Throws InvalidDBRequestException if any
   * error occured to the database connection.
   *
   * @param name the instructor's user name
   * @return a vector containing the list of courses
   * @throws InvalidDBRequestException
   */
  public Vector getCourseList(String name) throws InvalidDBRequestException {
    Vector courseList = new Vector();

    try {
      Connection db;

      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      ResultSet rs;

      // get the course list
      rs =
          stmt.executeQuery(
              "select course_num, course_name from course where instructor = '"
                  + name
                  + "' order by course_num");
      while (rs.next()) courseList.add(rs.getString(1) + " - " + rs.getString(2));

      rs.close();
      stmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in getCourseList: " + e.getMessage());
      throw new InvalidDBRequestException("???");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Server Error");
    }

    return courseList;
  }
Exemplo n.º 4
0
 /**
  * Re-scans the bus for devices. <i>ScanForDevices()</i> is called automatically by <i>{@link
  * #open() open()}</i>. <i>You must terminate use of all USB devices before calling
  * scanForDevices()!</i> After calling <i>scanForDevices()</i> you can reestablish connections to
  * USB devices.
  *
  * @return This device manager, useful for chaining together multiple operations.
  * @throws OperationFailedException
  */
 public USBDeviceManager scanForDevices() {
   if (isOpen()) {
     deviceList.clear();
     final int MAX_DEVICES = 100;
     int devices[] = new int[1 + MAX_DEVICES * 2]; // device index-product ID pairs
     final int result =
         getDeviceByProductID(MIN_PRODUCT_ID, MAX_PRODUCT_ID, devices); // get all devices
     if (result != SUCCESS) throw new OperationFailedException(result);
     final int numDevices = devices[0];
     for (int index = 0; index < numDevices; index++) {
       USBDevice device = null;
       final int deviceIndex = devices[1 + index * 2];
       final int productID = devices[1 + index * 2 + 1];
       if (USB_AI16_Family.isSupportedProductID(productID)) {
         device = new USB_AI16_Family(productID, deviceIndex);
       } else if (USB_AO16_Family.isSupportedProductID(productID)) {
         device = new USB_AO16_Family(productID, deviceIndex);
       } else if (USB_CTR_15_Family.isSupportedProductID(productID)) {
         device = new USB_CTR_15_Family(productID, deviceIndex);
       } else if (USB_DA12_8A_Family.isSupportedProductID(productID)) {
         device = new USB_DA12_8A_Family(productID, deviceIndex);
       } else if (USB_DA12_8E_Family.isSupportedProductID(productID)) {
         device = new USB_DA12_8E_Family(productID, deviceIndex);
       } else if (USB_DIO_16_Family.isSupportedProductID(productID)) {
         device = new USB_DIO_16_Family(productID, deviceIndex);
       } else if (USB_DIO_32_Family.isSupportedProductID(productID)) {
         device = new USB_DIO_32_Family(productID, deviceIndex);
       } else if (USB_DIO_Family.isSupportedProductID(productID)) {
         device = new USB_DIO_Family(productID, deviceIndex);
       } // else if( USB_DIO_Family.isSupportedProductID( ...
       if (device != null) deviceList.add(device);
     } // for( int index ...
   } else throw new OperationFailedException(MESSAGE_NOT_OPEN);
   return this;
 } // scanForDevices()
Exemplo n.º 5
0
 public void addConnectionListener(NCCPConnection.ConnectionListener l) {
   if (!listeners.contains(l)) {
     ExpCoordinator.printer.print(
         new String("NCCPConnection.addConnectionListener to " + toString()), 6);
     listeners.add(l);
   }
 }
Exemplo n.º 6
0
 /**
  * Gets a list of all the devices found on the bus matching the specified serial number. Only
  * devices exactly matching the specified serial number will be returned. In theory, there ought
  * to be only one device matching a given serial number, but this method returns a vector in order
  * to be consistent with the other search methods, and in unlikely event that multiple devices do
  * share the same serial number.
  *
  * @param serialNumber the serial number to search for.
  * @return An array of all the devices found. If no devices were found matching the specified
  *     serial number, the array will be empty (i.e. contain zero items).
  */
 public USBDevice[] getDeviceBySerialNumber(long serialNumber) {
   Vector<USBDevice> devices = new Vector<USBDevice>();
   for (int index = 0; index < deviceList.size(); index++) {
     if (deviceList.get(index).getSerialNumber() == serialNumber)
       devices.add(deviceList.get(index));
   } // for( int index ...
   return devices.toArray(new USBDevice[0]);
 } // getDeviceBySerialNumber()
Exemplo n.º 7
0
  public void go(SystemEnvironment sysEnv) throws SDMSException {
    sysEnv.checkFeatureAvailability(SystemEnvironment.S_OBJECT_MONITOR);
    SDMSOutputContainer d_container = null;
    Vector desc = new Vector();

    desc.add("ID");
    desc.add("NAME");
    desc.add("PRIVS");

    d_container = new SDMSOutputContainer(sysEnv, "List of Watch Types", desc);

    Collections.sort(d_container.dataset, d_container.getComparator(sysEnv, 1));

    result.setOutputContainer(d_container);

    result.setFeedback(
        new SDMSMessage(
            sysEnv, "02108241006", "$1 Watch Type(s) found", new Integer(d_container.lines)));
  }
Exemplo n.º 8
0
  /**
   * It sets the useful parameter to those classifiers int the population having the best value of
   * numerosity * prediction. It's is used by the Strong version of the Dixon's reduction algorithm.
   */
  void setUsefulAccurateClassifier(boolean value) {
    double max = (double) set[0].getNumerosity() * set[0].getPrediction();
    Vector bestCls = new Vector();
    bestCls.add((Classifier) set[0]);

    for (int i = 1; i < macroClSum; i++) {

      if ((double) set[i].getNumerosity() * set[i].getPrediction() > max) {
        max = (double) set[i].getNumerosity() * set[i].getPrediction();
        bestCls.removeAllElements();
        bestCls.add(set[i]);
      } else if ((double) set[i].getNumerosity() * set[i].getPrediction() == max) {
        bestCls.add(set[i]);
      }
    }

    for (int i = 0; i < bestCls.size(); i++) {
      ((Classifier) bestCls.get(i)).setUseful(value);
    }
  } // end setUsefulAccurateClassifier
Exemplo n.º 9
0
 public void sendMessage(NCCP.Message msg) {
   if (isClosed() || isFailed()) connect();
   if (isConnected()) {
     ExpCoordinator.printer.print("NCCPConnection::sendMessage", 5);
     if (proxy != null) proxy.sendMessage(msg, this);
     else {
       if (nonProxy != null) nonProxy.sendMessage(msg);
     }
   } else // still can't connect
   {
     pendingMessages.add(msg);
   }
 }
Exemplo n.º 10
0
 /**
  * Gets a list of all the devices found on the bus matching the specified product ID range. Any
  * device with a product ID greater than or equal to <i>minProductID</i> and less than or equal to
  * <i>maxProductID</i> will be returned. You can obtain the entire list of devices detected by
  * passing a value of 0 for <i>minProductID</i> and a value of 0xffff for <i>maxProductID</i>.
  * Then you can search the list obtained using your own search criteria.
  *
  * @param minProductID the minimum product ID to search for.
  * @param maxProductID the maximum product ID to search for.
  * @return An array of all the devices found. If no devices were found matching the specified
  *     product ID range, the array will be empty (i.e. contain zero items).
  * @throws IllegalArgumentException
  */
 public USBDevice[] getDeviceByProductID(int minProductID, int maxProductID) {
   if (minProductID < MIN_PRODUCT_ID
       || minProductID > MAX_PRODUCT_ID
       || maxProductID < minProductID
       || maxProductID > MAX_PRODUCT_ID)
     throw new IllegalArgumentException(
         "Invalid product IDs: " + minProductID + ", " + maxProductID);
   Vector<USBDevice> devices = new Vector<USBDevice>();
   for (int index = 0; index < deviceList.size(); index++) {
     final int productID = deviceList.get(index).getProductID();
     if (productID >= minProductID && productID <= maxProductID)
       devices.add(deviceList.get(index));
   } // for( int index ...
   return devices.toArray(new USBDevice[0]);
 } // getDeviceByProductID()
Exemplo n.º 11
0
 /**
  * Gets a list of all the devices found on the bus matching the specified set of product IDs. Any
  * device with a product ID equal to one of the products listed in <i>productIDs[]</i> will be
  * returned. You can search for devices by product name using {@link #productNameToID( String[]
  * productName ) productNameToID()}, like so:
  *
  * <pre>USBDevice[] devices = deviceManager.getDeviceByProductID(
  *  deviceManager.productNameToID( new String[] { "USB-AO16-16A", "USB-AO16-16" } ) );</pre>
  *
  * @param productIDs an array containing one or more product IDs to search for.
  * @return An array of all the devices found. If no devices were found matching the specified set
  *     of product IDs, the array will be empty (i.e. contain zero items).
  * @throws IllegalArgumentException
  */
 public USBDevice[] getDeviceByProductID(int[] productIDs) {
   if (productIDs == null || productIDs.length < 1)
     throw new IllegalArgumentException("Invalid product ID array");
   for (int index = 0; index < productIDs.length; index++) {
     if (productIDs[index] < MIN_PRODUCT_ID || productIDs[index] > MAX_PRODUCT_ID)
       throw new IllegalArgumentException("Invalid product ID: " + productIDs[index]);
   } // for( int index ...
   int[] sortedProductIDs = productIDs.clone();
   Arrays.sort(sortedProductIDs);
   Vector<USBDevice> devices = new Vector<USBDevice>();
   for (int index = 0; index < deviceList.size(); index++) {
     final int productID = deviceList.get(index).getProductID();
     if (Arrays.binarySearch(sortedProductIDs, productID) >= 0) devices.add(deviceList.get(index));
   } // for( int index ...
   return devices.toArray(new USBDevice[0]);
 } // getDeviceByProductID()
Exemplo n.º 12
0
  /**
   * Query students grades for a course on a particular quiz Throws InvalidDBRequestException if
   * quiz is not used in the course, or if any error occured to the database connection.
   *
   * @param courseID course unique id
   * @param quizname quiz unique name
   * @return a vector that contains the students information and the grades
   * @throws InvalidDBRequestException
   */
  public Vector getQuizGrades(String courseID, String quizName) throws InvalidDBRequestException {
    Vector grades = new Vector();

    try {
      Connection db;

      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      ResultSet rs;

      rs =
          stmt.executeQuery(
              "select valid from courseTest where course_id = '"
                  + courseID
                  + "' and test_name = '"
                  + quizName
                  + "'");
      if (rs.next()) {
        rs =
            stmt.executeQuery(
                "select login, last_name, first_name, start_time, num_questions, num_correct from student, scores, courseRoster "
                    + "where student.login = scores.user_login "
                    + "and scores.user_login = courseRoster.user_login "
                    + "and scores.test_name = '"
                    + quizName
                    + "' "
                    + "and course_id = '"
                    + courseID
                    + "' "
                    + "order by last_name, first_name, login, scores.start_time");

        // use @ as delimiter since the date_time contains space
        while (rs.next())
          grades.add(
              rs.getString(1)
                  + "@"
                  + rs.getString(2)
                  + "@"
                  + rs.getString(3)
                  + "@"
                  + rs.getString(4)
                  + "@"
                  + rs.getString(5)
                  + "@"
                  + rs.getString(6));
      } else throw new InvalidDBRequestException("Quiz is not used for the course");

      rs.close();
      stmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in instructor login: "******"???");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Server Error");
    }
    return grades;
  }
Exemplo n.º 13
0
 /**
  * ********************************************************************* * Modifiers to the
  * CMIObjective Data. SCOs should not invoke these * methods. SCOs should call LMSSetValue()
  * **********************************************************************
  */
 public void setObjectives(CMIObjectiveData objective, int index) {
   objectives.add(index, objective);
 } // end of setObjectives
Exemplo n.º 14
0
  /**
   * ************************************************************************ * * Method: performSet
   * * Input: CMIRequest theRequest - tokenized LMSSetValue() request * DMErrorManager dmErroMgr -
   * Error Manager * Output: none * * Description: This method takes the necessary steps to process
   * * an LMSSetValue() request *
   * *************************************************************************
   */
  public void performSet(CMIRequest theRequest, DMErrorManager dmErrorMgr) {
    if (true) {
      System.out.println("CMIObjectives::performSet()");
    }

    // The next token must be an array.  If not throw
    // an exception for this request.
    int index = -1;

    // Get the next token off of the request
    String token = theRequest.getNextToken();

    if (true) {
      System.out.println("Token being processed: " + token);
    }

    // Check to see if next token is an array index.  For
    // a LMSSetValue() this is true
    try {
      // Try to convert the token to the index
      Integer tmpInt = new Integer(token);
      index = tmpInt.intValue();

      // Get the Objective Data at position of the index
      CMIObjectiveData tmpObj = (CMIObjectiveData) objectives.elementAt(index);

      // An objective existed at the given index.
      // Invoke the performSet() on the Objective Data
      tmpObj.performSet(theRequest, dmErrorMgr);

      // replace the old ObjectiveData with the newly set Objective
      // Data.
      objectives.set(index, tmpObj);
    } catch (NumberFormatException nfe) {
      if (theRequest.isAKeywordRequest() == true) {
        dmErrorMgr.recKeyWordError(token);
      } else {
        if (true) {
          // Invalid parameter passed to LMSSetValue()
          System.out.println("Error - Data Model Element not implemented");
          System.out.println(
              "Invalid data model element: "
                  + theRequest.getRequest()
                  + " passed to LMSSetValue()");
        }

        // Notify error manager
        dmErrorMgr.recNotImplementedError(theRequest);
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      if (true) {
        System.out.println("First time setting the Objective Data");
      }

      if (index <= objectives.size()) {
        // A new Objective Data.
        CMIObjectiveData objData = new CMIObjectiveData();

        // Invoke performSet() on the new Objective Data
        objData.performSet(theRequest, dmErrorMgr);

        // Place the Objective data into the vector at the
        // index position
        objectives.add(index, objData);
      } else {
        dmErrorMgr.SetCurrentErrorCode("201");
      }
    }

    // Done processing.  Let CMIRequest object know the processing
    // of the LMSGetValue() is done.
    theRequest.done();

    return;
  } // end of performSet
Exemplo n.º 15
0
  /**
   * Labels the image using the code of p.65 in Computer Vision by by Shapiro and Stockman. The
   * background pixels are labelled with zero.
   *
   * @param none
   * @return A Vector of number of labels as an Integer, the 1d integer array of color values for
   *     each label number and the 2d integer array of the labelled image.
   */
  public Vector applyLabelling() {
    int rows = imageHeight;
    int columns = imageWidth;

    // System.out.println("In applyLabelling of LabelImage.");
    int label = 1;
    int minLabel;
    int[] priorNeigLabel = new int[4];
    int[] parentArray = new int[rows * columns];
    Vector labelVector = new Vector(3);
    parentArray[0] = -1; // this is a root, it is there for the background pixels

    int j = 0;
    int noOfbPixels = 0;
    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < columns; c++) {
        pixelLabel[r][c] = -1; // Initialize
      }
      for (int c = 0; c < columns; c++) {
        if (inputImage[r][c] == bPix) {
          pixelLabel[r][c] = bPixLabel;
          continue;
        }

        j = 0;

        // check 4 neighbors that are already processed, record the ones that are in the same region
        for (int i = 0; i < 4; i++) {
          if ((r + rPos[i]) >= 0
              && (c + cPos[i]) >= 0
              && (r + rPos[i]) < imageHeight
              && (c + cPos[i]) < imageWidth) {
            if (Math.abs(inputImage[r][c] - inputImage[r + rPos[i]][c + cPos[i]]) < 8) {
              priorNeigLabel[j] = pixelLabel[r + rPos[i]][c + cPos[i]];
              j++;
            }
          }
        }

        // System.out.println("There are " + j + "prior neighbors in the same region.");
        if (j == 0) { // there are no prior neighbors in the same region
          pixelLabel[r][c] = label;
          noOfLabels++;
          parentArray[label] = -1; // this label is a root
          label++;
          // System.out.println("Labeled ("+r+", "+c+") with " + label);
        } else { // Find the minimum label of the neighbors
          minLabel = priorNeigLabel[0];
          for (int i = 1; i < j; i++) {
            if (priorNeigLabel[i] < minLabel) minLabel = priorNeigLabel[i];
          }
          // System.out.println("min label is " + minLabel);
          pixelLabel[r][c] = minLabel;
          // System.out.println("Labeled ("+r+", "+c+") with " + minLabel);
        }
        for (int i = 0; i < j; i++) {
          if (pixelLabel[r][c] != priorNeigLabel[i]) {
            union(pixelLabel[r][c], priorNeigLabel[i], parentArray);
            // noOfLabels--;
          }
        }
      }
    }
    // System.out.println("End of first pass. There are " + noOfLabels+ " labels.");

    // Second pass replaces the first pass labels with equivalence class labels
    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < columns; c++) {
        if (pixelLabel[r][c] != bPixLabel) { // 0 is the background label
          pixelLabel[r][c] = findParent(pixelLabel[r][c], parentArray);
        }
      }
    }
    // System.out.println("No of label is " + label);
    int[] labelsMap = new int[label];
    noOfLabels = 0;
    for (int i = 0; i < label; i++) {
      if (parentArray[i] == -1) { // a root
        labelsMap[i] = noOfLabels;
        noOfLabels++;
      }
    }
    // System.out.println("End of second pass. There are " + noOfLabels+ " labels.");

    labelsArray = new int[noOfLabels];

    // Third pass replaces the second pass labels with consecutive numbered labels
    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < columns; c++) {
        pixelLabel[r][c] = labelsMap[pixelLabel[r][c]];
        labelsArray[pixelLabel[r][c]] = inputImage[r][c];
        // pixelLabel[r][c] = ((int)(255/noOfLabels))*pixelLabel[r][c];
      }
    }
    // System.out.println("End of third pass. There are " + noOfLabels+ " labels.");

    // System.out.println("There are " + noOfLabels + " objects.");

    labelVector.add(new Integer(noOfLabels)); // Count of Blobs
    labelVector.add(labelsArray); // Array holding the mapping of sequential labels to pixel labels
    // Note that label 0 in labelsMap will point to some label x in pixelLabel
    labelVector.add(pixelLabel); // Pixel Labels
    return labelVector;
  }
Exemplo n.º 16
0
  /**
   * Query a student list from the database. If quiz name is not specified, the list will contain
   * all students who are registered in the instructor's courses. Otherwise, it will contain all
   * students who has taken the quiz and are registered to the instructor's course(s) that use the
   * quiz Throws InvalidDBRequestException if any error occured to the database connection.
   *
   * @param name instructor's user name
   * @param quiz quiz name. Can be empty String to get the list of all students who are registered
   *     in the instructor's courses.
   * @return a vector that contains the list of students
   * @throws InvalidDBRequestException
   */
  public Vector getStudentList(String name, String quiz) throws InvalidDBRequestException {
    Vector list = new Vector();

    try {
      Connection db;

      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      ResultSet rs;

      if (!quiz.equals("")) {
        // get the list that contains all students who has taken the quiz and are registered to the
        // instructor's course(s) that use the quiz
        rs =
            stmt.executeQuery(
                "select login, last_name, first_name, scores.start_time from student, scores, courseRoster, course "
                    + "where student.login = scores.user_login "
                    + "and scores.user_login = courseRoster.user_login "
                    + "and courseRoster.course_id = course.course_id "
                    + "and scores.test_name = '"
                    + quiz
                    + "' "
                    + "and instructor = '"
                    + name
                    + "' "
                    + "order by last_name, first_name, login, scores.start_time");

        while (rs.next()) {
          list.add(
              rs.getString(2)
                  + ", "
                  + rs.getString(3)
                  + " ("
                  + rs.getString(1)
                  + ") <"
                  + rs.getString(4)
                  + ">");
        }
      } else {
        // get the list that contains all students who are registered in the instructor's courses
        rs =
            stmt.executeQuery(
                "select distinct login, last_name, first_name from student, courseRoster, course "
                    + "where student.login = courseRoster.user_login "
                    + "and courseRoster.course_id = course.course_id "
                    + "and instructor = '"
                    + name
                    + "' "
                    + "order by last_name, first_name, login");

        while (rs.next()) {
          list.add(rs.getString(2) + ", " + rs.getString(3) + " (" + rs.getString(1) + ")");
        }
      }

      rs.close();
      stmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in getStudentList: " + e.getMessage());
      throw new InvalidDBRequestException("???");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Internal Server Error");
    }

    return list;
  }
Exemplo n.º 17
0
 public void addForce(Vector f) {
   //    println("adding force = " + f);
   netForce.add(f);
 }