Esempio n. 1
0
  public static void main(String args[]) {

    wmatrix wmatrix = new wmatrix();
    wmatrix.start();
    try {
      PrintWriter profilefout =
          new PrintWriter(
              new BufferedWriter(
                  new FileWriter(
                      "profile_"
                          + Data.kinease
                          + "_"
                          + Data.code
                          + "_"
                          + Data.windows_size
                          + ".csv")));

      profilefout.print("Position=");
      for (int j = 0; j < Data.windows_size; j++) {
        profilefout.print("," + (j - Data.windows_size / 2));
      }
      profilefout.println();

      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < Data.windows_size; j++) {
          profilefout.print("," + wm[i][j]);
        }
        profilefout.println();
      }
      profilefout.close();

    } catch (IOException ex) {

    }
  }
Esempio n. 2
0
 /**
  * It draws the population to a file. A character allele is drawn as 1 o 0. Otherwise, a real
  * allele is drawn in ten points, that represent the interval [0..1] divided in ten fragments. In
  * each fragment, three types of symbol are possible: . --> The fragment is not covered by the
  * classifier. o --> The fragment is partially covered by the classifier. O --> The fragment is
  * totally covered by the classifier.
  *
  * <p>This notation has been obtained from Wilson2000 XCSR
  *
  * @param fout is the file where the population has to be drawn.
  */
 public void draw(PrintWriter fout) {
   double lower = 0, upper = 0;
   if (Config.ternaryRep) {
     fout.print(" " + ((char) rep[0].getAllele()) + " ");
     for (int i = 1; i < rep.length; i++) {
       fout.print("| " + ((char) rep[i].getAllele()) + " ");
     }
   } else {
     if (Config.typeOfAttributes[0].equals("character")) {
       fout.print(" " + ((char) rep[0].getAllele()) + " ");
     } else {
       printInterval(fout, rep[0].getLowerAllele(), rep[0].getUpperAllele());
     }
     for (int i = 1; i < rep.length; i++) {
       if (Config.typeOfAttributes[i].equals("character")) {
         fout.print("| " + ((char) rep[i].getAllele()) + " ");
       } else if (Config.typeOfAttributes[i].equals("integer")) {
         printInterval(i, fout, ((int) rep[i].getLowerAllele()), ((int) rep[i].getUpperAllele()));
       } else {
         printInterval(fout, rep[i].getLowerAllele(), rep[i].getUpperAllele());
       }
     }
   }
   fout.print("\t " + action);
 } // end draw
Esempio n. 3
0
 /**
  * Prints the classifier to the specified file.
  *
  * @param fout is the file output where the classifier has to be printed.
  */
 public void print(PrintWriter fout) {
   fout.print(" ");
   for (int i = 0; i < rep.length; i++) {
     rep[i].print(fout);
   }
   fout.print("  " + action + "  ");
   if (parameters != null) parameters.print(fout);
 }
Esempio n. 4
0
  /**
   * Prints the classifier to the specified file.
   *
   * @param fout is the output file.
   */
  public void print(PrintWriter fout) {

    fout.print(" ");
    for (int i = 0; i < rep.length; i++) {
      rep[i].print(fout);
    }

    fout.print("\t " + action);
  } // end print
Esempio n. 5
0
 /**
  * It draws an integer interval
  *
  * @param fout is a reference to the file where the classifier has to be drawn.
  * @param numInterval is the position of the interval in the classifier.
  * @param lower is the lower value of the interval
  * @param upper is the upper value of the interval.
  */
 private void printInterval(int numInterval, PrintWriter fout, int lower, int upper) {
   double aux = 0.0;
   int points = Config.realDrawnPrecision;
   int inc =
       ((int) Config.attBounds[numInterval][1] - (int) Config.attBounds[numInterval][0] + 1)
           / points;
   for (int i = 0; i < points; i++) {
     if (i * inc >= lower && i * inc <= upper) {
       fout.print("O");
     } else {
       fout.print(".");
     }
   }
   fout.print(" | ");
 }
