|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|