linear_score.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##################################################################
  4. #
  5. # Copyright (c) 2023 CICV, Inc. All Rights Reserved
  6. #
  7. ##################################################################
  8. """
  9. @Authors: yangzihao(yangzihao@china-icv.cn)
  10. @Data: 2024/03/19
  11. @Last Modified: 2024/03/19
  12. @Summary: Score cal
  13. """
  14. class ScoreModel(object):
  15. """
  16. """
  17. # def __init__(self, kind_list, max_list, min_list, arr):
  18. def __init__(self, kind_list, optimal_list, multiple_list, arr):
  19. max_list = [optimal * multiple[1] for optimal, multiple in zip(optimal_list, multiple_list)]
  20. min_list = [optimal * multiple[0] for optimal, multiple in zip(optimal_list, multiple_list)]
  21. self.kind = kind_list
  22. self.maxx = max_list
  23. self.minn = min_list
  24. self.data = arr
  25. def cal_score(self):
  26. """
  27. Args:
  28. kind_list:
  29. max_list:
  30. min_list:
  31. arr:
  32. Returns:
  33. scores:
  34. """
  35. scores = []
  36. # zzip = zip(self.kind, self.maxx, self.minn, self.data[0])
  37. for kind, max_val, min_val, val in zip(self.kind, self.maxx, self.minn, self.data[0]):
  38. if kind == -1:
  39. if val <= min_val:
  40. scores.append(100)
  41. elif val >= max_val:
  42. scores.append(0)
  43. else:
  44. score = (max_val - val) / (max_val - min_val) * 100
  45. scores.append(score)
  46. elif kind == 1:
  47. if val >= max_val:
  48. scores.append(100)
  49. elif val <= min_val:
  50. scores.append(0)
  51. else:
  52. score = (val - min_val) / (max_val - min_val) * 100
  53. scores.append(score)
  54. elif kind == 0:
  55. if min_val <= val <= max_val:
  56. scores.append(100)
  57. else:
  58. scores.append(0)
  59. scores = [round(x, 2) for x in scores]
  60. return scores
  61. if __name__ == "__main__":
  62. kind_list = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]
  63. optimal_list = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]
  64. 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],
  65. [0.5, 2], [0.5, 2]]
  66. # max_list = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]
  67. # min_list = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
  68. arr = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
  69. custom = ScoreModel(kind_list, optimal_list, multiple_list, arr)
  70. scores = custom.cal_score()
  71. print(scores)
  72. print('over')