-
Notifications
You must be signed in to change notification settings - Fork 0
/
main1.py
77 lines (74 loc) · 3.75 KB
/
main1.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
###################################################################################################
# <MODULES>
import sys
import json
import numpy as np
###################################################################################################
# <CLASS>
class MedicalDiagnosticModule():
def __init__( self ):
self.preloadedmatrix = np.array(
[
[0.8, 0 , 0.6, 0 , 0.4, 0 , 0 , 0.6, 0.8, 0.7, 0.8, 0.6, 0 , 0 , 0 ],
[0 , 0.6, 0.8, 0.8, 0.7, 0 , 0 , 0.4, 0.6, 0.5, 0.4, 0.7, 0 , 0 , 0.5],
[0 , 0.8, 0.4, 0.7, 0.5, 0 , 0 , 0.7, 0 , 0.7, 0.5, 0 , 0 , 0.4, 0 ],
[0 , 0.2, 0.9, 0.5, 0.7, 0.8, 0 , 0.4, 0 , 0 , 0.9, 0 , 0 , 0 , 0 ],
[0 , 0 , 0.8, 0.3, 0.7, 0 , 0 , 0.7, 0.5, 0.7, 0.7, 0 , 0 , 0 , 0 ],
[0.9, 0.6, 0.5, 0.4, 0.6, 0.9, 0 , 0.8, 0.7, 0.2, 0.8, 0.5, 0 , 0 , 0 ],
[0 , 0 , 0.4, 0 , 0.7, 0 , 0 , 0.6, 0.9, 0.6, 0 , 0 , 0.8, 0 , 0.9],
[0.7, 0.7, 0.8, 0.9, 0.5, 0.5, 0 , 0.6, 0.7, 0.4, 0.6, 0.6, 0 , 0.6, 0 ],
[0 , 0 , 0.5, 0.6, 0.8, 0 , 0.8, 0.6, 0.9, 0.6, 0 , 0.8, 0 , 0 , 0 ],
[0 , 0.6, 0.9, 0 , 0.6, 0 , 0 , 0.7, 0.9, 0.9, 0 , 0.8, 0 , 0 , 0 ]
] , dtype=np.float64 )
self.intersectionmatrix = np.zeros( ( 10 , 16 ) , dtype=np.float64 )
self.diagnosisresult = np.zeros( ( 1 , 10 ) , dtype=np.float64 )
self.usersymptoms = []
self.listdiseases = []
def processARGV( self ):
matrix = sys.argv[1]
matrix = matrix.replace( ' ' , '' )
matrix = matrix.replace( ' ' , '' )
matrix = matrix.replace( '[[' , '' )
matrix = matrix.replace( ']]' , '' )
matrix = matrix.split( '],[' )
try:
self.usersymptoms = np.array( [matrix[0].split( ',' )] , dtype=np.float64 )
except ValueError:
print( '>VALUES CANNOT BE CONVERTED< (Symptom values are incorrect)' )
exit()
self.listdiseases = np.array( matrix[1].split( ',' ) )
def generalDiagnosis( self ):
for i in range( 0 , self.preloadedmatrix.shape[0] ):
for j in range( 0 , self.preloadedmatrix.shape[1] ):
if self.preloadedmatrix[i][j] >= self.usersymptoms[0][j]:
self.intersectionmatrix[i][j] = self.usersymptoms[0][j]
else:
self.intersectionmatrix[i][j] = self.preloadedmatrix[i][j]
for i in range( 0 , self.intersectionmatrix.shape[0] ):
for j in range( 0 , self.intersectionmatrix.shape[1]-1 ):
self.intersectionmatrix[i][15] += self.intersectionmatrix[i][j]
self.diagnosisresult[0][i] = self.intersectionmatrix[i][15]
def specificDiagnosis( self ):
self.generalDiagnosis()
for i in range( 0 , 10 ):
if str( i ) not in self.listdiseases:
self.diagnosisresult[0][i] = -1
###################################################################################################
# <MAIN>
if __name__ == '__main__':
mdm = MedicalDiagnosticModule()
try:
if len( sys.argv[1] ) > 1 :
mdm.processARGV()
except IndexError:
print( '>ARGUMENTS NOT RECEIVED<' )
exit()
if mdm.listdiseases[0] == '':
try:
mdm.generalDiagnosis()
except IndexError:
print( '>INVALID ARGUMENTS RECEIVED<' )
exit()
else:
mdm.specificDiagnosis()
print( json.dumps( mdm.diagnosisresult[0].tolist() ) )