示例#1
0
  @Override
  public ArrayList<ArrayList<String>> convertToRowWise(DataSet dataSet) {

    ArrayList<ArrayList<String>> columnDataArrayList = new ArrayList<ArrayList<String>>();
    ArrayList<ArrayList<String>> rowArrayList = new ArrayList<ArrayList<String>>();

    for (int index = 0; index < dataSet.getColumns().size(); index++) {

      columnDataArrayList.add(
          dataSet.getData().get(dataSet.getColumns().get(index).getId()).getValues());
    }

    for (int i = 0; i < columnDataArrayList.size(); i++) {
      ArrayList<String> colwisewRow = columnDataArrayList.get(i);

      for (int j = 0; j < colwisewRow.size(); j++) {

        if (i == 0) {
          ArrayList<String> temp = new ArrayList<String>();
          rowArrayList.add(temp);
        }

        rowArrayList.get(j).add(colwisewRow.get(j));
      }
    }

    return rowArrayList;
  }
示例#2
0
  @Override
  public void setDatasetInfo(String id, DataSet dataset) {

    DataSetInfo dataSetInfo = new DataSetInfo(dataset.getName(), 1900);
    dataSetInfo.setId(dataset.getId());
    dataSetInfo.setName(dataset.getName());
    DataSets.dataSetsInfos.put(id, dataSetInfo);
  }
 private List<ArrayList<String>> getCSVFormat(String datasetId) {
   List<ArrayList<String>> csvLines = new ArrayList<ArrayList<String>>();
   DataSet dataSet = DataSets.dataSets.get(datasetId);
   ArrayList<DataSetColumn> columns = dataSet.getColumns();
   DataSetServiceImpl dataSetServiceImpl = new DataSetServiceImpl();
   ArrayList<String> datasetCols = new ArrayList<String>();
   for (int i = 0; i < columns.size(); i++) {
     datasetCols.add(columns.get(i).getName());
   }
   csvLines.add(datasetCols);
   csvLines.addAll(dataSetServiceImpl.convertToRowWise(dataSet));
   return csvLines;
 }
示例#4
0
  private void putDatasetinStaticMemory(DataSet dataSet) {

    DataSets.dataSets.put(dataSet.getId(), dataSet);
  }
示例#5
0
  @Override
  public DataSet parseFile(String fileUrl, char delimiter, boolean isFileRaw) {
    DataSet dataSet = new DataSet();
    Random randomGenerator = new Random();
    String dataSetId = FilenameUtils.getBaseName(fileUrl); // randomGenerator.nextInt(10000)
    // + "";
    dataSet.setId(dataSetId);
    dataSet.setIsRaw(isFileRaw);

    if (!isFileRaw) {
      ArrayList<DataSetColumn> columns = new ArrayList<DataSetColumn>();
      HashMap<String, DataSetValues<String>> data = new HashMap<String, DataSetValues<String>>();
      try {
        FileReader fileReader = new FileReader(fileUrl);
        CSVReader reader = new CSVReader(fileReader, delimiter);
        List<String[]> entries = reader.readAll();

        // My CSV Code

        String[] values = entries.get(0);
        for (int i = 0; i < values.length; i++) {
          String columnId = randomGenerator.nextInt(10000) + "";

          DataSetColumn column = new DataSetColumn(columnId);
          column.setColumnType(ColumnType.TEXT);
          column.setName(values[i]);
          columns.add(column);

          ArrayList<String> columnValue = new ArrayList<String>();

          DataSetValues<String> dataSetValues = new DataSetValues<String>();
          dataSetValues.setColumnId(columnId);
          dataSetValues.setValues(columnValue);

          data.put(columnId, dataSetValues);
        }

        for (int j = 1; j < entries.size(); j++) {

          values = entries.get(j);
          for (int i = 0; i < columns.size(); i++) {

            data.get(columns.get(i).getId()).addValue(values[i]);
          }
        }
        reader.close();
        fileReader.close();

      } catch (Exception e) { // Catch exception if any
        System.err.println("Error: " + e.getMessage());
      }

      dataSet.setColumns(columns);
      dataSet.setData(data);

    } else {

      try {
        String content = FileUtils.readFileToString(new File(fileUrl));
        dataSet.setRawcontent(content);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    putDatasetinStaticMemory(dataSet);
    return dataSet;
  }