Browse Source

分支批量计算,增加阈值的参数

dev_shibei_match
wxz 5 years ago
parent
commit
9f9a3903ce
  1. 23
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java
  2. 7
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java
  3. 12
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java

23
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java

@ -22,10 +22,11 @@ public class BatchScoreCalculator {
List<SampleValue> indexValueVOs = i.getIndexValueVOs();
BigDecimal weight = i.getWeight();
ScoreCalculator scoreCalculator = i.getScoreCalculator();
BigDecimal threshold = i.getThreshold();
// 循环同一个指标内的多个样本值的SampleValue列表
List<SampleScore> scores4OneIndex = indexValueVOs.stream().map(vo -> {
BigDecimal score = scoreCalculator.normalize(vo.getSampleValue(), weight).setScale(6, RoundingMode.HALF_UP);;
BigDecimal score = scoreCalculator.normalize(getFinalSampleValue(vo.getSampleValue(), threshold), weight).setScale(6, RoundingMode.HALF_UP);;
return new SampleScore(vo.getSampleId(), score);
}).collect(Collectors.toList());
@ -48,10 +49,11 @@ public class BatchScoreCalculator {
List<SampleValue> indexValueVOs = idx.getIndexValueVOs();
BigDecimal weight = idx.getWeight();
ScoreCalculator scoreCalculator = idx.getScoreCalculator();
BigDecimal threshold = idx.getThreshold();
for (SampleValue vo : indexValueVOs) {
String sampleId = vo.getSampleId();
BigDecimal score = scoreCalculator.normalize(vo.getSampleValue(), weight);
BigDecimal score = scoreCalculator.normalize(getFinalSampleValue(vo.getSampleValue(), threshold), weight);
if (scoreCountOfSamples.containsKey(sampleId)) {
BigDecimal newScore = scoreCountOfSamples.get(sampleId).add(score).setScale(6, RoundingMode.HALF_UP);
scoreCountOfSamples.put(sampleId, newScore);
@ -64,4 +66,21 @@ public class BatchScoreCalculator {
return scoreCountOfSamples;
}
/**
* 获取最终样本值
* @param realValue
* @param threshold
* @return
*/
public BigDecimal getFinalSampleValue(Object realValue, BigDecimal threshold) {
BigDecimal bdRealValue = new BigDecimal(realValue.toString());
if (threshold.equals(-1)) {
// -1表示不使用阈值
return bdRealValue;
}
return (bdRealValue.compareTo(threshold) < 0) || (bdRealValue.equals(threshold))
? bdRealValue
: threshold ;
}
}

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

@ -11,7 +11,7 @@ import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IndexInputVO<T> {
public class IndexInputVO<T extends Number> {
/**
* 指标标记由使用者传入用以标记该条指标的独有特性一般用id或者code
@ -24,6 +24,11 @@ public class IndexInputVO<T> {
*/
private List<SampleValue<T>> indexValueVOs;
/**
* 样本阈值
*/
private BigDecimal threshold;
/**
* 权重
*/

12
epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java

@ -78,8 +78,8 @@ public class DemoScoreCal {
List<SampleValue<Integer>> index2SampleValues = Arrays.asList(new SampleValue<>("id1", 1), new SampleValue<>("id2", 8), new SampleValue<>("id3", 3));
// 每个指标的信息,包括样本列表,权重,指标标记
IndexInputVO<Integer> index1VO = new IndexInputVO<>("aaa", index1SampleValues, new BigDecimal(1), sc1);
IndexInputVO<Integer> index2VO = new IndexInputVO<>("bbb", index2SampleValues, new BigDecimal(1), sc2);
IndexInputVO<Integer> index1VO = new IndexInputVO<>("aaa", index1SampleValues, new BigDecimal(10), new BigDecimal(1), sc1);
IndexInputVO<Integer> index2VO = new IndexInputVO<>("bbb", index2SampleValues, new BigDecimal(10), new BigDecimal(1), sc2);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO);
@ -104,8 +104,8 @@ public class DemoScoreCal {
List<SampleValue> index2SampleValues = Arrays.asList(new SampleValue<>("id1", new BigDecimal(1)), new SampleValue<>("id2", new BigDecimal(8)), new SampleValue<>("id3", new BigDecimal(3)));
// 每个指标的信息,包括样本列表,权重,指标标记
IndexInputVO index1VO = new IndexInputVO("aaa", index1SampleValues, new BigDecimal(1), sc1);
IndexInputVO index2VO = new IndexInputVO("bbb", index2SampleValues, new BigDecimal(1), sc2);
IndexInputVO index1VO = new IndexInputVO("aaa", index1SampleValues, new BigDecimal(6), new BigDecimal(1), sc1);
IndexInputVO index2VO = new IndexInputVO("bbb", index2SampleValues, new BigDecimal(6), new BigDecimal(1), sc2);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO);
@ -130,8 +130,8 @@ public class DemoScoreCal {
List<SampleValue> index2SampleValues = Arrays.asList(new SampleValue<>("id1", new BigDecimal(1)), new SampleValue<>("id2", new BigDecimal(8)), new SampleValue<>("id3", new BigDecimal(3)));
// 每个指标的信息,包括样本列表,权重,指标标记
IndexInputVO index1VO = new IndexInputVO("aaa", index1SampleValues, new BigDecimal(1), sc1);
IndexInputVO index2VO = new IndexInputVO("bbb", index2SampleValues, new BigDecimal(1), sc2);
IndexInputVO index1VO = new IndexInputVO("aaa", index1SampleValues, new BigDecimal(6), new BigDecimal(1), sc1);
IndexInputVO index2VO = new IndexInputVO("bbb", index2SampleValues, new BigDecimal(6), new BigDecimal(1), sc2);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO);

Loading…
Cancel
Save