Browse Source

阈值

dev_shibei_match
jianjun 5 years ago
parent
commit
af9298e087
  1. 19
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java
  2. 6
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml
  3. 64
      epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/normalizing/DemoScoreCal.java

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

@ -88,16 +88,17 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
totalEntity.setScore(new BigDecimal(0));
cpcScoreTotalMap.put(userId, totalEntity);
}
//todo 自建群活跃度——议题转项目率 有阈值 >60%按60%算
//自建群活跃度——议题转项目率 有阈值 >60%按60%算
BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight());
log.info("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total);
totalEntity.setScore(totalEntity.getScore().add(total));
}
});
insertBatch(cpcScoreTotalMap.values().stream().collect(Collectors.toList()));
deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(),cpcScoreTotalMap.values().stream().collect(Collectors.toList()));
}
private void insertBatch(Collection<CpcScoreEntity> values) {
private void deleteAndInsertBatch(String customerId, String monthId, String indexCode, Collection<CpcScoreEntity> values) {
cpcScoreDao.deleteByMonthId(customerId, monthId, indexCode);
cpcScoreDao.insertBatch(values);
}
@ -198,14 +199,14 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
*/
@Transactional(rollbackFor = Exception.class)
public void saveCpcScore(CalculateCommonFormDTO formDTO, Map<String, CpcScoreEntity> indexDetails, String parentIndexCode, HashMap<String, BigDecimal> result) {
cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode);
List<CpcScoreEntity> list = new ArrayList<>();
result.forEach((userId, score) -> {
CpcScoreEntity cpcScoreEntity = indexDetails.get(userId);
cpcScoreEntity.setScore(score);
list.add(cpcScoreEntity);
});
this.insertBatch(list);
this.deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),parentIndexCode,list);
}
@ -234,9 +235,13 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN);
//最大值key
String maxValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MAX);
minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey)));
maxValue = new BigDecimal(String.valueOf(minAndMaxMap.get(maxValueKey)));
minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey)));
//如果最大值超过阈值 则最大值为阈值
if (new BigDecimal(NumConstant.ONE_NEG).compareTo(index.getThreshold()) != NumConstant.ZERO
&& maxValue.compareTo(new BigDecimal(NumConstant.ONE_NEG)) == NumConstant.ONE){
maxValue = index.getThreshold();
}
//分值计算器
ScoreCalculator<Integer> scoreCalculator = new BigDecimalScoreCalculator(minValue,
maxValue,

6
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml

@ -19,7 +19,11 @@
</resultMap>
<delete id="deleteByMonthId">
delete from fact_index_cpc_score where CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and MONTH_ID = #{monthId,jdbcType=VARCHAR} and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
delete from fact_index_cpc_score
where
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
and MONTH_ID = #{monthId,jdbcType=VARCHAR}
and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}
</delete>
<select id="getPartScore" resultType="com.epmet.entity.indexscore.CpcScoreEntity">

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

@ -182,4 +182,68 @@ public class DemoScoreCal {
}
@Test
public void testCpc() throws InterruptedException {
//{4,8,1,3,2}
//分值计算器 每个指标需要单独的分值计算器,因为每个指标的最大最小值是不同的
ScoreCalculator sc1 = new BigDecimalScoreCalculator(new BigDecimal(10), new BigDecimal(100), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator sc2 = new BigDecimalScoreCalculator(new BigDecimal(20), new BigDecimal(80), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator sc3 = new BigDecimalScoreCalculator(new BigDecimal(10), new BigDecimal(100), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
ScoreCalculator sc4 = new BigDecimalScoreCalculator(new BigDecimal(0.1), new BigDecimal(0.6), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE);
//每个指标的数值 比如 a指标里有5条数据
List<SampleValue> index1SampleValues = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(80)),
new SampleValue<>("id2", new BigDecimal(10)),
new SampleValue<>("id3", new BigDecimal(100)),
new SampleValue<>("id4", new BigDecimal(50)),
new SampleValue<>("id5", new BigDecimal(40))
);
List<SampleValue> index1SampleValues2 = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(20)),
new SampleValue<>("id2", new BigDecimal(50)),
new SampleValue<>("id3", new BigDecimal(40)),
new SampleValue<>("id4", new BigDecimal(35)),
new SampleValue<>("id5", new BigDecimal(80))
);
List<SampleValue> index1SampleValues3 = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(100)),
new SampleValue<>("id2", new BigDecimal(70)),
new SampleValue<>("id3", new BigDecimal(50)),
new SampleValue<>("id4", new BigDecimal(55)),
new SampleValue<>("id5", new BigDecimal(10))
);
List<SampleValue> index1SampleValues4 = Arrays.asList(
new SampleValue<>("id1", new BigDecimal(1)),
new SampleValue<>("id2", new BigDecimal(0.1)),
new SampleValue<>("id3", new BigDecimal(1)),
new SampleValue<>("id4", new BigDecimal(0.3)),
new SampleValue<>("id5", new BigDecimal(1))
);
// 每个指标的信息,包括样本列表,权重,指标标记
IndexInputVO index1VO = new IndexInputVO("aaa1", index1SampleValues, new BigDecimal(-1), new BigDecimal(0.3), sc1);
IndexInputVO index2VO = new IndexInputVO("aaa2", index1SampleValues2, new BigDecimal(-1), new BigDecimal(0.2), sc2);
IndexInputVO index3VO = new IndexInputVO("aaa3", index1SampleValues3, new BigDecimal(-1), new BigDecimal(0.2), sc3);
IndexInputVO index4VO = new IndexInputVO("aaa4", index1SampleValues4, new BigDecimal(0.6), new BigDecimal(0.3), sc4);
List<IndexInputVO> indexInputVOS = Arrays.asList(index1VO, index2VO,index3VO,index4VO);
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator();
HashMap<String, BigDecimal> result = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS);
System.err.println("----------------1----------------");
result.forEach((key, value) -> {
System.out.println(key.concat("的得分为:").concat(value.toString()));
});
System.err.println("-----------------2---------------");
}
}

Loading…
Cancel
Save