/
utils.py
102 lines (84 loc) · 2.9 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from enum import Enum
import pandas as pd
from statistics import mean
class Constants(Enum):
MALO = "MALO"
REGULAR = "REGULAR"
BUENO = "BUENO"
NINGUNO = "NINGUNO"
NO_HAY = "NO_HAY"
GRAVE = "GRAVE"
MODERADO = "MODERADO"
LEVE = "LEVE"
X1 = "1"
X2_5 = "2_5"
X5_N = "5_N"
class RemapException(Exception):
def __init__(self, message):
super().__init__(message)
def remap(value, x_min, x_max, y_min, y_max):
return ((value - x_min) / (x_max - x_min)) * (y_max - y_min) + y_min
def remap_nmrb(s):
if s == Constants.NO_HAY.value:
return 0
if s == Constants.MALO.value:
return 33
elif s == Constants.REGULAR.value:
return 66
elif s == Constants.BUENO.value:
return 100
raise RemapException("No existe la opción " + s)
def remap_gml(s):
if s == Constants.GRAVE.value:
return 0
if s == Constants.MODERADO.value:
return 33
elif s == Constants.LEVE.value:
return 66
raise RemapException("No existe la opción " + s)
def remap_veces(v, s):
if v == Constants.X1.value and s == Constants.NINGUNO.value:
return 66
elif v == Constants.X1.value and s == Constants.LEVE.value:
return 66
elif v == Constants.X1.value and s == Constants.MODERADO.value:
return 33
elif v == Constants.X1.value and s == Constants.GRAVE.value:
return 33
elif v == Constants.X2_5.value and s == Constants.NINGUNO.value:
return 66
elif v == Constants.X2_5.value and s == Constants.LEVE.value:
return 33
elif v == Constants.X2_5.value and s == Constants.MODERADO.value:
return 33
elif v == Constants.X2_5.value and s == Constants.GRAVE.value:
return 0
elif v == Constants.X5_N.value and s == Constants.NINGUNO.value:
return 33
elif v == Constants.X5_N.value and s == Constants.LEVE.value:
return 33
elif v == Constants.X5_N.value and s == Constants.MODERADO.value:
return 0
elif v == Constants.X5_N.value and s == Constants.GRAVE.value:
return 0
raise RemapException("No existe la opción " + s + " | " + v)
def procesable(row, column):
return not pd.isna(row[column]) and row[column] != Constants.NINGUNO.value
def calculate_score(mapeo, code, letters, remap_function):
evaluaciones = []
for letter in letters:
if procesable(mapeo, code + letter):
evaluaciones.append(remap_function(mapeo[code + letter]))
if len(evaluaciones) > 0:
return int(round(mean(evaluaciones)))
return 300
def calculate_score_riesgo(mapeo, code_veces, code, letters):
evaluaciones = []
v = mapeo[code_veces]
for letter in letters:
if procesable(mapeo, code + letter):
c = mapeo[code + letter]
evaluaciones.append(remap_veces(v, c))
if len(evaluaciones) > 0:
return int(round(mean(evaluaciones)))
return 300