Browse Source

错误修改

dev_shibei_match
jianjun 5 years ago
parent
commit
efbc456eae
  1. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  2. 22
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java
  3. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreCalculator.java
  4. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/IndexInputVO.java
  5. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java
  6. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml
  7. 56
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java

@ -240,7 +240,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
ScoreConstants.MAX_SCORE, ScoreConstants.MAX_SCORE,
Correlation.getCorrelation(index.getCorrelation()) Correlation.getCorrelation(index.getCorrelation())
); );
IndexInputVO indexInputVO = new IndexInputVO(index.getIndexCode(),new ArrayList<>(),index.getThreshold(),index.getWeight(),scoreCalculator); IndexInputVO indexInputVO = new IndexInputVO(index.getIndexCode(), new ArrayList<>(), index.getThreshold(), index.getWeight(), scoreCalculator);
map.put(index.getIndexCode(), indexInputVO); map.put(index.getIndexCode(), indexInputVO);
} }
return map; return map;

22
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/BigDecimalScoreCalculator.java

@ -1,6 +1,9 @@
package com.epmet.support.normalizing; package com.epmet.support.normalizing;
import com.alibaba.fastjson.JSON;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -9,14 +12,14 @@ import java.util.List;
*/ */
public class BigDecimalScoreCalculator extends ScoreCalculator { public class BigDecimalScoreCalculator extends ScoreCalculator {
/** /* *//**
* 初始化基于原数组的整数分值计算 * 初始化基于原数组的整数分值计算
* 务必在该构造方法最后调用父类的prepare()方法 * 务必在该构造方法最后调用父类的prepare()方法
* @param sourceArray 源数据完整数组 * @param sourceArray 源数据完整数组
* @param minScore 分值区间的左边界 * @param minScore 分值区间的左边界
* @param maxScore 分值区间的右边界 * @param maxScore 分值区间的右边界
* @param correlation 相关性 * @param correlation 相关性
*/ *//*
public BigDecimalScoreCalculator(BigDecimal[] sourceArray, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) { public BigDecimalScoreCalculator(BigDecimal[] sourceArray, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) {
this.sourceArrary = sourceArray.clone(); this.sourceArrary = sourceArray.clone();
this.minScore = minScore; this.minScore = minScore;
@ -26,13 +29,13 @@ public class BigDecimalScoreCalculator extends ScoreCalculator {
System.out.println("最小值:"+minScore+";最大值:"+maxScore); System.out.println("最小值:"+minScore+";最大值:"+maxScore);
} }
/** *//**
* 初始化基于原数组的整数分值计算 * 初始化基于原数组的整数分值计算
* @param sourceList 源数据完整列表 * @param sourceList 源数据完整列表
* @param minScore 分值区间的左边界 * @param minScore 分值区间的左边界
* @param maxScore 分值区间的右边界 * @param maxScore 分值区间的右边界
* @param correlation 相关性 * @param correlation 相关性
*/ *//*
public BigDecimalScoreCalculator(List<BigDecimal> sourceList, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) { public BigDecimalScoreCalculator(List<BigDecimal> sourceList, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) {
this.sourceArrary = sourceList.toArray(); this.sourceArrary = sourceList.toArray();
this.minScore = minScore; this.minScore = minScore;
@ -40,7 +43,7 @@ public class BigDecimalScoreCalculator extends ScoreCalculator {
this.correlation = correlation; this.correlation = correlation;
prepare4SourceArray(); prepare4SourceArray();
System.out.println("最小值:"+minScore+";最大值:"+maxScore); System.out.println("最小值:"+minScore+";最大值:"+maxScore);
} }*/
/** /**
* 初始化基于边界值的整数分值计算 * 初始化基于边界值的整数分值计算
@ -77,4 +80,13 @@ public class BigDecimalScoreCalculator extends ScoreCalculator {
public BigDecimal convertValue2BigDecimal(Object sourceValue) { public BigDecimal convertValue2BigDecimal(Object sourceValue) {
return (BigDecimal) sourceValue; return (BigDecimal) sourceValue;
} }
public static void main(String[] args) {
BigDecimal minScore = new BigDecimal(0);
BigDecimal maxScore = new BigDecimal(100);
ScoreCalculator sc = new BigDecimalScoreCalculator(new BigDecimal("0.1"),new BigDecimal("1"), minScore, maxScore, Correlation.POSITIVE);
List<BigDecimal> ts = Arrays.asList(new BigDecimal("0.1"),new BigDecimal("1"));
List normalize = sc.normalize(ts);
System.out.println(JSON.toJSONString(normalize));
}
} }

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreCalculator.java

@ -55,8 +55,8 @@ public abstract class ScoreCalculator<T> {
maxValue = getMaxFromSourceArray(); maxValue = getMaxFromSourceArray();
minValue = getMinFromSourceArray(); minValue = getMinFromSourceArray();
//计算系数 //计算系数
System.out.println("最小值:"+minScore+";最大值:"+maxScore);
coefficient = calcuteCoefficient(minValue, maxValue); coefficient = calcuteCoefficient(minValue, maxValue);
//System.out.println("最小分值:"+minScore+";最大分值:"+maxScore+";系数:"+coefficient);
} }
/** /**
@ -176,7 +176,6 @@ public abstract class ScoreCalculator<T> {
if (fenmu.compareTo(BigDecimal.ZERO)==0)return new BigDecimal(0); if (fenmu.compareTo(BigDecimal.ZERO)==0)return new BigDecimal(0);
BigDecimal fenzi = maxScore.subtract(minScore); BigDecimal fenzi = maxScore.subtract(minScore);
BigDecimal divide = fenzi.divide(fenmu, MathContext.DECIMAL32); BigDecimal divide = fenzi.divide(fenmu, MathContext.DECIMAL32);
System.out.println("分子:"+fenzi+"分母:"+fenmu+"系数:"+divide.toString());
return divide; return divide;
} }

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

@ -3,15 +3,16 @@ package com.epmet.support.normalizing.batch;
import com.epmet.support.normalizing.ScoreCalculator; import com.epmet.support.normalizing.ScoreCalculator;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class IndexInputVO<T extends Number> { public class IndexInputVO<T extends Number> implements Serializable {
private static final long serialVersionUID = -4855313801481921595L;
/** /**
* 指标标记由使用者传入用以标记该条指标的独有特性一般用id或者code * 指标标记由使用者传入用以标记该条指标的独有特性一般用id或者code
* 非必填 * 非必填

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/SampleValue.java

@ -3,13 +3,16 @@ package com.epmet.support.normalizing.batch;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
/** /**
* 样本值对象 * 样本值对象
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class SampleValue<T> { public class SampleValue<T> implements Serializable {
private static final long serialVersionUID = 8661385412757324539L;
private String sampleId; private String sampleId;
private T sampleValue; private T sampleValue;

2
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexcoll/FactIndexPartyAblityCpcMonthlyDao.xml

@ -73,7 +73,7 @@
SELECT SELECT
MIN( CREATE_TOPIC_COUNT ) CREATE_TOPIC_COUNT_MIN, MIN( CREATE_TOPIC_COUNT ) CREATE_TOPIC_COUNT_MIN,
MAX( CREATE_TOPIC_COUNT ) CREATE_TOPIC_COUNT_MAX, MAX( CREATE_TOPIC_COUNT ) CREATE_TOPIC_COUNT_MAX,
MAX( JOIN_TOPIC_COUNT ) JOIN_TOPIC_COUNT_MIN, MIN( JOIN_TOPIC_COUNT ) JOIN_TOPIC_COUNT_MIN,
MAX( JOIN_TOPIC_COUNT ) JOIN_TOPIC_COUNT_MAX, MAX( JOIN_TOPIC_COUNT ) JOIN_TOPIC_COUNT_MAX,
MIN( SHIFT_ISSUE_COUNT ) SHIFT_ISSUE_COUNT_MIN, MIN( SHIFT_ISSUE_COUNT ) SHIFT_ISSUE_COUNT_MIN,
MAX( SHIFT_ISSUE_COUNT ) SHIFT_ISSUE_COUNT_MAX, MAX( SHIFT_ISSUE_COUNT ) SHIFT_ISSUE_COUNT_MAX,

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

@ -122,27 +122,63 @@ public class DemoScoreCal {
public void testBigDecimalBatchCalculateGroupBySampleId() throws InterruptedException { public void testBigDecimalBatchCalculateGroupBySampleId() throws InterruptedException {
//{4,8,1,3,2} //{4,8,1,3,2}
// 每个指标需要单独的分支计算器,因为每个指标的最大最小值是不同的 //分值计算器 每个指标需要单独的分值计算器,因为每个指标的最大最小值是不同的
ScoreCalculator sc1 = new BigDecimalScoreCalculator(new BigDecimal(1), new BigDecimal(8), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); ScoreCalculator sc1 = new BigDecimalScoreCalculator(new BigDecimal(50), new BigDecimal(100), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator sc2 = new BigDecimalScoreCalculator(new BigDecimal(1), new BigDecimal(8), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.NEGATIVE); ScoreCalculator sc2 = new BigDecimalScoreCalculator(new BigDecimal(20), new BigDecimal(100), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator sc3 = new BigDecimalScoreCalculator(new BigDecimal(20), new BigDecimal(40), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator sc4 = new BigDecimalScoreCalculator(new BigDecimal(10), new BigDecimal(100), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
//每个指标的数值 比如 a指标里有5条数据
List<SampleValue> index1SampleValues = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(100)),
new SampleValue<>("id2", new BigDecimal(50)),
new SampleValue<>("id3", new BigDecimal(60)),
new SampleValue<>("id4", new BigDecimal(80)),
new SampleValue<>("id5", new BigDecimal(80))
);
List<SampleValue> index1SampleValues2 = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(100)),
new SampleValue<>("id2", new BigDecimal(80)),
new SampleValue<>("id3", new BigDecimal(80)),
new SampleValue<>("id4", new BigDecimal(20)),
new SampleValue<>("id5", new BigDecimal(20))
);
List<SampleValue> index1SampleValues3 = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(40)),
new SampleValue<>("id2", new BigDecimal(20)),
new SampleValue<>("id3", new BigDecimal(40)),
new SampleValue<>("id4", new BigDecimal(30)),
new SampleValue<>("id5", new BigDecimal(20))
);
List<SampleValue> index1SampleValues4 = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(20)),
new SampleValue<>("id2", new BigDecimal(100)),
new SampleValue<>("id3", new BigDecimal(10)),
new SampleValue<>("id4", new BigDecimal(50)),
new SampleValue<>("id5", new BigDecimal(20))
);
List<SampleValue> index1SampleValues = Arrays.asList(new SampleValue<>("id1", new BigDecimal(4)), new SampleValue<>("id2", new BigDecimal(1)), new SampleValue<>("id3", new BigDecimal(8)));
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(6), new BigDecimal(1), sc1); IndexInputVO index1VO = new IndexInputVO("aaa1", index1SampleValues, new BigDecimal(-1), new BigDecimal(0.2), sc1);
IndexInputVO index2VO = new IndexInputVO("bbb", index2SampleValues, new BigDecimal(6), new BigDecimal(1), sc2); IndexInputVO index2VO = new IndexInputVO("aaa2", index1SampleValues2, new BigDecimal(-1), new BigDecimal(0.15), sc2);
IndexInputVO index3VO = new IndexInputVO("aaa3", index1SampleValues3, new BigDecimal(-1), new BigDecimal(0.15), sc3);
IndexInputVO index4VO = new IndexInputVO("aaa4", index1SampleValues4, new BigDecimal(-1), new BigDecimal(0.5), sc4);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO,index3VO,index4VO);
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator();
HashMap<String, BigDecimal> result = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); HashMap<String, BigDecimal> result = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS);
System.err.println("--------------------------------"); System.err.println("----------------1----------------");
result.forEach((key, value) -> { result.forEach((key, value) -> {
System.out.println(key.concat("的得分为:").concat(value.toString())); System.out.println(key.concat("的得分为:").concat(value.toString()));
}); });
System.err.println("--------------------------------"); System.err.println("-----------------2---------------");
} }

Loading…
Cancel
Save