@@ -1,322 +1,322 | |||||
1 | from django.shortcuts import redirect, render, get_object_or_404 |
|
1 | from django.shortcuts import redirect, render, get_object_or_404 | |
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 | from django.http import HttpResponse |
|
3 | from django.http import HttpResponse | |
4 |
|
4 | |||
5 | from apps.main.models import Experiment, Configuration |
|
5 | from apps.main.models import Experiment, Configuration | |
6 | from .models import CGSConfiguration |
|
6 | from .models import CGSConfiguration | |
7 |
|
7 | |||
8 | from .forms import CGSConfigurationForm, UploadFileForm |
|
8 | from .forms import CGSConfigurationForm, UploadFileForm | |
9 | from apps.main.views import sidebar |
|
9 | from apps.main.views import sidebar | |
10 |
|
10 | |||
11 | import requests |
|
11 | import requests | |
12 | import json |
|
12 | import json | |
13 | #from __builtin__ import None |
|
13 | #from __builtin__ import None | |
14 | # Create your views here. |
|
14 | # Create your views here. | |
15 |
|
15 | |||
16 | def cgs_conf(request, id_conf): |
|
16 | def cgs_conf(request, id_conf): | |
17 |
|
17 | |||
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
19 |
|
19 | |||
20 | ip=conf.device.ip_address |
|
20 | ip=conf.device.ip_address | |
21 | port=conf.device.port_address |
|
21 | port=conf.device.port_address | |
22 |
|
22 | |||
23 | kwargs = {} |
|
23 | kwargs = {} | |
24 |
|
24 | |||
25 | kwargs['status'] = conf.device.get_status_display() |
|
25 | kwargs['status'] = conf.device.get_status_display() | |
26 |
|
26 | |||
27 | #if request.method=='GET': |
|
27 | #if request.method=='GET': | |
28 | #r: response = icon, status |
|
28 | #r: response = icon, status | |
29 | # try: |
|
29 | # try: | |
30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
31 | # r = requests.get(route) |
|
31 | # r = requests.get(route) | |
32 | # response = str(r.text) |
|
32 | # response = str(r.text) | |
33 | # response = response.split(";") |
|
33 | # response = response.split(";") | |
34 | # icon = response[0] |
|
34 | # icon = response[0] | |
35 | # status = response[-1] |
|
35 | # status = response[-1] | |
36 | #print r.text |
|
36 | #print r.text | |
37 | #"icon" could be: "alert" or "okay" |
|
37 | #"icon" could be: "alert" or "okay" | |
38 | # Si hay alerta pero esta conectado |
|
38 | # Si hay alerta pero esta conectado | |
39 | # if "alert" in icon: |
|
39 | # if "alert" in icon: | |
40 | # if "Starting Up" in status: #No Esta conectado |
|
40 | # if "Starting Up" in status: #No Esta conectado | |
41 | # kwargs['connected'] = False |
|
41 | # kwargs['connected'] = False | |
42 | # else: |
|
42 | # else: | |
43 | # kwargs['connected'] = True |
|
43 | # kwargs['connected'] = True | |
44 | # elif "okay" in icon: |
|
44 | # elif "okay" in icon: | |
45 | # kwargs['connected'] = True |
|
45 | # kwargs['connected'] = True | |
46 | # else: |
|
46 | # else: | |
47 | # kwargs['connected'] = False |
|
47 | # kwargs['connected'] = False | |
48 |
|
48 | |||
49 | # except: |
|
49 | # except: | |
50 | # kwargs['connected'] = False |
|
50 | # kwargs['connected'] = False | |
51 | # status = "The Device is not connected." |
|
51 | # status = "The Device is not connected." | |
52 |
|
52 | |||
53 | #if not kwargs['connected']: |
|
53 | #if not kwargs['connected']: | |
54 | # messages.error(request, message=status) |
|
54 | # messages.error(request, message=status) | |
55 |
|
55 | |||
56 | kwargs['dev_conf'] = conf |
|
56 | kwargs['dev_conf'] = conf | |
57 |
kwargs['dev_conf_keys'] = [' |
|
57 | kwargs['dev_conf_keys'] = ['name', | |
58 | 'freq0', 'freq1', |
|
58 | 'freq0', 'freq1', | |
59 | 'freq2', 'freq3'] |
|
59 | 'freq2', 'freq3'] | |
60 |
|
60 | |||
61 | kwargs['title'] = 'CGS Configuration' |
|
61 | kwargs['title'] = 'CGS Configuration' | |
62 | kwargs['suptitle'] = 'Details' |
|
62 | kwargs['suptitle'] = 'Details' | |
63 |
|
63 | |||
64 | kwargs['button'] = 'Edit Configuration' |
|
64 | kwargs['button'] = 'Edit Configuration' | |
65 |
|
65 | |||
66 | kwargs['no_play'] = True |
|
66 | kwargs['no_play'] = True | |
67 |
|
67 | |||
68 | ###### SIDEBAR ###### |
|
68 | ###### SIDEBAR ###### | |
69 | kwargs.update(sidebar(conf=conf)) |
|
69 | kwargs.update(sidebar(conf=conf)) | |
70 |
|
70 | |||
71 | return render(request, 'cgs_conf.html', kwargs) |
|
71 | return render(request, 'cgs_conf.html', kwargs) | |
72 |
|
72 | |||
73 | def cgs_conf_edit(request, id_conf): |
|
73 | def cgs_conf_edit(request, id_conf): | |
74 |
|
74 | |||
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
76 |
|
76 | |||
77 | if request.method=='GET': |
|
77 | if request.method=='GET': | |
78 | form = CGSConfigurationForm(instance=conf) |
|
78 | form = CGSConfigurationForm(instance=conf) | |
79 |
|
79 | |||
80 | if request.method=='POST': |
|
80 | if request.method=='POST': | |
81 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
81 | form = CGSConfigurationForm(request.POST, instance=conf) | |
82 |
|
82 | |||
83 | if form.is_valid(): |
|
83 | if form.is_valid(): | |
84 | if conf.freq0 == None: conf.freq0 = 0 |
|
84 | if conf.freq0 == None: conf.freq0 = 0 | |
85 | if conf.freq1 == None: conf.freq1 = 0 |
|
85 | if conf.freq1 == None: conf.freq1 = 0 | |
86 | if conf.freq2 == None: conf.freq2 = 0 |
|
86 | if conf.freq2 == None: conf.freq2 = 0 | |
87 | if conf.freq3 == None: conf.freq3 = 0 |
|
87 | if conf.freq3 == None: conf.freq3 = 0 | |
88 |
|
88 | |||
89 | conf = form.save(commit=False) |
|
89 | conf = form.save(commit=False) | |
90 |
|
90 | |||
91 | if conf.verify_frequencies(): |
|
91 | if conf.verify_frequencies(): | |
92 | conf.save() |
|
92 | conf.save() | |
93 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
93 | return redirect('url_cgs_conf', id_conf=conf.id) | |
94 |
|
94 | |||
95 | ##ERRORS |
|
95 | ##ERRORS | |
96 |
|
96 | |||
97 | kwargs = {} |
|
97 | kwargs = {} | |
98 | kwargs['id_dev'] = conf.id |
|
98 | kwargs['id_dev'] = conf.id | |
99 | kwargs['form'] = form |
|
99 | kwargs['form'] = form | |
100 | kwargs['title'] = 'Device Configuration' |
|
100 | kwargs['title'] = 'Device Configuration' | |
101 | kwargs['suptitle'] = 'Edit' |
|
101 | kwargs['suptitle'] = 'Edit' | |
102 | kwargs['button'] = 'Save' |
|
102 | kwargs['button'] = 'Save' | |
103 |
|
103 | |||
104 | return render(request, 'cgs_conf_edit.html', kwargs) |
|
104 | return render(request, 'cgs_conf_edit.html', kwargs) | |
105 | # |
|
105 | # | |
106 | # def cgs_conf_write(request, id_conf): |
|
106 | # def cgs_conf_write(request, id_conf): | |
107 | # |
|
107 | # | |
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
109 | # ip=conf.device.ip_address |
|
109 | # ip=conf.device.ip_address | |
110 | # port=conf.device.port_address |
|
110 | # port=conf.device.port_address | |
111 | # |
|
111 | # | |
112 | # #Frequencies from form |
|
112 | # #Frequencies from form | |
113 | # f0 = conf.freq0 |
|
113 | # f0 = conf.freq0 | |
114 | # f1 = conf.freq1 |
|
114 | # f1 = conf.freq1 | |
115 | # f2 = conf.freq2 |
|
115 | # f2 = conf.freq2 | |
116 | # f3 = conf.freq3 |
|
116 | # f3 = conf.freq3 | |
117 | # |
|
117 | # | |
118 | # try: |
|
118 | # try: | |
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
121 | # r = requests.post(route, post_data) |
|
121 | # r = requests.post(route, post_data) | |
122 | # text = r.text |
|
122 | # text = r.text | |
123 | # text = text.split(',') |
|
123 | # text = text.split(',') | |
124 | # |
|
124 | # | |
125 | # try: |
|
125 | # try: | |
126 | # if len(text)>1: |
|
126 | # if len(text)>1: | |
127 | # title = text[0] |
|
127 | # title = text[0] | |
128 | # status = text[1] |
|
128 | # status = text[1] | |
129 | # status_ok = r.status_code |
|
129 | # status_ok = r.status_code | |
130 | # if title == "okay": |
|
130 | # if title == "okay": | |
131 | # messages.success(request, status) |
|
131 | # messages.success(request, status) | |
132 | # else: |
|
132 | # else: | |
133 | # messages.error(request, status) |
|
133 | # messages.error(request, status) | |
134 | # |
|
134 | # | |
135 | # else: |
|
135 | # else: | |
136 | # title = text[0] |
|
136 | # title = text[0] | |
137 | # messages.error(request, title) |
|
137 | # messages.error(request, title) | |
138 | # |
|
138 | # | |
139 | # except: |
|
139 | # except: | |
140 | # messages.error(request, "An hardware error was found.") |
|
140 | # messages.error(request, "An hardware error was found.") | |
141 | # |
|
141 | # | |
142 | # except: |
|
142 | # except: | |
143 | # messages.error(request, "Could not write parameters.") |
|
143 | # messages.error(request, "Could not write parameters.") | |
144 | # |
|
144 | # | |
145 | # |
|
145 | # | |
146 | # |
|
146 | # | |
147 | # |
|
147 | # | |
148 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
148 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
149 | # |
|
149 | # | |
150 | # def cgs_conf_read(request, id_conf): |
|
150 | # def cgs_conf_read(request, id_conf): | |
151 | # |
|
151 | # | |
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
153 | # |
|
153 | # | |
154 | # ip=conf.device.ip_address |
|
154 | # ip=conf.device.ip_address | |
155 | # port=conf.device.port_address |
|
155 | # port=conf.device.port_address | |
156 | # |
|
156 | # | |
157 | # if request.method=='POST': |
|
157 | # if request.method=='POST': | |
158 | # form = CGSConfigurationForm(request.POST, instance=conf) |
|
158 | # form = CGSConfigurationForm(request.POST, instance=conf) | |
159 | # |
|
159 | # | |
160 | # if form.is_valid(): |
|
160 | # if form.is_valid(): | |
161 | # cgs_model = form.save(commit=False) |
|
161 | # cgs_model = form.save(commit=False) | |
162 | # |
|
162 | # | |
163 | # if cgs_model.verify_frequencies(): |
|
163 | # if cgs_model.verify_frequencies(): | |
164 | # |
|
164 | # | |
165 | # cgs_model.save() |
|
165 | # cgs_model.save() | |
166 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
166 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
167 | # |
|
167 | # | |
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") |
|
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") | |
169 | # |
|
169 | # | |
170 | # data = {} |
|
170 | # data = {} | |
171 | # |
|
171 | # | |
172 | # |
|
172 | # | |
173 | # if request.method=='GET': |
|
173 | # if request.method=='GET': | |
174 | # #r: response = icon, status |
|
174 | # #r: response = icon, status | |
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
176 | # try: |
|
176 | # try: | |
177 | # r = requests.get(route) |
|
177 | # r = requests.get(route) | |
178 | # response = str(r.text) |
|
178 | # response = str(r.text) | |
179 | # response = response.split(";") |
|
179 | # response = response.split(";") | |
180 | # icon = response[0] |
|
180 | # icon = response[0] | |
181 | # status = response[-1] |
|
181 | # status = response[-1] | |
182 | # print r.text |
|
182 | # print r.text | |
183 | # #"icon" could be: "alert" or "okay" |
|
183 | # #"icon" could be: "alert" or "okay" | |
184 | # if "okay" in icon: |
|
184 | # if "okay" in icon: | |
185 | # messages.success(request, status) |
|
185 | # messages.success(request, status) | |
186 | # else: |
|
186 | # else: | |
187 | # messages.error(request, status) |
|
187 | # messages.error(request, status) | |
188 | # #Get Frequencies |
|
188 | # #Get Frequencies | |
189 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
189 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
190 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') |
|
190 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') | |
191 | # frequencies = requests.get(route) |
|
191 | # frequencies = requests.get(route) | |
192 | # frequencies = frequencies.json() |
|
192 | # frequencies = frequencies.json() | |
193 | # frequencies = frequencies.get("Frecuencias") |
|
193 | # frequencies = frequencies.get("Frecuencias") | |
194 | # f0 = frequencies.get("f0") |
|
194 | # f0 = frequencies.get("f0") | |
195 | # f1 = frequencies.get("f1") |
|
195 | # f1 = frequencies.get("f1") | |
196 | # f2 = frequencies.get("f2") |
|
196 | # f2 = frequencies.get("f2") | |
197 | # f3 = frequencies.get("f3") |
|
197 | # f3 = frequencies.get("f3") | |
198 | # print f0,f1,f2,f3 |
|
198 | # print f0,f1,f2,f3 | |
199 | # |
|
199 | # | |
200 | # |
|
200 | # | |
201 | # if not response: |
|
201 | # if not response: | |
202 | # messages.error(request, "Could not read parameters from Device") |
|
202 | # messages.error(request, "Could not read parameters from Device") | |
203 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
203 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
204 | # |
|
204 | # | |
205 | # data = {'experiment' : conf.experiment.id, |
|
205 | # data = {'experiment' : conf.experiment.id, | |
206 | # 'device' : conf.device.id, |
|
206 | # 'device' : conf.device.id, | |
207 | # 'freq0' : f0, |
|
207 | # 'freq0' : f0, | |
208 | # 'freq1' : f1, |
|
208 | # 'freq1' : f1, | |
209 | # 'freq2' : f2, |
|
209 | # 'freq2' : f2, | |
210 | # 'freq3' : f3, |
|
210 | # 'freq3' : f3, | |
211 | # } |
|
211 | # } | |
212 | # except: |
|
212 | # except: | |
213 | # messages.error(request, "Could not read parameters from Device") |
|
213 | # messages.error(request, "Could not read parameters from Device") | |
214 | # data = {'experiment' : conf.experiment.id, |
|
214 | # data = {'experiment' : conf.experiment.id, | |
215 | # 'device' : conf.device.id, |
|
215 | # 'device' : conf.device.id, | |
216 | # 'freq0' : None, |
|
216 | # 'freq0' : None, | |
217 | # 'freq1' : None, |
|
217 | # 'freq1' : None, | |
218 | # 'freq2' : None, |
|
218 | # 'freq2' : None, | |
219 | # 'freq3' : None, |
|
219 | # 'freq3' : None, | |
220 | # } |
|
220 | # } | |
221 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
221 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
222 | # |
|
222 | # | |
223 | # form = CGSConfigurationForm(initial = data) |
|
223 | # form = CGSConfigurationForm(initial = data) | |
224 | # |
|
224 | # | |
225 | # kwargs = {} |
|
225 | # kwargs = {} | |
226 | # kwargs['id_dev'] = conf.id |
|
226 | # kwargs['id_dev'] = conf.id | |
227 | # kwargs['form'] = form |
|
227 | # kwargs['form'] = form | |
228 | # kwargs['title'] = 'Device Configuration' |
|
228 | # kwargs['title'] = 'Device Configuration' | |
229 | # kwargs['suptitle'] = 'Parameters read from device' |
|
229 | # kwargs['suptitle'] = 'Parameters read from device' | |
230 | # kwargs['button'] = 'Save' |
|
230 | # kwargs['button'] = 'Save' | |
231 | # |
|
231 | # | |
232 | # ###### SIDEBAR ###### |
|
232 | # ###### SIDEBAR ###### | |
233 | # kwargs.update(sidebar(conf)) |
|
233 | # kwargs.update(sidebar(conf)) | |
234 | # |
|
234 | # | |
235 | # return render(request, 'cgs_conf_edit.html', kwargs) |
|
235 | # return render(request, 'cgs_conf_edit.html', kwargs) | |
236 | # |
|
236 | # | |
237 | # def cgs_conf_import(request, id_conf): |
|
237 | # def cgs_conf_import(request, id_conf): | |
238 | # |
|
238 | # | |
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
240 | # |
|
240 | # | |
241 | # if request.method == 'POST': |
|
241 | # if request.method == 'POST': | |
242 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
242 | # file_form = UploadFileForm(request.POST, request.FILES) | |
243 | # |
|
243 | # | |
244 | # if file_form.is_valid(): |
|
244 | # if file_form.is_valid(): | |
245 | # |
|
245 | # | |
246 | # try: |
|
246 | # try: | |
247 | # if conf.update_from_file(request.FILES['file']): |
|
247 | # if conf.update_from_file(request.FILES['file']): | |
248 | # |
|
248 | # | |
249 | # try: |
|
249 | # try: | |
250 | # conf.full_clean() |
|
250 | # conf.full_clean() | |
251 | # except ValidationError as e: |
|
251 | # except ValidationError as e: | |
252 | # messages.error(request, e) |
|
252 | # messages.error(request, e) | |
253 | # else: |
|
253 | # else: | |
254 | # conf.save() |
|
254 | # conf.save() | |
255 | # |
|
255 | # | |
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) |
|
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) | |
257 | # #messages.warning(request,"") |
|
257 | # #messages.warning(request,"") | |
258 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
258 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
259 | # except: |
|
259 | # except: | |
260 | # messages.error(request, "No JSON object could be decoded.") |
|
260 | # messages.error(request, "No JSON object could be decoded.") | |
261 | # |
|
261 | # | |
262 | # messages.error(request, "Could not import parameters from file") |
|
262 | # messages.error(request, "Could not import parameters from file") | |
263 | # |
|
263 | # | |
264 | # else: |
|
264 | # else: | |
265 | # file_form = UploadFileForm(initial={'title': '.json'}) |
|
265 | # file_form = UploadFileForm(initial={'title': '.json'}) | |
266 | # |
|
266 | # | |
267 | # |
|
267 | # | |
268 | # kwargs = {} |
|
268 | # kwargs = {} | |
269 | # kwargs['id_dev'] = conf.id |
|
269 | # kwargs['id_dev'] = conf.id | |
270 | # kwargs['title'] = 'Device Configuration' |
|
270 | # kwargs['title'] = 'Device Configuration' | |
271 | # kwargs['form'] = file_form |
|
271 | # kwargs['form'] = file_form | |
272 | # kwargs['suptitle'] = 'Importing file' |
|
272 | # kwargs['suptitle'] = 'Importing file' | |
273 | # kwargs['button'] = 'Import' |
|
273 | # kwargs['button'] = 'Import' | |
274 | # |
|
274 | # | |
275 | # kwargs.update(sidebar(conf)) |
|
275 | # kwargs.update(sidebar(conf)) | |
276 | # |
|
276 | # | |
277 | # return render(request, 'cgs_conf_import.html', kwargs) |
|
277 | # return render(request, 'cgs_conf_import.html', kwargs) | |
278 | # |
|
278 | # | |
279 | # def handle_uploaded_file(f): |
|
279 | # def handle_uploaded_file(f): | |
280 | # |
|
280 | # | |
281 | # data = {'freq0' : 62500000, |
|
281 | # data = {'freq0' : 62500000, | |
282 | # 'freq1' : 62500000, |
|
282 | # 'freq1' : 62500000, | |
283 | # 'freq2' : 62500000, |
|
283 | # 'freq2' : 62500000, | |
284 | # 'freq3' : 62500000, |
|
284 | # 'freq3' : 62500000, | |
285 | # } |
|
285 | # } | |
286 | # |
|
286 | # | |
287 | # return data |
|
287 | # return data | |
288 | # |
|
288 | # | |
289 | # def cgs_conf_export(request, id_conf): |
|
289 | # def cgs_conf_export(request, id_conf): | |
290 | # |
|
290 | # | |
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
292 | # ip=conf.device.ip_address |
|
292 | # ip=conf.device.ip_address | |
293 | # port=conf.device.port_address |
|
293 | # port=conf.device.port_address | |
294 | # |
|
294 | # | |
295 | # #if request.method=='GET': |
|
295 | # #if request.method=='GET': | |
296 | # # data = {"Frequencies": [ |
|
296 | # # data = {"Frequencies": [ | |
297 | # # ["freq0", conf.freq0], |
|
297 | # # ["freq0", conf.freq0], | |
298 | # # ["freq1", conf.freq1], |
|
298 | # # ["freq1", conf.freq1], | |
299 | # # ["freq2", conf.freq2], |
|
299 | # # ["freq2", conf.freq2], | |
300 | # # ["freq3", conf.freq3] |
|
300 | # # ["freq3", conf.freq3] | |
301 | # # ]} |
|
301 | # # ]} | |
302 | # # json_data = json.dumps(data) |
|
302 | # # json_data = json.dumps(data) | |
303 | # # conf.parameters = json_data |
|
303 | # # conf.parameters = json_data | |
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") |
|
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") | |
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' |
|
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' | |
306 | # |
|
306 | # | |
307 | # # return response |
|
307 | # # return response | |
308 | # |
|
308 | # | |
309 | # kwargs = {} |
|
309 | # kwargs = {} | |
310 | # kwargs['dev_conf'] = conf |
|
310 | # kwargs['dev_conf'] = conf | |
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', | |
312 | # 'freq0', 'freq1', |
|
312 | # 'freq0', 'freq1', | |
313 | # 'freq2', 'freq3'] |
|
313 | # 'freq2', 'freq3'] | |
314 | # |
|
314 | # | |
315 | # kwargs['title'] = 'CGS Configuration' |
|
315 | # kwargs['title'] = 'CGS Configuration' | |
316 | # kwargs['suptitle'] = 'Details' |
|
316 | # kwargs['suptitle'] = 'Details' | |
317 | # |
|
317 | # | |
318 | # kwargs['button'] = 'Edit Configuration' |
|
318 | # kwargs['button'] = 'Edit Configuration' | |
319 | # |
|
319 | # | |
320 | # ###### SIDEBAR ###### |
|
320 | # ###### SIDEBAR ###### | |
321 | # kwargs.update(sidebar(conf)) |
|
321 | # kwargs.update(sidebar(conf)) | |
322 | # return render(request, 'cgs_conf.html', kwargs) No newline at end of file |
|
322 | # return render(request, 'cgs_conf.html', kwargs) |
@@ -1,231 +1,229 | |||||
1 | # Create your views here. |
|
1 | # Create your views here. | |
2 | from django.shortcuts import redirect, render, get_object_or_404 |
|
2 | from django.shortcuts import redirect, render, get_object_or_404 | |
3 |
|
3 | |||
4 | # from apps.main.models import Experiment, Configuration |
|
4 | # from apps.main.models import Experiment, Configuration | |
5 | from apps.main.views import sidebar |
|
5 | from apps.main.views import sidebar | |
6 |
|
6 | |||
7 | from .models import DDSConfiguration |
|
7 | from .models import DDSConfiguration | |
8 | from .forms import DDSConfigurationForm |
|
8 | from .forms import DDSConfigurationForm | |
9 | # Create your views here. |
|
9 | # Create your views here. | |
10 |
|
10 | |||
11 | def dds_conf(request, id_conf): |
|
11 | def dds_conf(request, id_conf): | |
12 |
|
12 | |||
13 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
13 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
14 |
|
14 | |||
15 | kwargs = {} |
|
15 | kwargs = {} | |
16 |
|
16 | |||
17 | kwargs['status'] = conf.device.get_status_display() |
|
17 | kwargs['status'] = conf.device.get_status_display() | |
18 |
|
18 | |||
19 | # if not kwargs['connected']: |
|
19 | # if not kwargs['connected']: | |
20 | # messages.error(request, message=answer) |
|
20 | # messages.error(request, message=answer) | |
21 |
|
21 | |||
22 | kwargs['dev_conf'] = conf |
|
22 | kwargs['dev_conf'] = conf | |
23 | kwargs['dev_conf_keys'] = ['name', |
|
23 | kwargs['dev_conf_keys'] = ['name', | |
24 | 'experiment', |
|
|||
25 | 'device', |
|
|||
26 | 'clock', |
|
24 | 'clock', | |
27 | 'multiplier', |
|
25 | 'multiplier', | |
28 | 'frequencyA_Mhz', |
|
26 | 'frequencyA_Mhz', | |
29 | 'frequencyA', |
|
27 | 'frequencyA', | |
30 | 'frequencyB_Mhz', |
|
28 | 'frequencyB_Mhz', | |
31 | 'frequencyB', |
|
29 | 'frequencyB', | |
32 | 'phaseA_degrees', |
|
30 | 'phaseA_degrees', | |
33 | 'phaseB_degrees', |
|
31 | 'phaseB_degrees', | |
34 | 'modulation', |
|
32 | 'modulation', | |
35 | 'amplitude_enabled', |
|
33 | 'amplitude_enabled', | |
36 | 'amplitudeI', |
|
34 | 'amplitudeI', | |
37 | 'amplitudeQ'] |
|
35 | 'amplitudeQ'] | |
38 |
|
36 | |||
39 | kwargs['title'] = 'DDS Configuration' |
|
37 | kwargs['title'] = 'DDS Configuration' | |
40 | kwargs['suptitle'] = 'Details' |
|
38 | kwargs['suptitle'] = 'Details' | |
41 |
|
39 | |||
42 | kwargs['button'] = 'Edit Configuration' |
|
40 | kwargs['button'] = 'Edit Configuration' | |
43 |
|
41 | |||
44 | ###### SIDEBAR ###### |
|
42 | ###### SIDEBAR ###### | |
45 | kwargs.update(sidebar(conf=conf)) |
|
43 | kwargs.update(sidebar(conf=conf)) | |
46 |
|
44 | |||
47 | return render(request, 'dds_conf.html', kwargs) |
|
45 | return render(request, 'dds_conf.html', kwargs) | |
48 |
|
46 | |||
49 | def dds_conf_edit(request, id_conf): |
|
47 | def dds_conf_edit(request, id_conf): | |
50 |
|
48 | |||
51 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
49 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
52 |
|
50 | |||
53 | if request.method=='GET': |
|
51 | if request.method=='GET': | |
54 | form = DDSConfigurationForm(instance=conf) |
|
52 | form = DDSConfigurationForm(instance=conf) | |
55 |
|
53 | |||
56 | if request.method=='POST': |
|
54 | if request.method=='POST': | |
57 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
55 | form = DDSConfigurationForm(request.POST, instance=conf) | |
58 |
|
56 | |||
59 | if form.is_valid(): |
|
57 | if form.is_valid(): | |
60 | conf = form.save(commit=False) |
|
58 | conf = form.save(commit=False) | |
61 |
|
59 | |||
62 | if conf.verify_frequencies(): |
|
60 | if conf.verify_frequencies(): | |
63 |
|
61 | |||
64 | conf.save() |
|
62 | conf.save() | |
65 | return redirect('url_dds_conf', id_conf=conf.id) |
|
63 | return redirect('url_dds_conf', id_conf=conf.id) | |
66 |
|
64 | |||
67 | ##ERRORS |
|
65 | ##ERRORS | |
68 |
|
66 | |||
69 | kwargs = {} |
|
67 | kwargs = {} | |
70 | kwargs['id_dev'] = conf.id |
|
68 | kwargs['id_dev'] = conf.id | |
71 | kwargs['form'] = form |
|
69 | kwargs['form'] = form | |
72 | kwargs['title'] = 'Device Configuration' |
|
70 | kwargs['title'] = 'Device Configuration' | |
73 | kwargs['suptitle'] = 'Edit' |
|
71 | kwargs['suptitle'] = 'Edit' | |
74 | kwargs['button'] = 'Save' |
|
72 | kwargs['button'] = 'Save' | |
75 |
|
73 | |||
76 | return render(request, 'dds_conf_edit.html', kwargs) |
|
74 | return render(request, 'dds_conf_edit.html', kwargs) | |
77 |
|
75 | |||
78 | # def dds_conf_import(request, id_conf): |
|
76 | # def dds_conf_import(request, id_conf): | |
79 | # |
|
77 | # | |
80 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
78 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
81 | # |
|
79 | # | |
82 | # if request.method == 'GET': |
|
80 | # if request.method == 'GET': | |
83 | # file_form = UploadFileForm() |
|
81 | # file_form = UploadFileForm() | |
84 | # |
|
82 | # | |
85 | # if request.method == 'POST': |
|
83 | # if request.method == 'POST': | |
86 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
84 | # file_form = UploadFileForm(request.POST, request.FILES) | |
87 | # |
|
85 | # | |
88 | # if file_form.is_valid(): |
|
86 | # if file_form.is_valid(): | |
89 | # |
|
87 | # | |
90 | # parms = files.read_dds_file(request.FILES['file']) |
|
88 | # parms = files.read_dds_file(request.FILES['file']) | |
91 | # |
|
89 | # | |
92 | # if parms: |
|
90 | # if parms: | |
93 | # |
|
91 | # | |
94 | # if not parms['clock']: |
|
92 | # if not parms['clock']: | |
95 | # messages.warning(request, "Clock Input could not be imported from '%s'. Please fill it out." %request.FILES['file'].name) |
|
93 | # messages.warning(request, "Clock Input could not be imported from '%s'. Please fill it out." %request.FILES['file'].name) | |
96 | # else: |
|
94 | # else: | |
97 | # messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
95 | # messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
98 | # |
|
96 | # | |
99 | # form = DDSConfigurationForm(initial=parms, instance=conf) |
|
97 | # form = DDSConfigurationForm(initial=parms, instance=conf) | |
100 | # |
|
98 | # | |
101 | # kwargs = {} |
|
99 | # kwargs = {} | |
102 | # kwargs['id_dev'] = conf.id |
|
100 | # kwargs['id_dev'] = conf.id | |
103 | # kwargs['form'] = form |
|
101 | # kwargs['form'] = form | |
104 | # kwargs['title'] = 'Device Configuration' |
|
102 | # kwargs['title'] = 'Device Configuration' | |
105 | # kwargs['suptitle'] = 'Parameters imported' |
|
103 | # kwargs['suptitle'] = 'Parameters imported' | |
106 | # kwargs['button'] = 'Save' |
|
104 | # kwargs['button'] = 'Save' | |
107 | # kwargs['action'] = conf.get_absolute_url_edit() |
|
105 | # kwargs['action'] = conf.get_absolute_url_edit() | |
108 | # kwargs['previous'] = conf.get_absolute_url() |
|
106 | # kwargs['previous'] = conf.get_absolute_url() | |
109 | # |
|
107 | # | |
110 | # ###### SIDEBAR ###### |
|
108 | # ###### SIDEBAR ###### | |
111 | # kwargs.update(sidebar(conf)) |
|
109 | # kwargs.update(sidebar(conf)) | |
112 | # |
|
110 | # | |
113 | # return render(request, 'dds_conf_edit.html', kwargs) |
|
111 | # return render(request, 'dds_conf_edit.html', kwargs) | |
114 | # |
|
112 | # | |
115 | # messages.error(request, "Could not import parameters from file") |
|
113 | # messages.error(request, "Could not import parameters from file") | |
116 | # |
|
114 | # | |
117 | # kwargs = {} |
|
115 | # kwargs = {} | |
118 | # kwargs['id_dev'] = conf.id |
|
116 | # kwargs['id_dev'] = conf.id | |
119 | # kwargs['title'] = 'Device Configuration' |
|
117 | # kwargs['title'] = 'Device Configuration' | |
120 | # kwargs['form'] = file_form |
|
118 | # kwargs['form'] = file_form | |
121 | # kwargs['suptitle'] = 'Importing file' |
|
119 | # kwargs['suptitle'] = 'Importing file' | |
122 | # kwargs['button'] = 'Import' |
|
120 | # kwargs['button'] = 'Import' | |
123 | # |
|
121 | # | |
124 | # kwargs.update(sidebar(conf)) |
|
122 | # kwargs.update(sidebar(conf)) | |
125 | # |
|
123 | # | |
126 | # return render(request, 'dds_conf_import.html', kwargs) |
|
124 | # return render(request, 'dds_conf_import.html', kwargs) | |
127 | # |
|
125 | # | |
128 | # def dds_conf_export(request, id_conf): |
|
126 | # def dds_conf_export(request, id_conf): | |
129 | # |
|
127 | # | |
130 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
128 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
131 | # |
|
129 | # | |
132 | # response = HttpResponse(content_type='text/plain') |
|
130 | # response = HttpResponse(content_type='text/plain') | |
133 | # response['Content-Disposition'] = 'attachment; filename="%s.dds"' %conf.name |
|
131 | # response['Content-Disposition'] = 'attachment; filename="%s.dds"' %conf.name | |
134 | # response.write(conf.export_parms_to_dict()) |
|
132 | # response.write(conf.export_parms_to_dict()) | |
135 | # |
|
133 | # | |
136 | # return response |
|
134 | # return response | |
137 | # |
|
135 | # | |
138 | # def dds_conf_start(request, id_conf): |
|
136 | # def dds_conf_start(request, id_conf): | |
139 | # |
|
137 | # | |
140 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
138 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
141 | # |
|
139 | # | |
142 | # if conf.start_device(): |
|
140 | # if conf.start_device(): | |
143 | # messages.success(request, conf.message) |
|
141 | # messages.success(request, conf.message) | |
144 | # else: |
|
142 | # else: | |
145 | # messages.error(request, conf.message) |
|
143 | # messages.error(request, conf.message) | |
146 | # |
|
144 | # | |
147 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
145 | # return redirect('url_dds_conf', id_conf=conf.id) | |
148 | # |
|
146 | # | |
149 | # def dds_conf_stop(request, id_conf): |
|
147 | # def dds_conf_stop(request, id_conf): | |
150 | # |
|
148 | # | |
151 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
149 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
152 | # |
|
150 | # | |
153 | # if conf.stop_device(): |
|
151 | # if conf.stop_device(): | |
154 | # messages.success(request, conf.message) |
|
152 | # messages.success(request, conf.message) | |
155 | # else: |
|
153 | # else: | |
156 | # messages.error(request, conf.message) |
|
154 | # messages.error(request, conf.message) | |
157 | # |
|
155 | # | |
158 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
156 | # return redirect('url_dds_conf', id_conf=conf.id) | |
159 | # |
|
157 | # | |
160 | # def dds_conf_status(request, id_conf): |
|
158 | # def dds_conf_status(request, id_conf): | |
161 | # |
|
159 | # | |
162 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
160 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
163 | # |
|
161 | # | |
164 | # if conf.status_device(): |
|
162 | # if conf.status_device(): | |
165 | # messages.success(request, conf.message) |
|
163 | # messages.success(request, conf.message) | |
166 | # else: |
|
164 | # else: | |
167 | # messages.error(request, conf.message) |
|
165 | # messages.error(request, conf.message) | |
168 | # |
|
166 | # | |
169 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
167 | # return redirect('url_dds_conf', id_conf=conf.id) | |
170 | # |
|
168 | # | |
171 | # |
|
169 | # | |
172 | # def dds_conf_write(request, id_conf): |
|
170 | # def dds_conf_write(request, id_conf): | |
173 | # |
|
171 | # | |
174 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
172 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
175 | # |
|
173 | # | |
176 | # answer = conf.write_device() |
|
174 | # answer = conf.write_device() | |
177 | # |
|
175 | # | |
178 | # if answer: |
|
176 | # if answer: | |
179 | # messages.success(request, conf.message) |
|
177 | # messages.success(request, conf.message) | |
180 | # |
|
178 | # | |
181 | # conf.pk = None |
|
179 | # conf.pk = None | |
182 | # conf.id = None |
|
180 | # conf.id = None | |
183 | # conf.type = 1 |
|
181 | # conf.type = 1 | |
184 | # conf.template = 0 |
|
182 | # conf.template = 0 | |
185 | # conf.save() |
|
183 | # conf.save() | |
186 | # |
|
184 | # | |
187 | # else: |
|
185 | # else: | |
188 | # messages.error(request, conf.message) |
|
186 | # messages.error(request, conf.message) | |
189 | # |
|
187 | # | |
190 | # return redirect('url_dds_conf', id_conf=id_conf) |
|
188 | # return redirect('url_dds_conf', id_conf=id_conf) | |
191 | # |
|
189 | # | |
192 | # def dds_conf_read(request, id_conf): |
|
190 | # def dds_conf_read(request, id_conf): | |
193 | # |
|
191 | # | |
194 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
192 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
195 | # |
|
193 | # | |
196 | # if request.method=='GET': |
|
194 | # if request.method=='GET': | |
197 | # |
|
195 | # | |
198 | # parms = conf.read_device() |
|
196 | # parms = conf.read_device() | |
199 | # |
|
197 | # | |
200 | # if not parms: |
|
198 | # if not parms: | |
201 | # messages.error(request, conf.message) |
|
199 | # messages.error(request, conf.message) | |
202 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
200 | # return redirect('url_dds_conf', id_conf=conf.id) | |
203 | # |
|
201 | # | |
204 | # messages.warning(request, "Clock Input cannot be read from device. Please fill it out.") |
|
202 | # messages.warning(request, "Clock Input cannot be read from device. Please fill it out.") | |
205 | # |
|
203 | # | |
206 | # form = DDSConfigurationForm(initial=parms, instance=conf) |
|
204 | # form = DDSConfigurationForm(initial=parms, instance=conf) | |
207 | # |
|
205 | # | |
208 | # if request.method=='POST': |
|
206 | # if request.method=='POST': | |
209 | # form = DDSConfigurationForm(request.POST, instance=conf) |
|
207 | # form = DDSConfigurationForm(request.POST, instance=conf) | |
210 | # |
|
208 | # | |
211 | # if form.is_valid(): |
|
209 | # if form.is_valid(): | |
212 | # dds_model = form.save(commit=False) |
|
210 | # dds_model = form.save(commit=False) | |
213 | # |
|
211 | # | |
214 | # if dds_model.verify_frequencies(): |
|
212 | # if dds_model.verify_frequencies(): | |
215 | # |
|
213 | # | |
216 | # dds_model.save() |
|
214 | # dds_model.save() | |
217 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
215 | # return redirect('url_dds_conf', id_conf=conf.id) | |
218 | # |
|
216 | # | |
219 | # messages.error(request, "DDS parameters could not be saved") |
|
217 | # messages.error(request, "DDS parameters could not be saved") | |
220 | # |
|
218 | # | |
221 | # kwargs = {} |
|
219 | # kwargs = {} | |
222 | # kwargs['id_dev'] = conf.id |
|
220 | # kwargs['id_dev'] = conf.id | |
223 | # kwargs['form'] = form |
|
221 | # kwargs['form'] = form | |
224 | # kwargs['title'] = 'Device Configuration' |
|
222 | # kwargs['title'] = 'Device Configuration' | |
225 | # kwargs['suptitle'] = 'Parameters read from device' |
|
223 | # kwargs['suptitle'] = 'Parameters read from device' | |
226 | # kwargs['button'] = 'Save' |
|
224 | # kwargs['button'] = 'Save' | |
227 | # |
|
225 | # | |
228 | # ###### SIDEBAR ###### |
|
226 | # ###### SIDEBAR ###### | |
229 | # kwargs.update(sidebar(conf)) |
|
227 | # kwargs.update(sidebar(conf)) | |
230 | # |
|
228 | # | |
231 | # return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
|
229 | # return render(request, 'dds_conf_edit.html', kwargs) |
@@ -1,146 +1,146 | |||||
1 | from django.shortcuts import render_to_response |
|
1 | from django.shortcuts import render_to_response | |
2 | from django.template import RequestContext |
|
2 | from django.template import RequestContext | |
3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
3 | from django.shortcuts import redirect, render, get_object_or_404 | |
4 | from django.contrib import messages |
|
4 | from django.contrib import messages | |
5 |
|
5 | |||
6 | from apps.main.models import Device |
|
6 | from apps.main.models import Device | |
7 | from apps.main.views import sidebar |
|
7 | from apps.main.views import sidebar | |
8 |
|
8 | |||
9 | from .models import JARSConfiguration, JARSfilter |
|
9 | from .models import JARSConfiguration, JARSfilter | |
10 | from .forms import JARSConfigurationForm, JARSfilterForm |
|
10 | from .forms import JARSConfigurationForm, JARSfilterForm | |
11 | # Create your views here. |
|
11 | # Create your views here. | |
12 |
|
12 | |||
13 | def jars_conf(request, id_conf): |
|
13 | def jars_conf(request, id_conf): | |
14 |
|
14 | |||
15 | conf = get_object_or_404(JARSConfiguration, pk=id_conf) |
|
15 | conf = get_object_or_404(JARSConfiguration, pk=id_conf) | |
16 |
|
16 | |||
17 | ip=conf.device.ip_address |
|
17 | ip=conf.device.ip_address | |
18 | port=conf.device.port_address |
|
18 | port=conf.device.port_address | |
19 |
|
19 | |||
20 | kwargs = {} |
|
20 | kwargs = {} | |
21 | kwargs['status'] = conf.device.get_status_display() |
|
21 | kwargs['status'] = conf.device.get_status_display() | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | kwargs['dev_conf'] = conf |
|
24 | kwargs['dev_conf'] = conf | |
25 |
kwargs['dev_conf_keys'] = [' |
|
25 | kwargs['dev_conf_keys'] = ['name', | |
26 | 'cards_number', 'channels_number', 'channels', |
|
26 | 'cards_number', 'channels_number', 'channels', | |
27 | 'rd_directory', 'raw_data_blocks', 'data_type', |
|
27 | 'rd_directory', 'raw_data_blocks', 'data_type', | |
28 | 'acq_profiles', 'profiles_block', 'fftpoints', |
|
28 | 'acq_profiles', 'profiles_block', 'fftpoints', | |
29 | 'incohe_integr', 'filter', 'spectral_number', |
|
29 | 'incohe_integr', 'filter', 'spectral_number', | |
30 | 'spectral', 'create_directory', 'include_expname', |
|
30 | 'spectral', 'create_directory', 'include_expname', | |
31 | 'acq_link', 'view_raw_data', 'save_ch_dc'] |
|
31 | 'acq_link', 'view_raw_data', 'save_ch_dc'] | |
32 |
|
32 | |||
33 | kwargs['title'] = 'JARS Configuration' |
|
33 | kwargs['title'] = 'JARS Configuration' | |
34 | kwargs['suptitle'] = 'Details' |
|
34 | kwargs['suptitle'] = 'Details' | |
35 |
|
35 | |||
36 | kwargs['button'] = 'Edit Configuration' |
|
36 | kwargs['button'] = 'Edit Configuration' | |
37 |
|
37 | |||
38 | kwargs['no_play'] = True |
|
38 | kwargs['no_play'] = True | |
39 |
|
39 | |||
40 | ###### SIDEBAR ###### |
|
40 | ###### SIDEBAR ###### | |
41 | kwargs.update(sidebar(conf=conf)) |
|
41 | kwargs.update(sidebar(conf=conf)) | |
42 |
|
42 | |||
43 | return render(request, 'jars_conf.html', kwargs) |
|
43 | return render(request, 'jars_conf.html', kwargs) | |
44 |
|
44 | |||
45 | def jars_conf_edit(request, id_conf): |
|
45 | def jars_conf_edit(request, id_conf): | |
46 |
|
46 | |||
47 | conf = get_object_or_404(JARSConfiguration, pk=id_conf) |
|
47 | conf = get_object_or_404(JARSConfiguration, pk=id_conf) | |
48 |
|
48 | |||
49 | if request.method=='GET': |
|
49 | if request.method=='GET': | |
50 | form = JARSConfigurationForm(instance=conf) |
|
50 | form = JARSConfigurationForm(instance=conf) | |
51 |
|
51 | |||
52 | if request.method=='POST': |
|
52 | if request.method=='POST': | |
53 | form = JARSConfigurationForm(request.POST, instance=conf) |
|
53 | form = JARSConfigurationForm(request.POST, instance=conf) | |
54 |
|
54 | |||
55 | if form.is_valid(): |
|
55 | if form.is_valid(): | |
56 | conf = form.save(commit=False) |
|
56 | conf = form.save(commit=False) | |
57 | conf.save() |
|
57 | conf.save() | |
58 | return redirect('url_jars_conf', id_conf=conf.id) |
|
58 | return redirect('url_jars_conf', id_conf=conf.id) | |
59 |
|
59 | |||
60 | ##ERRORS |
|
60 | ##ERRORS | |
61 |
|
61 | |||
62 | kwargs = {} |
|
62 | kwargs = {} | |
63 |
|
63 | |||
64 | kwargs['filter_id'] = conf.filter.id |
|
64 | kwargs['filter_id'] = conf.filter.id | |
65 | kwargs['id_dev'] = conf.id |
|
65 | kwargs['id_dev'] = conf.id | |
66 | kwargs['form'] = form |
|
66 | kwargs['form'] = form | |
67 | kwargs['title'] = 'Device Configuration' |
|
67 | kwargs['title'] = 'Device Configuration' | |
68 | kwargs['suptitle'] = 'Edit' |
|
68 | kwargs['suptitle'] = 'Edit' | |
69 | kwargs['button'] = 'Save' |
|
69 | kwargs['button'] = 'Save' | |
70 |
|
70 | |||
71 | return render(request, 'jars_conf_edit.html', kwargs) |
|
71 | return render(request, 'jars_conf_edit.html', kwargs) | |
72 |
|
72 | |||
73 | def view_filter(request, conf_id, filter_id): |
|
73 | def view_filter(request, conf_id, filter_id): | |
74 |
|
74 | |||
75 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
75 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) | |
76 | filter = get_object_or_404(JARSfilter, pk=filter_id) |
|
76 | filter = get_object_or_404(JARSfilter, pk=filter_id) | |
77 |
|
77 | |||
78 | filter_parms = eval(conf.filter_parms) |
|
78 | filter_parms = eval(conf.filter_parms) | |
79 | filter.name = filter_parms['name'] |
|
79 | filter.name = filter_parms['name'] | |
80 | filter.clock = filter_parms['clock'] |
|
80 | filter.clock = filter_parms['clock'] | |
81 | filter.mult = filter_parms['mult'] |
|
81 | filter.mult = filter_parms['mult'] | |
82 | filter.fch = filter_parms['fch'] |
|
82 | filter.fch = filter_parms['fch'] | |
83 | filter.filter_fir = filter_parms['filter_fir'] |
|
83 | filter.filter_fir = filter_parms['filter_fir'] | |
84 | filter.filter_2 = filter_parms['filter_2'] |
|
84 | filter.filter_2 = filter_parms['filter_2'] | |
85 | filter.filter_5 = filter_parms['filter_5'] |
|
85 | filter.filter_5 = filter_parms['filter_5'] | |
86 | filter.speed = filter_parms['speed'] |
|
86 | filter.speed = filter_parms['speed'] | |
87 |
|
87 | |||
88 | kwargs = {} |
|
88 | kwargs = {} | |
89 | kwargs['conf'] = conf |
|
89 | kwargs['conf'] = conf | |
90 | kwargs['filter'] = filter |
|
90 | kwargs['filter'] = filter | |
91 | kwargs['dev_conf'] = filter |
|
91 | kwargs['dev_conf'] = filter | |
92 | kwargs['dev_conf_keys'] = ['name', 'clock', |
|
92 | kwargs['dev_conf_keys'] = ['name', 'clock', | |
93 | 'mult', 'fch', |
|
93 | 'mult', 'fch', | |
94 | 'filter_fir', 'filter_2', |
|
94 | 'filter_fir', 'filter_2', | |
95 | 'filter_5', 'speed'] |
|
95 | 'filter_5', 'speed'] | |
96 |
|
96 | |||
97 | kwargs['title'] = 'Filter View' |
|
97 | kwargs['title'] = 'Filter View' | |
98 | kwargs['suptitle'] = 'Details' |
|
98 | kwargs['suptitle'] = 'Details' | |
99 | kwargs['button'] = 'SI' |
|
99 | kwargs['button'] = 'SI' | |
100 | kwargs['edit_button'] = 'Edit Filter' |
|
100 | kwargs['edit_button'] = 'Edit Filter' | |
101 | kwargs['add_button'] = 'Add Filter' |
|
101 | kwargs['add_button'] = 'Add Filter' | |
102 |
|
102 | |||
103 | return render(request, 'jars_filter.html', kwargs) |
|
103 | return render(request, 'jars_filter.html', kwargs) | |
104 |
|
104 | |||
105 | def edit_filter(request, conf_id, filter_id): |
|
105 | def edit_filter(request, conf_id, filter_id): | |
106 |
|
106 | |||
107 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
107 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) | |
108 | filter_parms = eval(conf.filter_parms) |
|
108 | filter_parms = eval(conf.filter_parms) | |
109 |
|
109 | |||
110 | if filter_id: |
|
110 | if filter_id: | |
111 | filter = get_object_or_404(JARSfilter, pk=filter_id) |
|
111 | filter = get_object_or_404(JARSfilter, pk=filter_id) | |
112 |
|
112 | |||
113 | if request.method=='GET': |
|
113 | if request.method=='GET': | |
114 | form = JARSfilterForm(initial=filter_parms) |
|
114 | form = JARSfilterForm(initial=filter_parms) | |
115 |
|
115 | |||
116 | if request.method=='POST': |
|
116 | if request.method=='POST': | |
117 | parms = {} |
|
117 | parms = {} | |
118 | parms['name'] = request.POST['name'] |
|
118 | parms['name'] = request.POST['name'] | |
119 | parms['clock'] = request.POST['clock'] |
|
119 | parms['clock'] = request.POST['clock'] | |
120 | parms['mult'] = request.POST['mult'] |
|
120 | parms['mult'] = request.POST['mult'] | |
121 | parms['fch'] = request.POST['fch'] |
|
121 | parms['fch'] = request.POST['fch'] | |
122 | parms['filter_fir'] = request.POST['filter_fir'] |
|
122 | parms['filter_fir'] = request.POST['filter_fir'] | |
123 | parms['filter_2'] = request.POST['filter_2'] |
|
123 | parms['filter_2'] = request.POST['filter_2'] | |
124 | parms['filter_5'] = request.POST['filter_5'] |
|
124 | parms['filter_5'] = request.POST['filter_5'] | |
125 | parms['speed'] = request.POST['speed'] |
|
125 | parms['speed'] = request.POST['speed'] | |
126 |
|
126 | |||
127 | conf.filter_parms = parms |
|
127 | conf.filter_parms = parms | |
128 | conf.save() |
|
128 | conf.save() | |
129 |
|
129 | |||
130 | #form = JARSfilterForm(request.POST) |
|
130 | #form = JARSfilterForm(request.POST) | |
131 | #form = JARSfilterForm(request.POST, instance=filter) |
|
131 | #form = JARSfilterForm(request.POST, instance=filter) | |
132 | #if form.is_valid(): |
|
132 | #if form.is_valid(): | |
133 | #form.save() |
|
133 | #form.save() | |
134 | # messages.success(request, 'JARS Filter successfully updated') |
|
134 | # messages.success(request, 'JARS Filter successfully updated') | |
135 | # return redirect('url_jars_filter', conf.id, filter.id) |
|
135 | # return redirect('url_jars_filter', conf.id, filter.id) | |
136 | return redirect('url_jars_filter', conf.id, filter.id) |
|
136 | return redirect('url_jars_filter', conf.id, filter.id) | |
137 |
|
137 | |||
138 | kwargs = {} |
|
138 | kwargs = {} | |
139 | kwargs['form'] = form |
|
139 | kwargs['form'] = form | |
140 | kwargs['title'] = conf.name |
|
140 | kwargs['title'] = conf.name | |
141 | kwargs['suptitle'] = 'Edit Filter' |
|
141 | kwargs['suptitle'] = 'Edit Filter' | |
142 | kwargs['button'] = 'Save' |
|
142 | kwargs['button'] = 'Save' | |
143 | # kwargs['previous'] = conf.get_absolute_url_edit() |
|
143 | # kwargs['previous'] = conf.get_absolute_url_edit() | |
144 | kwargs['dev_conf'] = conf |
|
144 | kwargs['dev_conf'] = conf | |
145 |
|
145 | |||
146 | return render(request, 'jars_filter_edit.html', kwargs) No newline at end of file |
|
146 | return render(request, 'jars_filter_edit.html', kwargs) |
@@ -1,10 +1,10 | |||||
1 | [ |
|
1 | [ | |
2 |
{"fields": {"name": " |
|
2 | {"fields": {"name": "JRO Imaging", "description": ""}, "model": "main.location", "pk": 1}, | |
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, |
|
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, | |
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, |
|
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, | |
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, |
|
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, | |
6 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, |
|
6 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, | |
7 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, |
|
7 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, | |
8 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, |
|
8 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, | |
9 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4} |
|
9 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4} | |
10 | ] |
|
10 | ] |
@@ -1,155 +1,190 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | |||
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
5 |
|
5 | |||
6 | FILE_FORMAT = ( |
|
6 | FILE_FORMAT = ( | |
7 | ('json', 'json'), |
|
7 | ('json', 'json'), | |
8 | ) |
|
8 | ) | |
9 |
|
9 | |||
10 | DDS_FILE_FORMAT = ( |
|
10 | DDS_FILE_FORMAT = ( | |
11 | ('json', 'json'), |
|
11 | ('json', 'json'), | |
12 | ('text', 'dds') |
|
12 | ('text', 'dds') | |
13 | ) |
|
13 | ) | |
14 |
|
14 | |||
15 | RC_FILE_FORMAT = ( |
|
15 | RC_FILE_FORMAT = ( | |
16 | ('json', 'json'), |
|
16 | ('json', 'json'), | |
17 | ('text', 'racp'), |
|
17 | ('text', 'racp'), | |
18 | ('binary', 'dat'), |
|
18 | ('binary', 'dat'), | |
19 | ) |
|
19 | ) | |
20 |
|
20 | |||
21 | def add_empty_choice(choices, pos=0, label='-----'): |
|
21 | def add_empty_choice(choices, pos=0, label='-----'): | |
22 | if len(choices)>0: |
|
22 | if len(choices)>0: | |
23 | choices = list(choices) |
|
23 | choices = list(choices) | |
24 | choices.insert(0, (0, label)) |
|
24 | choices.insert(0, (0, label)) | |
25 | return choices |
|
25 | return choices | |
26 | else: |
|
26 | else: | |
27 | return [(0, label)] |
|
27 | return [(0, label)] | |
28 |
|
28 | |||
29 | class DatepickerWidget(forms.widgets.TextInput): |
|
29 | class DatepickerWidget(forms.widgets.TextInput): | |
30 | def render(self, name, value, attrs=None): |
|
30 | def render(self, name, value, attrs=None): | |
31 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
31 | input_html = super(DatepickerWidget, self).render(name, value, attrs) | |
32 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
32 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' | |
33 | return mark_safe(html) |
|
33 | return mark_safe(html) | |
34 |
|
34 | |||
|
35 | class DateRangepickerWidget(forms.widgets.TextInput): | |||
|
36 | def render(self, name, value, attrs=None): | |||
|
37 | start = attrs['start_date'] | |||
|
38 | end = attrs['end_date'] | |||
|
39 | html = '''<div class="col-md-5 input-group date" style="float:inherit"> | |||
|
40 | <input class="form-control" id="id_start_date" name="start_date" placeholder="Start" title="" type="text" value="{}"> | |||
|
41 | <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> | |||
|
42 | </div> | |||
|
43 | <div class="col-md-5 col-md-offset-2 input-group date" style="float:inherit"> | |||
|
44 | <input class="form-control" id="id_end_date" name="end_date" placeholder="End" title="" type="text" value="{}"> | |||
|
45 | <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> | |||
|
46 | </div>'''.format(start, end) | |||
|
47 | return mark_safe(html) | |||
|
48 | ||||
35 | class TimepickerWidget(forms.widgets.TextInput): |
|
49 | class TimepickerWidget(forms.widgets.TextInput): | |
36 | def render(self, name, value, attrs=None): |
|
50 | def render(self, name, value, attrs=None): | |
37 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
51 | input_html = super(TimepickerWidget, self).render(name, value, attrs) | |
38 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
52 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' | |
39 | return mark_safe(html) |
|
53 | return mark_safe(html) | |
40 |
|
54 | |||
41 | class CampaignForm(forms.ModelForm): |
|
55 | class CampaignForm(forms.ModelForm): | |
42 |
|
56 | |||
43 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), |
|
57 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), | |
44 | queryset=Experiment.objects.filter(template=True), |
|
58 | queryset=Experiment.objects.filter(template=True), | |
45 | required=False) |
|
59 | required=False) | |
46 |
|
60 | |||
47 | def __init__(self, *args, **kwargs): |
|
61 | def __init__(self, *args, **kwargs): | |
48 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
62 | super(CampaignForm, self).__init__(*args, **kwargs) | |
49 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
63 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) | |
50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
64 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
51 | self.fields['description'].widget.attrs = {'rows': 2} |
|
65 | self.fields['description'].widget.attrs = {'rows': 2} | |
52 |
|
66 | |||
53 | if self.instance.pk: |
|
67 | if self.instance.pk: | |
54 | self.fields['experiments'].queryset |= self.instance.experiments.all() |
|
68 | self.fields['experiments'].queryset |= self.instance.experiments.all() | |
55 |
|
69 | |||
56 | class Meta: |
|
70 | class Meta: | |
57 | model = Campaign |
|
71 | model = Campaign | |
58 | exclude = [''] |
|
72 | exclude = [''] | |
59 |
|
73 | |||
60 |
|
74 | |||
61 | class ExperimentForm(forms.ModelForm): |
|
75 | class ExperimentForm(forms.ModelForm): | |
62 |
|
76 | |||
63 | def __init__(self, *args, **kwargs): |
|
77 | def __init__(self, *args, **kwargs): | |
64 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
78 | super(ExperimentForm, self).__init__(*args, **kwargs) | |
65 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
79 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
66 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
80 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
67 |
|
81 | |||
68 | class Meta: |
|
82 | class Meta: | |
69 | model = Experiment |
|
83 | model = Experiment | |
70 | exclude = ['status'] |
|
84 | exclude = ['status'] | |
71 |
|
85 | |||
72 | class LocationForm(forms.ModelForm): |
|
86 | class LocationForm(forms.ModelForm): | |
73 | class Meta: |
|
87 | class Meta: | |
74 | model = Location |
|
88 | model = Location | |
75 | exclude = [''] |
|
89 | exclude = [''] | |
76 |
|
90 | |||
77 | class DeviceForm(forms.ModelForm): |
|
91 | class DeviceForm(forms.ModelForm): | |
78 | class Meta: |
|
92 | class Meta: | |
79 | model = Device |
|
93 | model = Device | |
80 | exclude = ['status'] |
|
94 | exclude = ['status'] | |
81 |
|
95 | |||
82 | class ConfigurationForm(forms.ModelForm): |
|
96 | class ConfigurationForm(forms.ModelForm): | |
83 |
|
97 | |||
84 | def __init__(self, *args, **kwargs): |
|
98 | def __init__(self, *args, **kwargs): | |
85 | super(ConfigurationForm, self).__init__(*args, **kwargs) |
|
99 | super(ConfigurationForm, self).__init__(*args, **kwargs) | |
86 |
|
100 | |||
87 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): |
|
101 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): | |
88 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' |
|
102 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |
89 |
|
103 | |||
90 | class Meta: |
|
104 | class Meta: | |
91 | model = Configuration |
|
105 | model = Configuration | |
92 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
106 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
93 |
|
107 | |||
94 | class DeviceTypeForm(forms.Form): |
|
108 | class DeviceTypeForm(forms.Form): | |
95 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
109 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) | |
96 |
|
110 | |||
97 |
|
111 | |||
98 | class UploadFileForm(forms.Form): |
|
112 | class UploadFileForm(forms.Form): | |
99 |
|
113 | |||
100 | file = forms.FileField() |
|
114 | file = forms.FileField() | |
101 |
|
115 | |||
102 | class DownloadFileForm(forms.Form): |
|
116 | class DownloadFileForm(forms.Form): | |
103 |
|
117 | |||
104 | format = forms.ChoiceField(choices= ((0, 'json'),) ) |
|
118 | format = forms.ChoiceField(choices= ((0, 'json'),) ) | |
105 |
|
119 | |||
106 | def __init__(self, device_type, *args, **kwargs): |
|
120 | def __init__(self, device_type, *args, **kwargs): | |
107 |
|
121 | |||
108 | super(DownloadFileForm, self).__init__(*args, **kwargs) |
|
122 | super(DownloadFileForm, self).__init__(*args, **kwargs) | |
109 |
|
123 | |||
110 | self.fields['format'].choices = FILE_FORMAT |
|
124 | self.fields['format'].choices = FILE_FORMAT | |
111 |
|
125 | |||
112 | if device_type == 'dds': |
|
126 | if device_type == 'dds': | |
113 | self.fields['format'].choices = DDS_FILE_FORMAT |
|
127 | self.fields['format'].choices = DDS_FILE_FORMAT | |
114 |
|
128 | |||
115 | if device_type == 'rc': |
|
129 | if device_type == 'rc': | |
116 | self.fields['format'].choices = RC_FILE_FORMAT |
|
130 | self.fields['format'].choices = RC_FILE_FORMAT | |
117 |
|
131 | |||
118 | class OperationForm(forms.Form): |
|
132 | class OperationForm(forms.Form): | |
119 | # today = datetime.today() |
|
133 | # today = datetime.today() | |
120 | # -----Campaigns from this month------[:5] |
|
134 | # -----Campaigns from this month------[:5] | |
121 | campaign = forms.ChoiceField(label="Campaign") |
|
135 | campaign = forms.ChoiceField(label="Campaign") | |
122 |
|
136 | |||
123 | def __init__(self, *args, **kwargs): |
|
137 | def __init__(self, *args, **kwargs): | |
124 |
|
138 | |||
125 | if 'length' not in kwargs.keys(): |
|
139 | if 'length' not in kwargs.keys(): | |
126 | length = None |
|
140 | length = None | |
127 | else: |
|
141 | else: | |
128 | length = kwargs['length'] |
|
142 | length = kwargs['length'] | |
129 |
|
143 | |||
130 | kwargs.pop('length') |
|
144 | kwargs.pop('length') | |
131 |
|
145 | |||
132 | super(OperationForm, self).__init__(*args, **kwargs) |
|
146 | super(OperationForm, self).__init__(*args, **kwargs) | |
133 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] |
|
147 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] | |
134 |
|
148 | |||
|
149 | ||||
135 | class OperationSearchForm(forms.Form): |
|
150 | class OperationSearchForm(forms.Form): | |
136 | # -----ALL Campaigns------ |
|
151 | # -----ALL Campaigns------ | |
137 | campaign = forms.ChoiceField(label="Campaign") |
|
152 | campaign = forms.ChoiceField(label="Campaign") | |
138 |
|
153 | |||
139 | def __init__(self, *args, **kwargs): |
|
154 | def __init__(self, *args, **kwargs): | |
140 | super(OperationSearchForm, self).__init__(*args, **kwargs) |
|
155 | super(OperationSearchForm, self).__init__(*args, **kwargs) | |
141 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') |
|
156 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') | |
142 |
|
157 | |||
|
158 | ||||
143 | class NewForm(forms.Form): |
|
159 | class NewForm(forms.Form): | |
144 |
|
160 | |||
145 | create_from = forms.ChoiceField(choices=((0, '-----'), |
|
161 | create_from = forms.ChoiceField(choices=((0, '-----'), | |
146 | (1, 'Empty (blank)'), |
|
162 | (1, 'Empty (blank)'), | |
147 | (2, 'Template'))) |
|
163 | (2, 'Template'))) | |
148 | choose_template = forms.ChoiceField() |
|
164 | choose_template = forms.ChoiceField() | |
149 |
|
165 | |||
150 | def __init__(self, *args, **kwargs): |
|
166 | def __init__(self, *args, **kwargs): | |
151 |
|
167 | |||
152 | template_choices = kwargs.pop('template_choices', []) |
|
168 | template_choices = kwargs.pop('template_choices', []) | |
153 | super(NewForm, self).__init__(*args, **kwargs) |
|
169 | super(NewForm, self).__init__(*args, **kwargs) | |
154 | self.fields['choose_template'].choices = add_empty_choice(template_choices) |
|
170 | self.fields['choose_template'].choices = add_empty_choice(template_choices) | |
|
171 | ||||
|
172 | ||||
|
173 | class FilterForm(forms.Form): | |||
|
174 | ||||
|
175 | def __init__(self, *args, **kwargs): | |||
|
176 | extra_fields = kwargs.pop('extra_fields', []) | |||
|
177 | super(FilterForm, self).__init__(*args, **kwargs) | |||
|
178 | ||||
|
179 | for field in extra_fields: | |||
|
180 | if 'range_date' in field: | |||
|
181 | self.fields[field] = forms.CharField(required=False) | |||
|
182 | self.fields[field].widget = DateRangepickerWidget() | |||
|
183 | if 'initial' in kwargs: | |||
|
184 | self.fields[field].widget.attrs = {'start_date':kwargs['initial'].get('start_date', ''), | |||
|
185 | 'end_date':kwargs['initial'].get('end_date', '')} | |||
|
186 | elif 'template' in field: | |||
|
187 | self.fields['template'] = forms.BooleanField(required=False) | |||
|
188 | else: | |||
|
189 | self.fields[field] = forms.CharField(required=False) | |||
155 | No newline at end of file |
|
190 |
@@ -1,592 +1,602 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from datetime import datetime |
|
2 | from datetime import datetime | |
3 |
|
3 | |||
4 | from django.db import models |
|
4 | from django.db import models | |
5 | from polymorphic import PolymorphicModel |
|
5 | from polymorphic import PolymorphicModel | |
6 |
|
6 | |||
7 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | CONF_STATES = ( |
|
10 | CONF_STATES = ( | |
11 | (0, 'Disconnected'), |
|
11 | (0, 'Disconnected'), | |
12 | (1, 'Connected'), |
|
12 | (1, 'Connected'), | |
13 | (2, 'Running'), |
|
13 | (2, 'Running'), | |
14 | ) |
|
14 | ) | |
15 |
|
15 | |||
16 | EXP_STATES = ( |
|
16 | EXP_STATES = ( | |
17 | (0,'Error'), #RED |
|
17 | (0,'Error'), #RED | |
18 | (1,'Configured'), #BLUE |
|
18 | (1,'Configured'), #BLUE | |
19 | (2,'Running'), #GREEN |
|
19 | (2,'Running'), #GREEN | |
20 | (3,'Waiting'), #YELLOW |
|
20 | (3,'Waiting'), #YELLOW | |
21 | (4,'Not Configured'), #WHITE |
|
21 | (4,'Not Configured'), #WHITE | |
22 | ) |
|
22 | ) | |
23 |
|
23 | |||
24 | CONF_TYPES = ( |
|
24 | CONF_TYPES = ( | |
25 | (0, 'Active'), |
|
25 | (0, 'Active'), | |
26 | (1, 'Historical'), |
|
26 | (1, 'Historical'), | |
27 | ) |
|
27 | ) | |
28 |
|
28 | |||
29 | DEV_STATES = ( |
|
29 | DEV_STATES = ( | |
30 | (0, 'No connected'), |
|
30 | (0, 'No connected'), | |
31 | (1, 'Connected'), |
|
31 | (1, 'Connected'), | |
32 | (2, 'Configured'), |
|
32 | (2, 'Configured'), | |
33 | (3, 'Running'), |
|
33 | (3, 'Running'), | |
34 | ) |
|
34 | ) | |
35 |
|
35 | |||
36 | DEV_TYPES = ( |
|
36 | DEV_TYPES = ( | |
37 | ('', 'Select a device type'), |
|
37 | ('', 'Select a device type'), | |
38 | ('rc', 'Radar Controller'), |
|
38 | ('rc', 'Radar Controller'), | |
39 | ('rc_mix', 'Radar Controller (Mix)'), |
|
39 | ('rc_mix', 'Radar Controller (Mix)'), | |
40 | ('dds', 'Direct Digital Synthesizer'), |
|
40 | ('dds', 'Direct Digital Synthesizer'), | |
41 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
41 | ('jars', 'Jicamarca Radar Acquisition System'), | |
42 | ('usrp', 'Universal Software Radio Peripheral'), |
|
42 | ('usrp', 'Universal Software Radio Peripheral'), | |
43 | ('cgs', 'Clock Generator System'), |
|
43 | ('cgs', 'Clock Generator System'), | |
44 | ('abs', 'Automatic Beam Switching'), |
|
44 | ('abs', 'Automatic Beam Switching'), | |
45 | ) |
|
45 | ) | |
46 |
|
46 | |||
47 | DEV_PORTS = { |
|
47 | DEV_PORTS = { | |
48 | 'rc' : 2000, |
|
48 | 'rc' : 2000, | |
49 | 'rc_mix': 2000, |
|
49 | 'rc_mix': 2000, | |
50 | 'dds' : 2000, |
|
50 | 'dds' : 2000, | |
51 | 'jars' : 2000, |
|
51 | 'jars' : 2000, | |
52 | 'usrp' : 2000, |
|
52 | 'usrp' : 2000, | |
53 | 'cgs' : 8080, |
|
53 | 'cgs' : 8080, | |
54 | 'abs' : 8080 |
|
54 | 'abs' : 8080 | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | RADAR_STATES = ( |
|
57 | RADAR_STATES = ( | |
58 | (0, 'No connected'), |
|
58 | (0, 'No connected'), | |
59 | (1, 'Connected'), |
|
59 | (1, 'Connected'), | |
60 | (2, 'Configured'), |
|
60 | (2, 'Configured'), | |
61 | (3, 'Running'), |
|
61 | (3, 'Running'), | |
62 | (4, 'Scheduled'), |
|
62 | (4, 'Scheduled'), | |
63 | ) |
|
63 | ) | |
64 | # Create your models here. |
|
64 | # Create your models here. | |
65 |
|
65 | |||
66 | class Location(models.Model): |
|
66 | class Location(models.Model): | |
67 |
|
67 | |||
68 | name = models.CharField(max_length = 30) |
|
68 | name = models.CharField(max_length = 30) | |
69 | description = models.TextField(blank=True, null=True) |
|
69 | description = models.TextField(blank=True, null=True) | |
70 |
|
70 | |||
71 | class Meta: |
|
71 | class Meta: | |
72 | db_table = 'db_location' |
|
72 | db_table = 'db_location' | |
73 |
|
73 | |||
74 | def __unicode__(self): |
|
74 | def __unicode__(self): | |
75 | return u'%s' % self.name |
|
75 | return u'%s' % self.name | |
76 |
|
76 | |||
77 | def get_absolute_url(self): |
|
77 | def get_absolute_url(self): | |
78 |
return reverse('url_ |
|
78 | return reverse('url_location', args=[str(self.id)]) | |
79 |
|
79 | |||
80 |
|
80 | |||
81 | class DeviceType(models.Model): |
|
81 | class DeviceType(models.Model): | |
82 |
|
82 | |||
83 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
83 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
84 | description = models.TextField(blank=True, null=True) |
|
84 | description = models.TextField(blank=True, null=True) | |
85 |
|
85 | |||
86 | class Meta: |
|
86 | class Meta: | |
87 | db_table = 'db_device_types' |
|
87 | db_table = 'db_device_types' | |
88 |
|
88 | |||
89 | def __unicode__(self): |
|
89 | def __unicode__(self): | |
90 | return u'%s' % self.get_name_display() |
|
90 | return u'%s' % self.get_name_display() | |
91 |
|
91 | |||
92 | class Device(models.Model): |
|
92 | class Device(models.Model): | |
93 |
|
93 | |||
94 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
94 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
95 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
95 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
96 |
|
96 | |||
97 | name = models.CharField(max_length=40, default='') |
|
97 | name = models.CharField(max_length=40, default='') | |
98 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
98 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
99 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
99 | port_address = models.PositiveSmallIntegerField(default=2000) | |
100 | description = models.TextField(blank=True, null=True) |
|
100 | description = models.TextField(blank=True, null=True) | |
101 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
101 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
102 |
|
102 | |||
103 | class Meta: |
|
103 | class Meta: | |
104 | db_table = 'db_devices' |
|
104 | db_table = 'db_devices' | |
105 |
|
105 | |||
106 | def __unicode__(self): |
|
106 | def __unicode__(self): | |
107 | return u'[{}]: {}'.format(self.device_type.name.upper(), |
|
107 | return u'[{}]: {}'.format(self.device_type.name.upper(), | |
108 | self.name) |
|
108 | self.name) | |
109 |
|
109 | |||
110 | def get_status(self): |
|
110 | def get_status(self): | |
111 | return self.status |
|
111 | return self.status | |
112 |
|
112 | |||
113 | @property |
|
113 | @property | |
114 | def status_color(self): |
|
114 | def status_color(self): | |
115 | color = 'muted' |
|
115 | color = 'muted' | |
116 | if self.status == 0: |
|
116 | if self.status == 0: | |
117 | color = "danger" |
|
117 | color = "danger" | |
118 | elif self.status == 1: |
|
118 | elif self.status == 1: | |
119 | color = "warning" |
|
119 | color = "warning" | |
120 | elif self.status == 2: |
|
120 | elif self.status == 2: | |
121 | color = "info" |
|
121 | color = "info" | |
122 | elif self.status == 3: |
|
122 | elif self.status == 3: | |
123 | color = "success" |
|
123 | color = "success" | |
124 |
|
124 | |||
125 | return color |
|
125 | return color | |
126 |
|
126 | |||
127 | def get_absolute_url(self): |
|
127 | def get_absolute_url(self): | |
128 | return reverse('url_device', args=[str(self.id)]) |
|
128 | return reverse('url_device', args=[str(self.id)]) | |
129 |
|
129 | |||
130 |
|
130 | |||
131 | class Campaign(models.Model): |
|
131 | class Campaign(models.Model): | |
132 |
|
132 | |||
133 | template = models.BooleanField(default=False) |
|
133 | template = models.BooleanField(default=False) | |
134 | name = models.CharField(max_length=60, unique=True) |
|
134 | name = models.CharField(max_length=60, unique=True) | |
135 | start_date = models.DateTimeField(blank=True, null=True) |
|
135 | start_date = models.DateTimeField(blank=True, null=True) | |
136 | end_date = models.DateTimeField(blank=True, null=True) |
|
136 | end_date = models.DateTimeField(blank=True, null=True) | |
137 | tags = models.CharField(max_length=40) |
|
137 | tags = models.CharField(max_length=40) | |
138 | description = models.TextField(blank=True, null=True) |
|
138 | description = models.TextField(blank=True, null=True) | |
139 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
139 | experiments = models.ManyToManyField('Experiment', blank=True) | |
140 |
|
140 | |||
141 | class Meta: |
|
141 | class Meta: | |
142 | db_table = 'db_campaigns' |
|
142 | db_table = 'db_campaigns' | |
143 | ordering = ('name',) |
|
143 | ordering = ('name',) | |
144 |
|
144 | |||
145 | def __unicode__(self): |
|
145 | def __unicode__(self): | |
146 | return u'%s' % (self.name) |
|
146 | if self.template: | |
|
147 | return u'{} (template)'.format(self.name) | |||
|
148 | else: | |||
|
149 | return u'{}'.format(self.name) | |||
147 |
|
150 | |||
148 | def get_absolute_url(self): |
|
|||
149 | return reverse('url_campaign', args=[str(self.id)]) |
|
|||
150 |
|
151 | |||
151 | def parms_to_dict(self): |
|
152 | def parms_to_dict(self): | |
152 |
|
153 | |||
153 | import json |
|
154 | import json | |
154 |
|
155 | |||
155 | parameters = {} |
|
156 | parameters = {} | |
156 | exp_parameters = {} |
|
157 | exp_parameters = {} | |
157 | experiments = Experiment.objects.filter(campaign = self) |
|
158 | experiments = Experiment.objects.filter(campaign = self) | |
158 |
|
159 | |||
159 | i=1 |
|
160 | i=1 | |
160 | for experiment in experiments: |
|
161 | for experiment in experiments: | |
161 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) |
|
162 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) | |
162 | i += 1 |
|
163 | i += 1 | |
163 |
|
164 | |||
164 |
|
165 | |||
165 | parameters['experiments'] = exp_parameters |
|
166 | parameters['experiments'] = exp_parameters | |
166 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") |
|
167 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
167 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") |
|
168 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
168 | parameters['campaign'] = self.__unicode__() |
|
169 | parameters['campaign'] = self.__unicode__() | |
169 | parameters['tags'] =self.tags |
|
170 | parameters['tags'] =self.tags | |
170 |
|
171 | |||
171 | parameters = json.dumps(parameters, indent=2, sort_keys=False) |
|
172 | parameters = json.dumps(parameters, indent=2, sort_keys=False) | |
172 |
|
173 | |||
173 | return parameters |
|
174 | return parameters | |
174 |
|
175 | |||
175 | def import_from_file(self, fp): |
|
176 | def import_from_file(self, fp): | |
176 |
|
177 | |||
177 | import os, json |
|
178 | import os, json | |
178 |
|
179 | |||
179 | parms = {} |
|
180 | parms = {} | |
180 |
|
181 | |||
181 | path, ext = os.path.splitext(fp.name) |
|
182 | path, ext = os.path.splitext(fp.name) | |
182 |
|
183 | |||
183 | if ext == '.json': |
|
184 | if ext == '.json': | |
184 | parms = json.load(fp) |
|
185 | parms = json.load(fp) | |
185 |
|
186 | |||
186 | return parms |
|
187 | return parms | |
187 |
|
188 | |||
188 | def dict_to_parms(self, parms, CONF_MODELS): |
|
189 | def dict_to_parms(self, parms, CONF_MODELS): | |
189 |
|
190 | |||
190 | experiments = Experiment.objects.filter(campaign = self) |
|
191 | experiments = Experiment.objects.filter(campaign = self) | |
191 | configurations = Configuration.objects.filter(experiment = experiments) |
|
192 | configurations = Configuration.objects.filter(experiment = experiments) | |
192 |
|
193 | |||
193 | if configurations: |
|
194 | if configurations: | |
194 | for configuration in configurations: |
|
195 | for configuration in configurations: | |
195 | configuration.delete() |
|
196 | configuration.delete() | |
196 |
|
197 | |||
197 | if experiments: |
|
198 | if experiments: | |
198 | for experiment in experiments: |
|
199 | for experiment in experiments: | |
199 | experiment.delete() |
|
200 | experiment.delete() | |
200 |
|
201 | |||
201 | for parms_exp in parms['experiments']: |
|
202 | for parms_exp in parms['experiments']: | |
202 | location = Location.objects.get(name = parms['experiments'][parms_exp]['radar']) |
|
203 | location = Location.objects.get(name = parms['experiments'][parms_exp]['radar']) | |
203 | new_exp = Experiment( |
|
204 | new_exp = Experiment( | |
204 | name = parms['experiments'][parms_exp]['experiment'], |
|
205 | name = parms['experiments'][parms_exp]['experiment'], | |
205 | location = location, |
|
206 | location = location, | |
206 | start_time = parms['experiments'][parms_exp]['start_time'], |
|
207 | start_time = parms['experiments'][parms_exp]['start_time'], | |
207 | end_time = parms['experiments'][parms_exp]['end_time'], |
|
208 | end_time = parms['experiments'][parms_exp]['end_time'], | |
208 | ) |
|
209 | ) | |
209 | new_exp.save() |
|
210 | new_exp.save() | |
210 | new_exp.dict_to_parms(parms['experiments'][parms_exp],CONF_MODELS) |
|
211 | new_exp.dict_to_parms(parms['experiments'][parms_exp],CONF_MODELS) | |
211 | new_exp.save() |
|
212 | new_exp.save() | |
212 |
|
213 | |||
213 | self.name = parms['campaign'] |
|
214 | self.name = parms['campaign'] | |
214 | self.start_date = parms['start_date'] |
|
215 | self.start_date = parms['start_date'] | |
215 | self.end_date = parms['end_date'] |
|
216 | self.end_date = parms['end_date'] | |
216 | self.tags = parms['tags'] |
|
217 | self.tags = parms['tags'] | |
217 | self.experiments.add(new_exp) |
|
218 | self.experiments.add(new_exp) | |
218 | self.save() |
|
219 | self.save() | |
219 |
|
220 | |||
220 | return self |
|
221 | return self | |
221 |
|
222 | |||
222 | def get_absolute_url(self): |
|
223 | def get_absolute_url(self): | |
223 | return reverse('url_campaign', args=[str(self.id)]) |
|
224 | return reverse('url_campaign', args=[str(self.id)]) | |
224 |
|
225 | |||
225 | def get_absolute_url_edit(self): |
|
226 | def get_absolute_url_edit(self): | |
226 | return reverse('url_edit_campaign', args=[str(self.id)]) |
|
227 | return reverse('url_edit_campaign', args=[str(self.id)]) | |
227 |
|
228 | |||
228 | def get_absolute_url_export(self): |
|
229 | def get_absolute_url_export(self): | |
229 | return reverse('url_export_campaign', args=[str(self.id)]) |
|
230 | return reverse('url_export_campaign', args=[str(self.id)]) | |
230 |
|
231 | |||
231 | def get_absolute_url_import(self): |
|
232 | def get_absolute_url_import(self): | |
232 | return reverse('url_import_campaign', args=[str(self.id)]) |
|
233 | return reverse('url_import_campaign', args=[str(self.id)]) | |
233 |
|
234 | |||
234 |
|
235 | |||
235 |
|
236 | |||
236 | class RunningExperiment(models.Model): |
|
237 | class RunningExperiment(models.Model): | |
237 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
238 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
238 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
239 | running_experiment = models.ManyToManyField('Experiment', blank = True) | |
239 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
240 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
240 |
|
241 | |||
241 |
|
242 | |||
242 | class Experiment(models.Model): |
|
243 | class Experiment(models.Model): | |
243 |
|
244 | |||
244 | template = models.BooleanField(default=False) |
|
245 | template = models.BooleanField(default=False) | |
245 | name = models.CharField(max_length=40, default='', unique=True) |
|
246 | name = models.CharField(max_length=40, default='', unique=True) | |
246 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
247 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
247 | start_time = models.TimeField(default='00:00:00') |
|
248 | start_time = models.TimeField(default='00:00:00') | |
248 | end_time = models.TimeField(default='23:59:59') |
|
249 | end_time = models.TimeField(default='23:59:59') | |
249 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
250 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |
250 |
|
251 | |||
251 | class Meta: |
|
252 | class Meta: | |
252 | db_table = 'db_experiments' |
|
253 | db_table = 'db_experiments' | |
253 | ordering = ('template', 'name') |
|
254 | ordering = ('template', 'name') | |
254 |
|
255 | |||
255 | def __unicode__(self): |
|
256 | def __unicode__(self): | |
256 | if self.template: |
|
257 | if self.template: | |
257 | return u'%s (template)' % (self.name) |
|
258 | return u'%s (template)' % (self.name) | |
258 | else: |
|
259 | else: | |
259 | return u'%s' % (self.name) |
|
260 | return u'%s' % (self.name) | |
260 |
|
261 | |||
261 | @property |
|
262 | @property | |
262 | def radar(self): |
|
263 | def radar_system(self): | |
263 | return self.location |
|
264 | return self.location | |
264 |
|
265 | |||
265 | def clone(self, **kwargs): |
|
266 | def clone(self, **kwargs): | |
266 |
|
267 | |||
267 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
268 | confs = Configuration.objects.filter(experiment=self, type=0) | |
268 | self.pk = None |
|
269 | self.pk = None | |
269 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) |
|
270 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) | |
270 | for attr, value in kwargs.items(): |
|
271 | for attr, value in kwargs.items(): | |
271 | setattr(self, attr, value) |
|
272 | setattr(self, attr, value) | |
272 |
|
273 | |||
273 | self.save() |
|
274 | self.save() | |
274 |
|
275 | |||
275 | for conf in confs: |
|
276 | for conf in confs: | |
276 | conf.clone(experiment=self, template=False) |
|
277 | conf.clone(experiment=self, template=False) | |
277 |
|
278 | |||
278 | return self |
|
279 | return self | |
279 |
|
280 | |||
280 | def get_status(self): |
|
281 | def get_status(self): | |
281 | configurations = Configuration.objects.filter(experiment=self) |
|
282 | configurations = Configuration.objects.filter(experiment=self) | |
282 | exp_status=[] |
|
283 | exp_status=[] | |
283 | for conf in configurations: |
|
284 | for conf in configurations: | |
284 | print conf.status_device() |
|
285 | print conf.status_device() | |
285 | exp_status.append(conf.status_device()) |
|
286 | exp_status.append(conf.status_device()) | |
286 |
|
287 | |||
287 | if not exp_status: #No Configuration |
|
288 | if not exp_status: #No Configuration | |
288 | self.status = 4 |
|
289 | self.status = 4 | |
289 | self.save() |
|
290 | self.save() | |
290 | return |
|
291 | return | |
291 |
|
292 | |||
292 | total = 1 |
|
293 | total = 1 | |
293 | for e_s in exp_status: |
|
294 | for e_s in exp_status: | |
294 | total = total*e_s |
|
295 | total = total*e_s | |
295 |
|
296 | |||
296 | if total == 0: #Error |
|
297 | if total == 0: #Error | |
297 | status = 0 |
|
298 | status = 0 | |
298 | elif total == (3**len(exp_status)): #Running |
|
299 | elif total == (3**len(exp_status)): #Running | |
299 | status = 2 |
|
300 | status = 2 | |
300 | else: |
|
301 | else: | |
301 | status = 1 #Configurated |
|
302 | status = 1 #Configurated | |
302 |
|
303 | |||
303 | self.status = status |
|
304 | self.status = status | |
304 | self.save() |
|
305 | self.save() | |
305 |
|
306 | |||
306 | def status_color(self): |
|
307 | def status_color(self): | |
307 | color = 'muted' |
|
308 | color = 'muted' | |
308 | if self.status == 0: |
|
309 | if self.status == 0: | |
309 | color = "danger" |
|
310 | color = "danger" | |
310 | elif self.status == 1: |
|
311 | elif self.status == 1: | |
311 | color = "info" |
|
312 | color = "info" | |
312 | elif self.status == 2: |
|
313 | elif self.status == 2: | |
313 | color = "success" |
|
314 | color = "success" | |
314 | elif self.status == 3: |
|
315 | elif self.status == 3: | |
315 | color = "warning" |
|
316 | color = "warning" | |
316 |
|
317 | |||
317 | return color |
|
318 | return color | |
318 |
|
319 | |||
319 | def get_absolute_url(self): |
|
320 | def get_absolute_url(self): | |
320 | return reverse('url_experiment', args=[str(self.id)]) |
|
321 | return reverse('url_experiment', args=[str(self.id)]) | |
321 |
|
322 | |||
322 | def parms_to_dict(self): |
|
323 | def parms_to_dict(self): | |
323 |
|
324 | |||
324 | import json |
|
325 | import json | |
325 |
|
326 | |||
326 | configurations = Configuration.objects.filter(experiment=self) |
|
327 | configurations = Configuration.objects.filter(experiment=self) | |
327 | conf_parameters = {} |
|
328 | conf_parameters = {} | |
328 | parameters={} |
|
329 | parameters={} | |
329 |
|
330 | |||
330 | for configuration in configurations: |
|
331 | for configuration in configurations: | |
331 | if 'cgs' in configuration.device.device_type.name: |
|
332 | if 'cgs' in configuration.device.device_type.name: | |
332 | conf_parameters['cgs'] = configuration.parms_to_dict() |
|
333 | conf_parameters['cgs'] = configuration.parms_to_dict() | |
333 | if 'dds' in configuration.device.device_type.name: |
|
334 | if 'dds' in configuration.device.device_type.name: | |
334 | conf_parameters['dds'] = configuration.parms_to_dict() |
|
335 | conf_parameters['dds'] = configuration.parms_to_dict() | |
335 | if 'rc' in configuration.device.device_type.name: |
|
336 | if 'rc' in configuration.device.device_type.name: | |
336 | conf_parameters['rc'] = configuration.parms_to_dict() |
|
337 | conf_parameters['rc'] = configuration.parms_to_dict() | |
337 | if 'jars' in configuration.device.device_type.name: |
|
338 | if 'jars' in configuration.device.device_type.name: | |
338 | conf_parameters['jars'] = configuration.parms_to_dict() |
|
339 | conf_parameters['jars'] = configuration.parms_to_dict() | |
339 | if 'usrp' in configuration.device.device_type.name: |
|
340 | if 'usrp' in configuration.device.device_type.name: | |
340 | conf_parameters['usrp'] = configuration.parms_to_dict() |
|
341 | conf_parameters['usrp'] = configuration.parms_to_dict() | |
341 | if 'abs' in configuration.device.device_type.name: |
|
342 | if 'abs' in configuration.device.device_type.name: | |
342 | conf_parameters['abs'] = configuration.parms_to_dict() |
|
343 | conf_parameters['abs'] = configuration.parms_to_dict() | |
343 |
|
344 | |||
344 | parameters['configurations'] = conf_parameters |
|
345 | parameters['configurations'] = conf_parameters | |
345 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") |
|
346 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") | |
346 | parameters['start_time'] = self.start_time.strftime("%H:%M:%S") |
|
347 | parameters['start_time'] = self.start_time.strftime("%H:%M:%S") | |
347 | parameters['radar'] = self.radar.name |
|
348 | parameters['radar'] = self.radar.name | |
348 | parameters['experiment'] = self.name |
|
349 | parameters['experiment'] = self.name | |
349 | parameters = json.dumps(parameters, indent=2) |
|
350 | parameters = json.dumps(parameters, indent=2) | |
350 |
|
351 | |||
351 | return parameters |
|
352 | return parameters | |
352 |
|
353 | |||
353 | def import_from_file(self, fp): |
|
354 | def import_from_file(self, fp): | |
354 |
|
355 | |||
355 | import os, json |
|
356 | import os, json | |
356 |
|
357 | |||
357 | parms = {} |
|
358 | parms = {} | |
358 |
|
359 | |||
359 | path, ext = os.path.splitext(fp.name) |
|
360 | path, ext = os.path.splitext(fp.name) | |
360 |
|
361 | |||
361 | if ext == '.json': |
|
362 | if ext == '.json': | |
362 | parms = json.load(fp) |
|
363 | parms = json.load(fp) | |
363 |
|
364 | |||
364 | return parms |
|
365 | return parms | |
365 |
|
366 | |||
366 | def dict_to_parms(self, parms, CONF_MODELS): |
|
367 | def dict_to_parms(self, parms, CONF_MODELS): | |
367 |
|
368 | |||
368 | configurations = Configuration.objects.filter(experiment=self) |
|
369 | configurations = Configuration.objects.filter(experiment=self) | |
369 |
|
370 | |||
370 | if configurations: |
|
371 | if configurations: | |
371 | for configuration in configurations: |
|
372 | for configuration in configurations: | |
372 | configuration.delete() |
|
373 | configuration.delete() | |
373 |
|
374 | |||
374 | for conf_type in parms['configurations']: |
|
375 | for conf_type in parms['configurations']: | |
375 | #--For ABS Device: |
|
376 | #--For ABS Device: | |
376 | #--For USRP Device: |
|
377 | #--For USRP Device: | |
377 | #--For JARS Device: |
|
378 | #--For JARS Device: | |
378 | #--For RC Device: |
|
379 | #--For RC Device: | |
379 | if conf_type == 'rc': |
|
380 | if conf_type == 'rc': | |
380 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) |
|
381 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) | |
381 | DevConfModel = CONF_MODELS[conf_type] |
|
382 | DevConfModel = CONF_MODELS[conf_type] | |
382 | confrc_form = DevConfModel( |
|
383 | confrc_form = DevConfModel( | |
383 | experiment = self, |
|
384 | experiment = self, | |
384 | name = 'RC', |
|
385 | name = 'RC', | |
385 | device=device, |
|
386 | device=device, | |
386 | ) |
|
387 | ) | |
387 | confrc_form.dict_to_parms(parms['configurations']['rc']) |
|
388 | confrc_form.dict_to_parms(parms['configurations']['rc']) | |
388 | confrc_form.save() |
|
389 | confrc_form.save() | |
389 | #--For DDS Device: |
|
390 | #--For DDS Device: | |
390 | if conf_type == 'dds': |
|
391 | if conf_type == 'dds': | |
391 | device = get_object_or_404(Device, pk=parms['configurations']['dds']['device_id']) |
|
392 | device = get_object_or_404(Device, pk=parms['configurations']['dds']['device_id']) | |
392 | DevConfModel = CONF_MODELS[conf_type] |
|
393 | DevConfModel = CONF_MODELS[conf_type] | |
393 | confdds_form = DevConfModel( |
|
394 | confdds_form = DevConfModel( | |
394 | experiment = self, |
|
395 | experiment = self, | |
395 | name = 'DDS', |
|
396 | name = 'DDS', | |
396 | device=device, |
|
397 | device=device, | |
397 | ) |
|
398 | ) | |
398 | confdds_form.dict_to_parms(parms['configurations']['dds']) |
|
399 | confdds_form.dict_to_parms(parms['configurations']['dds']) | |
399 | confdds_form.save() |
|
400 | confdds_form.save() | |
400 | #--For CGS Device: |
|
401 | #--For CGS Device: | |
401 | if conf_type == 'cgs': |
|
402 | if conf_type == 'cgs': | |
402 | device = get_object_or_404(Device, pk=parms['configurations']['cgs']['device_id']) |
|
403 | device = get_object_or_404(Device, pk=parms['configurations']['cgs']['device_id']) | |
403 | DevConfModel = CONF_MODELS[conf_type] |
|
404 | DevConfModel = CONF_MODELS[conf_type] | |
404 | confcgs_form = DevConfModel( |
|
405 | confcgs_form = DevConfModel( | |
405 | experiment = self, |
|
406 | experiment = self, | |
406 | name = 'CGS', |
|
407 | name = 'CGS', | |
407 | device=device, |
|
408 | device=device, | |
408 | ) |
|
409 | ) | |
409 | confcgs_form.dict_to_parms(parms['configurations']['cgs']) |
|
410 | confcgs_form.dict_to_parms(parms['configurations']['cgs']) | |
410 | confcgs_form.save() |
|
411 | confcgs_form.save() | |
411 |
|
412 | |||
412 | location = Location.objects.get(name = parms['radar']) |
|
413 | location = Location.objects.get(name = parms['radar']) | |
413 | self.name = parms['experiment'] |
|
414 | self.name = parms['experiment'] | |
414 | self.location = location |
|
415 | self.location = location | |
415 | self.start_time = parms['start_time'] |
|
416 | self.start_time = parms['start_time'] | |
416 | self.end_time = parms['end_time'] |
|
417 | self.end_time = parms['end_time'] | |
417 | self.save() |
|
418 | self.save() | |
418 |
|
419 | |||
419 | return self |
|
420 | return self | |
420 |
|
421 | |||
421 | def get_absolute_url_edit(self): |
|
422 | def get_absolute_url_edit(self): | |
422 | return reverse('url_edit_experiment', args=[str(self.id)]) |
|
423 | return reverse('url_edit_experiment', args=[str(self.id)]) | |
423 |
|
424 | |||
424 | def get_absolute_url_import(self): |
|
425 | def get_absolute_url_import(self): | |
425 | return reverse('url_import_experiment', args=[str(self.id)]) |
|
426 | return reverse('url_import_experiment', args=[str(self.id)]) | |
426 |
|
427 | |||
427 | def get_absolute_url_export(self): |
|
428 | def get_absolute_url_export(self): | |
428 | return reverse('url_export_experiment', args=[str(self.id)]) |
|
429 | return reverse('url_export_experiment', args=[str(self.id)]) | |
429 |
|
430 | |||
430 |
|
431 | |||
431 | class Configuration(PolymorphicModel): |
|
432 | class Configuration(PolymorphicModel): | |
432 |
|
433 | |||
433 | template = models.BooleanField(default=False) |
|
434 | template = models.BooleanField(default=False) | |
434 |
|
435 | |||
435 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
436 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
436 |
|
437 | |||
437 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
438 | experiment = models.ForeignKey('Experiment', verbose_name='Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
438 | device = models.ForeignKey(Device, null=True, on_delete=models.CASCADE) |
|
439 | device = models.ForeignKey('Device', verbose_name='Device', null=True, on_delete=models.CASCADE) | |
439 |
|
440 | |||
440 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
441 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
441 |
|
442 | |||
442 | created_date = models.DateTimeField(auto_now_add=True) |
|
443 | created_date = models.DateTimeField(auto_now_add=True) | |
443 | programmed_date = models.DateTimeField(auto_now=True) |
|
444 | programmed_date = models.DateTimeField(auto_now=True) | |
444 |
|
445 | |||
445 | parameters = models.TextField(default='{}') |
|
446 | parameters = models.TextField(default='{}') | |
446 |
|
447 | |||
447 | message = "" |
|
448 | message = "" | |
448 |
|
449 | |||
449 | class Meta: |
|
450 | class Meta: | |
450 | db_table = 'db_configurations' |
|
451 | db_table = 'db_configurations' | |
451 |
|
452 | |||
452 | def __unicode__(self): |
|
453 | def __unicode__(self): | |
453 |
|
454 | |||
454 |
|
|
455 | device = '{}:'.format(self.device.device_type.name.upper()) | |
|
456 | ||||
|
457 | if 'mix' in self._meta.get_all_field_names(): | |||
|
458 | if self.mix: | |||
|
459 | device = '{} MIXED:'.format(self.device.device_type.name.upper()) | |||
|
460 | ||||
|
461 | if self.template: | |||
|
462 | return u'{} {} (template)'.format(device, self.name) | |||
|
463 | else: | |||
|
464 | return u'{} {}'.format(device, self.name) | |||
455 |
|
465 | |||
456 | def clone(self, **kwargs): |
|
466 | def clone(self, **kwargs): | |
457 |
|
467 | |||
458 | self.pk = None |
|
468 | self.pk = None | |
459 | self.id = None |
|
469 | self.id = None | |
460 | for attr, value in kwargs.items(): |
|
470 | for attr, value in kwargs.items(): | |
461 | setattr(self, attr, value) |
|
471 | setattr(self, attr, value) | |
462 |
|
472 | |||
463 | self.save() |
|
473 | self.save() | |
464 |
|
474 | |||
465 | return self |
|
475 | return self | |
466 |
|
476 | |||
467 | def parms_to_dict(self): |
|
477 | def parms_to_dict(self): | |
468 |
|
478 | |||
469 | parameters = {} |
|
479 | parameters = {} | |
470 |
|
480 | |||
471 | for key in self.__dict__.keys(): |
|
481 | for key in self.__dict__.keys(): | |
472 | parameters[key] = getattr(self, key) |
|
482 | parameters[key] = getattr(self, key) | |
473 |
|
483 | |||
474 | return parameters |
|
484 | return parameters | |
475 |
|
485 | |||
476 | def parms_to_text(self): |
|
486 | def parms_to_text(self): | |
477 |
|
487 | |||
478 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
488 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
479 |
|
489 | |||
480 | return '' |
|
490 | return '' | |
481 |
|
491 | |||
482 | def parms_to_binary(self): |
|
492 | def parms_to_binary(self): | |
483 |
|
493 | |||
484 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
494 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
485 |
|
495 | |||
486 | return '' |
|
496 | return '' | |
487 |
|
497 | |||
488 | def dict_to_parms(self, parameters): |
|
498 | def dict_to_parms(self, parameters): | |
489 |
|
499 | |||
490 | if type(parameters) != type({}): |
|
500 | if type(parameters) != type({}): | |
491 | return |
|
501 | return | |
492 |
|
502 | |||
493 | for key in parameters.keys(): |
|
503 | for key in parameters.keys(): | |
494 | setattr(self, key, parameters[key]) |
|
504 | setattr(self, key, parameters[key]) | |
495 |
|
505 | |||
496 | def export_to_file(self, format="json"): |
|
506 | def export_to_file(self, format="json"): | |
497 |
|
507 | |||
498 | import json |
|
508 | import json | |
499 |
|
509 | |||
500 | content_type = '' |
|
510 | content_type = '' | |
501 |
|
511 | |||
502 | if format == 'text': |
|
512 | if format == 'text': | |
503 | content_type = 'text/plain' |
|
513 | content_type = 'text/plain' | |
504 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
514 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
505 | content = self.parms_to_text() |
|
515 | content = self.parms_to_text() | |
506 |
|
516 | |||
507 | if format == 'binary': |
|
517 | if format == 'binary': | |
508 | content_type = 'application/octet-stream' |
|
518 | content_type = 'application/octet-stream' | |
509 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
519 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
510 | content = self.parms_to_binary() |
|
520 | content = self.parms_to_binary() | |
511 |
|
521 | |||
512 | if not content_type: |
|
522 | if not content_type: | |
513 | content_type = 'application/json' |
|
523 | content_type = 'application/json' | |
514 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
524 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |
515 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
525 | content = json.dumps(self.parms_to_dict(), indent=2) | |
516 |
|
526 | |||
517 | fields = {'content_type':content_type, |
|
527 | fields = {'content_type':content_type, | |
518 | 'filename':filename, |
|
528 | 'filename':filename, | |
519 | 'content':content |
|
529 | 'content':content | |
520 | } |
|
530 | } | |
521 |
|
531 | |||
522 | return fields |
|
532 | return fields | |
523 |
|
533 | |||
524 | def import_from_file(self, fp): |
|
534 | def import_from_file(self, fp): | |
525 |
|
535 | |||
526 | import os, json |
|
536 | import os, json | |
527 |
|
537 | |||
528 | parms = {} |
|
538 | parms = {} | |
529 |
|
539 | |||
530 | path, ext = os.path.splitext(fp.name) |
|
540 | path, ext = os.path.splitext(fp.name) | |
531 |
|
541 | |||
532 | if ext == '.json': |
|
542 | if ext == '.json': | |
533 | parms = json.load(fp) |
|
543 | parms = json.load(fp) | |
534 |
|
544 | |||
535 | return parms |
|
545 | return parms | |
536 |
|
546 | |||
537 | def status_device(self): |
|
547 | def status_device(self): | |
538 |
|
548 | |||
539 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
549 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
540 |
|
550 | |||
541 | return None |
|
551 | return None | |
542 |
|
552 | |||
543 | def stop_device(self): |
|
553 | def stop_device(self): | |
544 |
|
554 | |||
545 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
555 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
546 |
|
556 | |||
547 | return None |
|
557 | return None | |
548 |
|
558 | |||
549 | def start_device(self): |
|
559 | def start_device(self): | |
550 |
|
560 | |||
551 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
561 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
552 |
|
562 | |||
553 | return None |
|
563 | return None | |
554 |
|
564 | |||
555 | def write_device(self, parms): |
|
565 | def write_device(self, parms): | |
556 |
|
566 | |||
557 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
567 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
558 |
|
568 | |||
559 | return None |
|
569 | return None | |
560 |
|
570 | |||
561 | def read_device(self): |
|
571 | def read_device(self): | |
562 |
|
572 | |||
563 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
573 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
564 |
|
574 | |||
565 | return None |
|
575 | return None | |
566 |
|
576 | |||
567 | def get_absolute_url(self): |
|
577 | def get_absolute_url(self): | |
568 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
578 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
569 |
|
579 | |||
570 | def get_absolute_url_edit(self): |
|
580 | def get_absolute_url_edit(self): | |
571 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
581 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
572 |
|
582 | |||
573 | def get_absolute_url_import(self): |
|
583 | def get_absolute_url_import(self): | |
574 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
584 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
575 |
|
585 | |||
576 | def get_absolute_url_export(self): |
|
586 | def get_absolute_url_export(self): | |
577 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
587 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
578 |
|
588 | |||
579 | def get_absolute_url_write(self): |
|
589 | def get_absolute_url_write(self): | |
580 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
590 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
581 |
|
591 | |||
582 | def get_absolute_url_read(self): |
|
592 | def get_absolute_url_read(self): | |
583 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
593 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
584 |
|
594 | |||
585 | def get_absolute_url_start(self): |
|
595 | def get_absolute_url_start(self): | |
586 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
596 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
587 |
|
597 | |||
588 | def get_absolute_url_stop(self): |
|
598 | def get_absolute_url_stop(self): | |
589 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
599 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
590 |
|
600 | |||
591 | def get_absolute_url_status(self): |
|
601 | def get_absolute_url_status(self): | |
592 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
|
602 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,141 +1,143 | |||||
1 | <!DOCTYPE html> |
|
1 | <!DOCTYPE html> | |
2 | {% load static %} |
|
2 | {% load static %} | |
3 | <html lang="en"> |
|
3 | <html lang="en"> | |
4 | <head> |
|
4 | <head> | |
5 | <meta charset="utf-8"> |
|
5 | <meta charset="utf-8"> | |
6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> |
|
6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> | |
7 | <meta name="description" content=""> |
|
7 | <meta name="description" content=""> | |
8 | <meta name="author" content=""> |
|
8 | <meta name="author" content=""> | |
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
10 | {# bootstrap_css #} |
|
10 | {# bootstrap_css #} | |
11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> |
|
11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> | |
12 | <style type="text/css"> |
|
12 | <style type="text/css"> | |
13 | body {padding-top: 60px} |
|
13 | body {padding-top: 60px} | |
14 | .logo {padding-top: 5px; height: 50px} |
|
14 | .logo {padding-top: 5px; height: 50px} | |
15 | .clickable-row {cursor: pointer;} |
|
15 | .clickable-row {cursor: pointer;} | |
16 | .col-no-padding { padding-left:0;} |
|
16 | .col-no-padding { padding-left:0;} | |
17 | .gi-2x{font-size: 2em;} |
|
17 | .gi-2x{font-size: 2em;} | |
18 | .gi-3x{font-size: 3em;} |
|
18 | .gi-3x{font-size: 3em;} | |
19 | .gi-4x{font-size: 4em;} |
|
19 | .gi-4x{font-size: 4em;} | |
20 | .gi-5x{font-size: 5em;} |
|
20 | .gi-5x{font-size: 5em;} | |
21 | </style> |
|
21 | </style> | |
22 | <!--[if lt IE 9]> |
|
22 | <!--[if lt IE 9]> | |
23 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> |
|
23 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
24 | <![endif]--> |
|
24 | <![endif]--> | |
25 | <script src="{% static 'js/jquery.min.js' %}"></script> |
|
25 | <script src="{% static 'js/jquery.min.js' %}"></script> | |
26 | {% block extra-head %} |
|
26 | {% block extra-head %} | |
27 | {% endblock %} |
|
27 | {% endblock %} | |
28 | </head> |
|
28 | </head> | |
29 |
|
29 | |||
30 | <body> |
|
30 | <body> | |
31 |
|
31 | |||
32 | {% block main_menu %} |
|
32 | {% block main_menu %} | |
33 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> |
|
33 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> | |
34 | <div class="container-fluid"> |
|
34 | <div class="container-fluid"> | |
35 | <div class="navbar-header"> |
|
35 | <div class="navbar-header"> | |
36 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> |
|
36 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> | |
37 | <span class="sr-only">Toggle navigation</span> |
|
37 | <span class="sr-only">Toggle navigation</span> | |
38 | <span class="icon-bar"></span> |
|
38 | <span class="icon-bar"></span> | |
39 | <span class="icon-bar"></span> |
|
39 | <span class="icon-bar"></span> | |
40 | <span class="icon-bar"></span> |
|
40 | <span class="icon-bar"></span> | |
41 | </button> |
|
41 | </button> | |
42 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> |
|
42 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> | |
43 | </div> |
|
43 | </div> | |
44 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
44 | <div class="collapse navbar-collapse" id="navigationbar"> | |
45 | <ul class="nav navbar-nav"> |
|
45 | <ul class="nav navbar-nav"> | |
46 | <li class=" dropdown {% block operation-active %}{% endblock %}"><a href="{% url 'url_operation'%}">Operation</a> |
|
46 | <li class=" dropdown {% block operation-active %}{% endblock %}"><a href="{% url 'url_operation'%}">Operation</a> | |
47 | </li> |
|
47 | </li> | |
48 | <li class=" dropdown {% block new-active %}{% endblock %}"> |
|
48 | <li class=" dropdown {% block new-active %}{% endblock %}"> | |
49 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">New<span class="caret"></span></a> |
|
49 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">New<span class="caret"></span></a> | |
50 | <ul class="dropdown-menu" role="menu"> |
|
50 | <ul class="dropdown-menu" role="menu"> | |
51 | <li><a href="{% url 'url_add_campaign' %}">Campaign</a></li> |
|
51 | <li><a href="{% url 'url_add_campaign' %}">Campaign</a></li> | |
52 | <li><a href="{% url 'url_add_experiment' %}">Experiment</a></li> |
|
52 | <li><a href="{% url 'url_add_experiment' %}">Experiment</a></li> | |
53 | <li><a href="{% url 'url_add_dev_conf' 0%}">Device Configuration</a></li> |
|
53 | <li><a href="{% url 'url_add_dev_conf' 0%}">Device Configuration</a></li> | |
54 | <li><a href="{% url 'url_add_device'%}">Device</a></li> |
|
54 | <li><a href="{% url 'url_add_device'%}">Device</a></li> | |
|
55 | <li><a href="{% url 'url_add_location'%}">Radar System</a></li> | |||
55 | </ul> |
|
56 | </ul> | |
56 | </li> |
|
57 | </li> | |
57 | <li class=" dropdown {% block search-active %}{% endblock %}"> |
|
58 | <li class=" dropdown {% block search-active %}{% endblock %}"> | |
58 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Search<span class="caret"></span></a> |
|
59 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Search<span class="caret"></span></a> | |
59 | <ul class="dropdown-menu" role="menu"> |
|
60 | <ul class="dropdown-menu" role="menu"> | |
60 | <li><a href="{% url 'url_campaigns' %}">Campaigns</a></li> |
|
61 | <li><a href="{% url 'url_campaigns' %}">Campaigns</a></li> | |
61 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> |
|
62 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> | |
62 | <li><a href="{% url 'url_dev_confs' %}">Configurations</a></li> |
|
63 | <li><a href="{% url 'url_dev_confs' %}">Configurations</a></li> | |
63 | <li><a href="{% url 'url_devices' %}">Devices</a></li> |
|
64 | <li><a href="{% url 'url_devices' %}">Devices</a></li> | |
|
65 | <li><a href="{% url 'url_locations' %}">Radar Systems</a></li> | |||
64 | </ul> |
|
66 | </ul> | |
65 | </li> |
|
67 | </li> | |
66 | </ul> |
|
68 | </ul> | |
67 | <ul class="nav navbar-nav navbar-right"> |
|
69 | <ul class="nav navbar-nav navbar-right"> | |
68 | <li class="nav-divider"></li> |
|
70 | <li class="nav-divider"></li> | |
69 | {% if user.is_authenticated %} |
|
71 | {% if user.is_authenticated %} | |
70 | <li class="dropdown"> |
|
72 | <li class="dropdown"> | |
71 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> |
|
73 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> | |
72 | <ul class="dropdown-menu" role="menu"> |
|
74 | <ul class="dropdown-menu" role="menu"> | |
73 | <li><a href="#">Control Panel</a></li> |
|
75 | <li><a href="#">Control Panel</a></li> | |
74 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> |
|
76 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> | |
75 | </ul> |
|
77 | </ul> | |
76 | </li> |
|
78 | </li> | |
77 | {% else %} |
|
79 | {% else %} | |
78 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> |
|
80 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> | |
79 | {% endif %} |
|
81 | {% endif %} | |
80 | </ul> |
|
82 | </ul> | |
81 | </div> |
|
83 | </div> | |
82 | </div> |
|
84 | </div> | |
83 | </nav> |
|
85 | </nav> | |
84 | <div style="clear: both;"></div> |
|
86 | <div style="clear: both;"></div> | |
85 | {% endblock %} |
|
87 | {% endblock %} | |
86 |
|
88 | |||
87 | <div class="container"> |
|
89 | <div class="container"> | |
88 | <div id="page" class="row" style="min-height:600px"> |
|
90 | <div id="page" class="row" style="min-height:600px"> | |
89 |
|
91 | |||
90 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> |
|
92 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> | |
91 | <br><br> |
|
93 | <br><br> | |
92 | <div id="sidebar"> |
|
94 | <div id="sidebar"> | |
93 | {% block sidebar%} |
|
95 | {% block sidebar%} | |
94 | {% endblock %} |
|
96 | {% endblock %} | |
95 | </div> |
|
97 | </div> | |
96 | </div> |
|
98 | </div> | |
97 |
|
99 | |||
98 | <div class="col-md-9 col-xs-12" role="main"> |
|
100 | <div class="col-md-9 col-xs-12" role="main"> | |
99 | <div class="page-header"> |
|
101 | <div class="page-header"> | |
100 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> |
|
102 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> | |
101 | </div> |
|
103 | </div> | |
102 | {% block messages %} |
|
104 | {% block messages %} | |
103 | {% if messages %} |
|
105 | {% if messages %} | |
104 | {% for message in messages %} |
|
106 | {% for message in messages %} | |
105 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> |
|
107 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> | |
106 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> |
|
108 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> | |
107 | <strong>{{message.tags|title}}!</strong> {{ message }} |
|
109 | <strong>{{message.tags|title}}!</strong> {{ message }} | |
108 | </div> |
|
110 | </div> | |
109 | {% endfor %} |
|
111 | {% endfor %} | |
110 | {% endif %} |
|
112 | {% endif %} | |
111 | {% endblock %} |
|
113 | {% endblock %} | |
112 |
|
114 | |||
113 | {% block content %} |
|
115 | {% block content %} | |
114 | {% endblock %} |
|
116 | {% endblock %} | |
115 |
|
117 | |||
116 | </div> |
|
118 | </div> | |
117 |
|
119 | |||
118 | </div><!--/row--> |
|
120 | </div><!--/row--> | |
119 | </div> <!-- container --> |
|
121 | </div> <!-- container --> | |
120 |
|
122 | |||
121 | <div id="debug">{{debug}}</div> |
|
123 | <div id="debug">{{debug}}</div> | |
122 |
|
124 | |||
123 | {% block footer %} |
|
125 | {% block footer %} | |
124 | <footer class="footer"> |
|
126 | <footer class="footer"> | |
125 | <div class="container"> |
|
127 | <div class="container"> | |
126 | <p><hr></p> |
|
128 | <p><hr></p> | |
127 | <p> |
|
129 | <p> | |
128 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} |
|
130 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} | |
129 | </p> |
|
131 | </p> | |
130 | </div> |
|
132 | </div> | |
131 | </footer> |
|
133 | </footer> | |
132 | {% endblock %} |
|
134 | {% endblock %} | |
133 |
|
135 | |||
134 | {# bootstrap_javascript jquery=True #} |
|
136 | {# bootstrap_javascript jquery=True #} | |
135 |
|
137 | |||
136 | <script src="{% static 'js/bootstrap.min.js' %}"></script> |
|
138 | <script src="{% static 'js/bootstrap.min.js' %}"></script> | |
137 | {% block extra-js %} |
|
139 | {% block extra-js %} | |
138 | {% endblock%} |
|
140 | {% endblock%} | |
139 | </body> |
|
141 | </body> | |
140 | </html> |
|
142 | </html> | |
141 |
|
143 |
@@ -1,46 +1,73 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
|
5 | ||||
5 | {% block extra-head %} |
|
6 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
8 | {% endblock %} | |
8 |
|
9 | |||
9 |
{% block |
|
10 | {% block search-active %}active{% endblock %} | |
10 |
|
||||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
|
15 | ||||
|
16 | {% block content-filter %} | |||
|
17 | {% if form %} | |||
|
18 | <form class="form" method="get"> | |||
|
19 | {% bootstrap_form form layout='horizontal' size='medium' %} | |||
|
20 | <div class="pull-right"> | |||
|
21 | <button type="button" class="btn btn-primary" onclick="window.location.replace('?');"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></button> | |||
|
22 | <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button> | |||
|
23 | </div> | |||
|
24 | </form> | |||
|
25 | {% endif %} | |||
|
26 | {% endblock %} | |||
|
27 | <br><br> | |||
15 | <table class="table table-hover"> |
|
28 | <table class="table table-hover"> | |
16 | <tr> |
|
29 | <tr> | |
17 |
|
|
30 | <th>#</th> | |
18 |
|
|
31 | {% for key in keys %} | |
19 |
|
|
32 | <th>{{ key|title }}</th> | |
20 |
|
|
33 | {% endfor%} | |
21 | </tr> |
|
34 | </tr> | |
22 |
{% for |
|
35 | {% for object in objects %} | |
23 |
|
|
36 | <tr class="clickable-row" data-href="{{object.get_absolute_url}}"> | |
24 |
|
|
37 | <td>{{ forloop.counter|add:offset }}</td> | |
25 |
|
|
38 | {% for key in keys %} | |
26 |
|
|
39 | <td>{{ object|attr:key }}</td> | |
27 |
|
|
40 | {% endfor %} | |
28 |
|
|
41 | </tr> | |
29 | {% endfor %} |
|
42 | {% endfor %} | |
30 | </table> |
|
43 | </table> | |
31 |
|
44 | |||
32 | {% endblock %} |
|
45 | <div class="pagination"> | |
|
46 | <span class="step-links"> | |||
|
47 | {% if objects.has_previous %} | |||
|
48 | <a href="?page={{ objects.previous_page_number }}&{{q}}"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span></a> | |||
|
49 | {% endif %} | |||
|
50 | <span class="current"> | |||
|
51 | Page {{ objects.number }} of {{ objects.paginator.num_pages }}. | |||
|
52 | </span> | |||
|
53 | {% if objects.has_next %} | |||
|
54 | <a href="?page={{ objects.next_page_number }}&{{q}}"><span class="glyphicon glyphicon-menu-right aria-hidden="true"></span></a> | |||
|
55 | {% endif %} | |||
|
56 | </span> | |||
|
57 | </div> | |||
33 |
|
58 | |||
34 | {% block sidebar%} |
|
|||
35 | {% include "sidebar_devices.html" %} |
|
|||
36 | {% endblock %} |
|
59 | {% endblock %} | |
37 |
|
60 | |||
38 | {% block extra-js%} |
|
61 | {% block extra-js%} | |
|
62 | <script src="{% static 'js/moment.min.js' %}"></script> | |||
|
63 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> | |||
39 | <script type="text/javascript"> |
|
64 | <script type="text/javascript"> | |
40 |
|
65 | |||
|
66 | $('.input-group.date').datetimepicker({"format": "YYYY-MM-DD"}); | |||
|
67 | ||||
41 | $(".clickable-row").click(function() { |
|
68 | $(".clickable-row").click(function() { | |
42 |
|
|
69 | document.location = $(this).data("href"); | |
43 | }); |
|
70 | }); | |
44 |
|
71 | |||
45 | </script> |
|
72 | </script> | |
46 | {% endblock %} No newline at end of file |
|
73 | {% endblock %} |
@@ -1,149 +1,151 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 | {% block camp-active %}active{% endblock %} |
|
9 | {% block camp-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
15 |
|
15 | |||
16 | <!-- Not Empty--> |
|
16 | <!-- Not Empty--> | |
17 | {% if details %} |
|
17 | {% if details %} | |
18 |
|
18 | |||
19 | <form class="form" method="post" action=""> |
|
19 | <form class="form" method="post" action=""> | |
20 | {% csrf_token %} |
|
20 | {% csrf_token %} | |
21 |
|
21 | |||
22 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
22 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
23 | <div style="clear: both;"></div> |
|
23 | <div style="clear: both;"></div> | |
24 | <br> |
|
24 | <br> | |
25 | <!-- For deep search --> |
|
25 | <!-- For deep search --> | |
26 | {% if search_button == True %} |
|
26 | {% if search_button == True %} | |
27 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> |
|
27 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> | |
28 | {% endif %} |
|
28 | {% endif %} | |
29 | <br> |
|
29 | <br> | |
30 | <br> |
|
30 | <br> | |
31 | </form> |
|
31 | </form> | |
32 | <br> |
|
32 | <br> | |
33 | <br> |
|
33 | <br> | |
34 |
|
34 | |||
35 | {% endif %} |
|
35 | {% endif %} | |
36 |
|
36 | <div class="clearfix"></div> | ||
|
37 | <h2>Radar Systems</h2> | |||
|
38 | <br> | |||
37 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
39 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > | |
38 |
|
40 | |||
39 | {% for location in locations %} |
|
41 | {% for location in locations %} | |
40 |
|
42 | |||
41 | <div class="panel panel-default"> |
|
43 | <div class="panel panel-default"> | |
42 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
44 | <div class="panel-heading" role="tab" id="headingTwo"> | |
43 | <h4 class="panel-title"> |
|
45 | <h4 class="panel-title"> | |
44 |
|
46 | |||
45 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> |
|
47 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> | |
46 |
{{location.name}}: Experiment |
|
48 | {{location.name}}: Experiments | |
47 | <span> |
|
49 | <span> | |
48 | </span> |
|
50 | </span> | |
49 | </a> |
|
51 | </a> | |
50 |
|
52 | |||
51 | <button type="button" name="bt_play" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_play' campaign.id location.id %}" style="margin-left: 10px"> |
|
53 | <button type="button" name="bt_play" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_play' campaign.id location.id %}" style="margin-left: 10px"> | |
52 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> |
|
54 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> | |
53 | </button> |
|
55 | </button> | |
54 | <button type="button" name="bt_stop" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_stop' campaign.id location.id %}" aria-label="Left Align" style="margin-left: 10px"> |
|
56 | <button type="button" name="bt_stop" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_stop' campaign.id location.id %}" aria-label="Left Align" style="margin-left: 10px"> | |
55 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> |
|
57 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> | |
56 | </button> |
|
58 | </button> | |
57 | <button type="button" name="bt_refresh" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_refresh' campaign.id location.id %}" aria-label="Left Align" style="margin-left: 10px"> |
|
59 | <button type="button" name="bt_refresh" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_refresh' campaign.id location.id %}" aria-label="Left Align" style="margin-left: 10px"> | |
58 | <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> |
|
60 | <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> | |
59 | </button> |
|
61 | </button> | |
60 | </h4> |
|
62 | </h4> | |
61 | </div> |
|
63 | </div> | |
62 |
|
64 | |||
63 | <div id="collapseTwo-{{ location.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
65 | <div id="collapseTwo-{{ location.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
64 | <div class="panel-body"> |
|
66 | <div class="panel-body"> | |
65 | <table class="table table-hover"> |
|
67 | <table class="table table-hover"> | |
66 | <tr> |
|
68 | <tr> | |
67 | <th>#</th> |
|
69 | <th>#</th> | |
68 | {% for header in experiment_keys %} |
|
70 | {% for header in experiment_keys %} | |
69 | <th>{{ header|title }}</th> |
|
71 | <th>{{ header|title }}</th> | |
70 | {% endfor%} |
|
72 | {% endfor%} | |
71 | </tr> |
|
73 | </tr> | |
72 |
|
74 | |||
73 | {% for item in experiments %} |
|
75 | {% for item in experiments %} | |
74 | {% if location.name in item.location.name %} |
|
76 | {% if location.name in item.location.name %} | |
75 |
|
77 | |||
76 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > |
|
78 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > | |
77 | <td>{{ forloop.counter }}</td> |
|
79 | <td>{{ forloop.counter }}</td> | |
78 | {% for key in experiment_keys %} |
|
80 | {% for key in experiment_keys %} | |
79 | {% if 'status' in key %} |
|
81 | {% if 'status' in key %} | |
80 | <td class="text-{{item.status_color}}">{{ item|value:key }}</td> |
|
82 | <td class="text-{{item.status_color}}">{{ item|value:key }}</td> | |
81 | {% else %} |
|
83 | {% else %} | |
82 | <td>{{ item|value:key }}</td> |
|
84 | <td>{{ item|value:key }}</td> | |
83 | {% endif %} |
|
85 | {% endif %} | |
84 | {% endfor %} |
|
86 | {% endfor %} | |
85 | </tr> |
|
87 | </tr> | |
86 | {% endif %} |
|
88 | {% endif %} | |
87 | {% endfor %} |
|
89 | {% endfor %} | |
88 | </table> |
|
90 | </table> | |
89 | </div> |
|
91 | </div> | |
90 | </div> |
|
92 | </div> | |
91 | </div> |
|
93 | </div> | |
92 | {% endfor %} |
|
94 | {% endfor %} | |
93 | </div> |
|
95 | </div> | |
94 |
|
96 | |||
95 |
|
97 | |||
96 |
|
98 | |||
97 | {% endblock %} |
|
99 | {% endblock %} | |
98 |
|
100 | |||
99 |
|
101 | |||
100 |
|
102 | |||
101 | {% block extra-js%} |
|
103 | {% block extra-js%} | |
102 | <script type="text/javascript"> |
|
104 | <script type="text/javascript"> | |
103 |
|
105 | |||
104 | //--------For PLAY Button------- |
|
106 | //--------For PLAY Button------- | |
105 | $("#accordion").on("click", "button[name=bt_play]", function(){ |
|
107 | $("#accordion").on("click", "button[name=bt_play]", function(){ | |
106 | //alert($(this).data('url')); |
|
108 | //alert($(this).data('url')); | |
107 | document.location = $(this).data('url'); |
|
109 | document.location = $(this).data('url'); | |
108 | }); |
|
110 | }); | |
109 |
|
111 | |||
110 | //--------For STOP Button------- |
|
112 | //--------For STOP Button------- | |
111 | $("#accordion").on("click", "button[name=bt_stop]", function(){ |
|
113 | $("#accordion").on("click", "button[name=bt_stop]", function(){ | |
112 | //alert($(this).data('url')); |
|
114 | //alert($(this).data('url')); | |
113 | document.location = $(this).data('url'); |
|
115 | document.location = $(this).data('url'); | |
114 | }); |
|
116 | }); | |
115 |
|
117 | |||
116 | //--------For REFRESH Button------- |
|
118 | //--------For REFRESH Button------- | |
117 | $("#accordion").on("click", "button[name=bt_refresh]", function(){ |
|
119 | $("#accordion").on("click", "button[name=bt_refresh]", function(){ | |
118 | document.location = $(this).data('url'); |
|
120 | document.location = $(this).data('url'); | |
119 | }); |
|
121 | }); | |
120 |
|
122 | |||
121 | $(".clickable-row").click(function() { |
|
123 | $(".clickable-row").click(function() { | |
122 | document.location = $(this).data("href"); |
|
124 | document.location = $(this).data("href"); | |
123 | }); |
|
125 | }); | |
124 |
|
126 | |||
125 | {% if search_button == True %} |
|
127 | {% if search_button == True %} | |
126 | $(document).ready(function() { |
|
128 | $(document).ready(function() { | |
127 | $("#id_campaign").change(function() { |
|
129 | $("#id_campaign").change(function() { | |
128 | var id_camp = document.getElementById("id_campaign").value; |
|
130 | var id_camp = document.getElementById("id_campaign").value; | |
129 | //alert(id_camp); |
|
131 | //alert(id_camp); | |
130 | document.location = "{% url 'url_operation'%}"+String(id_camp); |
|
132 | document.location = "{% url 'url_operation'%}"+String(id_camp); | |
131 | }); |
|
133 | }); | |
132 | }); |
|
134 | }); | |
133 | {% else %} |
|
135 | {% else %} | |
134 | $(document).ready(function() { |
|
136 | $(document).ready(function() { | |
135 | $("#id_campaign").change(function() { |
|
137 | $("#id_campaign").change(function() { | |
136 | var id_camp = document.getElementById("id_campaign").value; |
|
138 | var id_camp = document.getElementById("id_campaign").value; | |
137 | //alert(id_camp); |
|
139 | //alert(id_camp); | |
138 | document.location = "{% url 'url_operation_search'%}"+String(id_camp); |
|
140 | document.location = "{% url 'url_operation_search'%}"+String(id_camp); | |
139 | }); |
|
141 | }); | |
140 | }); |
|
142 | }); | |
141 | {% endif %} |
|
143 | {% endif %} | |
142 |
|
144 | |||
143 | $("#button-1").click(function() { |
|
145 | $("#button-1").click(function() { | |
144 | document.location = "{% url 'url_operation_search' %}"; |
|
146 | document.location = "{% url 'url_operation_search' %}"; | |
145 | }); |
|
147 | }); | |
146 |
|
148 | |||
147 |
|
149 | |||
148 | </script> |
|
150 | </script> | |
149 | {% endblock %} No newline at end of file |
|
151 | {% endblock %} |
@@ -1,39 +1,42 | |||||
1 | from django.template.defaulttags import register |
|
1 | from django.template.defaulttags import register | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | |||
4 | @register.filter |
|
4 | @register.filter | |
5 | def attr(instance, key): |
|
5 | def attr(instance, key): | |
6 |
|
6 | |||
7 | display_key = "get_" + key + "_display" |
|
7 | display_key = "get_" + key + "_display" | |
8 |
|
8 | |||
|
9 | if key=='name': | |||
|
10 | return '{}'.format(instance) | |||
|
11 | ||||
9 | if hasattr(instance, display_key): |
|
12 | if hasattr(instance, display_key): | |
10 | return getattr(instance, display_key)() |
|
13 | return getattr(instance, display_key)() | |
11 |
|
14 | |||
12 | if hasattr(instance, key): |
|
15 | if hasattr(instance, key): | |
13 | return getattr(instance, key) |
|
16 | return getattr(instance, key) | |
14 |
|
17 | |||
15 | return instance.get(key) |
|
18 | return instance.get(key) | |
16 |
|
19 | |||
17 | @register.filter |
|
20 | @register.filter | |
18 | def title(s): |
|
21 | def title(s): | |
19 | return s.split('__')[-1].replace('_', ' ').title() |
|
22 | return s.split('__')[-1].replace('_', ' ').title() | |
20 |
|
23 | |||
21 | @register.filter |
|
24 | @register.filter | |
22 | def value(instance, key): |
|
25 | def value(instance, key): | |
23 |
|
26 | |||
24 | item = instance |
|
27 | item = instance | |
25 | if key=='name': |
|
28 | if key=='name': | |
26 | return '%s' % item |
|
29 | return '%s' % item | |
27 | for my_key in key.split("__"): |
|
30 | for my_key in key.split("__"): | |
28 | item = attr(item, my_key) |
|
31 | item = attr(item, my_key) | |
29 |
|
32 | |||
30 | return item |
|
33 | return item | |
31 |
|
34 | |||
32 | @register.simple_tag |
|
35 | @register.simple_tag | |
33 | def get_verbose_field_name(instance, field_name): |
|
36 | def get_verbose_field_name(instance, field_name): | |
34 | """ |
|
37 | """ | |
35 | Returns verbose_name for a field. |
|
38 | Returns verbose_name for a field. | |
36 | """ |
|
39 | """ | |
37 | if field_name=='ipp_unit': |
|
40 | if field_name=='ipp_unit': | |
38 |
return 'I |
|
41 | return 'IPP [Km(Units)]' | |
39 | return mark_safe(instance._meta.get_field(field_name).verbose_name) No newline at end of file |
|
42 | return mark_safe(instance._meta.get_field(field_name).verbose_name) |
@@ -1,1383 +1,1429 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 | from django.http import HttpResponseRedirect |
|
3 | from django.http import HttpResponseRedirect | |
4 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
|
5 | from django.db.models import Q | |||
|
6 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | |||
5 | from django.contrib import messages |
|
7 | from django.contrib import messages | |
6 | from datetime import datetime |
|
8 | from datetime import datetime | |
|
9 | import urllib | |||
7 |
|
10 | |||
8 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
11 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
9 | from .forms import OperationSearchForm |
|
12 | from .forms import OperationSearchForm, FilterForm | |
10 | from apps.cgs.forms import CGSConfigurationForm |
|
13 | from apps.cgs.forms import CGSConfigurationForm | |
11 | from apps.jars.forms import JARSConfigurationForm |
|
14 | from apps.jars.forms import JARSConfigurationForm | |
12 | from apps.usrp.forms import USRPConfigurationForm |
|
15 | from apps.usrp.forms import USRPConfigurationForm | |
13 | from apps.abs.forms import ABSConfigurationForm |
|
16 | from apps.abs.forms import ABSConfigurationForm | |
14 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm |
|
17 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm | |
15 | from apps.dds.forms import DDSConfigurationForm |
|
18 | from apps.dds.forms import DDSConfigurationForm | |
16 |
|
19 | |||
17 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
20 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
18 | from apps.cgs.models import CGSConfiguration |
|
21 | from apps.cgs.models import CGSConfiguration | |
19 | from apps.jars.models import JARSConfiguration |
|
22 | from apps.jars.models import JARSConfiguration | |
20 | from apps.usrp.models import USRPConfiguration |
|
23 | from apps.usrp.models import USRPConfiguration | |
21 | from apps.abs.models import ABSConfiguration |
|
24 | from apps.abs.models import ABSConfiguration | |
22 | from apps.rc.models import RCConfiguration, RCLine, RCLineType |
|
25 | from apps.rc.models import RCConfiguration, RCLine, RCLineType | |
23 | from apps.dds.models import DDSConfiguration |
|
26 | from apps.dds.models import DDSConfiguration | |
|
27 | from django.http.request import QueryDict | |||
24 |
|
28 | |||
25 | # Create your views here. |
|
29 | # Create your views here. | |
26 |
|
30 | |||
27 | CONF_FORMS = { |
|
31 | CONF_FORMS = { | |
28 | 'rc': RCConfigurationForm, |
|
32 | 'rc': RCConfigurationForm, | |
29 | 'dds': DDSConfigurationForm, |
|
33 | 'dds': DDSConfigurationForm, | |
30 | 'jars': JARSConfigurationForm, |
|
34 | 'jars': JARSConfigurationForm, | |
31 | 'cgs': CGSConfigurationForm, |
|
35 | 'cgs': CGSConfigurationForm, | |
32 | 'abs': ABSConfigurationForm, |
|
36 | 'abs': ABSConfigurationForm, | |
33 | 'usrp': USRPConfigurationForm, |
|
37 | 'usrp': USRPConfigurationForm, | |
34 | } |
|
38 | } | |
35 |
|
39 | |||
36 | CONF_MODELS = { |
|
40 | CONF_MODELS = { | |
37 | 'rc': RCConfiguration, |
|
41 | 'rc': RCConfiguration, | |
38 | 'dds': DDSConfiguration, |
|
42 | 'dds': DDSConfiguration, | |
39 | 'jars': JARSConfiguration, |
|
43 | 'jars': JARSConfiguration, | |
40 | 'cgs': CGSConfiguration, |
|
44 | 'cgs': CGSConfiguration, | |
41 | 'abs': ABSConfiguration, |
|
45 | 'abs': ABSConfiguration, | |
42 | 'usrp': USRPConfiguration, |
|
46 | 'usrp': USRPConfiguration, | |
43 | } |
|
47 | } | |
44 |
|
48 | |||
45 | MIX_MODES = { |
|
49 | MIX_MODES = { | |
46 | '0': 'P', |
|
50 | '0': 'P', | |
47 | '1': 'S', |
|
51 | '1': 'S', | |
48 | } |
|
52 | } | |
49 |
|
53 | |||
50 | MIX_OPERATIONS = { |
|
54 | MIX_OPERATIONS = { | |
51 | '0': 'OR', |
|
55 | '0': 'OR', | |
52 | '1': 'XOR', |
|
56 | '1': 'XOR', | |
53 | '2': 'AND', |
|
57 | '2': 'AND', | |
54 | '3': 'NAND', |
|
58 | '3': 'NAND', | |
55 | } |
|
59 | } | |
56 |
|
60 | |||
57 |
|
61 | |||
58 | def index(request): |
|
62 | def index(request): | |
59 | kwargs = {} |
|
63 | kwargs = {} | |
60 |
|
64 | |||
61 | return render(request, 'index.html', kwargs) |
|
65 | return render(request, 'index.html', kwargs) | |
62 |
|
66 | |||
63 |
|
67 | |||
64 | def locations(request): |
|
68 | def locations(request): | |
65 |
|
69 | |||
66 | locations = Location.objects.all().order_by('name') |
|
70 | page = request.GET.get('page') | |
67 |
|
71 | order = ('name',) | ||
68 | keys = ['id', 'name', 'description'] |
|
72 | ||
|
73 | kwargs = get_paginator(Location, page, order) | |||
69 |
|
74 | |||
70 | kwargs = {} |
|
75 | kwargs['keys'] = ['name', 'description'] | |
71 | kwargs['location_keys'] = keys[1:] |
|
76 | kwargs['title'] = 'Radar System' | |
72 | kwargs['locations'] = locations |
|
|||
73 | kwargs['title'] = 'Location' |
|
|||
74 | kwargs['suptitle'] = 'List' |
|
77 | kwargs['suptitle'] = 'List' | |
75 | kwargs['button'] = 'New Location' |
|
|||
76 |
|
78 | |||
77 |
return render(request, ' |
|
79 | return render(request, 'base_list.html', kwargs) | |
78 |
|
80 | |||
79 |
|
81 | |||
80 | def location(request, id_loc): |
|
82 | def location(request, id_loc): | |
81 |
|
83 | |||
82 | location = get_object_or_404(Location, pk=id_loc) |
|
84 | location = get_object_or_404(Location, pk=id_loc) | |
83 |
|
85 | |||
84 | kwargs = {} |
|
86 | kwargs = {} | |
85 | kwargs['location'] = location |
|
87 | kwargs['location'] = location | |
86 | kwargs['location_keys'] = ['name', 'description'] |
|
88 | kwargs['location_keys'] = ['name', 'description'] | |
87 |
|
89 | |||
88 | kwargs['title'] = 'Location' |
|
90 | kwargs['title'] = 'Location' | |
89 | kwargs['suptitle'] = 'Details' |
|
91 | kwargs['suptitle'] = 'Details' | |
90 |
|
92 | |||
91 | return render(request, 'location.html', kwargs) |
|
93 | return render(request, 'location.html', kwargs) | |
92 |
|
94 | |||
93 |
|
95 | |||
94 | def location_new(request): |
|
96 | def location_new(request): | |
95 |
|
97 | |||
96 | if request.method == 'GET': |
|
98 | if request.method == 'GET': | |
97 | form = LocationForm() |
|
99 | form = LocationForm() | |
98 |
|
100 | |||
99 | if request.method == 'POST': |
|
101 | if request.method == 'POST': | |
100 | form = LocationForm(request.POST) |
|
102 | form = LocationForm(request.POST) | |
101 |
|
103 | |||
102 | if form.is_valid(): |
|
104 | if form.is_valid(): | |
103 | form.save() |
|
105 | form.save() | |
104 | return redirect('url_locations') |
|
106 | return redirect('url_locations') | |
105 |
|
107 | |||
106 | kwargs = {} |
|
108 | kwargs = {} | |
107 | kwargs['form'] = form |
|
109 | kwargs['form'] = form | |
108 |
kwargs['title'] = ' |
|
110 | kwargs['title'] = 'Radar System' | |
109 | kwargs['suptitle'] = 'New' |
|
111 | kwargs['suptitle'] = 'New' | |
110 | kwargs['button'] = 'Create' |
|
112 | kwargs['button'] = 'Create' | |
111 |
|
113 | |||
112 |
return render(request, ' |
|
114 | return render(request, 'base_edit.html', kwargs) | |
113 |
|
115 | |||
114 |
|
116 | |||
115 | def location_edit(request, id_loc): |
|
117 | def location_edit(request, id_loc): | |
116 |
|
118 | |||
117 | location = get_object_or_404(Location, pk=id_loc) |
|
119 | location = get_object_or_404(Location, pk=id_loc) | |
118 |
|
120 | |||
119 | if request.method=='GET': |
|
121 | if request.method=='GET': | |
120 | form = LocationForm(instance=location) |
|
122 | form = LocationForm(instance=location) | |
121 |
|
123 | |||
122 | if request.method=='POST': |
|
124 | if request.method=='POST': | |
123 | form = LocationForm(request.POST, instance=location) |
|
125 | form = LocationForm(request.POST, instance=location) | |
124 |
|
126 | |||
125 | if form.is_valid(): |
|
127 | if form.is_valid(): | |
126 | form.save() |
|
128 | form.save() | |
127 | return redirect('url_locations') |
|
129 | return redirect('url_locations') | |
128 |
|
130 | |||
129 | kwargs = {} |
|
131 | kwargs = {} | |
130 | kwargs['form'] = form |
|
132 | kwargs['form'] = form | |
131 | kwargs['title'] = 'Location' |
|
133 | kwargs['title'] = 'Location' | |
132 | kwargs['suptitle'] = 'Edit' |
|
134 | kwargs['suptitle'] = 'Edit' | |
133 | kwargs['button'] = 'Update' |
|
135 | kwargs['button'] = 'Update' | |
134 |
|
136 | |||
135 |
return render(request, ' |
|
137 | return render(request, 'base_edit.html', kwargs) | |
136 |
|
138 | |||
137 |
|
139 | |||
138 | def location_delete(request, id_loc): |
|
140 | def location_delete(request, id_loc): | |
139 |
|
141 | |||
140 | location = get_object_or_404(Location, pk=id_loc) |
|
142 | location = get_object_or_404(Location, pk=id_loc) | |
141 |
|
143 | |||
142 | if request.method=='POST': |
|
144 | if request.method=='POST': | |
143 |
|
145 | |||
144 | if request.user.is_staff: |
|
146 | if request.user.is_staff: | |
145 | location.delete() |
|
147 | location.delete() | |
146 | return redirect('url_locations') |
|
148 | return redirect('url_locations') | |
147 |
|
149 | |||
148 | messages.error(request, 'Not enough permission to delete this object') |
|
150 | messages.error(request, 'Not enough permission to delete this object') | |
149 | return redirect(location.get_absolute_url()) |
|
151 | return redirect(location.get_absolute_url()) | |
150 |
|
152 | |||
151 | kwargs = { |
|
153 | kwargs = { | |
152 | 'title': 'Delete', |
|
154 | 'title': 'Delete', | |
153 | 'suptitle': 'Location', |
|
155 | 'suptitle': 'Location', | |
154 | 'object': location, |
|
156 | 'object': location, | |
155 | 'previous': location.get_absolute_url(), |
|
157 | 'previous': location.get_absolute_url(), | |
156 | 'delete': True |
|
158 | 'delete': True | |
157 | } |
|
159 | } | |
158 |
|
160 | |||
159 | return render(request, 'confirm.html', kwargs) |
|
161 | return render(request, 'confirm.html', kwargs) | |
160 |
|
162 | |||
161 |
|
163 | |||
162 | def devices(request): |
|
164 | def devices(request): | |
163 |
|
165 | |||
164 | devices = Device.objects.all().order_by('device_type__name') |
|
166 | page = request.GET.get('page') | |
165 |
|
167 | order = ('device_type', 'name') | ||
166 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
168 | ||
167 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
169 | kwargs = get_paginator(Device, page, order) | |
168 |
|
170 | kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type'] | ||
169 | kwargs = {} |
|
|||
170 | kwargs['device_keys'] = keys[1:] |
|
|||
171 | kwargs['devices'] = devices#.values(*keys) |
|
|||
172 | kwargs['title'] = 'Device' |
|
171 | kwargs['title'] = 'Device' | |
173 | kwargs['suptitle'] = 'List' |
|
172 | kwargs['suptitle'] = 'List' | |
174 | kwargs['button'] = 'New Device' |
|
|||
175 |
|
173 | |||
176 |
return render(request, ' |
|
174 | return render(request, 'base_list.html', kwargs) | |
177 |
|
175 | |||
178 |
|
176 | |||
179 | def device(request, id_dev): |
|
177 | def device(request, id_dev): | |
180 |
|
178 | |||
181 | device = get_object_or_404(Device, pk=id_dev) |
|
179 | device = get_object_or_404(Device, pk=id_dev) | |
182 |
|
180 | |||
183 | kwargs = {} |
|
181 | kwargs = {} | |
184 | kwargs['device'] = device |
|
182 | kwargs['device'] = device | |
185 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
183 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
186 |
|
184 | |||
187 | kwargs['title'] = 'Device' |
|
185 | kwargs['title'] = 'Device' | |
188 | kwargs['suptitle'] = 'Details' |
|
186 | kwargs['suptitle'] = 'Details' | |
189 |
|
187 | |||
190 | return render(request, 'device.html', kwargs) |
|
188 | return render(request, 'device.html', kwargs) | |
191 |
|
189 | |||
192 |
|
190 | |||
193 | def device_new(request): |
|
191 | def device_new(request): | |
194 |
|
192 | |||
195 | if request.method == 'GET': |
|
193 | if request.method == 'GET': | |
196 | form = DeviceForm() |
|
194 | form = DeviceForm() | |
197 |
|
195 | |||
198 | if request.method == 'POST': |
|
196 | if request.method == 'POST': | |
199 | form = DeviceForm(request.POST) |
|
197 | form = DeviceForm(request.POST) | |
200 |
|
198 | |||
201 | if form.is_valid(): |
|
199 | if form.is_valid(): | |
202 | form.save() |
|
200 | form.save() | |
203 | return redirect('url_devices') |
|
201 | return redirect('url_devices') | |
204 |
|
202 | |||
205 | kwargs = {} |
|
203 | kwargs = {} | |
206 | kwargs['form'] = form |
|
204 | kwargs['form'] = form | |
207 | kwargs['title'] = 'Device' |
|
205 | kwargs['title'] = 'Device' | |
208 | kwargs['suptitle'] = 'New' |
|
206 | kwargs['suptitle'] = 'New' | |
209 | kwargs['button'] = 'Create' |
|
207 | kwargs['button'] = 'Create' | |
210 |
|
208 | |||
211 |
return render(request, ' |
|
209 | return render(request, 'base_edit.html', kwargs) | |
212 |
|
210 | |||
213 |
|
211 | |||
214 | def device_edit(request, id_dev): |
|
212 | def device_edit(request, id_dev): | |
215 |
|
213 | |||
216 | device = get_object_or_404(Device, pk=id_dev) |
|
214 | device = get_object_or_404(Device, pk=id_dev) | |
217 |
|
215 | |||
218 | if request.method=='GET': |
|
216 | if request.method=='GET': | |
219 | form = DeviceForm(instance=device) |
|
217 | form = DeviceForm(instance=device) | |
220 |
|
218 | |||
221 | if request.method=='POST': |
|
219 | if request.method=='POST': | |
222 | form = DeviceForm(request.POST, instance=device) |
|
220 | form = DeviceForm(request.POST, instance=device) | |
223 |
|
221 | |||
224 | if form.is_valid(): |
|
222 | if form.is_valid(): | |
225 | form.save() |
|
223 | form.save() | |
226 | return redirect(device.get_absolute_url()) |
|
224 | return redirect(device.get_absolute_url()) | |
227 |
|
225 | |||
228 | kwargs = {} |
|
226 | kwargs = {} | |
229 | kwargs['form'] = form |
|
227 | kwargs['form'] = form | |
230 | kwargs['title'] = 'Device' |
|
228 | kwargs['title'] = 'Device' | |
231 | kwargs['suptitle'] = 'Edit' |
|
229 | kwargs['suptitle'] = 'Edit' | |
232 | kwargs['button'] = 'Update' |
|
230 | kwargs['button'] = 'Update' | |
233 |
|
231 | |||
234 |
return render(request, ' |
|
232 | return render(request, 'base_edit.html', kwargs) | |
235 |
|
233 | |||
236 |
|
234 | |||
237 | def device_delete(request, id_dev): |
|
235 | def device_delete(request, id_dev): | |
238 |
|
236 | |||
239 | device = get_object_or_404(Device, pk=id_dev) |
|
237 | device = get_object_or_404(Device, pk=id_dev) | |
240 |
|
238 | |||
241 | if request.method=='POST': |
|
239 | if request.method=='POST': | |
242 |
|
240 | |||
243 | if request.user.is_staff: |
|
241 | if request.user.is_staff: | |
244 | device.delete() |
|
242 | device.delete() | |
245 | return redirect('url_devices') |
|
243 | return redirect('url_devices') | |
246 |
|
244 | |||
247 | messages.error(request, 'Not enough permission to delete this object') |
|
245 | messages.error(request, 'Not enough permission to delete this object') | |
248 | return redirect(device.get_absolute_url()) |
|
246 | return redirect(device.get_absolute_url()) | |
249 |
|
247 | |||
250 | kwargs = { |
|
248 | kwargs = { | |
251 | 'title': 'Delete', |
|
249 | 'title': 'Delete', | |
252 | 'suptitle': 'Device', |
|
250 | 'suptitle': 'Device', | |
253 | 'object': device, |
|
251 | 'object': device, | |
254 | 'previous': device.get_absolute_url(), |
|
252 | 'previous': device.get_absolute_url(), | |
255 | 'delete': True |
|
253 | 'delete': True | |
256 | } |
|
254 | } | |
257 |
|
255 | |||
258 | return render(request, 'confirm.html', kwargs) |
|
256 | return render(request, 'confirm.html', kwargs) | |
259 |
|
257 | |||
260 |
|
258 | |||
261 | def campaigns(request): |
|
259 | def campaigns(request): | |
262 |
|
260 | |||
263 | campaigns = Campaign.objects.all().order_by('start_date') |
|
261 | page = request.GET.get('page') | |
264 |
|
262 | order = ('start_date',) | ||
265 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
263 | filters = request.GET.copy() | |
|
264 | ||||
|
265 | kwargs = get_paginator(Campaign, page, order, filters) | |||
266 |
|
266 | |||
267 | kwargs = {} |
|
267 | form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template']) | |
268 | kwargs['campaign_keys'] = keys[1:] |
|
268 | kwargs['keys'] = ['name', 'start_date', 'end_date'] | |
269 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
|||
270 | kwargs['title'] = 'Campaign' |
|
269 | kwargs['title'] = 'Campaign' | |
271 | kwargs['suptitle'] = 'List' |
|
270 | kwargs['suptitle'] = 'List' | |
272 | kwargs['button'] = 'New Campaign' |
|
271 | kwargs['form'] = form | |
|
272 | filters.pop('page', None) | |||
|
273 | kwargs['q'] = urllib.urlencode(filters) | |||
273 |
|
274 | |||
274 |
return render(request, ' |
|
275 | return render(request, 'base_list.html', kwargs) | |
275 |
|
276 | |||
276 |
|
277 | |||
277 | def campaign(request, id_camp): |
|
278 | def campaign(request, id_camp): | |
278 |
|
279 | |||
279 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
280 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
280 | experiments = Experiment.objects.filter(campaign=campaign) |
|
281 | experiments = Experiment.objects.filter(campaign=campaign) | |
281 |
|
282 | |||
282 | form = CampaignForm(instance=campaign) |
|
283 | form = CampaignForm(instance=campaign) | |
283 |
|
284 | |||
284 | kwargs = {} |
|
285 | kwargs = {} | |
285 | kwargs['campaign'] = campaign |
|
286 | kwargs['campaign'] = campaign | |
286 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
287 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] | |
287 |
|
288 | |||
288 | kwargs['experiments'] = experiments |
|
289 | kwargs['experiments'] = experiments | |
289 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] |
|
290 | kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time'] | |
290 |
|
291 | |||
291 | kwargs['title'] = 'Campaign' |
|
292 | kwargs['title'] = 'Campaign' | |
292 | kwargs['suptitle'] = 'Details' |
|
293 | kwargs['suptitle'] = 'Details' | |
293 |
|
294 | |||
294 | kwargs['form'] = form |
|
295 | kwargs['form'] = form | |
295 | kwargs['button'] = 'Add Experiment' |
|
296 | kwargs['button'] = 'Add Experiment' | |
296 |
|
297 | |||
297 | return render(request, 'campaign.html', kwargs) |
|
298 | return render(request, 'campaign.html', kwargs) | |
298 |
|
299 | |||
299 |
|
300 | |||
300 | def campaign_new(request): |
|
301 | def campaign_new(request): | |
301 |
|
302 | |||
302 | kwargs = {} |
|
303 | kwargs = {} | |
303 |
|
304 | |||
304 | if request.method == 'GET': |
|
305 | if request.method == 'GET': | |
305 |
|
306 | |||
306 | if 'template' in request.GET: |
|
307 | if 'template' in request.GET: | |
307 | if request.GET['template']=='0': |
|
308 | if request.GET['template']=='0': | |
308 | form = NewForm(initial={'create_from':2}, |
|
309 | form = NewForm(initial={'create_from':2}, | |
309 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
310 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
310 | else: |
|
311 | else: | |
311 | kwargs['button'] = 'Create' |
|
312 | kwargs['button'] = 'Create' | |
312 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
313 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |
313 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
314 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
314 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
315 | camp = Campaign.objects.get(pk=request.GET['template']) | |
315 | form = CampaignForm(instance=camp, |
|
316 | form = CampaignForm(instance=camp, | |
316 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
317 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
317 | 'template':False}) |
|
318 | 'template':False}) | |
318 | elif 'blank' in request.GET: |
|
319 | elif 'blank' in request.GET: | |
319 | kwargs['button'] = 'Create' |
|
320 | kwargs['button'] = 'Create' | |
320 | form = CampaignForm() |
|
321 | form = CampaignForm() | |
321 | else: |
|
322 | else: | |
322 | form = NewForm() |
|
323 | form = NewForm() | |
323 |
|
324 | |||
324 | if request.method == 'POST': |
|
325 | if request.method == 'POST': | |
325 | kwargs['button'] = 'Create' |
|
326 | kwargs['button'] = 'Create' | |
326 | post = request.POST.copy() |
|
327 | post = request.POST.copy() | |
327 | experiments = [] |
|
328 | experiments = [] | |
328 |
|
329 | |||
329 | for id_exp in post.getlist('experiments'): |
|
330 | for id_exp in post.getlist('experiments'): | |
330 | exp = Experiment.objects.get(pk=id_exp) |
|
331 | exp = Experiment.objects.get(pk=id_exp) | |
331 | new_exp = exp.clone(template=False) |
|
332 | new_exp = exp.clone(template=False) | |
332 | experiments.append(new_exp) |
|
333 | experiments.append(new_exp) | |
333 |
|
334 | |||
334 | post.setlist('experiments', []) |
|
335 | post.setlist('experiments', []) | |
335 |
|
336 | |||
336 | form = CampaignForm(post) |
|
337 | form = CampaignForm(post) | |
337 |
|
338 | |||
338 | if form.is_valid(): |
|
339 | if form.is_valid(): | |
339 | campaign = form.save() |
|
340 | campaign = form.save() | |
340 | for exp in experiments: |
|
341 | for exp in experiments: | |
341 | campaign.experiments.add(exp) |
|
342 | campaign.experiments.add(exp) | |
342 | campaign.save() |
|
343 | campaign.save() | |
343 | return redirect('url_campaign', id_camp=campaign.id) |
|
344 | return redirect('url_campaign', id_camp=campaign.id) | |
344 |
|
345 | |||
345 | kwargs['form'] = form |
|
346 | kwargs['form'] = form | |
346 | kwargs['title'] = 'Campaign' |
|
347 | kwargs['title'] = 'Campaign' | |
347 | kwargs['suptitle'] = 'New' |
|
348 | kwargs['suptitle'] = 'New' | |
348 |
|
349 | |||
349 | return render(request, 'campaign_edit.html', kwargs) |
|
350 | return render(request, 'campaign_edit.html', kwargs) | |
350 |
|
351 | |||
351 |
|
352 | |||
352 | def campaign_edit(request, id_camp): |
|
353 | def campaign_edit(request, id_camp): | |
353 |
|
354 | |||
354 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
355 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
355 |
|
356 | |||
356 | if request.method=='GET': |
|
357 | if request.method=='GET': | |
357 | form = CampaignForm(instance=campaign) |
|
358 | form = CampaignForm(instance=campaign) | |
358 |
|
359 | |||
359 | if request.method=='POST': |
|
360 | if request.method=='POST': | |
360 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
361 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
361 | post = request.POST.copy() |
|
362 | post = request.POST.copy() | |
362 | new_exps = post.getlist('experiments') |
|
363 | new_exps = post.getlist('experiments') | |
363 | post.setlist('experiments', []) |
|
364 | post.setlist('experiments', []) | |
364 | form = CampaignForm(post, instance=campaign) |
|
365 | form = CampaignForm(post, instance=campaign) | |
365 |
|
366 | |||
366 | if form.is_valid(): |
|
367 | if form.is_valid(): | |
367 | camp = form.save() |
|
368 | camp = form.save() | |
368 | for id_exp in new_exps: |
|
369 | for id_exp in new_exps: | |
369 | if int(id_exp) in exps: |
|
370 | if int(id_exp) in exps: | |
370 | exps.pop(id_exp) |
|
371 | exps.pop(id_exp) | |
371 | else: |
|
372 | else: | |
372 | exp = Experiment.objects.get(pk=id_exp) |
|
373 | exp = Experiment.objects.get(pk=id_exp) | |
373 | if exp.template: |
|
374 | if exp.template: | |
374 | camp.experiments.add(exp.clone(template=False)) |
|
375 | camp.experiments.add(exp.clone(template=False)) | |
375 | else: |
|
376 | else: | |
376 | camp.experiments.add(exp) |
|
377 | camp.experiments.add(exp) | |
377 |
|
378 | |||
378 | for id_exp in exps: |
|
379 | for id_exp in exps: | |
379 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
380 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
380 |
|
381 | |||
381 | return redirect('url_campaign', id_camp=id_camp) |
|
382 | return redirect('url_campaign', id_camp=id_camp) | |
382 |
|
383 | |||
383 | kwargs = {} |
|
384 | kwargs = {} | |
384 | kwargs['form'] = form |
|
385 | kwargs['form'] = form | |
385 | kwargs['title'] = 'Campaign' |
|
386 | kwargs['title'] = 'Campaign' | |
386 | kwargs['suptitle'] = 'Edit' |
|
387 | kwargs['suptitle'] = 'Edit' | |
387 | kwargs['button'] = 'Update' |
|
388 | kwargs['button'] = 'Update' | |
388 |
|
389 | |||
389 | return render(request, 'campaign_edit.html', kwargs) |
|
390 | return render(request, 'campaign_edit.html', kwargs) | |
390 |
|
391 | |||
391 |
|
392 | |||
392 | def campaign_delete(request, id_camp): |
|
393 | def campaign_delete(request, id_camp): | |
393 |
|
394 | |||
394 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
395 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
395 |
|
396 | |||
396 | if request.method=='POST': |
|
397 | if request.method=='POST': | |
397 | if request.user.is_staff: |
|
398 | if request.user.is_staff: | |
398 |
|
399 | |||
399 | for exp in campaign.experiments.all(): |
|
400 | for exp in campaign.experiments.all(): | |
400 | for conf in Configuration.objects.filter(experiment=exp): |
|
401 | for conf in Configuration.objects.filter(experiment=exp): | |
401 | conf.delete() |
|
402 | conf.delete() | |
402 | exp.delete() |
|
403 | exp.delete() | |
403 | campaign.delete() |
|
404 | campaign.delete() | |
404 |
|
405 | |||
405 | return redirect('url_campaigns') |
|
406 | return redirect('url_campaigns') | |
406 |
|
407 | |||
407 | messages.error(request, 'Not enough permission to delete this object') |
|
408 | messages.error(request, 'Not enough permission to delete this object') | |
408 | return redirect(campaign.get_absolute_url()) |
|
409 | return redirect(campaign.get_absolute_url()) | |
409 |
|
410 | |||
410 | kwargs = { |
|
411 | kwargs = { | |
411 | 'title': 'Delete', |
|
412 | 'title': 'Delete', | |
412 | 'suptitle': 'Campaign', |
|
413 | 'suptitle': 'Campaign', | |
413 | 'object': campaign, |
|
414 | 'object': campaign, | |
414 | 'previous': campaign.get_absolute_url(), |
|
415 | 'previous': campaign.get_absolute_url(), | |
415 | 'delete': True |
|
416 | 'delete': True | |
416 | } |
|
417 | } | |
417 |
|
418 | |||
418 | return render(request, 'confirm.html', kwargs) |
|
419 | return render(request, 'confirm.html', kwargs) | |
419 |
|
420 | |||
420 | def campaign_export(request, id_camp): |
|
421 | def campaign_export(request, id_camp): | |
421 |
|
422 | |||
422 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
423 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
423 | content = campaign.parms_to_dict() |
|
424 | content = campaign.parms_to_dict() | |
424 | content_type = 'application/json' |
|
425 | content_type = 'application/json' | |
425 | filename = '%s_%s.json' %(campaign.name, campaign.id) |
|
426 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
426 |
|
427 | |||
427 | response = HttpResponse(content_type=content_type) |
|
428 | response = HttpResponse(content_type=content_type) | |
428 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
429 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
429 | response.write(content) |
|
430 | response.write(content) | |
430 |
|
431 | |||
431 | return response |
|
432 | return response | |
432 |
|
433 | |||
433 |
|
434 | |||
434 | def campaign_import(request, id_camp): |
|
435 | def campaign_import(request, id_camp): | |
435 |
|
436 | |||
436 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
437 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
437 |
|
438 | |||
438 | if request.method == 'GET': |
|
439 | if request.method == 'GET': | |
439 | file_form = UploadFileForm() |
|
440 | file_form = UploadFileForm() | |
440 |
|
441 | |||
441 | if request.method == 'POST': |
|
442 | if request.method == 'POST': | |
442 | file_form = UploadFileForm(request.POST, request.FILES) |
|
443 | file_form = UploadFileForm(request.POST, request.FILES) | |
443 |
|
444 | |||
444 | if file_form.is_valid(): |
|
445 | if file_form.is_valid(): | |
445 |
|
446 | |||
446 | parms = campaign.import_from_file(request.FILES['file']) |
|
447 | parms = campaign.import_from_file(request.FILES['file']) | |
447 |
|
448 | |||
448 | if parms: |
|
449 | if parms: | |
449 | parms['name'] = parms['campaign'] |
|
450 | parms['name'] = parms['campaign'] | |
450 |
|
451 | |||
451 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) |
|
452 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) | |
452 |
|
453 | |||
453 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
454 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
454 |
|
455 | |||
455 | return redirect(new_camp.get_absolute_url_edit()) |
|
456 | return redirect(new_camp.get_absolute_url_edit()) | |
456 |
|
457 | |||
457 | messages.error(request, "Could not import parameters from file") |
|
458 | messages.error(request, "Could not import parameters from file") | |
458 |
|
459 | |||
459 | kwargs = {} |
|
460 | kwargs = {} | |
460 | kwargs['title'] = 'Campaign' |
|
461 | kwargs['title'] = 'Campaign' | |
461 | kwargs['form'] = file_form |
|
462 | kwargs['form'] = file_form | |
462 | kwargs['suptitle'] = 'Importing file' |
|
463 | kwargs['suptitle'] = 'Importing file' | |
463 | kwargs['button'] = 'Import' |
|
464 | kwargs['button'] = 'Import' | |
464 |
|
465 | |||
465 | return render(request, 'campaign_import.html', kwargs) |
|
466 | return render(request, 'campaign_import.html', kwargs) | |
466 |
|
467 | |||
467 |
|
468 | |||
468 | def experiments(request): |
|
469 | def experiments(request): | |
469 |
|
470 | |||
470 | experiment_list = Experiment.objects.all() |
|
471 | page = request.GET.get('page') | |
471 |
|
472 | order = ('location',) | ||
472 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
473 | filters = request.GET.copy() | |
473 |
|
474 | |||
474 | kwargs = {} |
|
475 | kwargs = get_paginator(Experiment, page, order, filters) | |
475 |
|
476 | |||
476 | kwargs['experiment_keys'] = keys[1:] |
|
477 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) | |
477 | kwargs['experiments'] = experiment_list |
|
|||
478 |
|
478 | |||
|
479 | kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time'] | |||
479 | kwargs['title'] = 'Experiment' |
|
480 | kwargs['title'] = 'Experiment' | |
480 | kwargs['suptitle'] = 'List' |
|
481 | kwargs['suptitle'] = 'List' | |
481 |
kwargs[' |
|
482 | kwargs['form'] = form | |
|
483 | filters.pop('page', None) | |||
|
484 | kwargs['q'] = urllib.urlencode(filters) | |||
482 |
|
485 | |||
483 |
return render(request, ' |
|
486 | return render(request, 'base_list.html', kwargs) | |
484 |
|
487 | |||
485 |
|
488 | |||
486 | def experiment(request, id_exp): |
|
489 | def experiment(request, id_exp): | |
487 |
|
490 | |||
488 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
491 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
489 |
|
492 | |||
490 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
493 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
491 |
|
494 | |||
492 | kwargs = {} |
|
495 | kwargs = {} | |
493 |
|
496 | |||
494 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
497 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
495 | kwargs['experiment'] = experiment |
|
498 | kwargs['experiment'] = experiment | |
496 |
|
499 | |||
497 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] |
|
500 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] | |
498 | kwargs['configurations'] = configurations |
|
501 | kwargs['configurations'] = configurations | |
499 |
|
502 | |||
500 | kwargs['title'] = 'Experiment' |
|
503 | kwargs['title'] = 'Experiment' | |
501 | kwargs['suptitle'] = 'Details' |
|
504 | kwargs['suptitle'] = 'Details' | |
502 |
|
505 | |||
503 | kwargs['button'] = 'Add Configuration' |
|
506 | kwargs['button'] = 'Add Configuration' | |
504 |
|
507 | |||
505 | ###### SIDEBAR ###### |
|
508 | ###### SIDEBAR ###### | |
506 | kwargs.update(sidebar(experiment=experiment)) |
|
509 | kwargs.update(sidebar(experiment=experiment)) | |
507 |
|
510 | |||
508 | return render(request, 'experiment.html', kwargs) |
|
511 | return render(request, 'experiment.html', kwargs) | |
509 |
|
512 | |||
510 |
|
513 | |||
511 | def experiment_new(request, id_camp=None): |
|
514 | def experiment_new(request, id_camp=None): | |
512 |
|
515 | |||
513 | kwargs = {} |
|
516 | kwargs = {} | |
514 |
|
517 | |||
515 | if request.method == 'GET': |
|
518 | if request.method == 'GET': | |
516 | if 'template' in request.GET: |
|
519 | if 'template' in request.GET: | |
517 | if request.GET['template']=='0': |
|
520 | if request.GET['template']=='0': | |
518 | form = NewForm(initial={'create_from':2}, |
|
521 | form = NewForm(initial={'create_from':2}, | |
519 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
522 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
520 | else: |
|
523 | else: | |
521 | kwargs['button'] = 'Create' |
|
524 | kwargs['button'] = 'Create' | |
522 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
525 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |
523 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
526 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] | |
524 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
527 | exp=Experiment.objects.get(pk=request.GET['template']) | |
525 | form = ExperimentForm(instance=exp, |
|
528 | form = ExperimentForm(instance=exp, | |
526 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
529 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
527 | 'template': False}) |
|
530 | 'template': False}) | |
528 | elif 'blank' in request.GET: |
|
531 | elif 'blank' in request.GET: | |
529 | kwargs['button'] = 'Create' |
|
532 | kwargs['button'] = 'Create' | |
530 | form = ExperimentForm() |
|
533 | form = ExperimentForm() | |
531 | else: |
|
534 | else: | |
532 | form = NewForm() |
|
535 | form = NewForm() | |
533 |
|
536 | |||
534 | if request.method == 'POST': |
|
537 | if request.method == 'POST': | |
535 |
form = ExperimentForm(request.POST) |
|
538 | form = ExperimentForm(request.POST) | |
|
539 | print form.data | |||
536 | if form.is_valid(): |
|
540 | if form.is_valid(): | |
537 | experiment = form.save() |
|
541 | experiment = form.save() | |
538 |
|
542 | |||
539 | if 'template' in request.GET: |
|
543 | if 'template' in request.GET: | |
540 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
544 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |
541 | for conf in configurations: |
|
545 | for conf in configurations: | |
542 | conf.clone(experiment=experiment, template=False) |
|
546 | conf.clone(experiment=experiment, template=False) | |
543 |
|
547 | |||
544 | return redirect('url_experiment', id_exp=experiment.id) |
|
548 | return redirect('url_experiment', id_exp=experiment.id) | |
545 |
|
549 | |||
546 | kwargs['form'] = form |
|
550 | kwargs['form'] = form | |
547 | kwargs['title'] = 'Experiment' |
|
551 | kwargs['title'] = 'Experiment' | |
548 | kwargs['suptitle'] = 'New' |
|
552 | kwargs['suptitle'] = 'New' | |
549 |
|
553 | |||
550 | return render(request, 'experiment_edit.html', kwargs) |
|
554 | return render(request, 'experiment_edit.html', kwargs) | |
551 |
|
555 | |||
552 |
|
556 | |||
553 | def experiment_edit(request, id_exp): |
|
557 | def experiment_edit(request, id_exp): | |
554 |
|
558 | |||
555 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
559 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
556 |
|
560 | |||
557 | if request.method == 'GET': |
|
561 | if request.method == 'GET': | |
558 | form = ExperimentForm(instance=experiment) |
|
562 | form = ExperimentForm(instance=experiment) | |
559 |
|
563 | |||
560 | if request.method=='POST': |
|
564 | if request.method=='POST': | |
561 | form = ExperimentForm(request.POST, instance=experiment) |
|
565 | form = ExperimentForm(request.POST, instance=experiment) | |
562 |
|
566 | |||
563 | if form.is_valid(): |
|
567 | if form.is_valid(): | |
564 | experiment = form.save() |
|
568 | experiment = form.save() | |
565 | return redirect('url_experiment', id_exp=experiment.id) |
|
569 | return redirect('url_experiment', id_exp=experiment.id) | |
566 |
|
570 | |||
567 | kwargs = {} |
|
571 | kwargs = {} | |
568 | kwargs['form'] = form |
|
572 | kwargs['form'] = form | |
569 | kwargs['title'] = 'Experiment' |
|
573 | kwargs['title'] = 'Experiment' | |
570 | kwargs['suptitle'] = 'Edit' |
|
574 | kwargs['suptitle'] = 'Edit' | |
571 | kwargs['button'] = 'Update' |
|
575 | kwargs['button'] = 'Update' | |
572 |
|
576 | |||
573 | return render(request, 'experiment_edit.html', kwargs) |
|
577 | return render(request, 'experiment_edit.html', kwargs) | |
574 |
|
578 | |||
575 |
|
579 | |||
576 | def experiment_delete(request, id_exp): |
|
580 | def experiment_delete(request, id_exp): | |
577 |
|
581 | |||
578 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
582 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
579 |
|
583 | |||
580 | if request.method=='POST': |
|
584 | if request.method=='POST': | |
581 | if request.user.is_staff: |
|
585 | if request.user.is_staff: | |
582 | for conf in Configuration.objects.filter(experiment=experiment): |
|
586 | for conf in Configuration.objects.filter(experiment=experiment): | |
583 | conf.delete() |
|
587 | conf.delete() | |
584 | experiment.delete() |
|
588 | experiment.delete() | |
585 | return redirect('url_experiments') |
|
589 | return redirect('url_experiments') | |
586 |
|
590 | |||
587 | messages.error(request, 'Not enough permission to delete this object') |
|
591 | messages.error(request, 'Not enough permission to delete this object') | |
588 | return redirect(experiment.get_absolute_url()) |
|
592 | return redirect(experiment.get_absolute_url()) | |
589 |
|
593 | |||
590 | kwargs = { |
|
594 | kwargs = { | |
591 | 'title': 'Delete', |
|
595 | 'title': 'Delete', | |
592 | 'suptitle': 'Experiment', |
|
596 | 'suptitle': 'Experiment', | |
593 | 'object': experiment, |
|
597 | 'object': experiment, | |
594 | 'previous': experiment.get_absolute_url(), |
|
598 | 'previous': experiment.get_absolute_url(), | |
595 | 'delete': True |
|
599 | 'delete': True | |
596 | } |
|
600 | } | |
597 |
|
601 | |||
598 | return render(request, 'confirm.html', kwargs) |
|
602 | return render(request, 'confirm.html', kwargs) | |
599 |
|
603 | |||
600 |
|
604 | |||
601 | def experiment_export(request, id_exp): |
|
605 | def experiment_export(request, id_exp): | |
602 |
|
606 | |||
603 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
607 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
604 | content = experiment.parms_to_dict() |
|
608 | content = experiment.parms_to_dict() | |
605 | content_type = 'application/json' |
|
609 | content_type = 'application/json' | |
606 | filename = '%s_%s.json' %(experiment.name, experiment.id) |
|
610 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
607 |
|
611 | |||
608 | response = HttpResponse(content_type=content_type) |
|
612 | response = HttpResponse(content_type=content_type) | |
609 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
613 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
610 | response.write(content) |
|
614 | response.write(content) | |
611 |
|
615 | |||
612 | return response |
|
616 | return response | |
613 |
|
617 | |||
614 | def experiment_import(request, id_exp): |
|
618 | def experiment_import(request, id_exp): | |
615 |
|
619 | |||
616 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
620 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
617 | configurations = Configuration.objects.filter(experiment=experiment) |
|
621 | configurations = Configuration.objects.filter(experiment=experiment) | |
618 |
|
622 | |||
619 | if request.method == 'GET': |
|
623 | if request.method == 'GET': | |
620 | file_form = UploadFileForm() |
|
624 | file_form = UploadFileForm() | |
621 |
|
625 | |||
622 | if request.method == 'POST': |
|
626 | if request.method == 'POST': | |
623 | file_form = UploadFileForm(request.POST, request.FILES) |
|
627 | file_form = UploadFileForm(request.POST, request.FILES) | |
624 |
|
628 | |||
625 | if file_form.is_valid(): |
|
629 | if file_form.is_valid(): | |
626 |
|
630 | |||
627 | parms = experiment.import_from_file(request.FILES['file']) |
|
631 | parms = experiment.import_from_file(request.FILES['file']) | |
628 |
|
632 | |||
629 | if parms: |
|
633 | if parms: | |
630 |
|
634 | |||
631 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) |
|
635 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) | |
632 |
|
636 | |||
633 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
637 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
634 |
|
638 | |||
635 | return redirect(new_exp.get_absolute_url_edit()) |
|
639 | return redirect(new_exp.get_absolute_url_edit()) | |
636 |
|
640 | |||
637 | messages.error(request, "Could not import parameters from file") |
|
641 | messages.error(request, "Could not import parameters from file") | |
638 |
|
642 | |||
639 | kwargs = {} |
|
643 | kwargs = {} | |
640 | kwargs['title'] = 'Experiment' |
|
644 | kwargs['title'] = 'Experiment' | |
641 | kwargs['form'] = file_form |
|
645 | kwargs['form'] = file_form | |
642 | kwargs['suptitle'] = 'Importing file' |
|
646 | kwargs['suptitle'] = 'Importing file' | |
643 | kwargs['button'] = 'Import' |
|
647 | kwargs['button'] = 'Import' | |
644 |
|
648 | |||
645 | kwargs.update(sidebar(experiment=experiment)) |
|
649 | kwargs.update(sidebar(experiment=experiment)) | |
646 |
|
650 | |||
647 | return render(request, 'experiment_import.html', kwargs) |
|
651 | return render(request, 'experiment_import.html', kwargs) | |
648 |
|
652 | |||
649 | def experiment_mix(request, id_exp): |
|
653 | def experiment_mix(request, id_exp): | |
650 |
|
654 | |||
651 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
655 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
652 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, |
|
656 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, | |
653 | mix=False)] |
|
657 | mix=False)] | |
654 |
|
658 | |||
655 | if len(rc_confs)<2: |
|
659 | if len(rc_confs)<2: | |
656 | messages.warning(request, 'You need at least two RC Configurations to make a mix') |
|
660 | messages.warning(request, 'You need at least two RC Configurations to make a mix') | |
657 | return redirect(experiment.get_absolute_url()) |
|
661 | return redirect(experiment.get_absolute_url()) | |
658 |
|
662 | |||
659 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) |
|
663 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) | |
660 |
|
664 | |||
661 | if mix_confs: |
|
665 | if mix_confs: | |
662 | mix = mix_confs[0] |
|
666 | mix = mix_confs[0] | |
663 | else: |
|
667 | else: | |
664 | mix = RCConfiguration(experiment=experiment, |
|
668 | mix = RCConfiguration(experiment=experiment, | |
665 | device=rc_confs[0].device, |
|
669 | device=rc_confs[0].device, | |
666 | ipp=rc_confs[0].ipp, |
|
670 | ipp=rc_confs[0].ipp, | |
667 | clock_in=rc_confs[0].clock_in, |
|
671 | clock_in=rc_confs[0].clock_in, | |
668 | clock_divider=rc_confs[0].clock_divider, |
|
672 | clock_divider=rc_confs[0].clock_divider, | |
669 | mix=True, |
|
673 | mix=True, | |
670 | parameters='') |
|
674 | parameters='') | |
671 | mix.save() |
|
675 | mix.save() | |
672 |
|
676 | |||
673 | line_type = RCLineType.objects.get(name='mix') |
|
677 | line_type = RCLineType.objects.get(name='mix') | |
674 | for i in range(len(rc_confs[0].get_lines())): |
|
678 | for i in range(len(rc_confs[0].get_lines())): | |
675 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) |
|
679 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |
676 | line.save() |
|
680 | line.save() | |
677 |
|
681 | |||
678 | initial = {'name': mix.name, |
|
682 | initial = {'name': mix.name, | |
679 | 'result': parse_mix_result(mix.parameters), |
|
683 | 'result': parse_mix_result(mix.parameters), | |
680 | 'delay': 0, |
|
684 | 'delay': 0, | |
681 | 'mask': [0,1,2,3,4,5,6,7] |
|
685 | 'mask': [0,1,2,3,4,5,6,7] | |
682 | } |
|
686 | } | |
683 |
|
687 | |||
684 | if request.method=='GET': |
|
688 | if request.method=='GET': | |
685 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) |
|
689 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |
686 |
|
690 | |||
687 | if request.method=='POST': |
|
691 | if request.method=='POST': | |
688 | result = mix.parameters |
|
692 | result = mix.parameters | |
689 |
|
693 | |||
690 | if '{}|'.format(request.POST['experiment']) in result: |
|
694 | if '{}|'.format(request.POST['experiment']) in result: | |
691 | messages.error(request, 'Configuration already added') |
|
695 | messages.error(request, 'Configuration already added') | |
692 | else: |
|
696 | else: | |
693 | if 'operation' in request.POST: |
|
697 | if 'operation' in request.POST: | |
694 | operation = MIX_OPERATIONS[request.POST['operation']] |
|
698 | operation = MIX_OPERATIONS[request.POST['operation']] | |
695 | else: |
|
699 | else: | |
696 | operation = ' ' |
|
700 | operation = ' ' | |
697 |
|
701 | |||
698 | mode = MIX_MODES[request.POST['mode']] |
|
702 | mode = MIX_MODES[request.POST['mode']] | |
699 |
|
703 | |||
700 | if result: |
|
704 | if result: | |
701 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, |
|
705 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, | |
702 | request.POST['experiment'], |
|
706 | request.POST['experiment'], | |
703 | mode, |
|
707 | mode, | |
704 | operation, |
|
708 | operation, | |
705 | float(request.POST['delay']), |
|
709 | float(request.POST['delay']), | |
706 | parse_mask(request.POST.getlist('mask')) |
|
710 | parse_mask(request.POST.getlist('mask')) | |
707 | ) |
|
711 | ) | |
708 | else: |
|
712 | else: | |
709 | result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'], |
|
713 | result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'], | |
710 | mode, |
|
714 | mode, | |
711 | operation, |
|
715 | operation, | |
712 | float(request.POST['delay']), |
|
716 | float(request.POST['delay']), | |
713 | parse_mask(request.POST.getlist('mask')) |
|
717 | parse_mask(request.POST.getlist('mask')) | |
714 | ) |
|
718 | ) | |
715 |
|
719 | |||
716 | mix.parameters = result |
|
720 | mix.parameters = result | |
717 | mix.name = request.POST['name'] |
|
721 | mix.name = request.POST['name'] | |
718 | mix.save() |
|
722 | mix.save() | |
719 | mix.update_pulses() |
|
723 | mix.update_pulses() | |
720 |
|
724 | |||
721 | initial['result'] = parse_mix_result(result) |
|
725 | initial['result'] = parse_mix_result(result) | |
722 | initial['name'] = mix.name |
|
726 | initial['name'] = mix.name | |
723 |
|
727 | |||
724 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) |
|
728 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |
725 |
|
729 | |||
726 |
|
730 | |||
727 | kwargs = { |
|
731 | kwargs = { | |
728 | 'title': 'Experiment', |
|
732 | 'title': 'Experiment', | |
729 | 'suptitle': 'Mix Configurations', |
|
733 | 'suptitle': 'Mix Configurations', | |
730 | 'form' : form, |
|
734 | 'form' : form, | |
731 | 'extra_button': 'Delete', |
|
735 | 'extra_button': 'Delete', | |
732 | 'button': 'Add', |
|
736 | 'button': 'Add', | |
733 | 'cancel': 'Back', |
|
737 | 'cancel': 'Back', | |
734 | 'previous': experiment.get_absolute_url(), |
|
738 | 'previous': experiment.get_absolute_url(), | |
735 | 'id_exp':id_exp, |
|
739 | 'id_exp':id_exp, | |
736 |
|
740 | |||
737 | } |
|
741 | } | |
738 |
|
742 | |||
739 | return render(request, 'experiment_mix.html', kwargs) |
|
743 | return render(request, 'experiment_mix.html', kwargs) | |
740 |
|
744 | |||
741 |
|
745 | |||
742 | def experiment_mix_delete(request, id_exp): |
|
746 | def experiment_mix_delete(request, id_exp): | |
743 |
|
747 | |||
744 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) |
|
748 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |
745 | values = conf.parameters.split('-') |
|
749 | values = conf.parameters.split('-') | |
746 | conf.parameters = '-'.join(values[:-1]) |
|
750 | conf.parameters = '-'.join(values[:-1]) | |
747 | conf.save() |
|
751 | conf.save() | |
748 |
|
752 | |||
749 | return redirect('url_mix_experiment', id_exp=id_exp) |
|
753 | return redirect('url_mix_experiment', id_exp=id_exp) | |
750 |
|
754 | |||
751 |
|
755 | |||
752 | def parse_mix_result(s): |
|
756 | def parse_mix_result(s): | |
753 |
|
757 | |||
754 | values = s.split('-') |
|
758 | values = s.split('-') | |
755 | html = 'EXP MOD OPE DELAY MASK\r\n' |
|
759 | html = 'EXP MOD OPE DELAY MASK\r\n' | |
756 |
|
760 | |||
757 | if not values or values[0] in ('', ' '): |
|
761 | if not values or values[0] in ('', ' '): | |
758 | return mark_safe(html) |
|
762 | return mark_safe(html) | |
759 |
|
763 | |||
760 | for i, value in enumerate(values): |
|
764 | for i, value in enumerate(values): | |
761 | if not value: |
|
765 | if not value: | |
762 | continue |
|
766 | continue | |
763 | pk, mode, operation, delay, mask = value.split('|') |
|
767 | pk, mode, operation, delay, mask = value.split('|') | |
764 | conf = RCConfiguration.objects.get(pk=pk) |
|
768 | conf = RCConfiguration.objects.get(pk=pk) | |
765 | if i==0: |
|
769 | if i==0: | |
766 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
770 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
767 | conf.name, |
|
771 | conf.name, | |
768 | mode, |
|
772 | mode, | |
769 | ' ', |
|
773 | ' ', | |
770 | delay, |
|
774 | delay, | |
771 | mask) |
|
775 | mask) | |
772 | else: |
|
776 | else: | |
773 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
777 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
774 | conf.name, |
|
778 | conf.name, | |
775 | mode, |
|
779 | mode, | |
776 | operation, |
|
780 | operation, | |
777 | delay, |
|
781 | delay, | |
778 | mask) |
|
782 | mask) | |
779 |
|
783 | |||
780 | return mark_safe(html) |
|
784 | return mark_safe(html) | |
781 |
|
785 | |||
782 | def parse_mask(l): |
|
786 | def parse_mask(l): | |
783 |
|
787 | |||
784 | values = [] |
|
788 | values = [] | |
785 |
|
789 | |||
786 | for x in range(8): |
|
790 | for x in range(8): | |
787 | if '{}'.format(x) in l: |
|
791 | if '{}'.format(x) in l: | |
788 | values.append(1) |
|
792 | values.append(1) | |
789 | else: |
|
793 | else: | |
790 | values.append(0) |
|
794 | values.append(0) | |
791 |
|
795 | |||
792 | values.reverse() |
|
796 | values.reverse() | |
793 |
|
797 | |||
794 | return int(''.join([str(x) for x in values]), 2) |
|
798 | return int(''.join([str(x) for x in values]), 2) | |
795 |
|
799 | |||
796 |
|
800 | |||
797 | def dev_confs(request): |
|
801 | def dev_confs(request): | |
798 |
|
802 | |||
799 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
|||
800 |
|
||||
801 | kwargs = {} |
|
|||
802 |
|
803 | |||
803 | kwargs['configuration_keys'] = ['device', 'name', 'experiment', 'type', 'programmed_date'] |
|
804 | page = request.GET.get('page') | |
804 | kwargs['configurations'] = configurations |
|
805 | order = ('type', 'device__device_type', 'experiment') | |
|
806 | filters = request.GET.copy() | |||
|
807 | ||||
|
808 | kwargs = get_paginator(Configuration, page, order, filters) | |||
805 |
|
809 | |||
|
810 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) | |||
|
811 | kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] | |||
806 | kwargs['title'] = 'Configuration' |
|
812 | kwargs['title'] = 'Configuration' | |
807 | kwargs['suptitle'] = 'List' |
|
813 | kwargs['suptitle'] = 'List' | |
|
814 | kwargs['form'] = form | |||
|
815 | filters.pop('page', None) | |||
|
816 | kwargs['q'] = urllib.urlencode(filters) | |||
808 |
|
817 | |||
809 |
return render(request, ' |
|
818 | return render(request, 'base_list.html', kwargs) | |
810 |
|
819 | |||
811 |
|
820 | |||
812 | def dev_conf(request, id_conf): |
|
821 | def dev_conf(request, id_conf): | |
813 |
|
822 | |||
814 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
823 | conf = get_object_or_404(Configuration, pk=id_conf) | |
815 |
|
824 | |||
816 | return redirect(conf.get_absolute_url()) |
|
825 | return redirect(conf.get_absolute_url()) | |
817 |
|
826 | |||
818 |
|
827 | |||
819 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
828 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
820 |
|
829 | |||
821 | initial = {} |
|
830 | initial = {} | |
822 | kwargs = {} |
|
831 | kwargs = {} | |
823 |
|
832 | |||
824 | if id_exp<>0: |
|
833 | if id_exp<>0: | |
825 | initial['experiment'] = id_exp |
|
834 | initial['experiment'] = id_exp | |
826 |
|
835 | |||
827 | if id_dev<>0: |
|
836 | if id_dev<>0: | |
828 | initial['device'] = id_dev |
|
837 | initial['device'] = id_dev | |
829 |
|
838 | |||
830 | if request.method == 'GET': |
|
839 | if request.method == 'GET': | |
831 |
|
840 | |||
832 | if id_dev: |
|
841 | if id_dev: | |
833 | kwargs['button'] = 'Create' |
|
842 | kwargs['button'] = 'Create' | |
834 | device = Device.objects.get(pk=id_dev) |
|
843 | device = Device.objects.get(pk=id_dev) | |
835 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
844 | DevConfForm = CONF_FORMS[device.device_type.name] | |
836 | initial['name'] = request.GET['name'] |
|
845 | initial['name'] = request.GET['name'] | |
837 | form = DevConfForm(initial=initial) |
|
846 | form = DevConfForm(initial=initial) | |
838 | else: |
|
847 | else: | |
839 | if 'template' in request.GET: |
|
848 | if 'template' in request.GET: | |
840 | if request.GET['template']=='0': |
|
849 | if request.GET['template']=='0': | |
841 | choices = [(conf.pk, '{}'.format(conf)) for conf in Configuration.objects.filter(template=True)] |
|
850 | choices = [(conf.pk, '{}'.format(conf)) for conf in Configuration.objects.filter(template=True)] | |
842 | form = NewForm(initial={'create_from':2}, |
|
851 | form = NewForm(initial={'create_from':2}, | |
843 | template_choices=choices) |
|
852 | template_choices=choices) | |
844 | else: |
|
853 | else: | |
845 | kwargs['button'] = 'Create' |
|
854 | kwargs['button'] = 'Create' | |
846 | conf = Configuration.objects.get(pk=request.GET['template']) |
|
855 | conf = Configuration.objects.get(pk=request.GET['template']) | |
847 | id_dev = conf.device.pk |
|
856 | id_dev = conf.device.pk | |
848 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
857 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
849 | form = DevConfForm(instance=conf, |
|
858 | form = DevConfForm(instance=conf, | |
850 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), |
|
859 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), | |
851 | 'template': False, |
|
860 | 'template': False, | |
852 | 'experiment':id_exp}) |
|
861 | 'experiment':id_exp}) | |
853 | elif 'blank' in request.GET: |
|
862 | elif 'blank' in request.GET: | |
854 | kwargs['button'] = 'Create' |
|
863 | kwargs['button'] = 'Create' | |
855 | form = ConfigurationForm(initial=initial) |
|
864 | form = ConfigurationForm(initial=initial) | |
856 | else: |
|
865 | else: | |
857 | form = NewForm() |
|
866 | form = NewForm() | |
858 |
|
867 | |||
859 | if request.method == 'POST': |
|
868 | if request.method == 'POST': | |
860 |
|
869 | |||
861 | device = Device.objects.get(pk=request.POST['device']) |
|
870 | device = Device.objects.get(pk=request.POST['device']) | |
862 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
871 | DevConfForm = CONF_FORMS[device.device_type.name] | |
863 |
|
872 | |||
864 | form = DevConfForm(request.POST) |
|
873 | form = DevConfForm(request.POST) | |
865 | kwargs['button'] = 'Create' |
|
874 | kwargs['button'] = 'Create' | |
866 | if form.is_valid(): |
|
875 | if form.is_valid(): | |
867 | conf = form.save() |
|
876 | conf = form.save() | |
868 |
|
877 | |||
869 | if 'template' in request.GET and conf.device.device_type.name=='rc': |
|
878 | if 'template' in request.GET and conf.device.device_type.name=='rc': | |
870 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) |
|
879 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |
871 | for line in lines: |
|
880 | for line in lines: | |
872 | line.clone(rc_configuration=conf) |
|
881 | line.clone(rc_configuration=conf) | |
873 |
|
882 | |||
874 | if conf.device.device_type.name=='jars': |
|
883 | if conf.device.device_type.name=='jars': | |
875 | conf.add_parms_to_filter() |
|
884 | conf.add_parms_to_filter() | |
876 |
|
885 | |||
877 | return redirect('url_dev_conf', id_conf=conf.pk) |
|
886 | return redirect('url_dev_conf', id_conf=conf.pk) | |
878 |
|
||||
879 |
|
887 | |||
880 | kwargs['id_exp'] = id_exp |
|
888 | kwargs['id_exp'] = id_exp | |
881 | kwargs['form'] = form |
|
889 | kwargs['form'] = form | |
882 | kwargs['title'] = 'Configuration' |
|
890 | kwargs['title'] = 'Configuration' | |
883 | kwargs['suptitle'] = 'New' |
|
891 | kwargs['suptitle'] = 'New' | |
884 |
|
892 | |||
885 |
|
893 | |||
886 | if id_dev != 0: |
|
894 | if id_dev != 0: | |
887 | device = Device.objects.get(pk=id_dev) |
|
895 | device = Device.objects.get(pk=id_dev) | |
888 | kwargs['device'] = device.device_type.name |
|
896 | kwargs['device'] = device.device_type.name | |
889 |
|
897 | |||
890 | return render(request, 'dev_conf_edit.html', kwargs) |
|
898 | return render(request, 'dev_conf_edit.html', kwargs) | |
891 |
|
899 | |||
892 |
|
900 | |||
893 | def dev_conf_edit(request, id_conf): |
|
901 | def dev_conf_edit(request, id_conf): | |
894 |
|
902 | |||
895 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
903 | conf = get_object_or_404(Configuration, pk=id_conf) | |
896 |
|
904 | |||
897 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
905 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
898 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
906 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
899 |
|
907 | |||
900 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
908 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
901 |
|
909 | |||
902 | if request.method=='GET': |
|
910 | if request.method=='GET': | |
903 | form = DevConfForm(instance=dev_conf) |
|
911 | form = DevConfForm(instance=dev_conf) | |
904 |
|
912 | |||
905 | if request.method=='POST': |
|
913 | if request.method=='POST': | |
906 | form = DevConfForm(request.POST, instance=dev_conf) |
|
914 | form = DevConfForm(request.POST, instance=dev_conf) | |
907 |
|
915 | |||
908 | if form.is_valid(): |
|
916 | if form.is_valid(): | |
909 | form.save() |
|
917 | form.save() | |
910 | return redirect('url_dev_conf', id_conf=id_conf) |
|
918 | return redirect('url_dev_conf', id_conf=id_conf) | |
911 |
|
919 | |||
912 | kwargs = {} |
|
920 | kwargs = {} | |
913 | kwargs['form'] = form |
|
921 | kwargs['form'] = form | |
914 | kwargs['title'] = 'Device Configuration' |
|
922 | kwargs['title'] = 'Device Configuration' | |
915 | kwargs['suptitle'] = 'Edit' |
|
923 | kwargs['suptitle'] = 'Edit' | |
916 | kwargs['button'] = 'Update' |
|
924 | kwargs['button'] = 'Update' | |
917 |
|
925 | |||
918 | ###### SIDEBAR ###### |
|
926 | ###### SIDEBAR ###### | |
919 | kwargs.update(sidebar(conf=conf)) |
|
927 | kwargs.update(sidebar(conf=conf)) | |
920 |
|
928 | |||
921 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
929 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
922 |
|
930 | |||
923 |
|
931 | |||
924 | def dev_conf_start(request, id_conf): |
|
932 | def dev_conf_start(request, id_conf): | |
925 |
|
933 | |||
926 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
934 | conf = get_object_or_404(Configuration, pk=id_conf) | |
927 |
|
935 | |||
928 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
936 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
929 |
|
937 | |||
930 | conf = DevConfModel.objects.get(pk=id_conf) |
|
938 | conf = DevConfModel.objects.get(pk=id_conf) | |
931 |
|
939 | |||
932 | if conf.start_device(): |
|
940 | if conf.start_device(): | |
933 | messages.success(request, conf.message) |
|
941 | messages.success(request, conf.message) | |
934 | else: |
|
942 | else: | |
935 | messages.error(request, conf.message) |
|
943 | messages.error(request, conf.message) | |
936 |
|
944 | |||
937 | conf.status_device() |
|
945 | conf.status_device() | |
938 |
|
946 | |||
939 | return redirect(conf.get_absolute_url()) |
|
947 | return redirect(conf.get_absolute_url()) | |
940 |
|
948 | |||
941 |
|
949 | |||
942 | def dev_conf_stop(request, id_conf): |
|
950 | def dev_conf_stop(request, id_conf): | |
943 |
|
951 | |||
944 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
952 | conf = get_object_or_404(Configuration, pk=id_conf) | |
945 |
|
953 | |||
946 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
954 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
947 |
|
955 | |||
948 | conf = DevConfModel.objects.get(pk=id_conf) |
|
956 | conf = DevConfModel.objects.get(pk=id_conf) | |
949 |
|
957 | |||
950 | if conf.stop_device(): |
|
958 | if conf.stop_device(): | |
951 | messages.success(request, conf.message) |
|
959 | messages.success(request, conf.message) | |
952 | else: |
|
960 | else: | |
953 | messages.error(request, conf.message) |
|
961 | messages.error(request, conf.message) | |
954 |
|
962 | |||
955 | conf.status_device() |
|
963 | conf.status_device() | |
956 |
|
964 | |||
957 | return redirect(conf.get_absolute_url()) |
|
965 | return redirect(conf.get_absolute_url()) | |
958 |
|
966 | |||
959 |
|
967 | |||
960 | def dev_conf_status(request, id_conf): |
|
968 | def dev_conf_status(request, id_conf): | |
961 |
|
969 | |||
962 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
970 | conf = get_object_or_404(Configuration, pk=id_conf) | |
963 |
|
971 | |||
964 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
972 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
965 |
|
973 | |||
966 | conf = DevConfModel.objects.get(pk=id_conf) |
|
974 | conf = DevConfModel.objects.get(pk=id_conf) | |
967 |
|
975 | |||
968 | if conf.status_device(): |
|
976 | if conf.status_device(): | |
969 | messages.success(request, conf.message) |
|
977 | messages.success(request, conf.message) | |
970 | else: |
|
978 | else: | |
971 | messages.error(request, conf.message) |
|
979 | messages.error(request, conf.message) | |
972 |
|
980 | |||
973 | return redirect(conf.get_absolute_url()) |
|
981 | return redirect(conf.get_absolute_url()) | |
974 |
|
982 | |||
975 |
|
983 | |||
976 | def dev_conf_write(request, id_conf): |
|
984 | def dev_conf_write(request, id_conf): | |
977 |
|
985 | |||
978 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
986 | conf = get_object_or_404(Configuration, pk=id_conf) | |
979 |
|
987 | |||
980 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
988 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
981 |
|
989 | |||
982 | conf = DevConfModel.objects.get(pk=id_conf) |
|
990 | conf = DevConfModel.objects.get(pk=id_conf) | |
983 |
|
991 | |||
984 | answer = conf.write_device() |
|
992 | answer = conf.write_device() | |
985 | conf.status_device() |
|
993 | conf.status_device() | |
986 |
|
994 | |||
987 | if answer: |
|
995 | if answer: | |
988 | messages.success(request, conf.message) |
|
996 | messages.success(request, conf.message) | |
989 |
|
997 | |||
990 | #Creating a historical configuration |
|
998 | #Creating a historical configuration | |
991 | conf.clone(type=0, template=False) |
|
999 | conf.clone(type=0, template=False) | |
992 |
|
1000 | |||
993 | #Original configuration |
|
1001 | #Original configuration | |
994 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1002 | conf = DevConfModel.objects.get(pk=id_conf) | |
995 | else: |
|
1003 | else: | |
996 | messages.error(request, conf.message) |
|
1004 | messages.error(request, conf.message) | |
997 |
|
1005 | |||
998 | return redirect(conf.get_absolute_url()) |
|
1006 | return redirect(conf.get_absolute_url()) | |
999 |
|
1007 | |||
1000 |
|
1008 | |||
1001 | def dev_conf_read(request, id_conf): |
|
1009 | def dev_conf_read(request, id_conf): | |
1002 |
|
1010 | |||
1003 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1011 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1004 |
|
1012 | |||
1005 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1013 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
1006 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1014 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1007 |
|
1015 | |||
1008 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1016 | conf = DevConfModel.objects.get(pk=id_conf) | |
1009 |
|
1017 | |||
1010 | if request.method=='GET': |
|
1018 | if request.method=='GET': | |
1011 |
|
1019 | |||
1012 | parms = conf.read_device() |
|
1020 | parms = conf.read_device() | |
1013 | conf.status_device() |
|
1021 | conf.status_device() | |
1014 |
|
1022 | |||
1015 | if not parms: |
|
1023 | if not parms: | |
1016 | messages.error(request, conf.message) |
|
1024 | messages.error(request, conf.message) | |
1017 | return redirect(conf.get_absolute_url()) |
|
1025 | return redirect(conf.get_absolute_url()) | |
1018 |
|
1026 | |||
1019 | form = DevConfForm(initial=parms, instance=conf) |
|
1027 | form = DevConfForm(initial=parms, instance=conf) | |
1020 |
|
1028 | |||
1021 | if request.method=='POST': |
|
1029 | if request.method=='POST': | |
1022 | form = DevConfForm(request.POST, instance=conf) |
|
1030 | form = DevConfForm(request.POST, instance=conf) | |
1023 |
|
1031 | |||
1024 | if form.is_valid(): |
|
1032 | if form.is_valid(): | |
1025 | form.save() |
|
1033 | form.save() | |
1026 | return redirect(conf.get_absolute_url()) |
|
1034 | return redirect(conf.get_absolute_url()) | |
1027 |
|
1035 | |||
1028 | messages.error(request, "Parameters could not be saved") |
|
1036 | messages.error(request, "Parameters could not be saved") | |
1029 |
|
1037 | |||
1030 | kwargs = {} |
|
1038 | kwargs = {} | |
1031 | kwargs['id_dev'] = conf.id |
|
1039 | kwargs['id_dev'] = conf.id | |
1032 | kwargs['form'] = form |
|
1040 | kwargs['form'] = form | |
1033 | kwargs['title'] = 'Device Configuration' |
|
1041 | kwargs['title'] = 'Device Configuration' | |
1034 | kwargs['suptitle'] = 'Parameters read from device' |
|
1042 | kwargs['suptitle'] = 'Parameters read from device' | |
1035 | kwargs['button'] = 'Save' |
|
1043 | kwargs['button'] = 'Save' | |
1036 |
|
1044 | |||
1037 | ###### SIDEBAR ###### |
|
1045 | ###### SIDEBAR ###### | |
1038 | kwargs.update(sidebar(conf=conf)) |
|
1046 | kwargs.update(sidebar(conf=conf)) | |
1039 |
|
1047 | |||
1040 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
1048 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
1041 |
|
1049 | |||
1042 |
|
1050 | |||
1043 | def dev_conf_import(request, id_conf): |
|
1051 | def dev_conf_import(request, id_conf): | |
1044 |
|
1052 | |||
1045 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1053 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1046 |
|
1054 | |||
1047 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1055 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
1048 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1056 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1049 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1057 | conf = DevConfModel.objects.get(pk=id_conf) | |
1050 |
|
1058 | |||
1051 | if request.method == 'GET': |
|
1059 | if request.method == 'GET': | |
1052 | file_form = UploadFileForm() |
|
1060 | file_form = UploadFileForm() | |
1053 |
|
1061 | |||
1054 | if request.method == 'POST': |
|
1062 | if request.method == 'POST': | |
1055 | file_form = UploadFileForm(request.POST, request.FILES) |
|
1063 | file_form = UploadFileForm(request.POST, request.FILES) | |
1056 |
|
1064 | |||
1057 | if file_form.is_valid(): |
|
1065 | if file_form.is_valid(): | |
1058 |
|
1066 | |||
1059 | parms = conf.import_from_file(request.FILES['file']) |
|
1067 | parms = conf.import_from_file(request.FILES['file']) | |
1060 |
|
1068 | |||
1061 | if parms: |
|
1069 | if parms: | |
1062 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
1070 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
1063 | form = DevConfForm(initial=parms, instance=conf) |
|
1071 | form = DevConfForm(initial=parms, instance=conf) | |
1064 |
|
1072 | |||
1065 | kwargs = {} |
|
1073 | kwargs = {} | |
1066 | kwargs['id_dev'] = conf.id |
|
1074 | kwargs['id_dev'] = conf.id | |
1067 | kwargs['form'] = form |
|
1075 | kwargs['form'] = form | |
1068 | kwargs['title'] = 'Device Configuration' |
|
1076 | kwargs['title'] = 'Device Configuration' | |
1069 | kwargs['suptitle'] = 'Parameters imported' |
|
1077 | kwargs['suptitle'] = 'Parameters imported' | |
1070 | kwargs['button'] = 'Save' |
|
1078 | kwargs['button'] = 'Save' | |
1071 | kwargs['action'] = conf.get_absolute_url_edit() |
|
1079 | kwargs['action'] = conf.get_absolute_url_edit() | |
1072 | kwargs['previous'] = conf.get_absolute_url() |
|
1080 | kwargs['previous'] = conf.get_absolute_url() | |
1073 |
|
1081 | |||
1074 | ###### SIDEBAR ###### |
|
1082 | ###### SIDEBAR ###### | |
1075 | kwargs.update(sidebar(conf=conf)) |
|
1083 | kwargs.update(sidebar(conf=conf)) | |
1076 |
|
1084 | |||
1077 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1085 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1078 |
|
1086 | |||
1079 | messages.error(request, "Could not import parameters from file") |
|
1087 | messages.error(request, "Could not import parameters from file") | |
1080 |
|
1088 | |||
1081 | kwargs = {} |
|
1089 | kwargs = {} | |
1082 | kwargs['id_dev'] = conf.id |
|
1090 | kwargs['id_dev'] = conf.id | |
1083 | kwargs['title'] = 'Device Configuration' |
|
1091 | kwargs['title'] = 'Device Configuration' | |
1084 | kwargs['form'] = file_form |
|
1092 | kwargs['form'] = file_form | |
1085 | kwargs['suptitle'] = 'Importing file' |
|
1093 | kwargs['suptitle'] = 'Importing file' | |
1086 | kwargs['button'] = 'Import' |
|
1094 | kwargs['button'] = 'Import' | |
1087 |
|
1095 | |||
1088 | kwargs.update(sidebar(conf=conf)) |
|
1096 | kwargs.update(sidebar(conf=conf)) | |
1089 |
|
1097 | |||
1090 | return render(request, 'dev_conf_import.html', kwargs) |
|
1098 | return render(request, 'dev_conf_import.html', kwargs) | |
1091 |
|
1099 | |||
1092 |
|
1100 | |||
1093 | def dev_conf_export(request, id_conf): |
|
1101 | def dev_conf_export(request, id_conf): | |
1094 |
|
1102 | |||
1095 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1103 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1096 |
|
1104 | |||
1097 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1105 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
1098 |
|
1106 | |||
1099 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1107 | conf = DevConfModel.objects.get(pk=id_conf) | |
1100 |
|
1108 | |||
1101 | if request.method == 'GET': |
|
1109 | if request.method == 'GET': | |
1102 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1110 | file_form = DownloadFileForm(conf.device.device_type.name) | |
1103 |
|
1111 | |||
1104 | if request.method == 'POST': |
|
1112 | if request.method == 'POST': | |
1105 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
1113 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
1106 |
|
1114 | |||
1107 | if file_form.is_valid(): |
|
1115 | if file_form.is_valid(): | |
1108 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
1116 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
1109 |
|
1117 | |||
1110 | response = HttpResponse(content_type=fields['content_type']) |
|
1118 | response = HttpResponse(content_type=fields['content_type']) | |
1111 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
1119 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
1112 | response.write(fields['content']) |
|
1120 | response.write(fields['content']) | |
1113 |
|
1121 | |||
1114 | return response |
|
1122 | return response | |
1115 |
|
1123 | |||
1116 | messages.error(request, "Could not export parameters") |
|
1124 | messages.error(request, "Could not export parameters") | |
1117 |
|
1125 | |||
1118 | kwargs = {} |
|
1126 | kwargs = {} | |
1119 | kwargs['id_dev'] = conf.id |
|
1127 | kwargs['id_dev'] = conf.id | |
1120 | kwargs['title'] = 'Device Configuration' |
|
1128 | kwargs['title'] = 'Device Configuration' | |
1121 | kwargs['form'] = file_form |
|
1129 | kwargs['form'] = file_form | |
1122 | kwargs['suptitle'] = 'Exporting file' |
|
1130 | kwargs['suptitle'] = 'Exporting file' | |
1123 | kwargs['button'] = 'Export' |
|
1131 | kwargs['button'] = 'Export' | |
1124 |
|
1132 | |||
1125 | return render(request, 'dev_conf_export.html', kwargs) |
|
1133 | return render(request, 'dev_conf_export.html', kwargs) | |
1126 |
|
1134 | |||
1127 |
|
1135 | |||
1128 | def dev_conf_delete(request, id_conf): |
|
1136 | def dev_conf_delete(request, id_conf): | |
1129 |
|
1137 | |||
1130 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1138 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1131 |
|
1139 | |||
1132 | if request.method=='POST': |
|
1140 | if request.method=='POST': | |
1133 | if request.user.is_staff: |
|
1141 | if request.user.is_staff: | |
1134 | conf.delete() |
|
1142 | conf.delete() | |
1135 | return redirect('url_dev_confs') |
|
1143 | return redirect('url_dev_confs') | |
1136 |
|
1144 | |||
1137 | messages.error(request, 'Not enough permission to delete this object') |
|
1145 | messages.error(request, 'Not enough permission to delete this object') | |
1138 | return redirect(conf.get_absolute_url()) |
|
1146 | return redirect(conf.get_absolute_url()) | |
1139 |
|
1147 | |||
1140 | kwargs = { |
|
1148 | kwargs = { | |
1141 | 'title': 'Delete', |
|
1149 | 'title': 'Delete', | |
1142 | 'suptitle': 'Experiment', |
|
1150 | 'suptitle': 'Experiment', | |
1143 | 'object': conf, |
|
1151 | 'object': conf, | |
1144 | 'previous': conf.get_absolute_url(), |
|
1152 | 'previous': conf.get_absolute_url(), | |
1145 | 'delete': True |
|
1153 | 'delete': True | |
1146 | } |
|
1154 | } | |
1147 |
|
1155 | |||
1148 | return render(request, 'confirm.html', kwargs) |
|
1156 | return render(request, 'confirm.html', kwargs) | |
1149 |
|
1157 | |||
1150 |
|
1158 | |||
1151 | def sidebar(**kwargs): |
|
1159 | def sidebar(**kwargs): | |
1152 |
|
1160 | |||
1153 | side_data = {} |
|
1161 | side_data = {} | |
1154 |
|
1162 | |||
1155 | conf = kwargs.get('conf', None) |
|
1163 | conf = kwargs.get('conf', None) | |
1156 | experiment = kwargs.get('experiment', None) |
|
1164 | experiment = kwargs.get('experiment', None) | |
1157 |
|
1165 | |||
1158 | if not experiment: |
|
1166 | if not experiment: | |
1159 | experiment = conf.experiment |
|
1167 | experiment = conf.experiment | |
1160 |
|
1168 | |||
1161 | if experiment: |
|
1169 | if experiment: | |
1162 | side_data['experiment'] = experiment |
|
1170 | side_data['experiment'] = experiment | |
1163 | campaign = experiment.campaign_set.all() |
|
1171 | campaign = experiment.campaign_set.all() | |
1164 | if campaign: |
|
1172 | if campaign: | |
1165 | side_data['campaign'] = campaign[0] |
|
1173 | side_data['campaign'] = campaign[0] | |
1166 | experiments = campaign[0].experiments.all() |
|
1174 | experiments = campaign[0].experiments.all() | |
1167 | else: |
|
1175 | else: | |
1168 | experiments = [experiment] |
|
1176 | experiments = [experiment] | |
1169 | configurations = experiment.configuration_set.filter(type=0) |
|
1177 | configurations = experiment.configuration_set.filter(type=0) | |
1170 | side_data['side_experiments'] = experiments |
|
1178 | side_data['side_experiments'] = experiments | |
1171 | side_data['side_configurations'] = configurations |
|
1179 | side_data['side_configurations'] = configurations | |
1172 |
|
1180 | |||
1173 | return side_data |
|
1181 | return side_data | |
1174 |
|
1182 | |||
|
1183 | def get_paginator(model, page, order, filters={}, n=10): | |||
|
1184 | ||||
|
1185 | kwargs = {} | |||
|
1186 | query = Q() | |||
|
1187 | if isinstance(filters, QueryDict): | |||
|
1188 | filters = filters.dict() | |||
|
1189 | [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] | |||
|
1190 | filters.pop('page', None) | |||
|
1191 | ||||
|
1192 | if 'start_date' in filters: | |||
|
1193 | filters['start_date__gte'] = filters.pop('start_date') | |||
|
1194 | if 'end_date' in filters: | |||
|
1195 | filters['start_date__lte'] = filters.pop('end_date') | |||
|
1196 | if 'tags' in filters: | |||
|
1197 | tags = filters.pop('tags') | |||
|
1198 | if 'tags' in model._meta.get_all_field_names(): | |||
|
1199 | query = query | Q(tags__icontains=tags) | |||
|
1200 | if 'name' in model._meta.get_all_field_names(): | |||
|
1201 | query = query | Q(name__icontains=tags) | |||
|
1202 | if 'location' in model._meta.get_all_field_names(): | |||
|
1203 | query = query | Q(location__name__icontains=tags) | |||
|
1204 | if 'device' in model._meta.get_all_field_names(): | |||
|
1205 | query = query | Q(device__name__icontains=tags) | |||
|
1206 | ||||
|
1207 | object_list = model.objects.filter(query, **filters).order_by(*order) | |||
|
1208 | paginator = Paginator(object_list, n) | |||
|
1209 | ||||
|
1210 | try: | |||
|
1211 | objects = paginator.page(page) | |||
|
1212 | except PageNotAnInteger: | |||
|
1213 | objects = paginator.page(1) | |||
|
1214 | except EmptyPage: | |||
|
1215 | objects = paginator.page(paginator.num_pages) | |||
|
1216 | ||||
|
1217 | kwargs['objects'] = objects | |||
|
1218 | kwargs['offset'] = (int(page)-1)*n if page else 0 | |||
|
1219 | ||||
|
1220 | return kwargs | |||
1175 |
|
1221 | |||
1176 | def operation(request, id_camp=None): |
|
1222 | def operation(request, id_camp=None): | |
1177 |
|
1223 | |||
1178 | if not id_camp: |
|
1224 | if not id_camp: | |
1179 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1225 | campaigns = Campaign.objects.all().order_by('-start_date') | |
1180 |
|
1226 | |||
1181 | if not campaigns: |
|
1227 | if not campaigns: | |
1182 | kwargs = {} |
|
1228 | kwargs = {} | |
1183 | kwargs['title'] = 'No Campaigns' |
|
1229 | kwargs['title'] = 'No Campaigns' | |
1184 | kwargs['suptitle'] = 'Empty' |
|
1230 | kwargs['suptitle'] = 'Empty' | |
1185 | return render(request, 'operation.html', kwargs) |
|
1231 | return render(request, 'operation.html', kwargs) | |
1186 |
|
1232 | |||
1187 | id_camp = campaigns[0].id |
|
1233 | id_camp = campaigns[0].id | |
1188 |
|
1234 | |||
1189 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1235 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1190 |
|
1236 | |||
1191 | if request.method=='GET': |
|
1237 | if request.method=='GET': | |
1192 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
1238 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
1193 |
|
1239 | |||
1194 | if request.method=='POST': |
|
1240 | if request.method=='POST': | |
1195 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
1241 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
1196 |
|
1242 | |||
1197 | if form.is_valid(): |
|
1243 | if form.is_valid(): | |
1198 | return redirect('url_operation', id_camp=campaign.id) |
|
1244 | return redirect('url_operation', id_camp=campaign.id) | |
1199 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1245 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
1200 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1246 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
1201 | #for exs in experiments: |
|
1247 | #for exs in experiments: | |
1202 | # exs.get_status() |
|
1248 | # exs.get_status() | |
1203 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1249 | locations= Location.objects.filter(experiment=experiments).distinct() | |
1204 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
1250 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
1205 | kwargs = {} |
|
1251 | kwargs = {} | |
1206 | #---Campaign |
|
1252 | #---Campaign | |
1207 | kwargs['campaign'] = campaign |
|
1253 | kwargs['campaign'] = campaign | |
1208 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1254 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
1209 | #---Experiment |
|
1255 | #---Experiment | |
1210 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1256 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1211 | kwargs['experiment_keys'] = keys[1:] |
|
1257 | kwargs['experiment_keys'] = keys[1:] | |
1212 | kwargs['experiments'] = experiments |
|
1258 | kwargs['experiments'] = experiments | |
1213 | #---Radar |
|
1259 | #---Radar | |
1214 | kwargs['locations'] = locations |
|
1260 | kwargs['locations'] = locations | |
1215 | #---Else |
|
1261 | #---Else | |
1216 | kwargs['title'] = 'Campaign' |
|
1262 | kwargs['title'] = 'Campaign' | |
1217 | kwargs['suptitle'] = campaign.name |
|
1263 | kwargs['suptitle'] = campaign.name | |
1218 | kwargs['form'] = form |
|
1264 | kwargs['form'] = form | |
1219 | kwargs['button'] = 'Search' |
|
1265 | kwargs['button'] = 'Search' | |
1220 | kwargs['details'] = True |
|
1266 | kwargs['details'] = True | |
1221 | kwargs['search_button'] = True |
|
1267 | kwargs['search_button'] = True | |
1222 |
|
1268 | |||
1223 | return render(request, 'operation.html', kwargs) |
|
1269 | return render(request, 'operation.html', kwargs) | |
1224 |
|
1270 | |||
1225 |
|
1271 | |||
1226 | def operation_search(request, id_camp=None): |
|
1272 | def operation_search(request, id_camp=None): | |
1227 |
|
1273 | |||
1228 |
|
1274 | |||
1229 | if not id_camp: |
|
1275 | if not id_camp: | |
1230 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1276 | campaigns = Campaign.objects.all().order_by('-start_date') | |
1231 |
|
1277 | |||
1232 | if not campaigns: |
|
1278 | if not campaigns: | |
1233 | return render(request, 'operation.html', {}) |
|
1279 | return render(request, 'operation.html', {}) | |
1234 |
|
1280 | |||
1235 | id_camp = campaigns[0].id |
|
1281 | id_camp = campaigns[0].id | |
1236 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1282 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1237 |
|
1283 | |||
1238 | if request.method=='GET': |
|
1284 | if request.method=='GET': | |
1239 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1285 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1240 |
|
1286 | |||
1241 | if request.method=='POST': |
|
1287 | if request.method=='POST': | |
1242 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
1288 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
1243 |
|
1289 | |||
1244 | if form.is_valid(): |
|
1290 | if form.is_valid(): | |
1245 | return redirect('url_operation', id_camp=campaign.id) |
|
1291 | return redirect('url_operation', id_camp=campaign.id) | |
1246 |
|
1292 | |||
1247 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1293 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
1248 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1294 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
1249 | #for exs in experiments: |
|
1295 | #for exs in experiments: | |
1250 | # exs.get_status() |
|
1296 | # exs.get_status() | |
1251 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1297 | locations= Location.objects.filter(experiment=experiments).distinct() | |
1252 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1298 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1253 |
|
1299 | |||
1254 | kwargs = {} |
|
1300 | kwargs = {} | |
1255 | #---Campaign |
|
1301 | #---Campaign | |
1256 | kwargs['campaign'] = campaign |
|
1302 | kwargs['campaign'] = campaign | |
1257 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1303 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
1258 | #---Experiment |
|
1304 | #---Experiment | |
1259 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1305 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1260 | kwargs['experiment_keys'] = keys[1:] |
|
1306 | kwargs['experiment_keys'] = keys[1:] | |
1261 | kwargs['experiments'] = experiments |
|
1307 | kwargs['experiments'] = experiments | |
1262 | #---Radar |
|
1308 | #---Radar | |
1263 | kwargs['locations'] = locations |
|
1309 | kwargs['locations'] = locations | |
1264 | #---Else |
|
1310 | #---Else | |
1265 | kwargs['title'] = 'Campaign' |
|
1311 | kwargs['title'] = 'Campaign' | |
1266 | kwargs['suptitle'] = campaign.name |
|
1312 | kwargs['suptitle'] = campaign.name | |
1267 | kwargs['form'] = form |
|
1313 | kwargs['form'] = form | |
1268 | kwargs['button'] = 'Select' |
|
1314 | kwargs['button'] = 'Select' | |
1269 | kwargs['details'] = True |
|
1315 | kwargs['details'] = True | |
1270 | kwargs['search_button'] = False |
|
1316 | kwargs['search_button'] = False | |
1271 |
|
1317 | |||
1272 | return render(request, 'operation.html', kwargs) |
|
1318 | return render(request, 'operation.html', kwargs) | |
1273 |
|
1319 | |||
1274 |
|
1320 | |||
1275 | def radar_play(request, id_camp, id_radar): |
|
1321 | def radar_play(request, id_camp, id_radar): | |
1276 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1322 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1277 | radar = get_object_or_404(Location, pk = id_radar) |
|
1323 | radar = get_object_or_404(Location, pk = id_radar) | |
1278 | today = datetime.today() |
|
1324 | today = datetime.today() | |
1279 | now = today.time() |
|
1325 | now = today.time() | |
1280 |
|
1326 | |||
1281 | #--Clear Old Experiments From RunningExperiment Object |
|
1327 | #--Clear Old Experiments From RunningExperiment Object | |
1282 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1328 | running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1283 | if running_experiment: |
|
1329 | if running_experiment: | |
1284 | running_experiment = running_experiment[0] |
|
1330 | running_experiment = running_experiment[0] | |
1285 | running_experiment.running_experiment.clear() |
|
1331 | running_experiment.running_experiment.clear() | |
1286 | running_experiment.save() |
|
1332 | running_experiment.save() | |
1287 |
|
1333 | |||
1288 | #--If campaign datetime is ok: |
|
1334 | #--If campaign datetime is ok: | |
1289 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1335 | if today >= campaign.start_date and today <= campaign.end_date: | |
1290 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1336 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1291 | for exp in experiments: |
|
1337 | for exp in experiments: | |
1292 | #--If experiment time is ok: |
|
1338 | #--If experiment time is ok: | |
1293 | if now >= exp.start_time and now <= exp.end_time: |
|
1339 | if now >= exp.start_time and now <= exp.end_time: | |
1294 | configurations = Configuration.objects.filter(experiment = exp) |
|
1340 | configurations = Configuration.objects.filter(experiment = exp) | |
1295 | for conf in configurations: |
|
1341 | for conf in configurations: | |
1296 | if 'cgs' in conf.device.device_type.name: |
|
1342 | if 'cgs' in conf.device.device_type.name: | |
1297 | conf.status_device() |
|
1343 | conf.status_device() | |
1298 | else: |
|
1344 | else: | |
1299 | answer = conf.start_device() |
|
1345 | answer = conf.start_device() | |
1300 | conf.status_device() |
|
1346 | conf.status_device() | |
1301 | #--Running Experiment |
|
1347 | #--Running Experiment | |
1302 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1348 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1303 | #--If RunningExperiment element exists |
|
1349 | #--If RunningExperiment element exists | |
1304 | if old_running_experiment: |
|
1350 | if old_running_experiment: | |
1305 | old_running_experiment = old_running_experiment[0] |
|
1351 | old_running_experiment = old_running_experiment[0] | |
1306 | old_running_experiment.running_experiment.add(exp) |
|
1352 | old_running_experiment.running_experiment.add(exp) | |
1307 | old_running_experiment.status = 3 |
|
1353 | old_running_experiment.status = 3 | |
1308 | old_running_experiment.save() |
|
1354 | old_running_experiment.save() | |
1309 | #--Create a new Running_Experiment Object |
|
1355 | #--Create a new Running_Experiment Object | |
1310 | else: |
|
1356 | else: | |
1311 | new_running_experiment = RunningExperiment( |
|
1357 | new_running_experiment = RunningExperiment( | |
1312 | radar = radar, |
|
1358 | radar = radar, | |
1313 | status = 3, |
|
1359 | status = 3, | |
1314 | ) |
|
1360 | ) | |
1315 | new_running_experiment.save() |
|
1361 | new_running_experiment.save() | |
1316 | new_running_experiment.running_experiment.add(exp) |
|
1362 | new_running_experiment.running_experiment.add(exp) | |
1317 | new_running_experiment.save() |
|
1363 | new_running_experiment.save() | |
1318 |
|
1364 | |||
1319 | if answer: |
|
1365 | if answer: | |
1320 | messages.success(request, conf.message) |
|
1366 | messages.success(request, conf.message) | |
1321 | exp.status=2 |
|
1367 | exp.status=2 | |
1322 | exp.save() |
|
1368 | exp.save() | |
1323 | else: |
|
1369 | else: | |
1324 | messages.error(request, conf.message) |
|
1370 | messages.error(request, conf.message) | |
1325 | else: |
|
1371 | else: | |
1326 | if exp.status == 1 or exp.status == 3: |
|
1372 | if exp.status == 1 or exp.status == 3: | |
1327 | exp.status=3 |
|
1373 | exp.status=3 | |
1328 | exp.save() |
|
1374 | exp.save() | |
1329 |
|
1375 | |||
1330 |
|
1376 | |||
1331 | route = request.META['HTTP_REFERER'] |
|
1377 | route = request.META['HTTP_REFERER'] | |
1332 | route = str(route) |
|
1378 | route = str(route) | |
1333 | if 'search' in route: |
|
1379 | if 'search' in route: | |
1334 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1380 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1335 | else: |
|
1381 | else: | |
1336 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1382 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1337 |
|
1383 | |||
1338 |
|
1384 | |||
1339 | def radar_stop(request, id_camp, id_radar): |
|
1385 | def radar_stop(request, id_camp, id_radar): | |
1340 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1386 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1341 | radar = get_object_or_404(Location, pk = id_radar) |
|
1387 | radar = get_object_or_404(Location, pk = id_radar) | |
1342 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1388 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1343 |
|
1389 | |||
1344 | for exp in experiments: |
|
1390 | for exp in experiments: | |
1345 | configurations = Configuration.objects.filter(experiment = exp) |
|
1391 | configurations = Configuration.objects.filter(experiment = exp) | |
1346 | for conf in configurations: |
|
1392 | for conf in configurations: | |
1347 | if 'cgs' in conf.device.device_type.name: |
|
1393 | if 'cgs' in conf.device.device_type.name: | |
1348 | conf.status_device() |
|
1394 | conf.status_device() | |
1349 | else: |
|
1395 | else: | |
1350 | answer = conf.stop_device() |
|
1396 | answer = conf.stop_device() | |
1351 | conf.status_device() |
|
1397 | conf.status_device() | |
1352 |
|
1398 | |||
1353 | if answer: |
|
1399 | if answer: | |
1354 | messages.success(request, conf.message) |
|
1400 | messages.success(request, conf.message) | |
1355 | exp.status=1 |
|
1401 | exp.status=1 | |
1356 | exp.save() |
|
1402 | exp.save() | |
1357 | else: |
|
1403 | else: | |
1358 | messages.error(request, conf.message) |
|
1404 | messages.error(request, conf.message) | |
1359 |
|
1405 | |||
1360 |
|
1406 | |||
1361 | route = request.META['HTTP_REFERER'] |
|
1407 | route = request.META['HTTP_REFERER'] | |
1362 | route = str(route) |
|
1408 | route = str(route) | |
1363 | if 'search' in route: |
|
1409 | if 'search' in route: | |
1364 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1410 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1365 | else: |
|
1411 | else: | |
1366 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1412 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1367 |
|
1413 | |||
1368 |
|
1414 | |||
1369 | def radar_refresh(request, id_camp, id_radar): |
|
1415 | def radar_refresh(request, id_camp, id_radar): | |
1370 |
|
1416 | |||
1371 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1417 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1372 | radar = get_object_or_404(Location, pk = id_radar) |
|
1418 | radar = get_object_or_404(Location, pk = id_radar) | |
1373 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1419 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1374 | for exs in experiments: |
|
1420 | for exs in experiments: | |
1375 | exs.get_status() |
|
1421 | exs.get_status() | |
1376 |
|
1422 | |||
1377 | route = request.META['HTTP_REFERER'] |
|
1423 | route = request.META['HTTP_REFERER'] | |
1378 | route = str(route) |
|
1424 | route = str(route) | |
1379 | if 'search' in route: |
|
1425 | if 'search' in route: | |
1380 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1426 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1381 | else: |
|
1427 | else: | |
1382 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1428 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1383 |
|
1429 |
@@ -1,774 +1,766 | |||||
1 |
|
1 | |||
2 | import ast |
|
2 | import ast | |
3 | import json |
|
3 | import json | |
4 | import numpy as np |
|
4 | import numpy as np | |
5 |
|
5 | |||
6 | from polymorphic import PolymorphicModel |
|
6 | from polymorphic import PolymorphicModel | |
7 |
|
7 | |||
8 | from django.db import models |
|
8 | from django.db import models | |
9 | from django.core.urlresolvers import reverse |
|
9 | from django.core.urlresolvers import reverse | |
10 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
10 | from django.core.validators import MinValueValidator, MaxValueValidator | |
11 |
|
11 | |||
12 | from apps.main.models import Configuration |
|
12 | from apps.main.models import Configuration | |
13 | from devices.rc import api |
|
13 | from devices.rc import api | |
14 | from .utils import RCFile |
|
14 | from .utils import RCFile | |
15 |
|
15 | |||
16 | # Create your models here. |
|
16 | # Create your models here. | |
17 |
|
17 | |||
18 | LINE_TYPES = ( |
|
18 | LINE_TYPES = ( | |
19 | ('none', 'Not used'), |
|
19 | ('none', 'Not used'), | |
20 | ('tr', 'Transmission/reception selector signal'), |
|
20 | ('tr', 'Transmission/reception selector signal'), | |
21 | ('tx', 'A modulating signal (Transmission pulse)'), |
|
21 | ('tx', 'A modulating signal (Transmission pulse)'), | |
22 | ('codes', 'BPSK modulating signal'), |
|
22 | ('codes', 'BPSK modulating signal'), | |
23 | ('windows', 'Sample window signal'), |
|
23 | ('windows', 'Sample window signal'), | |
24 | ('sync', 'Synchronizing signal'), |
|
24 | ('sync', 'Synchronizing signal'), | |
25 | ('flip', 'IPP related periodic signal'), |
|
25 | ('flip', 'IPP related periodic signal'), | |
26 | ('prog_pulses', 'Programmable pulse'), |
|
26 | ('prog_pulses', 'Programmable pulse'), | |
27 | ('mix', 'Mixed line'), |
|
27 | ('mix', 'Mixed line'), | |
28 | ) |
|
28 | ) | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | SAMPLING_REFS = ( |
|
31 | SAMPLING_REFS = ( | |
32 | ('none', 'No Reference'), |
|
32 | ('none', 'No Reference'), | |
33 | ('first_baud', 'Middle of the first baud'), |
|
33 | ('first_baud', 'Middle of the first baud'), | |
34 | ('sub_baud', 'Middle of the sub-baud') |
|
34 | ('sub_baud', 'Middle of the sub-baud') | |
35 | ) |
|
35 | ) | |
36 |
|
36 | |||
37 | DAT_CMDS = { |
|
37 | DAT_CMDS = { | |
38 | # Pulse Design commands |
|
38 | # Pulse Design commands | |
39 | 'DISABLE' : 0, # Disables pulse generation |
|
39 | 'DISABLE' : 0, # Disables pulse generation | |
40 | 'ENABLE' : 24, # Enables pulse generation |
|
40 | 'ENABLE' : 24, # Enables pulse generation | |
41 | 'DELAY_START' : 40, # Write delay status to memory |
|
41 | 'DELAY_START' : 40, # Write delay status to memory | |
42 | 'FLIP_START' : 48, # Write flip status to memory |
|
42 | 'FLIP_START' : 48, # Write flip status to memory | |
43 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period |
|
43 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period | |
44 | 'TX_ONE' : 72, # Output '0' in line TX |
|
44 | 'TX_ONE' : 72, # Output '0' in line TX | |
45 | 'TX_ZERO' : 88, # Output '0' in line TX |
|
45 | 'TX_ZERO' : 88, # Output '0' in line TX | |
46 | 'SW_ONE' : 104, # Output '0' in line SW |
|
46 | 'SW_ONE' : 104, # Output '0' in line SW | |
47 | 'SW_ZERO' : 112, # Output '1' in line SW |
|
47 | 'SW_ZERO' : 112, # Output '1' in line SW | |
48 | 'RESTART': 120, # Restarts CR8 Firmware |
|
48 | 'RESTART': 120, # Restarts CR8 Firmware | |
49 | 'CONTINUE' : 253, # Function Unknown |
|
49 | 'CONTINUE' : 253, # Function Unknown | |
50 | # Commands available to new controllers |
|
50 | # Commands available to new controllers | |
51 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. |
|
51 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. | |
52 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion |
|
52 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion | |
53 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. |
|
53 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. | |
54 | 'CLOCK_DIVIDER' : 8, |
|
54 | 'CLOCK_DIVIDER' : 8, | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | class RCConfiguration(Configuration): |
|
58 | class RCConfiguration(Configuration): | |
59 |
|
59 | |||
60 |
ipp = models.FloatField(verbose_name='I |
|
60 | ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1), MaxValueValidator(9000)], default=300) | |
61 |
ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator( |
|
61 | ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator(400)], default=1) | |
62 | clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) |
|
62 | clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) | |
63 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) |
|
63 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) | |
64 | clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) |
|
64 | clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) | |
65 | time_before = models.PositiveIntegerField(verbose_name='Time before [μS]', default=12) |
|
65 | time_before = models.PositiveIntegerField(verbose_name='Time before [μS]', default=12) | |
66 | time_after = models.PositiveIntegerField(verbose_name='Time after [μS]', default=1) |
|
66 | time_after = models.PositiveIntegerField(verbose_name='Time after [μS]', default=1) | |
67 | sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0) |
|
67 | sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0) | |
68 | sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40) |
|
68 | sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40) | |
69 | control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False) |
|
69 | control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False) | |
70 | control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False) |
|
70 | control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False) | |
71 | total_units = models.PositiveIntegerField(default=0) |
|
71 | total_units = models.PositiveIntegerField(default=0) | |
72 | mix = models.BooleanField(default=False) |
|
72 | mix = models.BooleanField(default=False) | |
73 |
|
73 | |||
74 | class Meta: |
|
74 | class Meta: | |
75 | db_table = 'rc_configurations' |
|
75 | db_table = 'rc_configurations' | |
76 |
|
76 | |||
77 |
|
||||
78 | def __unicode__(self): |
|
|||
79 |
|
||||
80 | if self.mix: |
|
|||
81 | return u'[RC MIXED]: {}'.format(self.name) |
|
|||
82 | else: |
|
|||
83 | return u'[RC]: {}'.format(self.name) |
|
|||
84 |
|
||||
85 | def get_absolute_url_plot(self): |
|
77 | def get_absolute_url_plot(self): | |
86 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) |
|
78 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) | |
87 |
|
79 | |||
88 | def get_absolute_url_import(self): |
|
80 | def get_absolute_url_import(self): | |
89 | return reverse('url_import_rc_conf', args=[str(self.id)]) |
|
81 | return reverse('url_import_rc_conf', args=[str(self.id)]) | |
90 |
|
82 | |||
91 | @property |
|
83 | @property | |
92 | def ipp_unit(self): |
|
84 | def ipp_unit(self): | |
93 |
|
85 | |||
94 | return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit)) |
|
86 | return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit)) | |
95 |
|
87 | |||
96 | @property |
|
88 | @property | |
97 | def us2unit(self): |
|
89 | def us2unit(self): | |
98 |
|
90 | |||
99 | return self.clock_in/self.clock_divider |
|
91 | return self.clock_in/self.clock_divider | |
100 |
|
92 | |||
101 | @property |
|
93 | @property | |
102 | def km2unit(self): |
|
94 | def km2unit(self): | |
103 |
|
95 | |||
104 | return 20./3*(self.clock_in/self.clock_divider) |
|
96 | return 20./3*(self.clock_in/self.clock_divider) | |
105 |
|
97 | |||
106 | def clone(self, **kwargs): |
|
98 | def clone(self, **kwargs): | |
107 |
|
99 | |||
108 | lines = self.get_lines() |
|
100 | lines = self.get_lines() | |
109 | self.pk = None |
|
101 | self.pk = None | |
110 | self.id = None |
|
102 | self.id = None | |
111 | for attr, value in kwargs.items(): |
|
103 | for attr, value in kwargs.items(): | |
112 | setattr(self, attr, value) |
|
104 | setattr(self, attr, value) | |
113 | self.save() |
|
105 | self.save() | |
114 |
|
106 | |||
115 | for line in lines: |
|
107 | for line in lines: | |
116 | line.clone(rc_configuration=self) |
|
108 | line.clone(rc_configuration=self) | |
117 |
|
109 | |||
118 | return self |
|
110 | return self | |
119 |
|
111 | |||
120 | def get_lines(self, **kwargs): |
|
112 | def get_lines(self, **kwargs): | |
121 | ''' |
|
113 | ''' | |
122 | Retrieve configuration lines |
|
114 | Retrieve configuration lines | |
123 | ''' |
|
115 | ''' | |
124 |
|
116 | |||
125 | return RCLine.objects.filter(rc_configuration=self.pk, **kwargs) |
|
117 | return RCLine.objects.filter(rc_configuration=self.pk, **kwargs) | |
126 |
|
118 | |||
127 |
|
119 | |||
128 | def clean_lines(self): |
|
120 | def clean_lines(self): | |
129 | ''' |
|
121 | ''' | |
130 | ''' |
|
122 | ''' | |
131 |
|
123 | |||
132 | empty_line = RCLineType.objects.get(name='none') |
|
124 | empty_line = RCLineType.objects.get(name='none') | |
133 |
|
125 | |||
134 | for line in self.get_lines(): |
|
126 | for line in self.get_lines(): | |
135 | line.line_type = empty_line |
|
127 | line.line_type = empty_line | |
136 | line.params = '{}' |
|
128 | line.params = '{}' | |
137 | line.save() |
|
129 | line.save() | |
138 |
|
130 | |||
139 | def parms_to_dict(self): |
|
131 | def parms_to_dict(self): | |
140 | ''' |
|
132 | ''' | |
141 | ''' |
|
133 | ''' | |
142 |
|
134 | |||
143 | ignored = ('parameters', 'type', 'polymorphic_ctype', 'configuration_ptr', |
|
135 | ignored = ('parameters', 'type', 'polymorphic_ctype', 'configuration_ptr', | |
144 | 'created_date', 'programmed_date') |
|
136 | 'created_date', 'programmed_date') | |
145 |
|
137 | |||
146 | data = {} |
|
138 | data = {} | |
147 | for field in self._meta.fields: |
|
139 | for field in self._meta.fields: | |
148 | if field.name in ignored: |
|
140 | if field.name in ignored: | |
149 | continue |
|
141 | continue | |
150 | data[field.name] = '{}'.format(field.value_from_object(self)) |
|
142 | data[field.name] = '{}'.format(field.value_from_object(self)) | |
151 |
|
143 | |||
152 | data['lines'] = [] |
|
144 | data['lines'] = [] | |
153 |
|
145 | |||
154 | for line in self.get_lines(): |
|
146 | for line in self.get_lines(): | |
155 | line_data = json.loads(line.params) |
|
147 | line_data = json.loads(line.params) | |
156 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): |
|
148 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): | |
157 | line_data['TX_ref'] = RCLine.objects.get(pk=line_data['TX_ref']).get_name() |
|
149 | line_data['TX_ref'] = RCLine.objects.get(pk=line_data['TX_ref']).get_name() | |
158 | if 'code' in line_data: |
|
150 | if 'code' in line_data: | |
159 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name |
|
151 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name | |
160 | line_data['type'] = line.line_type.name |
|
152 | line_data['type'] = line.line_type.name | |
161 | data['lines'].append(line_data) |
|
153 | data['lines'].append(line_data) | |
162 |
|
154 | |||
163 | data['delays'] = self.get_delays() |
|
155 | data['delays'] = self.get_delays() | |
164 | data['pulses'] = self.get_pulses() |
|
156 | data['pulses'] = self.get_pulses() | |
165 |
|
157 | |||
166 | return data |
|
158 | return data | |
167 |
|
159 | |||
168 | def dict_to_parms(self, data): |
|
160 | def dict_to_parms(self, data): | |
169 | ''' |
|
161 | ''' | |
170 | ''' |
|
162 | ''' | |
171 |
|
163 | |||
172 | self.name = data['name'] |
|
164 | self.name = data['name'] | |
173 | self.ipp = data['ipp'] |
|
165 | self.ipp = data['ipp'] | |
174 | self.ntx = data['ntx'] |
|
166 | self.ntx = data['ntx'] | |
175 | self.clock_in = data['clock_in'] |
|
167 | self.clock_in = data['clock_in'] | |
176 | self.clock_divider = data['clock_divider'] |
|
168 | self.clock_divider = data['clock_divider'] | |
177 | self.clock = data['clock'] |
|
169 | self.clock = data['clock'] | |
178 | self.time_before = data['time_before'] |
|
170 | self.time_before = data['time_before'] | |
179 | self.time_after = data['time_after'] |
|
171 | self.time_after = data['time_after'] | |
180 | self.sync = data['sync'] |
|
172 | self.sync = data['sync'] | |
181 | self.sampling_reference = data['sampling_reference'] |
|
173 | self.sampling_reference = data['sampling_reference'] | |
182 | self.total_units = self.ipp*self.ntx*self.km2unit |
|
174 | self.total_units = self.ipp*self.ntx*self.km2unit | |
183 | self.save() |
|
175 | self.save() | |
184 | self.clean_lines() |
|
176 | self.clean_lines() | |
185 |
|
177 | |||
186 | lines = [] |
|
178 | lines = [] | |
187 | positions = {'tx':0, 'tr':0} |
|
179 | positions = {'tx':0, 'tr':0} | |
188 |
|
180 | |||
189 | for i, line_data in enumerate(data['lines']): |
|
181 | for i, line_data in enumerate(data['lines']): | |
190 | line_type = RCLineType.objects.get(name=line_data.pop('type')) |
|
182 | line_type = RCLineType.objects.get(name=line_data.pop('type')) | |
191 | if line_type.name=='codes': |
|
183 | if line_type.name=='codes': | |
192 | code = RCLineCode.objects.get(name=line_data['code']) |
|
184 | code = RCLineCode.objects.get(name=line_data['code']) | |
193 | line_data['code'] = code.pk |
|
185 | line_data['code'] = code.pk | |
194 | line = RCLine.objects.filter(rc_configuration=self, channel=i) |
|
186 | line = RCLine.objects.filter(rc_configuration=self, channel=i) | |
195 | if line: |
|
187 | if line: | |
196 | line = line[0] |
|
188 | line = line[0] | |
197 | line.line_type = line_type |
|
189 | line.line_type = line_type | |
198 | line.params = json.dumps(line_data) |
|
190 | line.params = json.dumps(line_data) | |
199 | else: |
|
191 | else: | |
200 | line = RCLine(rc_configuration=self, line_type=line_type, |
|
192 | line = RCLine(rc_configuration=self, line_type=line_type, | |
201 | params=json.dumps(line_data), |
|
193 | params=json.dumps(line_data), | |
202 | channel=i) |
|
194 | channel=i) | |
203 |
|
195 | |||
204 | if line_type.name=='tx': |
|
196 | if line_type.name=='tx': | |
205 | line.position = positions['tx'] |
|
197 | line.position = positions['tx'] | |
206 | positions['tx'] += 1 |
|
198 | positions['tx'] += 1 | |
207 |
|
199 | |||
208 | if line_type.name=='tr': |
|
200 | if line_type.name=='tr': | |
209 | line.position = positions['tr'] |
|
201 | line.position = positions['tr'] | |
210 | positions['tr'] += 1 |
|
202 | positions['tr'] += 1 | |
211 |
|
203 | |||
212 | line.save() |
|
204 | line.save() | |
213 | lines.append(line) |
|
205 | lines.append(line) | |
214 |
|
206 | |||
215 | for line, line_data in zip(lines, data['lines']): |
|
207 | for line, line_data in zip(lines, data['lines']): | |
216 | if 'TX_ref' in line_data: |
|
208 | if 'TX_ref' in line_data: | |
217 | params = json.loads(line.params) |
|
209 | params = json.loads(line.params) | |
218 | if line_data['TX_ref'] in (0, '0'): |
|
210 | if line_data['TX_ref'] in (0, '0'): | |
219 | params['TX_ref'] = '0' |
|
211 | params['TX_ref'] = '0' | |
220 | else: |
|
212 | else: | |
221 | params['TX_ref'] = [l.pk for l in lines if l.line_type.name=='tx' and line_data['TX_ref'] in l.get_name()][0] |
|
213 | params['TX_ref'] = [l.pk for l in lines if l.line_type.name=='tx' and line_data['TX_ref'] in l.get_name()][0] | |
222 | line.params = json.dumps(params) |
|
214 | line.params = json.dumps(params) | |
223 | line.save() |
|
215 | line.save() | |
224 |
|
216 | |||
225 |
|
217 | |||
226 | def get_delays(self): |
|
218 | def get_delays(self): | |
227 |
|
219 | |||
228 | pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
220 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
229 | points = [tup for tups in pulses for tup in tups] |
|
221 | points = [tup for tups in pulses for tup in tups] | |
230 | points = set([x for tup in points for x in tup]) |
|
222 | points = set([x for tup in points for x in tup]) | |
231 | points = list(points) |
|
223 | points = list(points) | |
232 | points.sort() |
|
224 | points.sort() | |
233 |
|
225 | |||
234 | if points[0]<>0: |
|
226 | if points[0]<>0: | |
235 | points.insert(0, 0) |
|
227 | points.insert(0, 0) | |
236 |
|
228 | |||
237 | return [points[i+1]-points[i] for i in range(len(points)-1)] |
|
229 | return [points[i+1]-points[i] for i in range(len(points)-1)] | |
238 |
|
230 | |||
239 |
|
231 | |||
240 | def get_pulses(self, binary=True): |
|
232 | def get_pulses(self, binary=True): | |
241 |
|
233 | |||
242 | pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
234 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
243 | points = [tup for tups in pulses for tup in tups] |
|
235 | points = [tup for tups in pulses for tup in tups] | |
244 | points = set([x for tup in points for x in tup]) |
|
236 | points = set([x for tup in points for x in tup]) | |
245 | points = list(points) |
|
237 | points = list(points) | |
246 | points.sort() |
|
238 | points.sort() | |
247 |
|
239 | |||
248 | line_points = [line.pulses_as_points() for line in self.get_lines()] |
|
240 | line_points = [line.pulses_as_points() for line in self.get_lines()] | |
249 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] |
|
241 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] | |
250 | line_points = [[t for x in tups for t in x] for tups in line_points] |
|
242 | line_points = [[t for x in tups for t in x] for tups in line_points] | |
251 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] |
|
243 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] | |
252 |
|
244 | |||
253 | if binary: |
|
245 | if binary: | |
254 | states.reverse() |
|
246 | states.reverse() | |
255 | states = [int(''.join([str(x) for x in flips]), 2) for flips in states] |
|
247 | states = [int(''.join([str(x) for x in flips]), 2) for flips in states] | |
256 |
|
248 | |||
257 | return states[:-1] |
|
249 | return states[:-1] | |
258 |
|
250 | |||
259 | def add_cmd(self, cmd): |
|
251 | def add_cmd(self, cmd): | |
260 |
|
252 | |||
261 | if cmd in DAT_CMDS: |
|
253 | if cmd in DAT_CMDS: | |
262 | return (255, DAT_CMDS[cmd]) |
|
254 | return (255, DAT_CMDS[cmd]) | |
263 |
|
255 | |||
264 | def add_data(self, value): |
|
256 | def add_data(self, value): | |
265 |
|
257 | |||
266 | return (254, value-1) |
|
258 | return (254, value-1) | |
267 |
|
259 | |||
268 | def parms_to_binary(self): |
|
260 | def parms_to_binary(self): | |
269 | ''' |
|
261 | ''' | |
270 | Create "dat" stream to be send to CR |
|
262 | Create "dat" stream to be send to CR | |
271 | ''' |
|
263 | ''' | |
272 |
|
264 | |||
273 | data = [] |
|
265 | data = [] | |
274 | # create header |
|
266 | # create header | |
275 | data.append(self.add_cmd('DISABLE')) |
|
267 | data.append(self.add_cmd('DISABLE')) | |
276 | data.append(self.add_cmd('CONTINUE')) |
|
268 | data.append(self.add_cmd('CONTINUE')) | |
277 | data.append(self.add_cmd('RESTART')) |
|
269 | data.append(self.add_cmd('RESTART')) | |
278 |
|
270 | |||
279 | if self.control_sw: |
|
271 | if self.control_sw: | |
280 | data.append(self.add_cmd('SW_ONE')) |
|
272 | data.append(self.add_cmd('SW_ONE')) | |
281 | else: |
|
273 | else: | |
282 | data.append(self.add_cmd('SW_ZERO')) |
|
274 | data.append(self.add_cmd('SW_ZERO')) | |
283 |
|
275 | |||
284 | if self.control_tx: |
|
276 | if self.control_tx: | |
285 | data.append(self.add_cmd('TX_ONE')) |
|
277 | data.append(self.add_cmd('TX_ONE')) | |
286 | else: |
|
278 | else: | |
287 | data.append(self.add_cmd('TX_ZERO')) |
|
279 | data.append(self.add_cmd('TX_ZERO')) | |
288 |
|
280 | |||
289 | # write divider |
|
281 | # write divider | |
290 | data.append(self.add_cmd('CLOCK_DIVIDER')) |
|
282 | data.append(self.add_cmd('CLOCK_DIVIDER')) | |
291 | data.append(self.add_data(self.clock_divider)) |
|
283 | data.append(self.add_data(self.clock_divider)) | |
292 |
|
284 | |||
293 | # write delays |
|
285 | # write delays | |
294 | data.append(self.add_cmd('DELAY_START')) |
|
286 | data.append(self.add_cmd('DELAY_START')) | |
295 | # first delay is always zero |
|
287 | # first delay is always zero | |
296 | data.append(self.add_data(1)) |
|
288 | data.append(self.add_data(1)) | |
297 |
|
289 | |||
298 | delays = self.get_delays() |
|
290 | delays = self.get_delays() | |
299 |
|
291 | |||
300 | for delay in delays: |
|
292 | for delay in delays: | |
301 | while delay>252: |
|
293 | while delay>252: | |
302 | data.append(self.add_data(253)) |
|
294 | data.append(self.add_data(253)) | |
303 | delay -= 253 |
|
295 | delay -= 253 | |
304 | data.append(self.add_data(delay)) |
|
296 | data.append(self.add_data(delay)) | |
305 |
|
297 | |||
306 | # write flips |
|
298 | # write flips | |
307 | data.append(self.add_cmd('FLIP_START')) |
|
299 | data.append(self.add_cmd('FLIP_START')) | |
308 |
|
300 | |||
309 | states = self.get_pulses(binary=False) |
|
301 | states = self.get_pulses(binary=False) | |
310 |
|
302 | |||
311 | for flips, delay in zip(states, delays): |
|
303 | for flips, delay in zip(states, delays): | |
312 | flips.reverse() |
|
304 | flips.reverse() | |
313 | flip = int(''.join([str(x) for x in flips]), 2) |
|
305 | flip = int(''.join([str(x) for x in flips]), 2) | |
314 | data.append(self.add_data(flip+1)) |
|
306 | data.append(self.add_data(flip+1)) | |
315 | while delay>252: |
|
307 | while delay>252: | |
316 | data.append(self.add_data(1)) |
|
308 | data.append(self.add_data(1)) | |
317 | delay -= 253 |
|
309 | delay -= 253 | |
318 |
|
310 | |||
319 | # write sampling period |
|
311 | # write sampling period | |
320 | data.append(self.add_cmd('SAMPLING_PERIOD')) |
|
312 | data.append(self.add_cmd('SAMPLING_PERIOD')) | |
321 | wins = self.get_lines(line_type__name='windows') |
|
313 | wins = self.get_lines(line_type__name='windows') | |
322 | if wins: |
|
314 | if wins: | |
323 | win_params = json.loads(wins[0].params)['params'] |
|
315 | win_params = json.loads(wins[0].params)['params'] | |
324 | if win_params: |
|
316 | if win_params: | |
325 | dh = int(win_params[0]['resolution']*self.km2unit) |
|
317 | dh = int(win_params[0]['resolution']*self.km2unit) | |
326 | else: |
|
318 | else: | |
327 | dh = 1 |
|
319 | dh = 1 | |
328 | else: |
|
320 | else: | |
329 | dh = 1 |
|
321 | dh = 1 | |
330 | data.append(self.add_data(dh)) |
|
322 | data.append(self.add_data(dh)) | |
331 |
|
323 | |||
332 | # write enable |
|
324 | # write enable | |
333 | data.append(self.add_cmd('ENABLE')) |
|
325 | data.append(self.add_cmd('ENABLE')) | |
334 |
|
326 | |||
335 | return '\n'.join(['{}'.format(x) for tup in data for x in tup]) |
|
327 | return '\n'.join(['{}'.format(x) for tup in data for x in tup]) | |
336 |
|
328 | |||
337 | def update_from_file(self, filename): |
|
329 | def update_from_file(self, filename): | |
338 | ''' |
|
330 | ''' | |
339 | Update instance from file |
|
331 | Update instance from file | |
340 | ''' |
|
332 | ''' | |
341 |
|
333 | |||
342 | f = RCFile(filename) |
|
334 | f = RCFile(filename) | |
343 | self.dict_to_parms(f.data) |
|
335 | self.dict_to_parms(f.data) | |
344 | self.update_pulses() |
|
336 | self.update_pulses() | |
345 |
|
337 | |||
346 | def update_pulses(self): |
|
338 | def update_pulses(self): | |
347 |
|
339 | |||
348 | for line in self.get_lines(): |
|
340 | for line in self.get_lines(): | |
349 | line.update_pulses() |
|
341 | line.update_pulses() | |
350 |
|
342 | |||
351 | def plot_pulses(self): |
|
343 | def plot_pulses(self): | |
352 |
|
344 | |||
353 | import matplotlib.pyplot as plt |
|
345 | import matplotlib.pyplot as plt | |
354 | from bokeh.resources import CDN |
|
346 | from bokeh.resources import CDN | |
355 | from bokeh.embed import components |
|
347 | from bokeh.embed import components | |
356 | from bokeh.mpl import to_bokeh |
|
348 | from bokeh.mpl import to_bokeh | |
357 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool |
|
349 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool | |
358 |
|
350 | |||
359 | lines = self.get_lines() |
|
351 | lines = self.get_lines() | |
360 |
|
352 | |||
361 | N = len(lines) |
|
353 | N = len(lines) | |
362 | fig = plt.figure(figsize=(10, 2+N*0.5)) |
|
354 | fig = plt.figure(figsize=(10, 2+N*0.5)) | |
363 | ax = fig.add_subplot(111) |
|
355 | ax = fig.add_subplot(111) | |
364 | labels = [] |
|
356 | labels = [] | |
365 |
|
357 | |||
366 | for i, line in enumerate(lines): |
|
358 | for i, line in enumerate(lines): | |
367 | labels.append(line.get_name()) |
|
359 | labels.append(line.get_name()) | |
368 | l = ax.plot((0, self.total_units),(N-i-1, N-i-1)) |
|
360 | l = ax.plot((0, self.total_units),(N-i-1, N-i-1)) | |
369 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points() if tup<>(0,0)] |
|
361 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points() if tup<>(0,0)] | |
370 | ax.broken_barh(points, (N-i-1, 0.5), |
|
362 | ax.broken_barh(points, (N-i-1, 0.5), | |
371 | edgecolor=l[0].get_color(), facecolor='none') |
|
363 | edgecolor=l[0].get_color(), facecolor='none') | |
372 |
|
364 | |||
373 | labels.reverse() |
|
365 | labels.reverse() | |
374 | ax.set_yticklabels(labels) |
|
366 | ax.set_yticklabels(labels) | |
375 | ax.set_xlabel = 'Units' |
|
367 | ax.set_xlabel = 'Units' | |
376 | plot = to_bokeh(fig, use_pandas=False) |
|
368 | plot = to_bokeh(fig, use_pandas=False) | |
377 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] |
|
369 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] | |
378 |
|
370 | |||
379 | return components(plot, CDN) |
|
371 | return components(plot, CDN) | |
380 |
|
372 | |||
381 | def status_device(self): |
|
373 | def status_device(self): | |
382 |
|
374 | |||
383 | return 0 |
|
375 | return 0 | |
384 |
|
376 | |||
385 | def stop_device(self): |
|
377 | def stop_device(self): | |
386 |
|
378 | |||
387 | answer = api.disable(ip = self.device.ip_address, |
|
379 | answer = api.disable(ip = self.device.ip_address, | |
388 | port = self.device.port_address) |
|
380 | port = self.device.port_address) | |
389 |
|
381 | |||
390 | if answer[0] != "1": |
|
382 | if answer[0] != "1": | |
391 | self.message = answer[0:] |
|
383 | self.message = answer[0:] | |
392 | return 0 |
|
384 | return 0 | |
393 |
|
385 | |||
394 | self.message = answer[2:] |
|
386 | self.message = answer[2:] | |
395 | return 1 |
|
387 | return 1 | |
396 |
|
388 | |||
397 | def start_device(self): |
|
389 | def start_device(self): | |
398 |
|
390 | |||
399 | answer = api.enable(ip = self.device.ip_address, |
|
391 | answer = api.enable(ip = self.device.ip_address, | |
400 | port = self.device.port_address) |
|
392 | port = self.device.port_address) | |
401 |
|
393 | |||
402 | if answer[0] != "1": |
|
394 | if answer[0] != "1": | |
403 | self.message = answer[0:] |
|
395 | self.message = answer[0:] | |
404 | return 0 |
|
396 | return 0 | |
405 |
|
397 | |||
406 | self.message = answer[2:] |
|
398 | self.message = answer[2:] | |
407 | return 1 |
|
399 | return 1 | |
408 |
|
400 | |||
409 | def write_device(self): |
|
401 | def write_device(self): | |
410 | answer = api.write_config(ip = self.device.ip_address, |
|
402 | answer = api.write_config(ip = self.device.ip_address, | |
411 | port = self.device.port_address, |
|
403 | port = self.device.port_address, | |
412 | parms = self.parms_to_dict()) |
|
404 | parms = self.parms_to_dict()) | |
413 |
|
405 | |||
414 | if answer[0] != "1": |
|
406 | if answer[0] != "1": | |
415 | self.message = answer[0:] |
|
407 | self.message = answer[0:] | |
416 | return 0 |
|
408 | return 0 | |
417 |
|
409 | |||
418 | self.message = answer[2:] |
|
410 | self.message = answer[2:] | |
419 | return 1 |
|
411 | return 1 | |
420 |
|
412 | |||
421 |
|
413 | |||
422 | class RCLineCode(models.Model): |
|
414 | class RCLineCode(models.Model): | |
423 |
|
415 | |||
424 | name = models.CharField(max_length=40) |
|
416 | name = models.CharField(max_length=40) | |
425 | bits_per_code = models.PositiveIntegerField(default=0) |
|
417 | bits_per_code = models.PositiveIntegerField(default=0) | |
426 | number_of_codes = models.PositiveIntegerField(default=0) |
|
418 | number_of_codes = models.PositiveIntegerField(default=0) | |
427 | codes = models.TextField(blank=True, null=True) |
|
419 | codes = models.TextField(blank=True, null=True) | |
428 |
|
420 | |||
429 | class Meta: |
|
421 | class Meta: | |
430 | db_table = 'rc_line_codes' |
|
422 | db_table = 'rc_line_codes' | |
431 | ordering = ('name',) |
|
423 | ordering = ('name',) | |
432 |
|
424 | |||
433 | def __unicode__(self): |
|
425 | def __unicode__(self): | |
434 | return u'%s' % self.name |
|
426 | return u'%s' % self.name | |
435 |
|
427 | |||
436 |
|
428 | |||
437 | class RCLineType(models.Model): |
|
429 | class RCLineType(models.Model): | |
438 |
|
430 | |||
439 | name = models.CharField(choices=LINE_TYPES, max_length=40) |
|
431 | name = models.CharField(choices=LINE_TYPES, max_length=40) | |
440 | description = models.TextField(blank=True, null=True) |
|
432 | description = models.TextField(blank=True, null=True) | |
441 | params = models.TextField(default='[]') |
|
433 | params = models.TextField(default='[]') | |
442 |
|
434 | |||
443 | class Meta: |
|
435 | class Meta: | |
444 | db_table = 'rc_line_types' |
|
436 | db_table = 'rc_line_types' | |
445 |
|
437 | |||
446 | def __unicode__(self): |
|
438 | def __unicode__(self): | |
447 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) |
|
439 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) | |
448 |
|
440 | |||
449 |
|
441 | |||
450 | class RCLine(models.Model): |
|
442 | class RCLine(models.Model): | |
451 |
|
443 | |||
452 | rc_configuration = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE) |
|
444 | rc_configuration = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE) | |
453 | line_type = models.ForeignKey(RCLineType) |
|
445 | line_type = models.ForeignKey(RCLineType) | |
454 | channel = models.PositiveIntegerField(default=0) |
|
446 | channel = models.PositiveIntegerField(default=0) | |
455 | position = models.PositiveIntegerField(default=0) |
|
447 | position = models.PositiveIntegerField(default=0) | |
456 | params = models.TextField(default='{}') |
|
448 | params = models.TextField(default='{}') | |
457 | pulses = models.TextField(default='') |
|
449 | pulses = models.TextField(default='') | |
458 |
|
450 | |||
459 | class Meta: |
|
451 | class Meta: | |
460 | db_table = 'rc_lines' |
|
452 | db_table = 'rc_lines' | |
461 | ordering = ['channel'] |
|
453 | ordering = ['channel'] | |
462 |
|
454 | |||
463 | def __unicode__(self): |
|
455 | def __unicode__(self): | |
464 | if self.rc_configuration: |
|
456 | if self.rc_configuration: | |
465 | return u'%s - %s' % (self.rc_configuration, self.get_name()) |
|
457 | return u'%s - %s' % (self.rc_configuration, self.get_name()) | |
466 |
|
458 | |||
467 | def clone(self, **kwargs): |
|
459 | def clone(self, **kwargs): | |
468 |
|
460 | |||
469 | self.pk = None |
|
461 | self.pk = None | |
470 |
|
462 | |||
471 | for attr, value in kwargs.items(): |
|
463 | for attr, value in kwargs.items(): | |
472 | setattr(self, attr, value) |
|
464 | setattr(self, attr, value) | |
473 |
|
465 | |||
474 | self.save() |
|
466 | self.save() | |
475 |
|
467 | |||
476 | return self |
|
468 | return self | |
477 |
|
469 | |||
478 | def get_name(self): |
|
470 | def get_name(self): | |
479 |
|
471 | |||
480 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
472 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
481 | s = '' |
|
473 | s = '' | |
482 |
|
474 | |||
483 | if self.line_type.name in ('tx',): |
|
475 | if self.line_type.name in ('tx',): | |
484 | s = chars[self.position] |
|
476 | s = chars[self.position] | |
485 | elif self.line_type.name in ('codes', 'windows', 'tr'): |
|
477 | elif self.line_type.name in ('codes', 'windows', 'tr'): | |
486 | if 'TX_ref' in json.loads(self.params): |
|
478 | if 'TX_ref' in json.loads(self.params): | |
487 | pk = json.loads(self.params)['TX_ref'] |
|
479 | pk = json.loads(self.params)['TX_ref'] | |
488 | if pk in (0, '0'): |
|
480 | if pk in (0, '0'): | |
489 | s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx')) |
|
481 | s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx')) | |
490 | else: |
|
482 | else: | |
491 | ref = RCLine.objects.get(pk=pk) |
|
483 | ref = RCLine.objects.get(pk=pk) | |
492 | s = chars[ref.position] |
|
484 | s = chars[ref.position] | |
493 | s = '({})'.format(s) |
|
485 | s = '({})'.format(s) | |
494 | if s: |
|
486 | if s: | |
495 | return '{}{} {}'.format(self.line_type.name.upper(), s, self.channel) |
|
487 | return '{}{} {}'.format(self.line_type.name.upper(), s, self.channel) | |
496 | else: |
|
488 | else: | |
497 | return '{} {}'.format(self.line_type.name.upper(), self.channel) |
|
489 | return '{} {}'.format(self.line_type.name.upper(), self.channel) | |
498 |
|
490 | |||
499 | def get_lines(self, **kwargs): |
|
491 | def get_lines(self, **kwargs): | |
500 |
|
492 | |||
501 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs) |
|
493 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs) | |
502 |
|
494 | |||
503 | def pulses_as_array(self): |
|
495 | def pulses_as_array(self): | |
504 |
|
496 | |||
505 | y = np.zeros(self.rc_configuration.total_units) |
|
497 | y = np.zeros(self.rc_configuration.total_units) | |
506 |
|
498 | |||
507 | for tup in ast.literal_eval(self.pulses): |
|
499 | for tup in ast.literal_eval(self.pulses): | |
508 | y[tup[0]:tup[1]] = 1 |
|
500 | y[tup[0]:tup[1]] = 1 | |
509 |
|
501 | |||
510 | return y.astype(np.int8) |
|
502 | return y.astype(np.int8) | |
511 |
|
503 | |||
512 | def pulses_as_points(self): |
|
504 | def pulses_as_points(self): | |
513 |
|
505 | |||
514 | return ast.literal_eval(self.pulses) |
|
506 | return ast.literal_eval(self.pulses) | |
515 |
|
507 | |||
516 | def get_win_ref(self, params, tx_id, km2unit): |
|
508 | def get_win_ref(self, params, tx_id, km2unit): | |
517 |
|
509 | |||
518 | ref = self.rc_configuration.sampling_reference |
|
510 | ref = self.rc_configuration.sampling_reference | |
519 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] |
|
511 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] | |
520 |
|
512 | |||
521 | if codes: |
|
513 | if codes: | |
522 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) |
|
514 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) | |
523 | else: |
|
515 | else: | |
524 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit |
|
516 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit | |
525 |
|
517 | |||
526 | if ref=='first_baud': |
|
518 | if ref=='first_baud': | |
527 | return int(1 + (tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit) |
|
519 | return int(1 + (tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit) | |
528 | elif ref=='sub_baud': |
|
520 | elif ref=='sub_baud': | |
529 | return int(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) |
|
521 | return int(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) | |
530 | else: |
|
522 | else: | |
531 | return 0 |
|
523 | return 0 | |
532 |
|
524 | |||
533 | def update_pulses(self): |
|
525 | def update_pulses(self): | |
534 | ''' |
|
526 | ''' | |
535 | Update pulses field |
|
527 | Update pulses field | |
536 | ''' |
|
528 | ''' | |
537 |
|
529 | |||
538 | km2unit = self.rc_configuration.km2unit |
|
530 | km2unit = self.rc_configuration.km2unit | |
539 | us2unit = self.rc_configuration.us2unit |
|
531 | us2unit = self.rc_configuration.us2unit | |
540 | ipp = self.rc_configuration.ipp |
|
532 | ipp = self.rc_configuration.ipp | |
541 | ntx = self.rc_configuration.ntx |
|
533 | ntx = self.rc_configuration.ntx | |
542 | ipp_u = int(ipp*km2unit) |
|
534 | ipp_u = int(ipp*km2unit) | |
543 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units |
|
535 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units | |
544 | y = [] |
|
536 | y = [] | |
545 |
|
537 | |||
546 | if self.line_type.name=='tr': |
|
538 | if self.line_type.name=='tr': | |
547 | tr_params = json.loads(self.params) |
|
539 | tr_params = json.loads(self.params) | |
548 |
|
540 | |||
549 | if tr_params['TX_ref'] in ('0', 0): |
|
541 | if tr_params['TX_ref'] in ('0', 0): | |
550 | txs = self.get_lines(line_type__name='tx') |
|
542 | txs = self.get_lines(line_type__name='tx') | |
551 | else: |
|
543 | else: | |
552 | txs = RCLine.objects.filter(pk=tr_params['TX_ref']) |
|
544 | txs = RCLine.objects.filter(pk=tr_params['TX_ref']) | |
553 |
|
545 | |||
554 | for tx in txs: |
|
546 | for tx in txs: | |
555 | params = json.loads(tx.params) |
|
547 | params = json.loads(tx.params) | |
556 |
|
548 | |||
557 | if float(params['pulse_width'])==0: |
|
549 | if float(params['pulse_width'])==0: | |
558 | continue |
|
550 | continue | |
559 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
551 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
560 | width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit) |
|
552 | width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit) | |
561 | before = 0 |
|
553 | before = 0 | |
562 | after = int(self.rc_configuration.time_after*us2unit) |
|
554 | after = int(self.rc_configuration.time_after*us2unit) | |
563 |
|
555 | |||
564 | y_tx = self.points(ntx, ipp_u, width, |
|
556 | y_tx = self.points(ntx, ipp_u, width, | |
565 | delay=delays, |
|
557 | delay=delays, | |
566 | before=before, |
|
558 | before=before, | |
567 | after=after, |
|
559 | after=after, | |
568 | sync=self.rc_configuration.sync) |
|
560 | sync=self.rc_configuration.sync) | |
569 |
|
561 | |||
570 | ranges = params['range'].split(',') |
|
562 | ranges = params['range'].split(',') | |
571 |
|
563 | |||
572 | if len(ranges)>0 and ranges[0]<>'0': |
|
564 | if len(ranges)>0 and ranges[0]<>'0': | |
573 | y_tx = self.mask_ranges(y_tx, ranges) |
|
565 | y_tx = self.mask_ranges(y_tx, ranges) | |
574 |
|
566 | |||
575 | tr_ranges = tr_params['range'].split(',') |
|
567 | tr_ranges = tr_params['range'].split(',') | |
576 |
|
568 | |||
577 | if len(tr_ranges)>0 and tr_ranges[0]<>'0': |
|
569 | if len(tr_ranges)>0 and tr_ranges[0]<>'0': | |
578 | y_tx = self.mask_ranges(y_tx, tr_ranges) |
|
570 | y_tx = self.mask_ranges(y_tx, tr_ranges) | |
579 |
|
571 | |||
580 | y.extend(y_tx) |
|
572 | y.extend(y_tx) | |
581 |
|
573 | |||
582 | self.pulses = unicode(y) |
|
574 | self.pulses = unicode(y) | |
583 | y = self.array_to_points(self.pulses_as_array()) |
|
575 | y = self.array_to_points(self.pulses_as_array()) | |
584 |
|
576 | |||
585 | elif self.line_type.name=='tx': |
|
577 | elif self.line_type.name=='tx': | |
586 | params = json.loads(self.params) |
|
578 | params = json.loads(self.params) | |
587 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
579 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
588 | width = float(params['pulse_width'])*km2unit |
|
580 | width = float(params['pulse_width'])*km2unit | |
589 |
|
581 | |||
590 | if width>0: |
|
582 | if width>0: | |
591 | before = int(self.rc_configuration.time_before*us2unit) |
|
583 | before = int(self.rc_configuration.time_before*us2unit) | |
592 | after = 0 |
|
584 | after = 0 | |
593 |
|
585 | |||
594 | y = self.points(ntx, ipp_u, width, |
|
586 | y = self.points(ntx, ipp_u, width, | |
595 | delay=delays, |
|
587 | delay=delays, | |
596 | before=before, |
|
588 | before=before, | |
597 | after=after, |
|
589 | after=after, | |
598 | sync=self.rc_configuration.sync) |
|
590 | sync=self.rc_configuration.sync) | |
599 |
|
591 | |||
600 | ranges = params['range'].split(',') |
|
592 | ranges = params['range'].split(',') | |
601 |
|
593 | |||
602 | if len(ranges)>0 and ranges[0]<>'0': |
|
594 | if len(ranges)>0 and ranges[0]<>'0': | |
603 | y = self.mask_ranges(y, ranges) |
|
595 | y = self.mask_ranges(y, ranges) | |
604 |
|
596 | |||
605 | elif self.line_type.name=='flip': |
|
597 | elif self.line_type.name=='flip': | |
606 | n = float(json.loads(self.params)['number_of_flips']) |
|
598 | n = float(json.loads(self.params)['number_of_flips']) | |
607 | width = n*ipp*km2unit |
|
599 | width = n*ipp*km2unit | |
608 | y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width) |
|
600 | y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width) | |
609 |
|
601 | |||
610 | elif self.line_type.name=='codes': |
|
602 | elif self.line_type.name=='codes': | |
611 | params = json.loads(self.params) |
|
603 | params = json.loads(self.params) | |
612 | tx = RCLine.objects.get(pk=params['TX_ref']) |
|
604 | tx = RCLine.objects.get(pk=params['TX_ref']) | |
613 | tx_params = json.loads(tx.params) |
|
605 | tx_params = json.loads(tx.params) | |
614 | delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] |
|
606 | delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] | |
615 | f = int(float(tx_params['pulse_width'])*km2unit)/len(params['codes'][0]) |
|
607 | f = int(float(tx_params['pulse_width'])*km2unit)/len(params['codes'][0]) | |
616 | codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] |
|
608 | codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] | |
617 | codes = [self.array_to_points(code) for code in codes] |
|
609 | codes = [self.array_to_points(code) for code in codes] | |
618 | n = len(codes) |
|
610 | n = len(codes) | |
619 |
|
611 | |||
620 | for i, tup in enumerate(tx.pulses_as_points()): |
|
612 | for i, tup in enumerate(tx.pulses_as_points()): | |
621 | code = codes[i%n] |
|
613 | code = codes[i%n] | |
622 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) |
|
614 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) | |
623 |
|
615 | |||
624 | ranges = tx_params['range'].split(',') |
|
616 | ranges = tx_params['range'].split(',') | |
625 | if len(ranges)>0 and ranges[0]<>'0': |
|
617 | if len(ranges)>0 and ranges[0]<>'0': | |
626 | y = self.mask_ranges(y, ranges) |
|
618 | y = self.mask_ranges(y, ranges) | |
627 |
|
619 | |||
628 | elif self.line_type.name=='sync': |
|
620 | elif self.line_type.name=='sync': | |
629 | params = json.loads(self.params) |
|
621 | params = json.loads(self.params) | |
630 | n = ipp_u*ntx |
|
622 | n = ipp_u*ntx | |
631 | if params['invert'] in ('1', 1): |
|
623 | if params['invert'] in ('1', 1): | |
632 | y = [(n-1, n)] |
|
624 | y = [(n-1, n)] | |
633 | else: |
|
625 | else: | |
634 | y = [(0, 1)] |
|
626 | y = [(0, 1)] | |
635 |
|
627 | |||
636 | elif self.line_type.name=='prog_pulses': |
|
628 | elif self.line_type.name=='prog_pulses': | |
637 | params = json.loads(self.params) |
|
629 | params = json.loads(self.params) | |
638 | if int(params['periodic'])==0: |
|
630 | if int(params['periodic'])==0: | |
639 | nntx = 1 |
|
631 | nntx = 1 | |
640 | nipp = ipp_u*ntx |
|
632 | nipp = ipp_u*ntx | |
641 | else: |
|
633 | else: | |
642 | nntx = ntx |
|
634 | nntx = ntx | |
643 | nipp = ipp_u |
|
635 | nipp = ipp_u | |
644 |
|
636 | |||
645 | if 'params' in params and len(params['params'])>0: |
|
637 | if 'params' in params and len(params['params'])>0: | |
646 | for p in params['params']: |
|
638 | for p in params['params']: | |
647 | y_pp = self.points(nntx, nipp, |
|
639 | y_pp = self.points(nntx, nipp, | |
648 | p['end']-p['begin'], |
|
640 | p['end']-p['begin'], | |
649 | before=p['begin']) |
|
641 | before=p['begin']) | |
650 |
|
642 | |||
651 | y.extend(y_pp) |
|
643 | y.extend(y_pp) | |
652 |
|
644 | |||
653 | elif self.line_type.name=='windows': |
|
645 | elif self.line_type.name=='windows': | |
654 | params = json.loads(self.params) |
|
646 | params = json.loads(self.params) | |
655 |
|
647 | |||
656 | if 'params' in params and len(params['params'])>0: |
|
648 | if 'params' in params and len(params['params'])>0: | |
657 | tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) |
|
649 | tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) | |
658 | tr_ranges = tr_params['range'].split(',') |
|
650 | tr_ranges = tr_params['range'].split(',') | |
659 | for p in params['params']: |
|
651 | for p in params['params']: | |
660 | y_win = self.points(ntx, ipp_u, |
|
652 | y_win = self.points(ntx, ipp_u, | |
661 | p['resolution']*p['number_of_samples']*km2unit, |
|
653 | p['resolution']*p['number_of_samples']*km2unit, | |
662 | before=int(self.rc_configuration.time_before*us2unit)+self.get_win_ref(p, params['TX_ref'], km2unit), |
|
654 | before=int(self.rc_configuration.time_before*us2unit)+self.get_win_ref(p, params['TX_ref'], km2unit), | |
663 | sync=self.rc_configuration.sync) |
|
655 | sync=self.rc_configuration.sync) | |
664 |
|
656 | |||
665 | if len(tr_ranges)>0 and tr_ranges[0]<>'0': |
|
657 | if len(tr_ranges)>0 and tr_ranges[0]<>'0': | |
666 | y_win = self.mask_ranges(y_win, tr_ranges) |
|
658 | y_win = self.mask_ranges(y_win, tr_ranges) | |
667 |
|
659 | |||
668 | y.extend(y_win) |
|
660 | y.extend(y_win) | |
669 |
|
661 | |||
670 | elif self.line_type.name=='mix': |
|
662 | elif self.line_type.name=='mix': | |
671 | values = self.rc_configuration.parameters.split('-') |
|
663 | values = self.rc_configuration.parameters.split('-') | |
672 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] |
|
664 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] | |
673 | modes = [value.split('|')[1] for value in values] |
|
665 | modes = [value.split('|')[1] for value in values] | |
674 | ops = [value.split('|')[2] for value in values] |
|
666 | ops = [value.split('|')[2] for value in values] | |
675 | delays = [value.split('|')[3] for value in values] |
|
667 | delays = [value.split('|')[3] for value in values] | |
676 | masks = [value.split('|')[4] for value in values] |
|
668 | masks = [value.split('|')[4] for value in values] | |
677 | mask = list('{:8b}'.format(int(masks[0]))) |
|
669 | mask = list('{:8b}'.format(int(masks[0]))) | |
678 | mask.reverse() |
|
670 | mask.reverse() | |
679 | if mask[self.channel] in ('0', '', ' '): |
|
671 | if mask[self.channel] in ('0', '', ' '): | |
680 | y = np.zeros(confs[0].total_units, dtype=np.int8) |
|
672 | y = np.zeros(confs[0].total_units, dtype=np.int8) | |
681 | else: |
|
673 | else: | |
682 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() |
|
674 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() | |
683 |
|
675 | |||
684 | for i in range(1, len(values)): |
|
676 | for i in range(1, len(values)): | |
685 | mask = list('{:8b}'.format(int(masks[i]))) |
|
677 | mask = list('{:8b}'.format(int(masks[i]))) | |
686 | mask.reverse() |
|
678 | mask.reverse() | |
687 |
|
679 | |||
688 | if mask[self.channel] in ('0', '', ' '): |
|
680 | if mask[self.channel] in ('0', '', ' '): | |
689 | continue |
|
681 | continue | |
690 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() |
|
682 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() | |
691 | delay = float(delays[i])*km2unit |
|
683 | delay = float(delays[i])*km2unit | |
692 |
|
684 | |||
693 | if modes[i]=='P': |
|
685 | if modes[i]=='P': | |
694 | if delay>0: |
|
686 | if delay>0: | |
695 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): |
|
687 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): | |
696 | y_temp = np.empty_like(Y) |
|
688 | y_temp = np.empty_like(Y) | |
697 | y_temp[:delay] = 0 |
|
689 | y_temp[:delay] = 0 | |
698 | y_temp[delay:] = Y[:-delay] |
|
690 | y_temp[delay:] = Y[:-delay] | |
699 | elif delay+len(Y)>len(y): |
|
691 | elif delay+len(Y)>len(y): | |
700 | y_new = np.zeros(delay+len(Y), dtype=np.int8) |
|
692 | y_new = np.zeros(delay+len(Y), dtype=np.int8) | |
701 | y_new[:len(y)] = y |
|
693 | y_new[:len(y)] = y | |
702 | y = y_new |
|
694 | y = y_new | |
703 | y_temp = np.zeros(delay+len(Y), dtype=np.int8) |
|
695 | y_temp = np.zeros(delay+len(Y), dtype=np.int8) | |
704 | y_temp[-len(Y):] = Y |
|
696 | y_temp[-len(Y):] = Y | |
705 | elif delay+len(Y)==len(y): |
|
697 | elif delay+len(Y)==len(y): | |
706 | y_temp = np.zeros(delay+len(Y)) |
|
698 | y_temp = np.zeros(delay+len(Y)) | |
707 | y_temp[-len(Y):] = Y |
|
699 | y_temp[-len(Y):] = Y | |
708 | elif delay+len(Y)<len(y): |
|
700 | elif delay+len(Y)<len(y): | |
709 | y_temp = np.zeros(len(y), dtype=np.int8) |
|
701 | y_temp = np.zeros(len(y), dtype=np.int8) | |
710 | y_temp[delay:delay+len(Y)] = Y |
|
702 | y_temp[delay:delay+len(Y)] = Y | |
711 |
|
703 | |||
712 | if ops[i]=='OR': |
|
704 | if ops[i]=='OR': | |
713 | y = y | y_temp |
|
705 | y = y | y_temp | |
714 | elif ops[i]=='XOR': |
|
706 | elif ops[i]=='XOR': | |
715 | y = y ^ y_temp |
|
707 | y = y ^ y_temp | |
716 | elif ops[i]=='AND': |
|
708 | elif ops[i]=='AND': | |
717 | y = y & y_temp |
|
709 | y = y & y_temp | |
718 | elif ops[i]=='NAND': |
|
710 | elif ops[i]=='NAND': | |
719 | y = y & ~y_temp |
|
711 | y = y & ~y_temp | |
720 | else: |
|
712 | else: | |
721 | y = np.concatenate([y, Y]) |
|
713 | y = np.concatenate([y, Y]) | |
722 |
|
714 | |||
723 | total = len(y) |
|
715 | total = len(y) | |
724 | y = self.array_to_points(y) |
|
716 | y = self.array_to_points(y) | |
725 |
|
717 | |||
726 | else: |
|
718 | else: | |
727 | y = [] |
|
719 | y = [] | |
728 |
|
720 | |||
729 | if self.rc_configuration.total_units <> total: |
|
721 | if self.rc_configuration.total_units <> total: | |
730 | self.rc_configuration.total_units = total |
|
722 | self.rc_configuration.total_units = total | |
731 | self.rc_configuration.save() |
|
723 | self.rc_configuration.save() | |
732 |
|
724 | |||
733 | self.pulses = unicode(y) |
|
725 | self.pulses = unicode(y) | |
734 | self.save() |
|
726 | self.save() | |
735 |
|
727 | |||
736 | @staticmethod |
|
728 | @staticmethod | |
737 | def array_to_points(X): |
|
729 | def array_to_points(X): | |
738 |
|
730 | |||
739 | d = X[1:]-X[:-1] |
|
731 | d = X[1:]-X[:-1] | |
740 |
|
732 | |||
741 | up = np.where(d==1)[0] |
|
733 | up = np.where(d==1)[0] | |
742 | if X[0]==1: |
|
734 | if X[0]==1: | |
743 | up = np.concatenate((np.array([-1]), up)) |
|
735 | up = np.concatenate((np.array([-1]), up)) | |
744 | up += 1 |
|
736 | up += 1 | |
745 |
|
737 | |||
746 | dw = np.where(d==-1)[0] |
|
738 | dw = np.where(d==-1)[0] | |
747 | if X[-1]==1: |
|
739 | if X[-1]==1: | |
748 | dw = np.concatenate((dw, np.array([len(X)-1]))) |
|
740 | dw = np.concatenate((dw, np.array([len(X)-1]))) | |
749 | dw += 1 |
|
741 | dw += 1 | |
750 |
|
742 | |||
751 | return [(tup[0], tup[1]) for tup in zip(up, dw)] |
|
743 | return [(tup[0], tup[1]) for tup in zip(up, dw)] | |
752 |
|
744 | |||
753 | @staticmethod |
|
745 | @staticmethod | |
754 | def mask_ranges(Y, ranges): |
|
746 | def mask_ranges(Y, ranges): | |
755 |
|
747 | |||
756 | y = [(0, 0) for __ in Y] |
|
748 | y = [(0, 0) for __ in Y] | |
757 |
|
749 | |||
758 | for index in ranges: |
|
750 | for index in ranges: | |
759 | if '-' in index: |
|
751 | if '-' in index: | |
760 | args = [int(a) for a in index.split('-')] |
|
752 | args = [int(a) for a in index.split('-')] | |
761 | y[args[0]-1:args[1]] = Y[args[0]-1:args[1]] |
|
753 | y[args[0]-1:args[1]] = Y[args[0]-1:args[1]] | |
762 | else: |
|
754 | else: | |
763 | y[int(index-1)] = Y[int(index-1)] |
|
755 | y[int(index-1)] = Y[int(index-1)] | |
764 |
|
756 | |||
765 | return y |
|
757 | return y | |
766 |
|
758 | |||
767 | @staticmethod |
|
759 | @staticmethod | |
768 | def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0): |
|
760 | def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0): | |
769 |
|
761 | |||
770 | delays = len(delay) |
|
762 | delays = len(delay) | |
771 |
|
763 | |||
772 | Y = [(ipp*x+before+delay[x%delays], ipp*x+width+before+delay[x%delays]+after) for x in range(ntx)] |
|
764 | Y = [(ipp*x+before+delay[x%delays], ipp*x+width+before+delay[x%delays]+after) for x in range(ntx)] | |
773 |
|
765 | |||
774 | return Y No newline at end of file |
|
766 | return Y |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now