Ejemplo n.º 1
0
  /**
   * 1.按照过滤条件读取数据<br>
   * 2.按照任务配置里设定的离散化方法,进行离散化<br>
   * 3.按照任务配置里的时间粒度,对数据进行聚合
   *
   * @param filterCondition 过滤条件
   * @param doAggregate 是否按时间对数据进行聚合
   * @param doDiscretize 是否考虑离散化
   * @return
   */
  private DataItems readInput(String filterCondition, boolean doAggregate, boolean doDiscretize) {
    String sqlStr =
        "SELECT 事件发生时间," + task.getMiningObject() + " " + "FROM " + conn.DB_TABLE + " WHERE ";
    if (task.getFilterCondition().length() > 0) sqlStr += task.getFilterCondition() + " AND ";
    if (filterCondition != null && filterCondition.length() > 0)
      sqlStr += filterCondition + " AND ";
    sqlStr += "1=1 ORDER BY 事件发生时间 asc"; // 按时间先后顺序读取数据
    conn.closeConn();
    ResultSet rs = conn.sqlQuery(sqlStr);
    if (rs == null) {
      return null;
    }
    ResultSetMetaData meta = null;
    int numRecords = 0;
    try {
      meta = rs.getMetaData();
      int numCols = meta.getColumnCount();
      data = new DataItems();
      while (rs.next()) {
        numRecords++;
        StringBuilder sb = new StringBuilder();
        for (int i = 2; i <= numCols; i++)
          if (rs.getString(i) != null) sb.append(rs.getString(i).trim() + ",");
        if (sb.length() > 0) {
          Date d = parseTime(rs.getString(1).trim());
          if (d != null) data.add1Data(d, sb.substring(0, sb.length() - 1));
          else System.out.println("");
        }
      }
      rs.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    System.out.println("共" + numRecords + "条记录!");
    System.out.println("读取完毕:" + data.getLength() + "条记录!");

    boolean isNonDouble = !data.isAllDataIsDouble();
    // 先进行时间粒度上的聚合
    if (doAggregate)
      data =
          DataPretreatment.aggregateData(
              data, task.getGranularity(), task.getAggregateMethod(), isNonDouble);
    // 再进行离散化(只有数值型才能够离散化,否则应该会报错!)
    if (doDiscretize)
      data =
          DataPretreatment.toDiscreteNumbers(
              data,
              task.getDiscreteMethod(),
              task.getDiscreteDimension(),
              task.getDiscreteEndNodes());
    data.setGranularity(task.getGranularity()); // 设置数据的一些参数,如粒度
    String endNodes = data.discreteNodes();
    task.setDiscreteEndNodes(endNodes);
    return data;
  }
Ejemplo n.º 2
0
  public DataItems readInputBefore(Date date) {
    Date dStart;
    Calendar cal = Calendar.getInstance();
    cal.set(1, 0, 1, 0, 0, 0);

    if (task.getDateStart().equals(cal.getTime())) // 如果没有设置在任务里设置时间,则采用软件总体的配置
    dStart = UtilsSimulation.instance.getStartTime();
    else // 如果在任务里设置了起始时间,则按任务的来
    dStart = task.getDateStart();

    return readInputBetween(dStart, date);
  }
Ejemplo n.º 3
0
  public DataItems readInputAfter(Date date) {
    Date dEnd;
    Calendar cal = Calendar.getInstance();
    cal.set(1, 0, 1, 0, 0, 0);

    if (task.getDateEnd() == null || task.getDateEnd().equals(cal.getTime()))
      dEnd = UtilsSimulation.instance.getCurTime();
    else dEnd = task.getDateEnd();
    if (dEnd.after(UtilsSimulation.instance.getCurTime()))
      dEnd = UtilsSimulation.instance.getCurTime();
    return readInputBetween(date, dEnd);
  }
  @Override
  public DataItems readInputByText(String[] conditions) {

    String whichNode = conditions[0]; // 得到需要预测的iP
    DataItems dataItems = new DataItems();
    Calendar lastYear = Calendar.getInstance();
    lastYear.set(2014, 9, 1, 0, 0, 0);
    String line = null;
    try {
      FileInputStream is = new FileInputStream(new File(task.getSourcePath()));
      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
      reader.readLine();
      while ((line = reader.readLine()) != null) {
        String[] values = line.split(",");
        String srcIp = values[1];
        String destIp = values[2];
        if (srcIp.compareTo(whichIp) == 0 || destIp.compareTo(whichIp) == 0) {
          lastYear.add(Calendar.HOUR_OF_DAY, 1);
          dataItems.add1Data(lastYear.getTime(), values[3]);
        }
      }
      reader.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return dataItems;
  }
Ejemplo n.º 5
0
 public DataInputUtils(TaskElement task) {
   this.task = task;
   if (task.getDataSource().equals("DataBase")) {
     conn = new OracleUtils();
     if (!conn.tryConnect()) UtilsUI.showErrMsg("数据库无法连接!");
   }
 }
 // private string node;
 public SingleNodeTrafficInputs(TaskElement task) {
   this.task = task;
   if (task.getDataSource().equals("DataBase")) {
     conn = new OracleUtils();
     if (!conn.tryConnect()) System.out.println("数据库无法连接!");
     // UtilsUI.showErrMsg("锟斤拷菘锟斤拷薹锟斤拷锟斤拷樱锟�);
   }
 }
Ejemplo n.º 7
0
  // 按照时间,sizeWindow和stepWindow将数据分成项集,再调用Itemset2File写入文件
  public static String[] movingdivide(DataItems datainput, TaskElement task, boolean FP)
      throws IOException {
    int sizeWindow = (int) ((ParamsSM) task.getMiningParams()).getSizeWindow() * 1000; // seconds
    int stepWindow = (int) ((ParamsSM) task.getMiningParams()).getStepWindow() * 1000; // seconds

    int len = datainput.getLength();
    List<Date> time = datainput.getTime();
    List<String> data = datainput.getData();

    List<String> DataSets = new ArrayList<String>();

    Date win_start_time = time.get(0);
    Date win_end_time = getDateAfter(win_start_time, sizeWindow);
    Date win_start_next = getDateAfter(win_start_time, stepWindow);
    int ind_next = -1;

    StringBuilder sb = new StringBuilder();
    int i = 0;
    do {
      DataItem item = datainput.getElementAt(i);
      i++;
      Date date = item.getTime();
      String val = item.getData();
      if (!date.before(win_start_time) && !date.after(win_end_time)) {
        if (sb.length() != 0) sb.append(" ");
        sb.append(val + " -1");
        if (!date.before(win_start_next) && ind_next == -1) ind_next = i - 1;
      } else {
        sb.append(" -2");
        DataSets.add(sb.toString());
        sb = new StringBuilder();

        if (ind_next == -1) {
          if (!date.before(getDateAfter(win_end_time, stepWindow))) {
            win_start_time = date;
            if (sb.length() != 0) sb.append(" ");
            sb.append(val + " -1");
          } else {
            win_start_time = win_start_next; // getDateAfter(win_start_time, stepWindow);
            if (sb.length() != 0) sb.append(" ");
            sb.append(val + " -1");
          }
        } else {
          i = ind_next;
          ind_next = -1;
          win_start_time = win_start_next;
        }
        win_end_time = getDateAfter(win_start_time, sizeWindow);
        win_start_next = getDateAfter(win_start_time, stepWindow);
      }

    } while (i < len);
    sb.append(" -2");
    DataSets.add(sb.toString());
    return DataSets.toArray(new String[0]);
  }
 public INetworkMiner createMiner(TaskElement task) {
   IReader reader = null;
   INetworkMiner miner = null;
   if (task == null) return null;
   if (allMiners.containsKey(task)) return allMiners.get(task);
   if (task.getTaskRange().equals(TaskRange.NodePairRange)) {
     reader = new nodePairReader(task, task.getRange().split(","));
   } else if (task.getTaskRange().equals(TaskRange.SingleNodeRange)) {
     // TODO 生成单节点读取数据Reader
   } else if (task.getTaskRange().equals(TaskRange.WholeNetworkRange)) {
     // TODO 生成整个网络读取数据Reader
   }
   if (task.getMiningMethod().equals(MiningMethod.MiningMethods_SequenceMining)) {
     miner = new NetworkMinerSM(task, reader);
   } else if (task.getMiningMethod().equals(MiningMethod.MiningMethods_TsAnalysis)) {
     miner = new NetworkMinerTSA(task, reader);
   } else if (task.getMiningMethod().equals(MiningMethod.MiningMethods_PeriodicityMining)) {
     miner = new NetworkMinerPM(task, reader);
   }
   allMiners.put(task, miner);
   return miner;
 }
 @Override
 public void onCreate() {
   TaskElement.addTaskListener(this);
 }
Ejemplo n.º 10
0
  /**
   * 按照任务配置读取数据,并按照任务配置里的时间粒度,对数据进行聚合
   *
   * @param doAggregate 是否聚合
   * @param doDiscretize 是否离散化
   * @return
   */
  public DataItems readInput(boolean doAggregate, boolean doDiscretize) {
    if (UtilsSimulation.instance.isUseSimulatedData()) // 使用
    {
      TextUtils txt = new TextUtils();
      txt.setTextPath(task.getSourcePath());
      DataItems dataItems = txt.readInput();
      boolean isNonDouble = !dataItems.isAllDataIsDouble(); // 离散的或非double型的
      if (doAggregate)
        dataItems =
            DataPretreatment.aggregateData(
                dataItems, task.getGranularity(), task.getAggregateMethod(), isNonDouble);
      if (doDiscretize)
        dataItems =
            DataPretreatment.toDiscreteNumbers(
                dataItems,
                task.getDiscreteMethod(),
                task.getDiscreteDimension(),
                task.getDiscreteEndNodes());
      String endNodes = dataItems.discreteNodes();
      task.setDiscreteEndNodes(endNodes);
      return dataItems;
    } else {
      Calendar cal = Calendar.getInstance();
      cal.set(1, 0, 1, 0, 0, 0);
      cal.set(Calendar.MILLISECOND, 0);
      Date dStart;
      Date dEnd;
      if (task.getDateStart() == null || task.getDateStart().equals(cal.getTime()))
        dStart = UtilsSimulation.instance.getStartTime();
      else dStart = task.getDateStart();

      if (task.getDateEnd() == null || task.getDateEnd().equals(cal.getTime()))
        dEnd = UtilsSimulation.instance.getCurTime();
      else dEnd = task.getDateEnd();
      if (dEnd.after(UtilsSimulation.instance.getCurTime()))
        dEnd = UtilsSimulation.instance.getCurTime();
      return readInputBetween(dStart, dEnd);
    }
  }