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