夜得朦胧 1 jaar geleden
bovenliggende
commit
4208eb99ca

+ 5 - 0
simulation-resource-server/pom.xml

@@ -125,6 +125,11 @@
         </dependency>
         <!-- 数据库 - 结束 -->
 
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math3</artifactId>
+            <version>3.6.1</version> <!-- 请检查最新版本 -->
+        </dependency>
         <!-- 参数校验 -->
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 68 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infra/util/CalculateUtils.java

@@ -0,0 +1,68 @@
+package com.css.simulation.resource.server.infra.util;
+
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
+public class CalculateUtils {
+    public static Double getStandardDeviationByStrList(List<String> doubleList) {
+        if (CollectionUtils.isEmpty(doubleList)) {
+            return null;
+        }
+        try {
+            DescriptiveStatistics stats = new DescriptiveStatistics();
+            for (String d : doubleList) {
+                stats.addValue(Double.valueOf(d));
+            }
+            return stats.getStandardDeviation();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+    public static Double getStandardDeviation(List<Double> doubleList) {
+        if (CollectionUtils.isEmpty(doubleList)) {
+            return null;
+        }
+        try {
+            DescriptiveStatistics stats = new DescriptiveStatistics();
+            for (Double d : doubleList) {
+                stats.addValue(d);
+            }
+
+            return stats.getStandardDeviation();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public static Double getAvaByStrList(List<String> doubleList) {
+        if (CollectionUtils.isEmpty(doubleList)) {
+            return null;
+        }
+        try {
+            DescriptiveStatistics stats = new DescriptiveStatistics();
+            for (String d : doubleList) {
+                stats.addValue(Double.valueOf(d));
+            }
+            return stats.getMean();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+    public static Double getAva(List<Double> doubleList) {
+        if (CollectionUtils.isEmpty(doubleList)) {
+            return null;
+        }
+        try {
+            DescriptiveStatistics stats = new DescriptiveStatistics();
+            for (Double d : doubleList) {
+                stats.addValue(d);
+            }
+            return stats.getMean();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+}