Example #1
0
  /**
   * Examines the supplied experiment to determine the results destination and attempts to load the
   * results.
   *
   * @param exp a value of type 'Experiment'
   */
  protected void setInstancesFromExp(Experiment exp) {

    if ((exp.getResultListener() instanceof CSVResultListener)) {
      File resultFile = ((CSVResultListener) exp.getResultListener()).getOutputFile();
      if ((resultFile == null)) {
        m_FromLab.setText("No result file");
      } else {
        setInstancesFromFile(resultFile);
      }
    } else if (exp.getResultListener() instanceof DatabaseResultListener) {
      String dbaseURL = ((DatabaseResultListener) exp.getResultListener()).getDatabaseURL();
      try {
        if (m_InstanceQuery == null) {
          m_InstanceQuery = new InstanceQuery();
        }
        m_InstanceQuery.setDatabaseURL(dbaseURL);
        m_InstanceQuery.connectToDatabase();
        String tableName = m_InstanceQuery.getResultsTableName(exp.getResultProducer());
        setInstancesFromDatabaseTable(tableName);
      } catch (Exception ex) {
        m_FromLab.setText("Problem reading database");
      }
    } else {
      m_FromLab.setText("Can't get results from experiment");
    }
  }
Example #2
0
  /** Queries the user enough to make a database query to retrieve experiment results. */
  protected void setInstancesFromDBaseQuery() {

    try {
      if (m_InstanceQuery == null) {
        m_InstanceQuery = new InstanceQuery();
      }
      String dbaseURL = m_InstanceQuery.getDatabaseURL();
      dbaseURL =
          (String)
              JOptionPane.showInputDialog(
                  this,
                  "Enter the database URL",
                  "Query Database",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  dbaseURL);
      if (dbaseURL == null) {
        m_FromLab.setText("Cancelled");
        return;
      }
      m_InstanceQuery.setDatabaseURL(dbaseURL);
      m_InstanceQuery.connectToDatabase();
      if (!m_InstanceQuery.experimentIndexExists()) {
        m_FromLab.setText("No experiment index");
        return;
      }
      m_FromLab.setText("Getting experiment index");
      Instances index =
          m_InstanceQuery.retrieveInstances("SELECT * FROM " + InstanceQuery.EXP_INDEX_TABLE);
      if (index.numInstances() == 0) {
        m_FromLab.setText("No experiments available");
        return;
      }
      m_FromLab.setText("Got experiment index");

      DefaultListModel lm = new DefaultListModel();
      for (int i = 0; i < index.numInstances(); i++) {
        lm.addElement(index.instance(i).toString());
      }
      JList jl = new JList(lm);
      ListSelectorDialog jd = new ListSelectorDialog(null, jl);
      int result = jd.showDialog();
      if (result != ListSelectorDialog.APPROVE_OPTION) {
        m_FromLab.setText("Cancelled");
        return;
      }
      Instance selInst = index.instance(jl.getSelectedIndex());
      Attribute tableAttr = index.attribute(InstanceQuery.EXP_RESULT_COL);
      String table = InstanceQuery.EXP_RESULT_PREFIX + selInst.toString(tableAttr);

      setInstancesFromDatabaseTable(table);
    } catch (Exception ex) {
      m_FromLab.setText("Problem reading database");
    }
  }
  public static Instances readDB(String sqlQuery, String tableName, int sourceIndex) {
    /*
    proper mysql query is needed.
    sqlQuery : "SELECT * FROM AccelerometerSensorProbe"
    */
    if (!sqlQuery.contains(tableName)) {
      System.out.println("tableName must be included in sqlQuery!");
      System.out.println("tableName : " + tableName + " / sqlQuery : " + sqlQuery);
      System.exit(-1);
    }
    ProjectEvaluator.tableUsed(tableName);

    Instances dataSet = null;
    try {
      InstanceQuery query = new InstanceQuery();
      if (sourceIndex == 0) {
        query.setDatabaseURL(DBConn.url);
        query.setUsername(DBConn.user);
        query.setPassword(DBConn.pwd);
      } else if (sourceIndex == 1) {
        query.setDatabaseURL(DBConn.url_validation);
        query.setUsername(DBConn.user_validation);
        query.setPassword(DBConn.pwd_validation);
      } else if (sourceIndex == 2) {
        query.setDatabaseURL(ProjectEvaluator.testUrl);
        query.setUsername(ProjectEvaluator.testUser);
        query.setPassword(ProjectEvaluator.testPwd);
      } else {
        throw new Exception("source index must be 0, 1 or 2!");
      }
      query.setQuery(sqlQuery);
      dataSet = query.retrieveInstances();
      dataSet.setClassIndex(dataSet.numAttributes() - 1);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return dataSet;
  }
Example #4
0
  /** Queries the user enough to make a database query to retrieve experiment results. */
  protected void setInstancesFromDBaseQuery() {

    try {
      if (m_InstanceQuery == null) {
        m_InstanceQuery = new InstanceQuery();
      }
      String dbaseURL = m_InstanceQuery.getDatabaseURL();
      String username = m_InstanceQuery.getUsername();
      String passwd = m_InstanceQuery.getPassword();
      /*dbaseURL = (String) JOptionPane.showInputDialog(this,
      "Enter the database URL",
      "Query Database",
      JOptionPane.PLAIN_MESSAGE,
      null,
      null,
      dbaseURL);*/

      DatabaseConnectionDialog dbd = new DatabaseConnectionDialog(null, dbaseURL, username);
      dbd.setVisible(true);

      // if (dbaseURL == null) {
      if (dbd.getReturnValue() == JOptionPane.CLOSED_OPTION) {
        m_FromLab.setText("Cancelled");
        return;
      }
      dbaseURL = dbd.getURL();
      username = dbd.getUsername();
      passwd = dbd.getPassword();
      m_InstanceQuery.setDatabaseURL(dbaseURL);
      m_InstanceQuery.setUsername(username);
      m_InstanceQuery.setPassword(passwd);
      m_InstanceQuery.setDebug(dbd.getDebug());

      m_InstanceQuery.connectToDatabase();
      if (!m_InstanceQuery.experimentIndexExists()) {
        System.err.println("not found");
        m_FromLab.setText("No experiment index");
        m_InstanceQuery.disconnectFromDatabase();
        return;
      }
      System.err.println("found");
      m_FromLab.setText("Getting experiment index");
      Instances index =
          m_InstanceQuery.retrieveInstances("SELECT * FROM " + InstanceQuery.EXP_INDEX_TABLE);
      if (index.numInstances() == 0) {
        m_FromLab.setText("No experiments available");
        m_InstanceQuery.disconnectFromDatabase();
        return;
      }
      m_FromLab.setText("Got experiment index");

      DefaultListModel lm = new DefaultListModel();
      for (int i = 0; i < index.numInstances(); i++) {
        lm.addElement(index.instance(i).toString());
      }
      JList jl = new JList(lm);
      jl.setSelectedIndex(0);
      int result;
      // display dialog only if there's not just one result!
      if (jl.getModel().getSize() != 1) {
        ListSelectorDialog jd = new ListSelectorDialog(null, jl);
        result = jd.showDialog();
      } else {
        result = ListSelectorDialog.APPROVE_OPTION;
      }
      if (result != ListSelectorDialog.APPROVE_OPTION) {
        m_FromLab.setText("Cancelled");
        m_InstanceQuery.disconnectFromDatabase();
        return;
      }
      Instance selInst = index.instance(jl.getSelectedIndex());
      Attribute tableAttr = index.attribute(InstanceQuery.EXP_RESULT_COL);
      String table = InstanceQuery.EXP_RESULT_PREFIX + selInst.toString(tableAttr);
      setInstancesFromDatabaseTable(table);

    } catch (Exception ex) {
      // 1. print complete stacktrace
      ex.printStackTrace();
      // 2. print message in panel
      m_FromLab.setText("Problem reading database: '" + ex.getMessage() + "'");
    }
  }