public static void exportToCSV()

in core/src/main/java/org/apache/sdap/mudrod/utils/MatrixUtil.java [457:496]


  public static void exportToCSV(RowMatrix matrix, List<String> rowKeys, List<String> colKeys, String fileName) {

    if (matrix.rows().isEmpty()) {
      return;
    }

    int rownum = (int) matrix.numRows();
    int colnum = (int) matrix.numCols();
    List<Vector> rows = matrix.rows().toJavaRDD().collect();

    File file = new File(fileName);
    if (file.exists()) {
      file.delete();
    }
    try {
      file.createNewFile();
    } catch (IOException e1) {
      LOG.error("Failed to create file : ", e1);
    }
    try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file.getAbsoluteFile()), StandardCharsets.UTF_8)){
      String coltitle = " Num" + ",";
      for (int j = 0; j < colnum; j++) {
        coltitle += "\"" + colKeys.get(j) + "\",";
      }
      coltitle = coltitle.substring(0, coltitle.length() - 1);
      osw.write(coltitle + "\n");

      for (int i = 0; i < rownum; i++) {
        double[] rowvlaue = rows.get(i).toArray();
        String row = rowKeys.get(i) + ",";
        for (int j = 0; j < colnum; j++) {
          row += rowvlaue[j] + ",";
        }
        row = row.substring(0, row.length() - 1);
        osw.write(row + "\n");
      }
    } catch (IOException e) {
      LOG.error("Failed to write to the file : ", e);
    }
  }