-
Notifications
You must be signed in to change notification settings - Fork 0
/
main2.py
76 lines (70 loc) · 2.99 KB
/
main2.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
import numpy as np
import sys
import json
class MDM():
matrizprecargada = None
matrizinterseccion = None
resultadosdiagnosticos = None
sintomasusuario = []
listaenfermedades = []
def __init__(self):
self.matrizinterseccion = np.zeros((10,16))
self.resultadosdiagnosticos = np.zeros((1,10))
self.matrizprecargada=np.array(
[
[0.5,0.0,0.9,0.8,0.8,0.0,0.0,0.6,0.0,0.0,0.0,0.4,0.0,0.0,0.0],
[0.6,0.0,0.0,0.0,0.5,0.7,0.0,0.0,0.0,0.0,0.0,0.0,0.7,0.0,0.0],
[0.9,0.3,0.8,0.8,0.0,0.0,0.5,0.6,0.0,0.0,0.0,0.7,0.0,0.5,0.0],
[0.9,0.7,0.7,0.0,0.0,0.0,0.6,0.9,0.0,0.0,0.0,0.0,0.0,0.0,0.0],
[0.0,0.0,0.9,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.9,0.0,0.0,0.0],
[0.0,0.0,0.3,0.0,0.5,0.0,0.0,0.0,0.0,0.0,0.8,0.7,0.0,0.0,0.0],
[0.4,0.7,0.9,0.6,0.0,0.0,0.6,0.0,0.0,0.0,0.0,0.3,0.5,0.0,0.0],
[0.3,0.0,0.7,0.8,0.0,0.0,0.5,0.0,0.0,0.0,0.6,0.9,0.0,0.0,0.4],
[0.0,0.0,0.8,0.7,0.0,0.0,0.0,0.0,0.0,0.7,0.5,0.6,0.0,0.0,0.6],
[0.0,0.0,0.5,0.5,0.3,0.0,0.7,0.0,0.9,0.4,0.7,0.7,0.0,0.9,0.0]
])
def diagnosticoG(self):
for a in range(0,self.matrizprecargada.shape[0]):
for b in range(0,self.matrizprecargada.shape[1]):
if self.matrizprecargada[a][b] >= self.sintomasusuario[0][b]:
self.matrizinterseccion[a][b] = self.sintomasusuario[0][b]
else:
self.matrizinterseccion[a][b] = self.matrizprecargada[a][b]
for a in range(0,self.matrizinterseccion.shape[0]):
for b in range(0,self.matrizinterseccion.shape[1]-1):
self.matrizinterseccion[a][15] += self.matrizinterseccion[a][b]
self.resultadosdiagnosticos[0][a] = self.matrizinterseccion[a][15]
def procesamientoARGV(self):
m = sys.argv[1]
m = m.replace(' ','')
m = m.replace(' ','')
m = m.replace('[[','')
m = m.replace(']]','')
m = m.split('],[')
try:
self.sintomasusuario = np.array([m[0].split(',')],dtype=np.float64)
except:
print('>LOS VALORES NO SE PUEDEN CONVERTIR <(Los valores de los síntomas son incorrectos)')
exit()
self.listaenfermedades = np.array(m[1].split( ',' ))
def diagnosticoE(self):
self.diagnosticoG()
for indice in range(0,10):
if str(indice) not in self.listaenfermedades:
self.resultadosdiagnosticos[0][indice] = -1
modulo = MDM()
try:
if len(sys.argv[1]) > 1:
modulo.procesamientoARGV()
except:
print('>ARGUMENTOS NO RECIBIDOS<')
exit()
if modulo.listaenfermedades[0] == '':
try:
modulo.diagnosticoG()
except:
print('>ARGUMENTOS NO VÁLIDOS RECIBIDOS<')
exit()
else:
modulo.diagnosticoE()
print(json.dumps(modulo.resultadosdiagnosticos[0].tolist()))