You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by le...@apache.org on 2025/02/23 17:44:06 UTC
(iotdb) 05/44: format code
This is an automated email from the ASF dual-hosted git repository.
leirui pushed a commit to branch research/area-visualization
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 545bff4a975f9da11f15d4228222eadd469880b2
Author: Lei Rui <10...@qq.com>
AuthorDate: Fri Jan 3 14:01:45 2025 +0800
format code
---
.../iotdb/db/query/simpiece/Visval_standard.java | 116 ++++++++++++---------
1 file changed, 68 insertions(+), 48 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval_standard.java b/server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval_standard.java
index b5033b86097..5471f62f65f 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval_standard.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/simpiece/Visval_standard.java
@@ -1,3 +1,22 @@
+/*
+ * 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.util.ArrayList;
@@ -8,7 +27,8 @@ import java.util.PriorityQueue;
import java.util.Random;
import java.util.stream.Collectors;
-// adapted from the open source C++ code https://github.com/ofZach/Visvalingam-Whyatt/blob/master/src/testApp.cpp
+// adapted from the open source C++ code
+// https://github.com/ofZach/Visvalingam-Whyatt/blob/master/src/testApp.cpp
class Triangle {
int[] indices = new int[3];
@@ -31,7 +51,7 @@ class vPoint {
public vPoint(double x, double y) {
this.x = x;
this.y = y;
- this.z = Double.POSITIVE_INFINITY;// effective area
+ this.z = Double.POSITIVE_INFINITY; // effective area
}
}
@@ -79,8 +99,9 @@ public class Visval_standard {
// 创建所有三角形并计算初始面积
for (int i = 1; i < total - 1; i++) {
int index1 = i - 1, index2 = i, index3 = i + 1;
- double area = triArea(lineToSimplify.get(index1), lineToSimplify.get(index2),
- lineToSimplify.get(index3));
+ double area =
+ triArea(
+ lineToSimplify.get(index1), lineToSimplify.get(index2), lineToSimplify.get(index3));
triangles[i - 1] = new Triangle(index1, index2, index3, area);
}
@@ -91,8 +112,8 @@ public class Visval_standard {
}
// 使用优先队列构建 minHeap
- PriorityQueue<Triangle> triangleHeap = new PriorityQueue<>(
- Comparator.comparingDouble(t -> t.area));
+ PriorityQueue<Triangle> triangleHeap =
+ new PriorityQueue<>(Comparator.comparingDouble(t -> t.area));
Collections.addAll(triangleHeap, triangles);
double previousEA = -1;
@@ -106,18 +127,18 @@ public class Visval_standard {
previousEA = tri.area;
}
results.get(tri.indices[1]).z = previousEA;
-// System.out.println(tri.indices[1] + "," + previousEA);
+ // System.out.println(tri.indices[1] + "," + previousEA);
// 更新相邻三角形
if (tri.prev != null) {
// 前一个三角形连到后一个三角形
tri.prev.next = tri.next;
tri.prev.indices[2] = tri.indices[2];
- tri.prev.area = triArea(
- lineToSimplify.get(tri.prev.indices[0]),
- lineToSimplify.get(tri.prev.indices[1]),
- lineToSimplify.get(tri.prev.indices[2])
- );
+ tri.prev.area =
+ triArea(
+ lineToSimplify.get(tri.prev.indices[0]),
+ lineToSimplify.get(tri.prev.indices[1]),
+ lineToSimplify.get(tri.prev.indices[2]));
// 重新加入堆
// 在 Java 的 PriorityQueue 中,修改元素的属性不会自动更新堆的顺序
@@ -130,11 +151,11 @@ public class Visval_standard {
// 后一个三角形连到前一个三角形
tri.next.prev = tri.prev;
tri.next.indices[0] = tri.indices[0];
- tri.next.area = triArea(
- lineToSimplify.get(tri.next.indices[0]),
- lineToSimplify.get(tri.next.indices[1]),
- lineToSimplify.get(tri.next.indices[2])
- );
+ tri.next.area =
+ triArea(
+ lineToSimplify.get(tri.next.indices[0]),
+ lineToSimplify.get(tri.next.indices[1]),
+ lineToSimplify.get(tri.next.indices[2]));
// 重新加入堆
triangleHeap.remove(tri.next);
@@ -169,10 +190,10 @@ public class Visval_standard {
System.out.println("Time taken to reduce points: " + (endTime - startTime) + "ms");
System.out.println(results.size());
-// for (int i = 0; i < results.size(); i++) {
-// vPoint point = results.get(i);
-// System.out.println("Point: (" + point.x + ", " + point.y + ", " + point.z + ")");
-// }
+ // for (int i = 0; i < results.size(); i++) {
+ // vPoint point = results.get(i);
+ // System.out.println("Point: (" + point.x + ", " + point.y + ", " + point.z + ")");
+ // }
System.out.println("---------------------------------");
List<List<vPoint>> resultsBatchList = new ArrayList<>();
@@ -192,8 +213,8 @@ public class Visval_standard {
System.out.println("---------------------------------");
// 使用 Stream API 合并所有列表
- List<vPoint> mergedList = resultsBatchList.stream().flatMap(List::stream)
- .collect(Collectors.toList());
+ List<vPoint> mergedList =
+ resultsBatchList.stream().flatMap(List::stream).collect(Collectors.toList());
int sameCnt = 0;
for (int i = 0; i < mergedList.size(); i++) {
if (mergedList.get(i).z == results.get(i).z) {
@@ -201,31 +222,30 @@ public class Visval_standard {
}
}
System.out.println("sameCnt=" + sameCnt + ", percent=" + sameCnt * 1.0 / mergedList.size());
-
}
-// float[] vlist = new float[]{11346, 33839, 35469, 23108, 22812, 5519, 5526, 4865, 5842, 23089};
-// for (int i = 0; i < vlist.length; i++) {
-// polyline.addVertex(new vPoint(i, vlist[i]));
-// }
-
-// ArrayList<Double> v = new ArrayList<>();
-// String filePath = "D://desktop//数据集//New York Stock Exchange//merged_prices.csv";
-// try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
-// String line;
-// int count = 0;
-// while ((line = br.readLine()) != null && count < 1000) {
-// String[] columns = line.split(","); // 假设 CSV 文件以逗号分隔
-// v.add(Double.parseDouble(columns[0])); // 读取第一列数据
-// count++;
-// }
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// // 打印数据长度
-// System.out.println("Data length: " + v.size());
-// for (int i = 0; i < v.size(); i++) {
-// polyline.addVertex(new vPoint(i, v.get(i)));
-// }
+ // float[] vlist = new float[]{11346, 33839, 35469, 23108, 22812, 5519, 5526, 4865, 5842,
+ // 23089};
+ // for (int i = 0; i < vlist.length; i++) {
+ // polyline.addVertex(new vPoint(i, vlist[i]));
+ // }
+
+ // ArrayList<Double> v = new ArrayList<>();
+ // String filePath = "D://desktop//数据集//New York Stock Exchange//merged_prices.csv";
+ // try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
+ // String line;
+ // int count = 0;
+ // while ((line = br.readLine()) != null && count < 1000) {
+ // String[] columns = line.split(","); // 假设 CSV 文件以逗号分隔
+ // v.add(Double.parseDouble(columns[0])); // 读取第一列数据
+ // count++;
+ // }
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // }
+ // // 打印数据长度
+ // System.out.println("Data length: " + v.size());
+ // for (int i = 0; i < v.size(); i++) {
+ // polyline.addVertex(new vPoint(i, v.get(i)));
+ // }
}
-