Esempio n. 6
0
 /**
  * Prints the classifier to the specified file.
  *
  * @param fout is the output file.
  */
 public void printNotNorm(PrintWriter fout) {
   int i = 0;
   fout.print(" ");
   try {
     for (i = 0; i < rep.length; i++) {
       if (Config.typeOfAttributes[i].equals("enumerate")) {
         rep[i].printNotNorm(fout, Config.enumConv[i]);
       } else if (Config.typeOfAttributes[i].equals("integer")) {
         if (Config.enumConv[i].size() > 0) rep[i].printNotNorm(fout, Config.enumConv[i]);
         else rep[i].printNotNorm(fout, (int) Config.attBounds[i][0]);
       } else if (Config.typeOfAttributes[i].equals("real")) {
         rep[i].printNotNorm(fout, Config.attBounds[i][0], Config.attBounds[i][1]);
       }
     }
   } catch (Exception e) {
     System.out.println("Exception when printing the attribute: " + i);
     e.printStackTrace();
   }
   fout.print("\t " + (String) Config.classConv.elementAt(action));
 } // end print
Esempio n. 7
0
  /**
   * Prints the desnormalized classifier to the specified file.
   *
   * @param fout is the file output where the classifier has to be printed.
   */
  public void printNotNorm(PrintWriter fout) {
    int i = 0;
    fout.print(" ");
    try {
      for (i = 0; i < rep.length; i++) {
        if (Config.typeOfAttributes[i].equals("ternary")) {
          rep[i].print(fout);
        } else if (Config.typeOfAttributes[i].equals("integer")) {
          rep[i].printNotNorm(fout, Config.attBounds[i][0]);
        } else if (Config.typeOfAttributes[i].equals("real")) {
          rep[i].printNotNorm(fout, Config.attBounds[i][0], Config.attBounds[i][1]);
        }
      }
    } catch (Exception e) {
      System.out.println("Exception when printing the attribute: " + i);
      e.printStackTrace();
    }
    fout.print("\t " + (String) Config.classConv.elementAt(action));

    if (parameters != null) parameters.print(fout);
  }
Esempio n. 8
0
 /**
  * It draws a real interval
  *
  * @param fout is a reference to the file where the classifier has to be drawn.
  * @param lower is the lower value of the interval
  * @param upper is the upper value of the interval.
  */
 private void printInterval(PrintWriter fout, double lower, double upper) {
   double aux = 0.0;
   int points = Config.realDrawnPrecision;
   double inc = 1. / (double) points;
   for (double i = 0.; i < (double) points; i++) {
     if (i * inc < lower && (i * inc + inc) <= lower) {
       fout.print(".");
     } else if (i * inc < lower && (i * inc + inc) > lower) {
       fout.print("o");
     } // In the next if, the value is bigger than the lower
     else if (i * inc < upper && (i * inc + inc) <= upper) {
       fout.print("O");
     } else if (i * inc < upper && (i * inc + inc) > upper) {
       fout.print("o");
     } else if (i * inc >= lower) {
       fout.print(".");
     } else {
       fout.print("ERR. Case not covered!!");
     }
   }
   fout.print(" | ");
 }
  /**
   * Remove a quiz from a course. Also deletes all the quiz visualization files from the students'
   * folder who is registered in the course. Caution: vizualisation file will be deleted eventhough
   * it also relates to anther course if the student is also registered to that course. (FIX ME!)
   * Throws InvalidDBRequestException if the quiz is not registered in the course, error occured
   * during deletion, or other exception occured.
   *
   * @param quizName quiz name
   * @param courseID course id (course number + instructor name)
   * @throws InvalidDBRequestException
   */
  public void deleteQuiz(String quizName, String courseID)
      throws InvalidDBRequestException, FileFailureException {
    try {
      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

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

      int count = 0;

      // check if quiz is used in the course
      rs =
          stmt.executeQuery(
              "select test_name from courseTest where test_name = '"
                  + quizName
                  + "' and course_id = '"
                  + courseID
                  + "'");
      if (!rs.next()) throw new InvalidDBRequestException("Quiz is not registered for the course");
      else {
        // remove quiz from course
        count =
            stmt.executeUpdate(
                "delete from courseTest where course_id = '"
                    + courseID
                    + "' and test_name = '"
                    + quizName
                    + "'");
        if (count != 1) throw new InvalidDBRequestException("Error occured during deletion");
        else {
          // delete quiz visualization files
          rs =
              stmt.executeQuery(
                  "select distinct unique_id, scores.user_login from scores, courseRoster "
                      + "where courseRoster.user_login = scores.user_login "
                      + "and course_id = '"
                      + courseID
                      + "' "
                      + "and test_name = '"
                      + quizName
                      + "'");
          while (rs.next()) {
            deleteVisualization(rs.getString(1), rs.getString(2), quizName);
            count =
                stmt.executeUpdate(
                    "delete from scores where unique_id = " + rs.getString(1).trim());
          }

          // rewrite the menu for the course
          rs =
              stmt.executeQuery(
                  "select distinct menu_text, name, script_type, visual_type from test t, courseTest c "
                      + "where t.name = c.test_name "
                      + "and course_id = '"
                      + courseID
                      + "'");
          PrintWriter fileOStream =
              new PrintWriter(new FileOutputStream("./html_root/cat/" + courseID + ".list"));
          while (rs.next()) {
            if (debug)
              System.out.println(
                  rs.getString(1).trim()
                      + "\n"
                      + rs.getString(2).trim()
                      + " "
                      + rs.getString(3).trim()
                      + " "
                      + rs.getString(4).trim().toLowerCase()
                      + "\n****\n");
            fileOStream.print(
                rs.getString(1).trim()
                    + "\n"
                    + rs.getString(2).trim()
                    + " "
                    + rs.getString(3).trim()
                    + " "
                    + rs.getString(4).trim().toLowerCase()
                    + "\n****\n");
          }
          fileOStream.flush();
          fileOStream.close();
        }
      }

      rs.close();
      stmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in addQuiz: " + e.getMessage());
      throw new InvalidDBRequestException("??? ");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Internal Server Error");
    } catch (Exception e) {
      System.err.println("Error in recreating menu for course: " + courseID);
      System.err.println(e.getMessage());
      throw new FileFailureException();
    }
  }
