Browse Source

优化的批量分支计算

master
wxz 5 years ago
parent
commit
445fb28380
  1. 14
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java
  2. 6
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java
  3. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexOutputVO.java
  4. 19
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleScore.java
  5. 17
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java
  6. 16
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java

14
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<IndexOutputVO> exec(List<IndexInputVO> indexVOS) {
this.indexVOS = indexVOS;
public List<IndexOutputVO> exec(List<IndexInputVO> indexInputVOS) {
this.indexVOS = indexInputVOS;
return indexVOS.stream().map(i -> {
return indexInputVOS.stream().map(i -> {
String indexId = i.getIndexId();
List indexValues = i.getIndexValues();
List<SampleValue> indexValueVOs = i.getIndexValueVOs();
BigDecimal weight = i.getWeight();
ScoreCalculator scoreCalculator = i.getScoreCalculator();
List scores4OneIndex = scoreCalculator.normalize(indexValues, weight);
// 循环同一个指标内的多个样本值的SampleValue列表
List<SampleScore> 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());

6
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java

@ -22,7 +22,7 @@ public class IndexInputVO<T> {
/**
* 指标的样本值
*/
private List<T> indexValues;
private List<SampleValue<T>> indexValueVOs;
/**
* 权重
@ -31,8 +31,8 @@ public class IndexInputVO<T> {
private ScoreCalculator<T> scoreCalculator;
public IndexInputVO(List<T> indexValues, BigDecimal weight, ScoreCalculator<T> scoreCalculator) {
this.indexValues = indexValues;
public IndexInputVO(List<SampleValue<T>> indexValueVOs, BigDecimal weight, ScoreCalculator<T> scoreCalculator) {
this.indexValueVOs = indexValueVOs;
this.weight = weight;
this.scoreCalculator = scoreCalculator;
}

4
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<T> {
public class IndexOutputVO {
/**
* 指标标记由使用者传入用以标记该条指标的独有特性一般用id或者code
@ -19,5 +19,5 @@ public class IndexOutputVO<T> {
/**
* 指标的样本值
*/
private List<BigDecimal> indexScores;
private List<SampleScore> indexScoreVOs;
}

19
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;
}

17
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<T> {
private String sampleId;
private T sampleValue;
}

16
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<Integer> sc1 = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE);
ScoreCalculator<Integer> sc2 = new IntegerScoreCalculator(1, 8, ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE);
List<SampleValue<Integer>> index1SampleValues = Arrays.asList(new SampleValue<>("id1", 4), new SampleValue<>("id2", 1), new SampleValue<>("id3", 8));
List<SampleValue<Integer>> index2SampleValues = Arrays.asList(new SampleValue<>("id1", 1), new SampleValue<>("id2", 8), new SampleValue<>("id3", 3));
// 每个指标的信息,包括样本列表,权重,指标标记
IndexInputVO<Integer> index1VO = new IndexInputVO<>("aaa", Arrays.asList(4, 1, 8), new BigDecimal(1), sc1);
IndexInputVO<Integer> index2VO = new IndexInputVO<>("bbb", Arrays.asList(1, 8, 3), new BigDecimal(1), sc2);
IndexInputVO<Integer> index1VO = new IndexInputVO<>("aaa", index1SampleValues, new BigDecimal(1), sc1);
IndexInputVO<Integer> index2VO = new IndexInputVO<>("bbb", index2SampleValues, new BigDecimal(1), sc2);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO);

Loading…
Cancel
Save