-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer_cards.py
219 lines (194 loc) · 6.84 KB
/
viewer_cards.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import json
import urllib
import socket
import copy
from mongodb import get
from claudia_interpretator import next_step
taxes = [
'Cardio-Loc',
'CHF-Words',
'DECLINE',
'dementia',
'MentalStatus',
'MI-Words',
'PVD-Words',
'FAMILY'
]
anns = [
'number',
'contains_number',
'text'
]
snap_file_name = "tmp/snapshot.json"
# This class generates a HTML-page for a card
class showCard:
def __init__(self, args, mongo, httpd):
computer = socket.gethostname()
if computer == 'noX540LJ':
html_file = 'cci/viewer/cards.html'
else:
html_file = '/home/andrey/work/Claudia/claudia/cci/viewer/cards.html'
lock = httpd.mLock
lock.acquire()
html_file = open(html_file, 'r')
html = html_file.read()
html_file.close()
lock.release()
html = anticache(html)
html = html.replace('<ID/>', args['id'])
html = html.replace('<DS/>', args['ds'])
html = html.replace('<FORMULA/>', args['formula'])
html = html.replace('TAB_SELECTED', str(args['tab']))
self.site = html
class getInfo:
def __init__(self, args, mongo, httpd):
state = urllib.unquote(args['args'])
state = json.loads(state)
print(json.dumps(state, indent=4))
# lock.acquire()
# snap_file = open(snap_file_name, 'w')
# snap_file.write(json.dumps([]))
# snap_file.close()
# lock.release()
# Code
lock = httpd.mLock
lock.acquire()
code = get("code.cla.json", formula=state['formula'],
mongo=mongo)
print('getInfo version: ' + code['version'])
lock.release()
state['code'] = []
for step in code['source']:
command = {}
command['text'] = step['text']
command['id'] = step['source_id']
command['changes'] = -1
command['visible'] = False
state['code'].append(command)
# Key words
lock.acquire()
state['key_words'] = get('key_words', number_of_card=state['id'],
dataset=state['ds'], mongo=mongo)
lock.release()
# Initilal document
lock.acquire()
doc = get('doc.html', number_of_card=state['id'],
dataset=state['ds'], mongo=mongo)
lock.release()
state['initial_doc'] = doc
# Annotations
lock.acquire()
doc = get('ch.json', number_of_card=state['id'],
dataset=state['ds'], mongo=mongo)
lock.release()
state['anns'] = doc
# Info
lock.acquire()
info = get('doc.json', number_of_card=state['id'],
dataset=state['ds'], mongo=mongo)
lock.release()
if info is None:
info = {}
state['info'] = info
# Ticket
lock.acquire()
cch = httpd.cch
if state['ticket'] != 'admin':
state['ticket'] = cch.getFreeTicket()
if state['ticket'] is None:
state['ticket'] = 'admin'
lock.release()
print('ticket: ' + state['ticket'])
#print(json.dumps(state, indent=4))
self.site = urllib.quote(json.dumps(state))
class runCode:
def __init__(self, args, mongo, httpd):
req = urllib.unquote(args['args'])
req = json.loads(req)
print('req' + str(req))
lock = httpd.mLock
lock.acquire()
code = get("code.cla.json", formula=req['formula'],
mongo=mongo)
print('runCode version: ' + code['version'])
lock.release()
doc = []
doc_data = {}
n = 0
while True:
print('Step: ' + str(n))
doc_data = next_step(doc_data, code, req['ds'], req['id'],
n, mongo)
if doc_data is None:
break
doc.append(doc_data)
# Save to file
snap_file = open(snap_file_name, 'w')
snap_file.write(json.dumps(doc, indent=4))
snap_file.close()
n += 1
answer = 'ready'
self.site = urllib.quote(json.dumps(answer, indent=4))
class getCode:
def __init__(self, args, mongo, httpd):
req = urllib.unquote(args['args'])
req = json.loads(req)
print('req: '+ str(req))
lock = httpd.mLock
lock.acquire()
if req['ticket'] == 'admin':
snap_file = open(snap_file_name, 'r')
doc = json.loads(snap_file.read())
snap_file.close()
else:
cch = httpd.cch
#print('Locks: ' + str(cch.mch.mLocks))
doc = cch.getValue(req['ticket'])
#print('doc: ' + str(doc))
if doc is None:
doc= []
lock.release()
if doc == []:
doc_data = {}
else:
doc_data = doc[-1]
lock.acquire()
code = get("code.cla.json", formula=req['formula'],
mongo=mongo)
print('GetCode version: ' + code['version'])
lock.release()
for n in range(len(doc), req['new_step'] + 1):
print('Step: ' + str(n))
doc_data = next_step(doc_data, code, req['ds'], req['id'],
n, mongo)
doc_copy = copy.deepcopy(doc_data)
doc.append(doc_copy)
new_cadres = doc[req['step']+1:]
lock.acquire()
if req['ticket'] == 'admin':
snap_file = open(snap_file_name, 'w')
snap_file.write(json.dumps(doc, indent=4))
snap_file.close()
else:
cch.putValue(req['ticket'], doc)
lock.release()
self.site = urllib.quote(json.dumps(new_cadres))
import datetime
def anticache(html):
now = datetime.datetime.now()
s = str(now.second)
html = html.replace('.js"', '.js?v=' + s + '"')
html = html.replace(".js'", ".js?v=" + s + "'")
html = html.replace('.css)', '.css?v=' + s + ')')
return html
class clearCache:
def __init__(self, args, mongo, httpd):
req = urllib.unquote(args['args'])
req = json.loads(req)
print('req: ' + str(req))
lock = httpd.mLock
lock.acquire()
cch = httpd.cch
cch.removeTicket(req['ticket'])
lock.release()
self.site = 'Ok.'