#!/usr/bin/env python # -*- coding: utf-8 -*- ################################################################## # # Copyright (c) 2023 CICV, Inc. All Rights Reserved # ################################################################## """ @Authors: yangzihao(yangzihao@china-icv.cn) @Data: 2024/03/19 @Last Modified: 2024/03/19 @Summary: Score cal """ class ScoreModel(object): """ """ # def __init__(self, kind_list, max_list, min_list, arr): def __init__(self, kind_list, optimal_list, multiple_list, arr): max_list = [optimal * multiple[1] for optimal, multiple in zip(optimal_list, multiple_list)] min_list = [optimal * multiple[0] for optimal, multiple in zip(optimal_list, multiple_list)] self.kind = kind_list self.maxx = max_list self.minn = min_list self.data = arr def cal_score(self): """ Args: kind_list: max_list: min_list: arr: Returns: scores: """ scores = [] # zzip = zip(self.kind, self.maxx, self.minn, self.data[0]) for kind, max_val, min_val, val in zip(self.kind, self.maxx, self.minn, self.data[0]): if kind == -1: if val <= min_val: scores.append(100) elif val >= max_val: scores.append(0) else: score = (max_val - val) / (max_val - min_val) * 100 scores.append(score) elif kind == 1: if val >= max_val: scores.append(100) elif val <= min_val: scores.append(0) else: score = (val - min_val) / (max_val - min_val) * 100 scores.append(score) elif kind == 0: if min_val <= val <= max_val: scores.append(100) else: scores.append(0) scores = [round(x, 2) for x in scores] return scores if __name__ == "__main__": kind_list = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1] optimal_list = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20] multiple_list = [[0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2], [0.5, 2]] # max_list = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20] # min_list = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] arr = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] custom = ScoreModel(kind_list, optimal_list, multiple_list, arr) scores = custom.cal_score() print(scores) print('over')