Esempio n. 10
0
  /**
   * Add a quiz to a course if not already so. Also write the menu file for the course. Throws
   * InvalidDBRequestException if quiz already in the course, error occured during insertion, or
   * other exception occured. Throws FileFailureException if fail to append quiz to the menu.
   *
   * @param quizname the quiz name
   * @param courseID the course id (course number + instructor name)
   * @throws InvalidDBRequestException
   */
  public void addQuiz(String quizName, String courseID)
      throws InvalidDBRequestException, FileFailureException {
    try {
      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      Statement cstmt = db.createStatement();
      ResultSet rs, courseRS;

      int count = 0;

      // get quiz info
      courseRS =
          cstmt.executeQuery(
              "select menu_text, script_type, visual_type from test where name = '"
                  + quizName
                  + "'");

      // check if quiz in the database
      if (!courseRS.next())
        throw new InvalidDBRequestException("Quiz is not registered in the database");
      else {
        // check if quiz already in the course
        rs =
            stmt.executeQuery(
                "select test_name from courseTest where test_name = '"
                    + quizName
                    + "' and course_id = '"
                    + courseID
                    + "'");
        if (rs.next()) throw new InvalidDBRequestException("Quiz is already added for the course");
        else {
          count =
              stmt.executeUpdate(
                  "insert into courseTest (course_id, test_name) values ('"
                      + courseID
                      + "', '"
                      + quizName
                      + "')");
          if (count != 1) throw new InvalidDBRequestException("Error occured during insertion");
          else {
            // append quiz info to the course menu
            try {
              PrintWriter fileOStream =
                  new PrintWriter(
                      new FileOutputStream("./html_root/cat/" + courseID + ".list", true));
              if (debug)
                System.out.println(
                    courseRS.getString(1).trim()
                        + "\n"
                        + quizName
                        + " "
                        + courseRS.getString(2).trim()
                        + " "
                        + courseRS.getString(3).trim().toLowerCase()
                        + "\n****\n");
              fileOStream.print(
                  courseRS.getString(1).trim()
                      + "\n"
                      + quizName
                      + " "
                      + courseRS.getString(2).trim()
                      + " "
                      + courseRS.getString(3).trim().toLowerCase()
                      + "\n****\n");
              fileOStream.flush();
              fileOStream.close();
            } catch (Exception e) {
              System.err.println("Error in creating the menu: " + e.getMessage());
              throw new FileFailureException("Error in creating the menu: " + e.getMessage());
            }
          }
        }
      }

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