forked from luyan/epmet-cloud-lingshan
				
			
				 29 changed files with 231 additions and 28 deletions
			
			
		@ -0,0 +1,13 @@ | 
				
			|||
package com.epmet.support.normalizing; | 
				
			|||
 | 
				
			|||
import java.math.BigDecimal; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 分值常量 | 
				
			|||
 */ | 
				
			|||
public class ScoreConstants { | 
				
			|||
 | 
				
			|||
    public static final BigDecimal MIN_SCORE = new BigDecimal(0); | 
				
			|||
    public static final BigDecimal MAX_SCORE = new BigDecimal(100); | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,35 @@ | 
				
			|||
package com.epmet.support.normalizing.batch; | 
				
			|||
 | 
				
			|||
import com.epmet.support.normalizing.ScoreCalculator; | 
				
			|||
 | 
				
			|||
import java.math.BigDecimal; | 
				
			|||
import java.util.List; | 
				
			|||
import java.util.stream.Collectors; | 
				
			|||
 | 
				
			|||
public class BatchScoreCalculator { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 每个指标都是一条数据,每一条数据中包含该指标的一组样本 | 
				
			|||
     */ | 
				
			|||
    private List<IndexInputVO> indexVOS; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 执行计算 | 
				
			|||
     * @return 每一条都是一个指标的,所有样本对应的,得分值 | 
				
			|||
     */ | 
				
			|||
    public List<IndexOutputVO> exec(List<IndexInputVO> indexVOS) { | 
				
			|||
        this.indexVOS = indexVOS; | 
				
			|||
 | 
				
			|||
        return indexVOS.stream().map(i -> { | 
				
			|||
            String indexId = i.getIndexId(); | 
				
			|||
            List indexValues = i.getIndexValues(); | 
				
			|||
            BigDecimal weight = i.getWeight(); | 
				
			|||
            ScoreCalculator scoreCalculator = i.getScoreCalculator(); | 
				
			|||
 | 
				
			|||
            List scores4OneIndex = scoreCalculator.normalize(indexValues, weight); | 
				
			|||
 | 
				
			|||
            return new IndexOutputVO(indexId, scores4OneIndex); | 
				
			|||
        }).collect(Collectors.toList()); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,39 @@ | 
				
			|||
package com.epmet.support.normalizing.batch; | 
				
			|||
 | 
				
			|||
import com.epmet.support.normalizing.ScoreCalculator; | 
				
			|||
import lombok.AllArgsConstructor; | 
				
			|||
import lombok.Data; | 
				
			|||
import lombok.NoArgsConstructor; | 
				
			|||
 | 
				
			|||
import java.math.BigDecimal; | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
@AllArgsConstructor | 
				
			|||
@NoArgsConstructor | 
				
			|||
public class IndexInputVO<T> { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 指标标记,由使用者传入,用以标记该条指标的独有特性,一般用id或者code | 
				
			|||
     * 非必填 | 
				
			|||
     */ | 
				
			|||
    private String indexId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 指标的样本值 | 
				
			|||
     */ | 
				
			|||
    private List<T> indexValues; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 权重 | 
				
			|||
     */ | 
				
			|||
    private BigDecimal weight; | 
				
			|||
 | 
				
			|||
    private ScoreCalculator<T> scoreCalculator; | 
				
			|||
 | 
				
			|||
    public IndexInputVO(List<T> indexValues, BigDecimal weight, ScoreCalculator<T> scoreCalculator) { | 
				
			|||
        this.indexValues = indexValues; | 
				
			|||
        this.weight = weight; | 
				
			|||
        this.scoreCalculator = scoreCalculator; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,23 @@ | 
				
			|||
package com.epmet.support.normalizing.batch; | 
				
			|||
 | 
				
			|||
import lombok.AllArgsConstructor; | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
import java.math.BigDecimal; | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
@AllArgsConstructor | 
				
			|||
public class IndexOutputVO<T> { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 指标标记,由使用者传入,用以标记该条指标的独有特性,一般用id或者code | 
				
			|||
     * 非必填 | 
				
			|||
     */ | 
				
			|||
    private String indexId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 指标的样本值 | 
				
			|||
     */ | 
				
			|||
    private List<BigDecimal> indexScores; | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue