This is an automated email from the ASF dual-hosted git repository.

leirui pushed a commit to branch research/LTS-visualization
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 842d8e4ee19e0e619fde66aa4b2391b5bb8c2c9a
Author: Lei Rui <[email protected]>
AuthorDate: Tue Oct 15 06:35:55 2024 +0800

    add
---
 .../iotdb/db/query/simpiece/MySample_fsw2.java     |   5 +
 .../iotdb/db/query/simpiece/MySample_fsw_UCR.java  |  95 +++++++++++++++++
 .../db/query/simpiece/MySample_simpiece2.java      |   5 +
 .../db/query/simpiece/MySample_simpiece_UCR.java   | 115 +++++++++++++++++++++
 4 files changed, 220 insertions(+)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java
index 9cd01f218bb..ed82643d7a8 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw2.java
@@ -136,7 +136,12 @@ public class MySample_fsw2 {
     boolean directMore = false;
     boolean skip = false;
     int threshold = 2;
+    int iterNum = 0;
     while (true) {
+      iterNum += 1;
+      if (iterNum > 1000) {
+        break;
+      }
       List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon);
       if (reducedPoints.size() > nout) {
         if (directMore) {
diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_UCR.java 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_UCR.java
new file mode 100644
index 00000000000..f40e7e0df6e
--- /dev/null
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_fsw_UCR.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.iotdb.db.query.simpiece;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+public class MySample_fsw_UCR {
+
+  public static void main(String[] args) {
+    String fileDir = "D:\\3\\UCRsets\\";
+    File folder = new File(fileDir);
+    // 调用递归函数遍历文件夹
+    listFiles(folder);
+  }
+
+  public static void listFiles(File folder) {
+    File[] files = folder.listFiles();
+
+    if (files != null) {
+      for (File file : files) {
+        if (file.isDirectory()) {
+          // 如果是文件夹,递归遍历
+          listFiles(file);
+        } else if (file.isFile() && file.getName().endsWith(".csv") && 
!file.getName()
+            .contains("-segment")) {
+          // 如果是csv文件,读取内容
+          System.out.println("Reading file: " + file.getAbsolutePath());
+          readCSV(file);
+        }
+      }
+    }
+  }
+
+  public static void readCSV(File file) {
+    int start = 0;
+    int N = -1;
+    boolean hasHeader = false;
+    try (FileInputStream inputStream = new FileInputStream(file)) {
+      String delimiter = ",";
+      TimeSeries ts =
+          TimeSeriesReader.getMyTimeSeries(
+              inputStream, delimiter, false, N, start, hasHeader, true);
+      int n = ts.length();
+
+      int nout = n / 2;
+      nout = (nout / 4) * 4; // for M4 requires nout to be four integer 
multiples
+
+      double epsilon = MySample_fsw2.getFSWParam(nout, ts, 1e-6);
+      List<Point> reducedPoints = FSW.reducePoints(ts.data, epsilon);
+      System.out.println(
+          file
+              + ": n="
+              + n
+              + ",target m="
+              + nout
+              + ",epsilon="
+              + epsilon
+              + ",actual m="
+              + reducedPoints.size());
+
+      String newFileName = file.getName().replace(".csv", "-segment-fsw.csv");
+      File newFile = new File(file.getParent(), newFileName);
+      try (PrintWriter writer = new PrintWriter(new FileWriter(newFile))) {
+        for (Point p : reducedPoints) {
+          writer.println(p.getTimestamp() + "," + p.getValue());
+        }
+      }
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}
diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java
 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java
index f79359c9780..d09e81dc543 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece2.java
@@ -136,7 +136,12 @@ public class MySample_simpiece2 {
     boolean directMore = false;
     boolean skip = false;
     int threshold = 2;
+    int iterNum = 0;
     while (true) {
+      iterNum += 1;
+      if (iterNum > 1000) {
+        break;
+      }
       SimPiece simPiece = new SimPiece(ts.data, epsilon);
       if (simPiece.segments.size() * 2 > nout) { // note *2 for disjoint
         if (directMore) {
diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_UCR.java
 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_UCR.java
new file mode 100644
index 00000000000..152e0c2c1b7
--- /dev/null
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/simpiece/MySample_simpiece_UCR.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.iotdb.db.query.simpiece;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Comparator;
+import java.util.List;
+
+public class MySample_simpiece_UCR {
+
+  public static void main(String[] args) {
+    String fileDir = "D:\\3\\UCRsets\\";
+    File folder = new File(fileDir);
+    // 调用递归函数遍历文件夹
+    listFiles(folder);
+  }
+
+  public static void listFiles(File folder) {
+    File[] files = folder.listFiles();
+
+    if (files != null) {
+      for (File file : files) {
+        if (file.isDirectory()) {
+          // 如果是文件夹,递归遍历
+          listFiles(file);
+        } else if (file.isFile() && file.getName().endsWith(".csv") && 
!file.getName()
+            .contains("-segment")) {
+          // 如果是csv文件,读取内容
+          System.out.println("Reading file: " + file.getAbsolutePath());
+          readCSV(file);
+        }
+      }
+    }
+  }
+
+  public static void readCSV(File file) {
+    int start = 0;
+    int N = -1;
+    boolean hasHeader = false;
+    try (FileInputStream inputStream = new FileInputStream(file)) {
+      String delimiter = ",";
+      TimeSeries ts =
+          TimeSeriesReader.getMyTimeSeries(
+              inputStream, delimiter, false, N, start, hasHeader, true);
+      int n = ts.length();
+
+      int nout = n / 2;
+      nout = (nout / 4) * 4; // for M4 requires nout to be four integer 
multiples
+
+      double epsilon = MySample_simpiece2.getSimPieceParam(nout, ts, 1e-6);
+      SimPiece simPiece = new SimPiece(ts.data, epsilon);
+      System.out.println(
+          file
+              + ": n="
+              + n
+              + ",target m="
+              + nout
+              + ",epsilon="
+              + epsilon
+              + ",actual m="
+              + simPiece.segments.size() * 2);
+
+      String newFileName = file.getName().replace(".csv", 
"-segment-simpiece.csv");
+      File newFile = new File(file.getParent(), newFileName);
+      List<SimPieceSegment> segments = simPiece.segments;
+      
segments.sort(Comparator.comparingLong(SimPieceSegment::getInitTimestamp));
+      try (PrintWriter writer = new PrintWriter(new FileWriter(newFile))) {
+        for (int i = 0; i < segments.size() - 1; i++) {
+          // start point of this segment
+          writer.println(segments.get(i).getInitTimestamp() + "," + 
segments.get(i).getB());
+          // end point of this segment
+          double v =
+              (segments.get(i + 1).getInitTimestamp() - 
segments.get(i).getInitTimestamp())
+                  * segments.get(i).getA()
+                  + segments.get(i).getB();
+          writer.println(segments.get(i + 1).getInitTimestamp() + "," + v);
+        }
+        // the two end points of the last segment
+        writer.println(
+            segments.get(segments.size() - 1).getInitTimestamp()
+                + ","
+                + segments.get(segments.size() - 1).getB());
+        double v =
+            (simPiece.lastTimeStamp - segments.get(segments.size() - 
1).getInitTimestamp())
+                * segments.get(segments.size() - 1).getA()
+                + segments.get(segments.size() - 1).getB();
+        writer.println(simPiece.lastTimeStamp + "," + v);
+      }
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}

Reply via email to