test_class.file: tools/export/src/test/java/kairosdb/export/csv/TransToTsfileTest.java
test_class.identifier: TransToTsfileTest
test_case.body: @Test
    public void writeTsfile() {
      TransToTsfile
          .transToTsfile("/Users/tianyu/git_project/iotdb-kairosdb/tools/export/res/test.csv",
              "/Users/tianyu/git_project/iotdb-kairosdb/tools/export/res/test.tsfile");
    }
test_case.class_method_signature: TransToTsfileTest.writeTsfile()
test_case.full_signature: @Test public void writeTsfile()
test_case.identifier: writeTsfile
test_case.invocations: transToTsfile
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void writeTsfile()
focal_class.file: tools/export/src/main/java/kairosdb/export/csv/TransToTsfile.java
focal_class.identifier: TransToTsfile
focal_class.class_method_signature: TransToTsfile.transToTsfile(String dirPath, String tsPath)
focal_class.full_signature: public static void transToTsfile(String dirPath, String tsPath)
focal_class.identifier: transToTsfile
focal_class.modifiers: public static
focal_class.parameters: (String dirPath, String tsPath)
focal_class.return: void
focal_class.signature: void transToTsfile(String dirPath, String tsPath)
focal_class.class_method_signature: TransToTsfile.main(String[] args)
focal_class.full_signature: public static void main(String[] args)
focal_class.identifier: main
focal_class.modifiers: public static
focal_class.parameters: (String[] args)
focal_class.return: void
focal_class.signature: void main(String[] args)
focal_method.body: public static void transToTsfile(String dirPath, String tsPath) {
      try {
        File f = new File(tsPath);
        if (!f.getParentFile().exists()) {
          f.getParentFile().mkdirs();
        }
  
        try (TsFileWriter tsFileWriter = new TsFileWriter(f)) {
          File[] csvFiles = new File(dirPath).listFiles();
          for (File csvFile : csvFiles) {
            try (BufferedReader csvReader = new BufferedReader(new FileReader(csvFile))) {
              String header = csvReader.readLine();
              String[] sensorFull = Arrays
                  .copyOfRange(header.split(","), 1, header.split(",").length);
              ArrayList<String> sensorList = new ArrayList<>(Arrays.asList(sensorFull));
              String device = sensorList.get(0).substring(0, sensorList.get(0).lastIndexOf('.'));
              for (int i = 0; i < sensorList.size(); i++) {
                sensorList.set(i, sensorList.get(i).replace(device, "").substring(1));
              }
              List<TSDataType> tsDataTypes = Arrays.asList(new TSDataType[sensorList.size()]);
              String intRegex = "[0-9]+";
              String floatRegex = "[0-9]+.[0-9]+";
              String line;
              while ((line = csvReader.readLine()) != null) {
                // construct TSRecord
                long time = Long.parseLong(line.split(",")[0]);
                TSRecord tsRecord = new TSRecord(time, device);
                String[] points = Arrays.copyOfRange(line.split(","), 1, line.split(",").length);
                for (int i = 0; i < points.length; i++) {
                  if (points[i].matches(intRegex)) {
                    if (tsDataTypes.get(i) == null) {
                      tsDataTypes.set(i, TSDataType.INT64);
                      try {
                        tsFileWriter.addMeasurement(new MeasurementSchema(sensorList.get(i),
                            TSDataType.INT64, TSEncoding.TS_2DIFF));
                      } catch (Exception e) {
                        //
                      }
                      DataPoint intPoint = new LongDataPoint(sensorList.get(i),
                          Long.parseLong(points[i]));
                      tsRecord.addTuple(intPoint);
                    } else {
                      DataPoint intPoint = new LongDataPoint(sensorList.get(i),
                          Long.parseLong(points[i]));
                      tsRecord.addTuple(intPoint);
                    }
                  } else if (points[i].matches(floatRegex)) {
                    if (tsDataTypes.get(i) == null) {
                      tsDataTypes.set(i, TSDataType.FLOAT);
                      try {
                        tsFileWriter.addMeasurement(new MeasurementSchema(sensorList.get(i),
                            TSDataType.FLOAT, TSEncoding.GORILLA));
                      } catch (Exception e) {
                        //
                      }
                      DataPoint floatPoint = new FloatDataPoint(sensorList.get(i),
                          Float.parseFloat(points[i]));
                      tsRecord.addTuple(floatPoint);
                    } else {
                      DataPoint floatPoint = new FloatDataPoint(sensorList.get(i),
                          Float.parseFloat(points[i]));
                      tsRecord.addTuple(floatPoint);
                    }
                  } else {
                    if (!points[i].equals("")) {
                      if (tsDataTypes.get(i) == null) {
                        tsDataTypes.set(i, TSDataType.TEXT);
                        try {
                          tsFileWriter.addMeasurement(new MeasurementSchema(sensorList.get(i),
                              TSDataType.TEXT, TSEncoding.PLAIN));
                        } catch (Exception e) {
                          //
                        }
                        DataPoint textPoint = new StringDataPoint(sensorList.get(i),
                            Binary.valueOf(points[i]));
                        tsRecord.addTuple(textPoint);
                      } else {
                        DataPoint textPoint = new StringDataPoint(sensorList.get(i),
                            Binary.valueOf(points[i]));
                        tsRecord.addTuple(textPoint);
                      }
                    }
                  }
                }
                tsFileWriter.write(tsRecord);
              }
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
  
    }
focal_method.class_method_signature: TransToTsfile.transToTsfile(String dirPath, String tsPath)
focal_method.full_signature: public static void transToTsfile(String dirPath, String tsPath)
focal_method.identifier: transToTsfile
focal_method.invocations: exists getParentFile mkdirs getParentFile listFiles readLine copyOfRange split split asList substring get lastIndexOf get size set substring replace get asList size readLine parseLong split copyOfRange split split matches get set addMeasurement get get parseLong addTuple get parseLong addTuple matches get set addMeasurement get get parseFloat addTuple get parseFloat addTuple equals get set addMeasurement get get valueOf addTuple get valueOf addTuple write printStackTrace
focal_method.modifiers: public static
focal_method.parameters: (String dirPath, String tsPath)
focal_method.return: void
focal_method.signature: void transToTsfile(String dirPath, String tsPath)