From 445fb28380aabe0f00416ed93147f06701649b71 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 26 Aug 2020 16:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9A=84=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=88=86=E6=94=AF=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../batch/BatchScoreCalculator.java | 14 +++++++++----- .../normalizing/batch/IndexInputVO.java | 6 +++--- .../normalizing/batch/IndexOutputVO.java | 4 ++-- .../normalizing/batch/SampleScore.java | 19 +++++++++++++++++++ .../normalizing/batch/SampleValue.java | 17 +++++++++++++++++ .../stats/test/normalizing/DemoScoreCal.java | 16 ++++++++-------- 6 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleScore.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java index 85b8cf501d..fb54b5960e 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java @@ -17,16 +17,20 @@ public class BatchScoreCalculator { * 执行计算 * @return 每一条都是一个指标的,所有样本对应的,得分值 */ - public List exec(List indexVOS) { - this.indexVOS = indexVOS; + public List exec(List indexInputVOS) { + this.indexVOS = indexInputVOS; - return indexVOS.stream().map(i -> { + return indexInputVOS.stream().map(i -> { String indexId = i.getIndexId(); - List indexValues = i.getIndexValues(); + List indexValueVOs = i.getIndexValueVOs(); BigDecimal weight = i.getWeight(); ScoreCalculator scoreCalculator = i.getScoreCalculator(); - List scores4OneIndex = scoreCalculator.normalize(indexValues, weight); + // 循环同一个指标内的多个样本值的SampleValue列表 + List scores4OneIndex = indexValueVOs.stream().map(vo -> { + BigDecimal score = scoreCalculator.normalize(vo.getSampleValue(), weight); + return new SampleScore(vo.getSampleId(), score); + }).collect(Collectors.toList()); return new IndexOutputVO(indexId, scores4OneIndex); }).collect(Collectors.toList()); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java index 984388d07d..94ea1ef0ad 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java @@ -22,7 +22,7 @@ public class IndexInputVO { /** * 指标的样本值 */ - private List indexValues; + private List> indexValueVOs; /** * 权重 @@ -31,8 +31,8 @@ public class IndexInputVO { private ScoreCalculator scoreCalculator; - public IndexInputVO(List indexValues, BigDecimal weight, ScoreCalculator scoreCalculator) { - this.indexValues = indexValues; + public IndexInputVO(List> indexValueVOs, BigDecimal weight, ScoreCalculator scoreCalculator) { + this.indexValueVOs = indexValueVOs; this.weight = weight; this.scoreCalculator = scoreCalculator; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexOutputVO.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexOutputVO.java index ab85a8cabf..fdf0a3dea9 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexOutputVO.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexOutputVO.java @@ -8,7 +8,7 @@ import java.util.List; @Data @AllArgsConstructor -public class IndexOutputVO { +public class IndexOutputVO { /** * 指标标记,由使用者传入,用以标记该条指标的独有特性,一般用id或者code @@ -19,5 +19,5 @@ public class IndexOutputVO { /** * 指标的样本值 */ - private List indexScores; + private List indexScoreVOs; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleScore.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleScore.java new file mode 100644 index 0000000000..bd677fc861 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleScore.java @@ -0,0 +1,19 @@ +package com.epmet.support.normalizing.batch; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 样本得分对象 + */ +@Data +@AllArgsConstructor +public class SampleScore { + + private String sampleId; + + private BigDecimal sampleScore; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java new file mode 100644 index 0000000000..0818cc8d97 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java @@ -0,0 +1,17 @@ +package com.epmet.support.normalizing.batch; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * 样本值对象 + */ +@Data +@AllArgsConstructor +public class SampleValue { + + private String sampleId; + + private T sampleValue; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java index 178468b0a0..1bb7514d5a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java @@ -4,6 +4,7 @@ import com.epmet.support.normalizing.*; import com.epmet.support.normalizing.batch.BatchScoreCalculator; import com.epmet.support.normalizing.batch.IndexInputVO; import com.epmet.support.normalizing.batch.IndexOutputVO; +import com.epmet.support.normalizing.batch.SampleValue; import org.junit.Test; import java.math.BigDecimal; @@ -24,10 +25,8 @@ public class DemoScoreCal { @Test public void demoInteger() { Integer[] iArray = {4, 8, 1, 3, 2}; - BigDecimal minScore = new BigDecimal(5); - BigDecimal maxScore = new BigDecimal(10); - ScoreCalculator sc = new IntegerScoreCalculator(iArray, minScore, maxScore, Correlation.NEGATIVE); + ScoreCalculator sc = new IntegerScoreCalculator(iArray, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); BigDecimal[] scores = sc.normalize(iArray); Arrays.stream(scores).forEach(s -> System.out.println(s)); } @@ -38,10 +37,8 @@ public class DemoScoreCal { @Test public void demoIntegerPartical() { Integer[] iArray = {4, 1, 8}; - BigDecimal minScore = new BigDecimal(5); - BigDecimal maxScore = new BigDecimal(10); - ScoreCalculator sc = new IntegerScoreCalculator(1, 8, minScore, maxScore, Correlation.NEGATIVE); + ScoreCalculator sc = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); BigDecimal[] scores = sc.normalize(iArray);// 此处也可以直接使用list参数的重载方法,计算阶段没有任何区别,区别在于new IntegerScoreCalculator()阶段 Arrays.stream(scores).forEach(s -> System.out.println(s)); } @@ -76,9 +73,12 @@ public class DemoScoreCal { ScoreCalculator sc1 = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); ScoreCalculator sc2 = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); + List> index1SampleValues = Arrays.asList(new SampleValue<>("id1", 4), new SampleValue<>("id2", 1), new SampleValue<>("id3", 8)); + List> index2SampleValues = Arrays.asList(new SampleValue<>("id1", 1), new SampleValue<>("id2", 8), new SampleValue<>("id3", 3)); + // 每个指标的信息,包括样本列表,权重,指标标记 - IndexInputVO index1VO = new IndexInputVO<>("aaa", Arrays.asList(4, 1, 8), new BigDecimal(1), sc1); - IndexInputVO index2VO = new IndexInputVO<>("bbb", Arrays.asList(1, 8, 3), new BigDecimal(1), sc2); + IndexInputVO index1VO = new IndexInputVO<>("aaa", index1SampleValues, new BigDecimal(1), sc1); + IndexInputVO index2VO = new IndexInputVO<>("bbb", index2SampleValues, new BigDecimal(1), sc2); List indexInputVOS = Arrays.asList(index1VO, index2VO);