From d81a76400bf9eebb5cb8d25548319b2d1669bb62 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 25 Aug 2020 10:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=92=E4=B8=80=E7=AE=97=E6=B3=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0list=E7=9A=84=E9=87=8D=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../normalizing/DoubleScoreCalculator.java | 9 +++++++++ .../normalizing/IntegerScoreCalculator.java | 10 ++++++++++ .../support/normalizing/ScoreCalculator.java | 20 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/DoubleScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/DoubleScoreCalculator.java index c626602393..01258d0f45 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/DoubleScoreCalculator.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/DoubleScoreCalculator.java @@ -1,6 +1,7 @@ package com.epmet.support.normalizing; import java.math.BigDecimal; +import java.util.List; /** * Double的分值计算 @@ -24,6 +25,14 @@ public class DoubleScoreCalculator extends ScoreCalculator { this.prepare(); } + public DoubleScoreCalculator(List sourceArray, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) { + this.sourceArrary = sourceArray.toArray(); + this.minScore = minScore; + this.maxScore = maxScore; + this.correlation = correlation; + this.prepare(); + } + @Override public BigDecimal getMaxFromSourceArray() { Double[] doubleSourceArrary = (Double[]) this.sourceArrary; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/IntegerScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/IntegerScoreCalculator.java index 7708b83fc0..98f837ab7e 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/IntegerScoreCalculator.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/IntegerScoreCalculator.java @@ -1,6 +1,7 @@ package com.epmet.support.normalizing; import java.math.BigDecimal; +import java.util.List; /** * Integer的分值计算 @@ -26,6 +27,15 @@ public class IntegerScoreCalculator extends ScoreCalculator { } + public IntegerScoreCalculator(List sourceList, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) { + this.sourceArrary = sourceList.toArray(); + this.minScore = minScore; + this.maxScore = maxScore; + this.correlation = correlation; + this.prepare(); + System.out.println("最小值:"+minScore+";最大值:"+maxScore); + } + @Override public BigDecimal getMaxFromSourceArray() { Integer[] intSourceArrary = (Integer[]) this.sourceArrary; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreCalculator.java index e3c98d5117..48692e92ce 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreCalculator.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreCalculator.java @@ -3,6 +3,8 @@ package com.epmet.support.normalizing; import java.math.BigDecimal; import java.math.MathContext; import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; /** * 所有数据类型计算器的父类,实现算法骨架,数据类型转换方法则由子类实现 @@ -93,6 +95,15 @@ public abstract class ScoreCalculator { return scores; } + /** + * 批量归一算法,返回List + * @param sourceValues + * @return + */ + public List normalize(List sourceValues) { + return sourceValues.stream().map(s -> normalize(s)).collect(Collectors.toList()); + } + /** * 批量归一算法,带权重 * @param sourceValues @@ -110,6 +121,15 @@ public abstract class ScoreCalculator { return scores; } + /** + * 批量归一算法,返回List + * @param sourceValues + * @return + */ + public List normalize(List sourceValues, BigDecimal weight) { + return sourceValues.stream().map(s -> normalize(s).multiply(weight)).collect(Collectors.toList()); + } + /** * 校验数组 * @param sourceArray