|
@@
-1,1976
+1,2028
|
|
1
|
1
|
import ast
|
|
2
|
2
|
import json
|
|
3
|
3
|
import hashlib
|
|
4
|
4
|
from datetime import datetime, timedelta
|
|
5
|
5
|
|
|
6
|
6
|
from django.shortcuts import render, redirect, get_object_or_404, HttpResponse
|
|
7
|
7
|
from django.utils.safestring import mark_safe
|
|
8
|
8
|
from django.http import HttpResponseRedirect
|
|
9
|
9
|
from django.urls import reverse
|
|
10
|
10
|
from django.db.models import Q
|
|
11
|
11
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|
12
|
12
|
from django.contrib import messages
|
|
13
|
13
|
from django.http.request import QueryDict
|
|
14
|
14
|
from django.contrib.auth.decorators import login_required, user_passes_test
|
|
15
|
15
|
|
|
16
|
16
|
from django.utils.timezone import is_aware
|
|
17
|
17
|
|
|
18
|
18
|
try:
|
|
19
|
19
|
from urllib.parse import urlencode
|
|
20
|
20
|
except ImportError:
|
|
21
|
21
|
from urllib import urlencode
|
|
22
|
22
|
|
|
23
|
23
|
from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm
|
|
24
|
24
|
from .forms import OperationSearchForm, FilterForm, ChangeIpForm
|
|
25
|
25
|
|
|
26
|
26
|
from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm
|
|
27
|
27
|
from apps.dds.forms import DDSConfigurationForm
|
|
28
|
28
|
from apps.jars.forms import JARSConfigurationForm
|
|
29
|
29
|
from apps.cgs.forms import CGSConfigurationForm
|
|
30
|
30
|
from apps.abs.forms import ABSConfigurationForm
|
|
31
|
31
|
from apps.usrp.forms import USRPConfigurationForm
|
|
32
|
32
|
from apps.dds_rest.forms import DDSRestConfigurationForm
|
|
33
|
33
|
from .utils import Params
|
|
34
|
34
|
|
|
35
|
35
|
from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES
|
|
36
|
36
|
from apps.cgs.models import CGSConfiguration
|
|
37
|
37
|
from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE
|
|
38
|
38
|
from apps.usrp.models import USRPConfiguration
|
|
39
|
39
|
from apps.abs.models import ABSConfiguration
|
|
40
|
40
|
from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock
|
|
41
|
41
|
from apps.dds.models import DDSConfiguration
|
|
42
|
42
|
from apps.dds_rest.models import DDSRestConfiguration
|
|
43
|
43
|
|
|
44
|
44
|
#from .tasks import task_start
|
|
45
|
45
|
from radarsys.celery import app
|
|
46
|
46
|
|
|
47
|
47
|
#comentario test
|
|
48
|
48
|
CONF_FORMS = {
|
|
49
|
49
|
'rc': RCConfigurationForm,
|
|
50
|
50
|
'dds': DDSConfigurationForm,
|
|
51
|
51
|
'dds_rest': DDSRestConfigurationForm,
|
|
52
|
52
|
'jars': JARSConfigurationForm,
|
|
53
|
53
|
'cgs': CGSConfigurationForm,
|
|
54
|
54
|
'abs': ABSConfigurationForm,
|
|
55
|
55
|
'usrp': USRPConfigurationForm,
|
|
56
|
56
|
}
|
|
57
|
57
|
|
|
58
|
58
|
CONF_MODELS = {
|
|
59
|
59
|
'rc': RCConfiguration,
|
|
60
|
60
|
'dds': DDSConfiguration,
|
|
61
|
61
|
'dds_rest': DDSRestConfiguration,
|
|
62
|
62
|
'jars': JARSConfiguration,
|
|
63
|
63
|
'cgs': CGSConfiguration,
|
|
64
|
64
|
'abs': ABSConfiguration,
|
|
65
|
65
|
'usrp': USRPConfiguration,
|
|
66
|
66
|
}
|
|
67
|
67
|
|
|
68
|
68
|
MIX_MODES = {
|
|
69
|
69
|
'0': 'P',
|
|
70
|
70
|
'1': 'S',
|
|
71
|
71
|
}
|
|
72
|
72
|
|
|
73
|
73
|
MIX_OPERATIONS = {
|
|
74
|
74
|
'0': 'OR',
|
|
75
|
75
|
'1': 'XOR',
|
|
76
|
76
|
'2': 'AND',
|
|
77
|
77
|
'3': 'NAND',
|
|
78
|
78
|
}
|
|
79
|
79
|
|
|
80
|
80
|
|
|
81
|
81
|
def is_developer(user):
|
|
82
|
82
|
|
|
83
|
83
|
groups = [str(g.name) for g in user.groups.all()]
|
|
84
|
84
|
return 'Developer' in groups or user.is_staff
|
|
85
|
85
|
|
|
86
|
86
|
|
|
87
|
87
|
def is_operator(user):
|
|
88
|
88
|
|
|
89
|
89
|
groups = [str(g.name) for g in user.groups.all()]
|
|
90
|
90
|
return 'Operator' in groups or user.is_staff
|
|
91
|
91
|
|
|
92
|
92
|
|
|
93
|
93
|
def has_been_modified(model):
|
|
94
|
94
|
|
|
95
|
95
|
prev_hash = model.hash
|
|
96
|
96
|
new_hash = hashlib.sha256(str(model.parms_to_dict).encode()).hexdigest()
|
|
97
|
97
|
if prev_hash != new_hash:
|
|
98
|
98
|
model.hash = new_hash
|
|
99
|
99
|
model.save()
|
|
100
|
100
|
return True
|
|
101
|
101
|
return False
|
|
102
|
102
|
|
|
103
|
103
|
|
|
104
|
104
|
def index(request):
|
|
105
|
105
|
kwargs = {'no_sidebar': True}
|
|
106
|
106
|
|
|
107
|
107
|
return render(request, 'index.html', kwargs)
|
|
108
|
108
|
|
|
109
|
109
|
|
|
110
|
110
|
def locations(request):
|
|
111
|
111
|
|
|
112
|
112
|
page = request.GET.get('page')
|
|
113
|
113
|
order = ('name',)
|
|
114
|
114
|
|
|
115
|
115
|
kwargs = get_paginator(Location, page, order)
|
|
116
|
116
|
|
|
117
|
117
|
kwargs['keys'] = ['name', 'description']
|
|
118
|
118
|
kwargs['title'] = 'Radar System'
|
|
119
|
119
|
kwargs['suptitle'] = 'List'
|
|
120
|
120
|
kwargs['no_sidebar'] = True
|
|
121
|
121
|
|
|
122
|
122
|
return render(request, 'base_list.html', kwargs)
|
|
123
|
123
|
|
|
124
|
124
|
|
|
125
|
125
|
def location(request, id_loc):
|
|
126
|
126
|
|
|
127
|
127
|
location = get_object_or_404(Location, pk=id_loc)
|
|
128
|
128
|
|
|
129
|
129
|
kwargs = {}
|
|
130
|
130
|
kwargs['location'] = location
|
|
131
|
131
|
kwargs['location_keys'] = ['name', 'description']
|
|
132
|
132
|
|
|
133
|
133
|
kwargs['title'] = 'Location'
|
|
134
|
134
|
kwargs['suptitle'] = 'Details'
|
|
135
|
135
|
|
|
136
|
136
|
return render(request, 'location.html', kwargs)
|
|
137
|
137
|
|
|
138
|
138
|
|
|
139
|
139
|
@login_required
|
|
140
|
140
|
def location_new(request):
|
|
141
|
141
|
|
|
142
|
142
|
if request.method == 'GET':
|
|
143
|
143
|
form = LocationForm()
|
|
144
|
144
|
|
|
145
|
145
|
if request.method == 'POST':
|
|
146
|
146
|
form = LocationForm(request.POST)
|
|
147
|
147
|
|
|
148
|
148
|
if form.is_valid():
|
|
149
|
149
|
form.save()
|
|
150
|
150
|
return redirect('url_locations')
|
|
151
|
151
|
|
|
152
|
152
|
kwargs = {}
|
|
153
|
153
|
kwargs['form'] = form
|
|
154
|
154
|
kwargs['title'] = 'Radar System'
|
|
155
|
155
|
kwargs['suptitle'] = 'New'
|
|
156
|
156
|
kwargs['button'] = 'Create'
|
|
157
|
157
|
|
|
158
|
158
|
return render(request, 'base_edit.html', kwargs)
|
|
159
|
159
|
|
|
160
|
160
|
|
|
161
|
161
|
@login_required
|
|
162
|
162
|
def location_edit(request, id_loc):
|
|
163
|
163
|
|
|
164
|
164
|
location = get_object_or_404(Location, pk=id_loc)
|
|
165
|
165
|
|
|
166
|
166
|
if request.method == 'GET':
|
|
167
|
167
|
form = LocationForm(instance=location)
|
|
168
|
168
|
|
|
169
|
169
|
if request.method == 'POST':
|
|
170
|
170
|
form = LocationForm(request.POST, instance=location)
|
|
171
|
171
|
|
|
172
|
172
|
if form.is_valid():
|
|
173
|
173
|
form.save()
|
|
174
|
174
|
return redirect('url_locations')
|
|
175
|
175
|
|
|
176
|
176
|
kwargs = {}
|
|
177
|
177
|
kwargs['form'] = form
|
|
178
|
178
|
kwargs['title'] = 'Location'
|
|
179
|
179
|
kwargs['suptitle'] = 'Edit'
|
|
180
|
180
|
kwargs['button'] = 'Update'
|
|
181
|
181
|
|
|
182
|
182
|
return render(request, 'base_edit.html', kwargs)
|
|
183
|
183
|
|
|
184
|
184
|
|
|
185
|
185
|
@login_required
|
|
186
|
186
|
def location_delete(request, id_loc):
|
|
187
|
187
|
|
|
188
|
188
|
location = get_object_or_404(Location, pk=id_loc)
|
|
189
|
189
|
|
|
190
|
190
|
if request.method == 'POST':
|
|
191
|
191
|
|
|
192
|
192
|
if is_developer(request.user):
|
|
193
|
193
|
location.delete()
|
|
194
|
194
|
return redirect('url_locations')
|
|
195
|
195
|
|
|
196
|
196
|
messages.error(request, 'Not enough permission to delete this object')
|
|
197
|
197
|
return redirect(location.get_absolute_url())
|
|
198
|
198
|
|
|
199
|
199
|
kwargs = {
|
|
200
|
200
|
'title': 'Delete',
|
|
201
|
201
|
'suptitle': 'Location',
|
|
202
|
202
|
'object': location,
|
|
203
|
203
|
'delete': True
|
|
204
|
204
|
}
|
|
205
|
205
|
|
|
206
|
206
|
return render(request, 'confirm.html', kwargs)
|
|
207
|
207
|
|
|
208
|
208
|
|
|
209
|
209
|
def devices(request):
|
|
210
|
210
|
|
|
211
|
211
|
page = request.GET.get('page')
|
|
212
|
212
|
order = ('location', 'device_type')
|
|
213
|
213
|
|
|
214
|
214
|
filters = request.GET.copy()
|
|
215
|
215
|
kwargs = get_paginator(Device, page, order, filters)
|
|
216
|
216
|
form = FilterForm(initial=request.GET, extra_fields=['tags'])
|
|
217
|
217
|
|
|
218
|
218
|
kwargs['keys'] = ['device_type', 'location',
|
|
219
|
219
|
'ip_address', 'port_address', 'actions']
|
|
220
|
220
|
kwargs['title'] = 'Device'
|
|
221
|
221
|
kwargs['suptitle'] = 'List'
|
|
222
|
222
|
kwargs['no_sidebar'] = True
|
|
223
|
223
|
kwargs['form'] = form
|
|
224
|
224
|
kwargs['add_url'] = reverse('url_add_device')
|
|
225
|
225
|
filters.pop('page', None)
|
|
226
|
226
|
kwargs['q'] = urlencode(filters)
|
|
227
|
227
|
kwargs['menu_devices'] = 'active'
|
|
228
|
228
|
return render(request, 'base_list.html', kwargs)
|
|
229
|
229
|
|
|
230
|
230
|
|
|
231
|
231
|
def device(request, id_dev):
|
|
232
|
232
|
|
|
233
|
233
|
device = get_object_or_404(Device, pk=id_dev)
|
|
234
|
234
|
|
|
235
|
235
|
kwargs = {}
|
|
236
|
236
|
kwargs['device'] = device
|
|
237
|
237
|
kwargs['device_keys'] = ['device_type',
|
|
238
|
238
|
'ip_address', 'port_address', 'description']
|
|
239
|
239
|
|
|
240
|
240
|
kwargs['title'] = 'Device'
|
|
241
|
241
|
kwargs['suptitle'] = 'Details'
|
|
242
|
242
|
kwargs['menu_devices'] = 'active'
|
|
243
|
243
|
|
|
244
|
244
|
return render(request, 'device.html', kwargs)
|
|
245
|
245
|
|
|
246
|
246
|
|
|
247
|
247
|
@login_required
|
|
248
|
248
|
def device_new(request):
|
|
249
|
249
|
|
|
250
|
250
|
if request.method == 'GET':
|
|
251
|
251
|
form = DeviceForm()
|
|
252
|
252
|
|
|
253
|
253
|
if request.method == 'POST':
|
|
254
|
254
|
form = DeviceForm(request.POST)
|
|
255
|
255
|
|
|
256
|
256
|
if form.is_valid():
|
|
257
|
257
|
form.save()
|
|
258
|
258
|
return redirect('url_devices')
|
|
259
|
259
|
|
|
260
|
260
|
kwargs = {}
|
|
261
|
261
|
kwargs['form'] = form
|
|
262
|
262
|
kwargs['title'] = 'Device'
|
|
263
|
263
|
kwargs['suptitle'] = 'New_2'
|
|
264
|
264
|
kwargs['button'] = 'Create'
|
|
265
|
265
|
kwargs['menu_devices'] = 'active'
|
|
266
|
266
|
|
|
267
|
267
|
return render(request, 'base_edit.html', kwargs)
|
|
268
|
268
|
|
|
269
|
269
|
|
|
270
|
270
|
@login_required
|
|
271
|
271
|
def device_edit(request, id_dev):
|
|
272
|
272
|
|
|
273
|
273
|
device = get_object_or_404(Device, pk=id_dev)
|
|
274
|
274
|
|
|
275
|
275
|
if request.method == 'GET':
|
|
276
|
276
|
form = DeviceForm(instance=device)
|
|
277
|
277
|
|
|
278
|
278
|
if request.method == 'POST':
|
|
279
|
279
|
form = DeviceForm(request.POST, instance=device)
|
|
280
|
280
|
|
|
281
|
281
|
if form.is_valid():
|
|
282
|
282
|
form.save()
|
|
283
|
283
|
return redirect(device.get_absolute_url())
|
|
284
|
284
|
|
|
285
|
285
|
kwargs = {}
|
|
286
|
286
|
kwargs['form'] = form
|
|
287
|
287
|
kwargs['title'] = 'Device'
|
|
288
|
288
|
kwargs['suptitle'] = 'Edit'
|
|
289
|
289
|
kwargs['button'] = 'Update'
|
|
290
|
290
|
kwargs['menu_devices'] = 'active'
|
|
291
|
291
|
|
|
292
|
292
|
return render(request, 'base_edit.html', kwargs)
|
|
293
|
293
|
|
|
294
|
294
|
|
|
295
|
295
|
@login_required
|
|
296
|
296
|
def device_delete(request, id_dev):
|
|
297
|
297
|
|
|
298
|
298
|
device = get_object_or_404(Device, pk=id_dev)
|
|
299
|
299
|
|
|
300
|
300
|
if request.method == 'POST':
|
|
301
|
301
|
|
|
302
|
302
|
if is_developer(request.user):
|
|
303
|
303
|
device.delete()
|
|
304
|
304
|
return redirect('url_devices')
|
|
305
|
305
|
|
|
306
|
306
|
messages.error(request, 'Not enough permission to delete this object')
|
|
307
|
307
|
return redirect(device.get_absolute_url())
|
|
308
|
308
|
|
|
309
|
309
|
kwargs = {
|
|
310
|
310
|
'title': 'Delete',
|
|
311
|
311
|
'suptitle': 'Device',
|
|
312
|
312
|
'object': device,
|
|
313
|
313
|
'delete': True
|
|
314
|
314
|
}
|
|
315
|
315
|
kwargs['menu_devices'] = 'active'
|
|
316
|
316
|
|
|
317
|
317
|
return render(request, 'confirm.html', kwargs)
|
|
318
|
318
|
|
|
319
|
319
|
|
|
320
|
320
|
@login_required
|
|
321
|
321
|
def device_change_ip(request, id_dev):
|
|
322
|
322
|
|
|
323
|
323
|
device = get_object_or_404(Device, pk=id_dev)
|
|
324
|
324
|
|
|
325
|
325
|
if request.method == 'POST':
|
|
326
|
326
|
|
|
327
|
327
|
if is_developer(request.user):
|
|
328
|
328
|
device.change_ip(**request.POST.dict())
|
|
329
|
329
|
|
|
330
|
330
|
print(device.ip_address, device.message)
|
|
331
|
331
|
|
|
332
|
332
|
level, message = device.message.split('|')
|
|
333
|
333
|
messages.add_message(request, level, message)
|
|
334
|
334
|
else:
|
|
335
|
335
|
messages.error(
|
|
336
|
336
|
request, 'Not enough permission to delete this object')
|
|
337
|
337
|
return redirect(device.get_absolute_url())
|
|
338
|
338
|
|
|
339
|
339
|
kwargs = {
|
|
340
|
340
|
'title': 'Device',
|
|
341
|
341
|
'suptitle': 'Change IP',
|
|
342
|
342
|
'object': device,
|
|
343
|
343
|
'previous': device.get_absolute_url(),
|
|
344
|
344
|
'form': ChangeIpForm(initial={'ip_address': device.ip_address}),
|
|
345
|
345
|
'message': ' ',
|
|
346
|
346
|
}
|
|
347
|
347
|
kwargs['menu_devices'] = 'active'
|
|
348
|
348
|
|
|
349
|
349
|
return render(request, 'confirm.html', kwargs)
|
|
350
|
350
|
|
|
351
|
351
|
|
|
352
|
352
|
def campaigns(request):
|
|
353
|
353
|
|
|
354
|
354
|
page = request.GET.get('page')
|
|
355
|
355
|
order = ('-start_date',)
|
|
356
|
356
|
filters = request.GET.copy()
|
|
357
|
357
|
|
|
358
|
358
|
kwargs = get_paginator(Campaign, page, order, filters)
|
|
359
|
359
|
|
|
360
|
360
|
form = FilterForm(initial=request.GET, extra_fields=[
|
|
361
|
361
|
'range_date', 'tags', 'template'])
|
|
362
|
362
|
kwargs['keys'] = ['name', 'start_date', 'end_date', 'actions']
|
|
363
|
363
|
kwargs['title'] = 'Campaign'
|
|
364
|
364
|
kwargs['suptitle'] = 'List'
|
|
365
|
365
|
kwargs['no_sidebar'] = True
|
|
366
|
366
|
kwargs['form'] = form
|
|
367
|
367
|
kwargs['add_url'] = reverse('url_add_campaign')
|
|
368
|
368
|
filters.pop('page', None)
|
|
369
|
369
|
kwargs['q'] = urlencode(filters)
|
|
370
|
370
|
kwargs['menu_campaigns'] = 'active'
|
|
371
|
371
|
|
|
372
|
372
|
return render(request, 'base_list.html', kwargs)
|
|
373
|
373
|
|
|
374
|
374
|
|
|
375
|
375
|
def campaign(request, id_camp):
|
|
376
|
376
|
|
|
377
|
377
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
378
|
378
|
experiments = Experiment.objects.filter(campaign=campaign)
|
|
379
|
379
|
|
|
380
|
380
|
form = CampaignForm(instance=campaign)
|
|
381
|
381
|
|
|
382
|
382
|
kwargs = {}
|
|
383
|
383
|
kwargs['campaign'] = campaign
|
|
384
|
384
|
kwargs['campaign_keys'] = ['template', 'name',
|
|
385
|
385
|
'start_date', 'end_date', 'tags', 'description']
|
|
386
|
386
|
|
|
387
|
387
|
kwargs['experiments'] = experiments
|
|
388
|
388
|
kwargs['experiment_keys'] = [
|
|
389
|
389
|
'name', 'radar_system', 'start_time', 'end_time']
|
|
390
|
390
|
|
|
391
|
391
|
kwargs['title'] = 'Campaign'
|
|
392
|
392
|
kwargs['suptitle'] = 'Details'
|
|
393
|
393
|
|
|
394
|
394
|
kwargs['form'] = form
|
|
395
|
395
|
kwargs['button'] = 'Add Experiment'
|
|
396
|
396
|
kwargs['menu_campaigns'] = 'active'
|
|
397
|
397
|
|
|
398
|
398
|
return render(request, 'campaign.html', kwargs)
|
|
399
|
399
|
|
|
400
|
400
|
|
|
401
|
401
|
@login_required
|
|
402
|
402
|
def campaign_new(request):
|
|
403
|
403
|
|
|
404
|
404
|
kwargs = {}
|
|
405
|
405
|
|
|
406
|
406
|
if request.method == 'GET':
|
|
407
|
407
|
|
|
408
|
408
|
if 'template' in request.GET:
|
|
409
|
409
|
if request.GET['template'] == '0':
|
|
410
|
410
|
form = NewForm(initial={'create_from': 2},
|
|
411
|
411
|
template_choices=Campaign.objects.filter(template=True).values_list('id', 'name'))
|
|
412
|
412
|
else:
|
|
413
|
413
|
kwargs['button'] = 'Create'
|
|
414
|
414
|
kwargs['experiments'] = Configuration.objects.filter(
|
|
415
|
415
|
experiment=request.GET['template'])
|
|
416
|
416
|
kwargs['experiment_keys'] = ['name', 'start_time', 'end_time']
|
|
417
|
417
|
camp = Campaign.objects.get(pk=request.GET['template'])
|
|
418
|
418
|
form = CampaignForm(instance=camp,
|
|
419
|
419
|
initial={'name': '{}_{:%Y%m%d}'.format(camp.name, datetime.now()),
|
|
420
|
420
|
'template': False})
|
|
421
|
421
|
elif 'blank' in request.GET:
|
|
422
|
422
|
kwargs['button'] = 'Create'
|
|
423
|
423
|
form = CampaignForm()
|
|
424
|
424
|
else:
|
|
425
|
425
|
form = NewForm()
|
|
426
|
426
|
|
|
427
|
427
|
if request.method == 'POST':
|
|
428
|
428
|
kwargs['button'] = 'Create'
|
|
429
|
429
|
post = request.POST.copy()
|
|
430
|
430
|
experiments = []
|
|
431
|
431
|
|
|
432
|
432
|
for id_exp in post.getlist('experiments'):
|
|
433
|
433
|
exp = Experiment.objects.get(pk=id_exp)
|
|
434
|
434
|
new_exp = exp.clone(template=False)
|
|
435
|
435
|
experiments.append(new_exp)
|
|
436
|
436
|
|
|
437
|
437
|
post.setlist('experiments', [])
|
|
438
|
438
|
|
|
439
|
439
|
form = CampaignForm(post)
|
|
440
|
440
|
|
|
441
|
441
|
if form.is_valid():
|
|
442
|
442
|
campaign = form.save(commit=False)
|
|
443
|
443
|
campaign.author = request.user
|
|
444
|
444
|
for exp in experiments:
|
|
445
|
445
|
campaign.experiments.add(exp)
|
|
446
|
446
|
campaign.save()
|
|
447
|
447
|
return redirect('url_campaign', id_camp=campaign.id)
|
|
448
|
448
|
|
|
449
|
449
|
kwargs['form'] = form
|
|
450
|
450
|
kwargs['title'] = 'Campaign'
|
|
451
|
451
|
kwargs['suptitle'] = 'New'
|
|
452
|
452
|
kwargs['menu_campaigns'] = 'active'
|
|
453
|
453
|
|
|
454
|
454
|
return render(request, 'campaign_edit.html', kwargs)
|
|
455
|
455
|
|
|
456
|
456
|
|
|
457
|
457
|
@login_required
|
|
458
|
458
|
def campaign_edit(request, id_camp):
|
|
459
|
459
|
|
|
460
|
460
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
461
|
461
|
|
|
462
|
462
|
if request.method == 'GET':
|
|
463
|
463
|
form = CampaignForm(instance=campaign)
|
|
464
|
464
|
|
|
465
|
465
|
if request.method == 'POST':
|
|
466
|
466
|
exps = campaign.experiments.all().values_list('pk', flat=True)
|
|
467
|
467
|
post = request.POST.copy()
|
|
468
|
468
|
new_exps = post.getlist('experiments')
|
|
469
|
469
|
post.setlist('experiments', [])
|
|
470
|
470
|
form = CampaignForm(post, instance=campaign)
|
|
471
|
471
|
|
|
472
|
472
|
if form.is_valid():
|
|
473
|
473
|
camp = form.save()
|
|
474
|
474
|
for id_exp in new_exps:
|
|
475
|
475
|
if int(id_exp) in exps:
|
|
476
|
476
|
exps.pop(id_exp)
|
|
477
|
477
|
else:
|
|
478
|
478
|
exp = Experiment.objects.get(pk=id_exp)
|
|
479
|
479
|
if exp.template:
|
|
480
|
480
|
camp.experiments.add(exp.clone(template=False))
|
|
481
|
481
|
else:
|
|
482
|
482
|
camp.experiments.add(exp)
|
|
483
|
483
|
|
|
484
|
484
|
for id_exp in exps:
|
|
485
|
485
|
camp.experiments.remove(Experiment.objects.get(pk=id_exp))
|
|
486
|
486
|
|
|
487
|
487
|
return redirect('url_campaign', id_camp=id_camp)
|
|
488
|
488
|
|
|
489
|
489
|
kwargs = {}
|
|
490
|
490
|
kwargs['form'] = form
|
|
491
|
491
|
kwargs['title'] = 'Campaign'
|
|
492
|
492
|
kwargs['suptitle'] = 'Edit'
|
|
493
|
493
|
kwargs['button'] = 'Update'
|
|
494
|
494
|
kwargs['menu_campaigns'] = 'active'
|
|
495
|
495
|
|
|
496
|
496
|
return render(request, 'campaign_edit.html', kwargs)
|
|
497
|
497
|
|
|
498
|
498
|
|
|
499
|
499
|
@login_required
|
|
500
|
500
|
def campaign_delete(request, id_camp):
|
|
501
|
501
|
|
|
502
|
502
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
503
|
503
|
|
|
504
|
504
|
if request.method == 'POST':
|
|
505
|
505
|
if is_developer(request.user):
|
|
506
|
506
|
|
|
507
|
507
|
for exp in campaign.experiments.all():
|
|
508
|
508
|
for conf in Configuration.objects.filter(experiment=exp):
|
|
509
|
509
|
conf.delete()
|
|
510
|
510
|
exp.delete()
|
|
511
|
511
|
campaign.delete()
|
|
512
|
512
|
|
|
513
|
513
|
return redirect('url_campaigns')
|
|
514
|
514
|
|
|
515
|
515
|
messages.error(request, 'Not enough permission to delete this object')
|
|
516
|
516
|
return redirect(campaign.get_absolute_url())
|
|
517
|
517
|
|
|
518
|
518
|
kwargs = {
|
|
519
|
519
|
'title': 'Delete',
|
|
520
|
520
|
'suptitle': 'Campaign',
|
|
521
|
521
|
'object': campaign,
|
|
522
|
522
|
'delete': True
|
|
523
|
523
|
}
|
|
524
|
524
|
kwargs['menu_campaigns'] = 'active'
|
|
525
|
525
|
|
|
526
|
526
|
return render(request, 'confirm.html', kwargs)
|
|
527
|
527
|
|
|
528
|
528
|
|
|
529
|
529
|
@login_required
|
|
530
|
530
|
def campaign_export(request, id_camp):
|
|
531
|
531
|
|
|
532
|
532
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
533
|
533
|
content = campaign.parms_to_dict()
|
|
534
|
534
|
content_type = 'application/json'
|
|
535
|
535
|
filename = '%s_%s.json' % (campaign.name, campaign.id)
|
|
536
|
536
|
|
|
537
|
537
|
response = HttpResponse(content_type=content_type)
|
|
538
|
538
|
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
|
|
539
|
539
|
response.write(json.dumps(content, indent=2))
|
|
540
|
540
|
|
|
541
|
541
|
return response
|
|
542
|
542
|
|
|
543
|
543
|
|
|
544
|
544
|
@login_required
|
|
545
|
545
|
def campaign_import(request, id_camp):
|
|
546
|
546
|
|
|
547
|
547
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
548
|
548
|
|
|
549
|
549
|
if request.method == 'GET':
|
|
550
|
550
|
file_form = UploadFileForm()
|
|
551
|
551
|
|
|
552
|
552
|
if request.method == 'POST':
|
|
553
|
553
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
554
|
554
|
|
|
555
|
555
|
if file_form.is_valid():
|
|
556
|
556
|
new_camp = campaign.dict_to_parms(
|
|
557
|
557
|
json.load(request.FILES['file']), CONF_MODELS)
|
|
558
|
558
|
messages.success(
|
|
559
|
559
|
request, "Parameters imported from: '%s'." % request.FILES['file'].name)
|
|
560
|
560
|
return redirect(new_camp.get_absolute_url_edit())
|
|
561
|
561
|
|
|
562
|
562
|
messages.error(request, "Could not import parameters from file")
|
|
563
|
563
|
|
|
564
|
564
|
kwargs = {}
|
|
565
|
565
|
kwargs['title'] = 'Campaign'
|
|
566
|
566
|
kwargs['form'] = file_form
|
|
567
|
567
|
kwargs['suptitle'] = 'Importing file'
|
|
568
|
568
|
kwargs['button'] = 'Import'
|
|
569
|
569
|
kwargs['menu_campaigns'] = 'active'
|
|
570
|
570
|
|
|
571
|
571
|
return render(request, 'campaign_import.html', kwargs)
|
|
572
|
572
|
|
|
573
|
573
|
|
|
574
|
574
|
def experiments(request):
|
|
575
|
575
|
|
|
576
|
576
|
page = request.GET.get('page')
|
|
577
|
577
|
order = ('location',)
|
|
578
|
578
|
filters = request.GET.copy()
|
|
579
|
579
|
|
|
580
|
580
|
if 'my experiments' in filters:
|
|
581
|
581
|
filters.pop('my experiments', None)
|
|
582
|
582
|
filters['mine'] = request.user.id
|
|
583
|
583
|
|
|
584
|
584
|
kwargs = get_paginator(Experiment, page, order, filters)
|
|
585
|
585
|
|
|
586
|
586
|
fields = ['tags', 'template']
|
|
587
|
587
|
if request.user.is_authenticated:
|
|
588
|
588
|
fields.append('my experiments')
|
|
589
|
589
|
|
|
590
|
590
|
form = FilterForm(initial=request.GET, extra_fields=fields)
|
|
591
|
591
|
|
|
592
|
592
|
kwargs['keys'] = ['name', 'radar_system',
|
|
593
|
593
|
'start_time', 'end_time', 'actions']
|
|
594
|
594
|
kwargs['title'] = 'Experiment'
|
|
595
|
595
|
kwargs['suptitle'] = 'List'
|
|
596
|
596
|
kwargs['no_sidebar'] = True
|
|
597
|
597
|
kwargs['form'] = form
|
|
598
|
598
|
kwargs['add_url'] = reverse('url_add_experiment')
|
|
599
|
599
|
filters = request.GET.copy()
|
|
600
|
600
|
filters.pop('page', None)
|
|
601
|
601
|
kwargs['q'] = urlencode(filters)
|
|
602
|
602
|
kwargs['menu_experiments'] = 'active'
|
|
603
|
603
|
|
|
604
|
604
|
return render(request, 'base_list.html', kwargs)
|
|
605
|
605
|
|
|
606
|
606
|
|
|
607
|
607
|
def experiment(request, id_exp):
|
|
608
|
608
|
|
|
609
|
609
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
610
|
610
|
|
|
611
|
611
|
configurations = Configuration.objects.filter(
|
|
612
|
612
|
experiment=experiment, type=0)
|
|
613
|
613
|
|
|
614
|
614
|
kwargs = {}
|
|
615
|
615
|
|
|
616
|
616
|
kwargs['experiment_keys'] = ['template', 'radar_system',
|
|
617
|
617
|
'name', 'freq', 'start_time', 'end_time']
|
|
618
|
618
|
kwargs['experiment'] = experiment
|
|
619
|
619
|
kwargs['configuration_keys'] = ['name', 'device__ip_address',
|
|
620
|
620
|
'device__port_address', 'device__status']
|
|
621
|
621
|
kwargs['configurations'] = configurations
|
|
622
|
622
|
kwargs['title'] = 'Experiment'
|
|
623
|
623
|
kwargs['suptitle'] = 'Details'
|
|
624
|
624
|
kwargs['button'] = 'Add Configuration'
|
|
625
|
625
|
kwargs['menu_experiments'] = 'active'
|
|
626
|
626
|
|
|
627
|
627
|
###### SIDEBAR ######
|
|
628
|
628
|
kwargs.update(sidebar(experiment=experiment))
|
|
629
|
629
|
|
|
630
|
630
|
return render(request, 'experiment.html', kwargs)
|
|
631
|
631
|
|
|
632
|
632
|
|
|
633
|
633
|
@login_required
|
|
634
|
634
|
def experiment_new(request, id_camp=None):
|
|
635
|
635
|
|
|
636
|
636
|
if not is_developer(request.user):
|
|
637
|
637
|
messages.error(
|
|
638
|
638
|
request, 'Developer required, to create new Experiments')
|
|
639
|
639
|
return redirect('index')
|
|
640
|
640
|
kwargs = {}
|
|
641
|
641
|
|
|
642
|
642
|
if request.method == 'GET':
|
|
643
|
643
|
if 'template' in request.GET:
|
|
644
|
644
|
if request.GET['template'] == '0':
|
|
645
|
645
|
form = NewForm(initial={'create_from': 2},
|
|
646
|
646
|
template_choices=Experiment.objects.filter(template=True).values_list('id', 'name'))
|
|
647
|
647
|
else:
|
|
648
|
648
|
kwargs['button'] = 'Create'
|
|
649
|
649
|
kwargs['configurations'] = Configuration.objects.filter(
|
|
650
|
650
|
experiment=request.GET['template'])
|
|
651
|
651
|
kwargs['configuration_keys'] = ['name', 'device__name',
|
|
652
|
652
|
'device__ip_address', 'device__port_address']
|
|
653
|
653
|
exp = Experiment.objects.get(pk=request.GET['template'])
|
|
654
|
654
|
form = ExperimentForm(instance=exp,
|
|
655
|
655
|
initial={'name': '{}_{:%y%m%d}'.format(exp.name, datetime.now()),
|
|
656
|
656
|
'template': False})
|
|
657
|
657
|
elif 'blank' in request.GET:
|
|
658
|
658
|
kwargs['button'] = 'Create'
|
|
659
|
659
|
form = ExperimentForm()
|
|
660
|
660
|
else:
|
|
661
|
661
|
form = NewForm()
|
|
662
|
662
|
|
|
663
|
663
|
if request.method == 'POST':
|
|
664
|
664
|
form = ExperimentForm(request.POST)
|
|
665
|
665
|
if form.is_valid():
|
|
666
|
666
|
experiment = form.save(commit=False)
|
|
667
|
667
|
experiment.author = request.user
|
|
668
|
668
|
experiment.save()
|
|
669
|
669
|
|
|
670
|
670
|
if 'template' in request.GET:
|
|
671
|
671
|
configurations = Configuration.objects.filter(
|
|
672
|
672
|
experiment=request.GET['template'], type=0)
|
|
673
|
673
|
for conf in configurations:
|
|
674
|
674
|
conf.clone(experiment=experiment, template=False)
|
|
675
|
675
|
|
|
676
|
676
|
return redirect('url_experiment', id_exp=experiment.id)
|
|
677
|
677
|
|
|
678
|
678
|
kwargs['form'] = form
|
|
679
|
679
|
kwargs['title'] = 'Experiment'
|
|
680
|
680
|
kwargs['suptitle'] = 'New'
|
|
681
|
681
|
kwargs['menu_experiments'] = 'active'
|
|
682
|
682
|
|
|
683
|
683
|
return render(request, 'experiment_edit.html', kwargs)
|
|
684
|
684
|
|
|
685
|
685
|
|
|
686
|
686
|
@login_required
|
|
687
|
687
|
def experiment_edit(request, id_exp):
|
|
688
|
688
|
|
|
689
|
689
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
690
|
690
|
|
|
691
|
691
|
if request.method == 'GET':
|
|
692
|
692
|
form = ExperimentForm(instance=experiment)
|
|
693
|
693
|
|
|
694
|
694
|
if request.method == 'POST':
|
|
695
|
695
|
form = ExperimentForm(request.POST, instance=experiment)
|
|
696
|
696
|
|
|
697
|
697
|
if form.is_valid():
|
|
698
|
698
|
experiment = form.save()
|
|
699
|
699
|
return redirect('url_experiment', id_exp=experiment.id)
|
|
700
|
700
|
|
|
701
|
701
|
kwargs = {}
|
|
702
|
702
|
kwargs['form'] = form
|
|
703
|
703
|
kwargs['title'] = 'Experiment'
|
|
704
|
704
|
kwargs['suptitle'] = 'Edit'
|
|
705
|
705
|
kwargs['button'] = 'Update'
|
|
706
|
706
|
kwargs['menu_experiments'] = 'active'
|
|
707
|
707
|
|
|
708
|
708
|
return render(request, 'experiment_edit.html', kwargs)
|
|
709
|
709
|
|
|
710
|
710
|
|
|
711
|
711
|
@login_required
|
|
712
|
712
|
def experiment_delete(request, id_exp):
|
|
713
|
713
|
|
|
714
|
714
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
715
|
715
|
|
|
716
|
716
|
if request.method == 'POST':
|
|
717
|
717
|
if is_developer(request.user):
|
|
718
|
718
|
for conf in Configuration.objects.filter(experiment=experiment):
|
|
719
|
719
|
conf.delete()
|
|
720
|
720
|
experiment.delete()
|
|
721
|
721
|
return redirect('url_experiments')
|
|
722
|
722
|
|
|
723
|
723
|
messages.error(request, 'Not enough permission to delete this object')
|
|
724
|
724
|
return redirect(experiment.get_absolute_url())
|
|
725
|
725
|
|
|
726
|
726
|
kwargs = {
|
|
727
|
727
|
'title': 'Delete',
|
|
728
|
728
|
'suptitle': 'Experiment',
|
|
729
|
729
|
'object': experiment,
|
|
730
|
730
|
'delete': True
|
|
731
|
731
|
}
|
|
732
|
732
|
|
|
733
|
733
|
return render(request, 'confirm.html', kwargs)
|
|
734
|
734
|
|
|
735
|
735
|
|
|
736
|
736
|
@login_required
|
|
737
|
737
|
def experiment_export(request, id_exp):
|
|
738
|
738
|
|
|
739
|
739
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
740
|
740
|
content = experiment.parms_to_dict()
|
|
741
|
741
|
content_type = 'application/json'
|
|
742
|
742
|
filename = '%s_%s.json' % (experiment.name, experiment.id)
|
|
743
|
743
|
|
|
744
|
744
|
response = HttpResponse(content_type=content_type)
|
|
745
|
745
|
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
|
|
746
|
746
|
response.write(json.dumps(content, indent=2))
|
|
747
|
747
|
|
|
748
|
748
|
return response
|
|
749
|
749
|
|
|
750
|
750
|
|
|
751
|
751
|
@login_required
|
|
752
|
752
|
def experiment_import(request, id_exp):
|
|
753
|
753
|
|
|
754
|
754
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
755
|
755
|
configurations = Configuration.objects.filter(experiment=experiment)
|
|
756
|
756
|
|
|
757
|
757
|
if request.method == 'GET':
|
|
758
|
758
|
file_form = UploadFileForm()
|
|
759
|
759
|
|
|
760
|
760
|
if request.method == 'POST':
|
|
761
|
761
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
762
|
762
|
|
|
763
|
763
|
if file_form.is_valid():
|
|
764
|
764
|
new_exp = experiment.dict_to_parms(
|
|
765
|
765
|
json.load(request.FILES['file']), CONF_MODELS)
|
|
766
|
766
|
messages.success(
|
|
767
|
767
|
request, "Parameters imported from: '%s'." % request.FILES['file'].name)
|
|
768
|
768
|
return redirect(new_exp.get_absolute_url_edit())
|
|
769
|
769
|
|
|
770
|
770
|
messages.error(request, "Could not import parameters from file")
|
|
771
|
771
|
|
|
772
|
772
|
kwargs = {}
|
|
773
|
773
|
kwargs['title'] = 'Experiment'
|
|
774
|
774
|
kwargs['form'] = file_form
|
|
775
|
775
|
kwargs['suptitle'] = 'Importing file'
|
|
776
|
776
|
kwargs['button'] = 'Import'
|
|
777
|
777
|
kwargs['menu_experiments'] = 'active'
|
|
778
|
778
|
|
|
779
|
779
|
kwargs.update(sidebar(experiment=experiment))
|
|
780
|
780
|
|
|
781
|
781
|
return render(request, 'experiment_import.html', kwargs)
|
|
782
|
782
|
|
|
783
|
783
|
|
|
784
|
784
|
@login_required
|
|
785
|
785
|
def experiment_start(request, id_exp):
|
|
786
|
786
|
|
|
787
|
787
|
exp = get_object_or_404(Experiment, pk=id_exp)
|
|
788
|
788
|
|
|
789
|
789
|
if exp.status == 2:
|
|
790
|
790
|
messages.warning(request, 'Experiment {} already runnnig'.format(exp))
|
|
791
|
791
|
else:
|
|
792
|
792
|
exp.status = exp.start()
|
|
793
|
793
|
if exp.status == 0:
|
|
794
|
794
|
messages.error(request, 'Experiment {} not start'.format(exp))
|
|
795
|
795
|
if exp.status == 2:
|
|
796
|
796
|
messages.success(request, 'Experiment {} started'.format(exp))
|
|
797
|
797
|
|
|
798
|
798
|
exp.save()
|
|
799
|
799
|
|
|
800
|
800
|
return redirect(exp.get_absolute_url())
|
|
801
|
801
|
|
|
802
|
802
|
|
|
803
|
803
|
@login_required
|
|
804
|
804
|
def experiment_stop(request, id_exp):
|
|
805
|
805
|
|
|
806
|
806
|
exp = get_object_or_404(Experiment, pk=id_exp)
|
|
807
|
807
|
|
|
808
|
808
|
if exp.status == 2:
|
|
809
|
809
|
exp.status = exp.stop()
|
|
810
|
810
|
exp.save()
|
|
811
|
811
|
messages.success(request, 'Experiment {} stopped'.format(exp))
|
|
812
|
812
|
else:
|
|
813
|
813
|
messages.error(request, 'Experiment {} not running'.format(exp))
|
|
814
|
814
|
|
|
815
|
815
|
return redirect(exp.get_absolute_url())
|
|
816
|
816
|
|
|
817
|
817
|
|
|
818
|
818
|
def experiment_status(request, id_exp):
|
|
819
|
819
|
|
|
820
|
820
|
exp = get_object_or_404(Experiment, pk=id_exp)
|
|
821
|
821
|
|
|
822
|
822
|
exp.get_status()
|
|
823
|
823
|
|
|
824
|
824
|
return redirect(exp.get_absolute_url())
|
|
825
|
825
|
|
|
826
|
826
|
|
|
827
|
827
|
@login_required
|
|
828
|
828
|
def experiment_mix(request, id_exp):
|
|
829
|
829
|
|
|
830
|
830
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
831
|
831
|
rc_confs = [conf for conf in RCConfiguration.objects.filter(
|
|
832
|
832
|
experiment=id_exp,
|
|
833
|
833
|
type=0,
|
|
834
|
834
|
mix=False)]
|
|
835
|
835
|
|
|
836
|
836
|
if len(rc_confs) < 2:
|
|
837
|
837
|
messages.warning(
|
|
838
|
838
|
request, 'You need at least two RC Configurations to make a mix')
|
|
839
|
839
|
return redirect(experiment.get_absolute_url())
|
|
840
|
840
|
|
|
841
|
841
|
mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True, type=0)
|
|
842
|
842
|
|
|
843
|
843
|
if mix_confs:
|
|
844
|
844
|
mix = mix_confs[0]
|
|
845
|
845
|
else:
|
|
846
|
846
|
mix = RCConfiguration(experiment=experiment,
|
|
847
|
847
|
device=rc_confs[0].device,
|
|
848
|
848
|
ipp=rc_confs[0].ipp,
|
|
849
|
849
|
clock_in=rc_confs[0].clock_in,
|
|
850
|
850
|
clock_divider=rc_confs[0].clock_divider,
|
|
851
|
851
|
mix=True,
|
|
852
|
852
|
parameters='')
|
|
853
|
853
|
mix.save()
|
|
854
|
854
|
|
|
855
|
855
|
line_type = RCLineType.objects.get(name='mix')
|
|
856
|
856
|
print("VIew obteniendo len getlines")
|
|
857
|
857
|
print(len(rc_confs[0].get_lines()))
|
|
858
|
858
|
for i in range(len(rc_confs[0].get_lines())):
|
|
859
|
859
|
line = RCLine(rc_configuration=mix, line_type=line_type, channel=i)
|
|
860
|
860
|
line.save()
|
|
861
|
861
|
|
|
862
|
862
|
initial = {'name': mix.name,
|
|
863
|
863
|
'result': parse_mix_result(mix.parameters),
|
|
864
|
864
|
'delay': 0,
|
|
865
|
865
|
'mask': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
|
|
866
|
866
|
}
|
|
867
|
867
|
|
|
868
|
868
|
if request.method == 'GET':
|
|
869
|
869
|
form = RCMixConfigurationForm(confs=rc_confs, initial=initial)
|
|
870
|
870
|
|
|
871
|
871
|
if request.method == 'POST':
|
|
872
|
872
|
result = mix.parameters
|
|
873
|
873
|
|
|
874
|
874
|
if '{}|'.format(request.POST['experiment']) in result:
|
|
875
|
875
|
messages.error(request, 'Configuration already added')
|
|
876
|
876
|
else:
|
|
877
|
877
|
if 'operation' in request.POST:
|
|
878
|
878
|
operation = MIX_OPERATIONS[request.POST['operation']]
|
|
879
|
879
|
else:
|
|
880
|
880
|
operation = ' '
|
|
881
|
881
|
|
|
882
|
882
|
mode = MIX_MODES[request.POST['mode']]
|
|
883
|
883
|
|
|
884
|
884
|
if result:
|
|
885
|
885
|
result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters,
|
|
886
|
886
|
request.POST['experiment'],
|
|
887
|
887
|
mode,
|
|
888
|
888
|
operation,
|
|
889
|
889
|
float(
|
|
890
|
890
|
request.POST['delay']),
|
|
891
|
891
|
parse_mask(
|
|
892
|
892
|
request.POST.getlist('mask'))
|
|
893
|
893
|
)
|
|
894
|
894
|
else:
|
|
895
|
895
|
result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'],
|
|
896
|
896
|
mode,
|
|
897
|
897
|
operation,
|
|
898
|
898
|
float(request.POST['delay']),
|
|
899
|
899
|
parse_mask(
|
|
900
|
900
|
request.POST.getlist('mask'))
|
|
901
|
901
|
)
|
|
902
|
902
|
|
|
903
|
903
|
mix.parameters = result
|
|
904
|
904
|
mix.save()
|
|
905
|
905
|
mix.update_pulses()
|
|
906
|
906
|
|
|
907
|
907
|
initial['result'] = parse_mix_result(result)
|
|
908
|
908
|
initial['name'] = mix.name
|
|
909
|
909
|
|
|
910
|
910
|
form = RCMixConfigurationForm(initial=initial, confs=rc_confs)
|
|
911
|
911
|
|
|
912
|
912
|
kwargs = {
|
|
913
|
913
|
'title': 'Experiment',
|
|
914
|
914
|
'suptitle': 'Mix Configurations',
|
|
915
|
915
|
'form': form,
|
|
916
|
916
|
'extra_button': 'Delete',
|
|
917
|
917
|
'button': 'Add',
|
|
918
|
918
|
'cancel': 'Back',
|
|
919
|
919
|
'previous': experiment.get_absolute_url(),
|
|
920
|
920
|
'id_exp': id_exp,
|
|
921
|
921
|
|
|
922
|
922
|
}
|
|
923
|
923
|
kwargs['menu_experiments'] = 'active'
|
|
924
|
924
|
|
|
925
|
925
|
return render(request, 'experiment_mix.html', kwargs)
|
|
926
|
926
|
|
|
927
|
927
|
|
|
928
|
928
|
@login_required
|
|
929
|
929
|
def experiment_mix_delete(request, id_exp):
|
|
930
|
930
|
|
|
931
|
931
|
conf = RCConfiguration.objects.get(experiment=id_exp, mix=True, type=0)
|
|
932
|
932
|
values = conf.parameters.split('-')
|
|
933
|
933
|
conf.parameters = '-'.join(values[:-1])
|
|
934
|
934
|
conf.save()
|
|
935
|
935
|
|
|
936
|
936
|
return redirect('url_mix_experiment', id_exp=id_exp)
|
|
937
|
937
|
|
|
938
|
938
|
|
|
939
|
939
|
def experiment_summary(request, id_exp):
|
|
940
|
940
|
|
|
941
|
941
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
942
|
942
|
configurations = Configuration.objects.filter(
|
|
943
|
943
|
experiment=experiment, type=0)
|
|
944
|
944
|
|
|
945
|
945
|
kwargs = {}
|
|
946
|
946
|
kwargs['experiment_keys'] = ['radar_system',
|
|
947
|
947
|
'name', 'freq', 'start_time', 'end_time']
|
|
948
|
948
|
kwargs['experiment'] = experiment
|
|
949
|
949
|
kwargs['configurations'] = []
|
|
950
|
950
|
kwargs['title'] = 'Experiment Summary'
|
|
951
|
951
|
kwargs['suptitle'] = 'Details'
|
|
952
|
952
|
kwargs['button'] = 'Verify Parameters'
|
|
953
|
953
|
|
|
954
|
954
|
c_vel = 3.0*(10**8) # m/s
|
|
955
|
955
|
ope_freq = experiment.freq*(10**6) # 1/s
|
|
956
|
956
|
radar_lambda = c_vel/ope_freq # m
|
|
957
|
957
|
kwargs['radar_lambda'] = radar_lambda
|
|
958
|
958
|
|
|
959
|
959
|
ipp = None
|
|
960
|
960
|
nsa = 1
|
|
961
|
961
|
code_id = 0
|
|
962
|
962
|
tx_line = {}
|
|
963
|
963
|
|
|
964
|
964
|
for configuration in configurations.filter(device__device_type__name = 'rc'):
|
|
965
|
965
|
|
|
966
|
966
|
if configuration.mix:
|
|
967
|
967
|
continue
|
|
968
|
968
|
conf = {'conf': configuration}
|
|
969
|
969
|
conf['keys'] = []
|
|
970
|
970
|
conf['NTxs'] = configuration.ntx
|
|
971
|
971
|
conf['keys'].append('NTxs')
|
|
972
|
972
|
ipp = configuration.ipp
|
|
973
|
973
|
conf['IPP'] = ipp
|
|
974
|
974
|
conf['keys'].append('IPP')
|
|
975
|
975
|
lines = configuration.get_lines(line_type__name='tx')
|
|
976
|
976
|
|
|
977
|
977
|
for tx_line in lines:
|
|
978
|
978
|
tx_params = json.loads(tx_line.params)
|
|
979
|
979
|
conf[tx_line.get_name()] = '{} Km'.format(tx_params['pulse_width'])
|
|
980
|
980
|
conf['keys'].append(tx_line.get_name())
|
|
981
|
981
|
delays = tx_params['delays']
|
|
982
|
982
|
if delays not in ('', '0'):
|
|
983
|
983
|
n = len(delays.split(','))
|
|
984
|
984
|
taus = '{} Taus: {}'.format(n, delays)
|
|
985
|
985
|
else:
|
|
986
|
986
|
taus = '-'
|
|
987
|
987
|
conf['Taus ({})'.format(tx_line.get_name())] = taus
|
|
988
|
988
|
conf['keys'].append('Taus ({})'.format(tx_line.get_name()))
|
|
989
|
989
|
for code_line in configuration.get_lines(line_type__name='codes'):
|
|
990
|
990
|
code_params = json.loads(code_line.params)
|
|
991
|
991
|
code_id = code_params['code']
|
|
992
|
992
|
if tx_line.pk == int(code_params['TX_ref']):
|
|
993
|
993
|
conf['Code ({})'.format(tx_line.get_name())] = '{}:{}'.format(RCLineCode.objects.get(pk=code_params['code']),
|
|
994
|
994
|
'-'.join(code_params['codes']))
|
|
995
|
995
|
conf['keys'].append('Code ({})'.format(tx_line.get_name()))
|
|
996
|
996
|
|
|
997
|
997
|
for windows_line in configuration.get_lines(line_type__name='windows'):
|
|
998
|
998
|
win_params = json.loads(windows_line.params)
|
|
999
|
999
|
if tx_line.pk == int(win_params['TX_ref']):
|
|
1000
|
1000
|
windows = ''
|
|
1001
|
1001
|
nsa = win_params['params'][0]['number_of_samples']
|
|
1002
|
1002
|
for i, params in enumerate(win_params['params']):
|
|
1003
|
1003
|
windows += 'W{}: Ho={first_height} km DH={resolution} km NSA={number_of_samples}<br>'.format(
|
|
1004
|
1004
|
i, **params)
|
|
1005
|
1005
|
conf['Window'] = mark_safe(windows)
|
|
1006
|
1006
|
conf['keys'].append('Window')
|
|
1007
|
1007
|
|
|
1008
|
1008
|
kwargs['configurations'].append(conf)
|
|
1009
|
1009
|
|
|
1010
|
1010
|
for configuration in configurations.filter(device__device_type__name = 'jars'):
|
|
1011
|
1011
|
|
|
1012
|
1012
|
conf = {'conf': configuration}
|
|
1013
|
1013
|
conf['keys'] = []
|
|
1014
|
1014
|
conf['Type of Data'] = EXPERIMENT_TYPE[configuration.exp_type][1]
|
|
1015
|
1015
|
conf['keys'].append('Type of Data')
|
|
1016
|
1016
|
channels_number = configuration.channels_number
|
|
1017
|
1017
|
exp_type = configuration.exp_type
|
|
1018
|
1018
|
fftpoints = configuration.fftpoints
|
|
1019
|
1019
|
filter_parms = json.loads(configuration.filter_parms)
|
|
1020
|
1020
|
spectral_number = configuration.spectral_number
|
|
1021
|
1021
|
acq_profiles = configuration.acq_profiles
|
|
1022
|
1022
|
cohe_integr = configuration.cohe_integr
|
|
1023
|
1023
|
profiles_block = configuration.profiles_block
|
|
1024
|
1024
|
|
|
1025
|
1025
|
conf['Num of Profiles'] = acq_profiles
|
|
1026
|
1026
|
conf['keys'].append('Num of Profiles')
|
|
1027
|
1027
|
|
|
1028
|
1028
|
conf['Prof per Block'] = profiles_block
|
|
1029
|
1029
|
conf['keys'].append('Prof per Block')
|
|
1030
|
1030
|
|
|
1031
|
1031
|
conf['Blocks per File'] = configuration.raw_data_blocks
|
|
1032
|
1032
|
conf['keys'].append('Blocks per File')
|
|
1033
|
1033
|
|
|
1034
|
1034
|
if exp_type == 0: # Short
|
|
1035
|
1035
|
bytes_ = 2
|
|
1036
|
1036
|
b = nsa*2*bytes_*channels_number
|
|
1037
|
1037
|
else: # Float
|
|
1038
|
1038
|
bytes_ = 4
|
|
1039
|
1039
|
channels = channels_number + spectral_number
|
|
1040
|
1040
|
b = nsa*2*bytes_*fftpoints*channels
|
|
1041
|
1041
|
|
|
1042
|
1042
|
codes_num = 7
|
|
1043
|
1043
|
if code_id == 2:
|
|
1044
|
1044
|
codes_num = 7
|
|
1045
|
1045
|
elif code_id == 12:
|
|
1046
|
1046
|
codes_num = 15
|
|
1047
|
1047
|
|
|
1048
|
1048
|
#Jars filter values:
|
|
1049
|
1049
|
|
|
1050
|
1050
|
clock = float(filter_parms['clock'])
|
|
1051
|
1051
|
filter_2 = int(filter_parms['cic_2'])
|
|
1052
|
1052
|
filter_5 = int(filter_parms['cic_5'])
|
|
1053
|
1053
|
filter_fir = int(filter_parms['fir'])
|
|
1054
|
1054
|
Fs_MHz = clock/(filter_2*filter_5*filter_fir)
|
|
1055
|
1055
|
|
|
1056
|
1056
|
#Jars values:
|
|
1057
|
1057
|
if ipp is not None:
|
|
1058
|
1058
|
IPP_units = ipp/0.15*Fs_MHz
|
|
1059
|
1059
|
IPP_us = IPP_units / Fs_MHz
|
|
1060
|
1060
|
IPP_s = IPP_units / (Fs_MHz * (10**6))
|
|
1061
|
1061
|
Ts = 1/(Fs_MHz*(10**6))
|
|
1062
|
1062
|
|
|
1063
|
1063
|
Va = radar_lambda/(4*Ts*cohe_integr)
|
|
1064
|
1064
|
rate_bh = ((nsa-codes_num)*channels_number*2 *
|
|
1065
|
1065
|
bytes_/IPP_us)*(36*(10**8)/cohe_integr)
|
|
1066
|
1066
|
rate_gh = rate_bh/(1024*1024*1024)
|
|
1067
|
1067
|
|
|
1068
|
1068
|
conf['Time per Block'] = IPP_s * profiles_block * cohe_integr
|
|
1069
|
1069
|
conf['keys'].append('Time per Block')
|
|
1070
|
1070
|
conf['Acq time'] = IPP_s * acq_profiles
|
|
1071
|
1071
|
conf['keys'].append('Acq time')
|
|
1072
|
1072
|
conf['Data rate'] = str(rate_gh)+" (GB/h)"
|
|
1073
|
1073
|
conf['keys'].append('Data rate')
|
|
1074
|
1074
|
conf['Va (m/s)'] = Va
|
|
1075
|
1075
|
conf['keys'].append('Va (m/s)')
|
|
1076
|
1076
|
conf['Vrange (m/s)'] = 3/(2*IPP_s*cohe_integr)
|
|
1077
|
1077
|
conf['keys'].append('Vrange (m/s)')
|
|
1078
|
1078
|
|
|
1079
|
1079
|
kwargs['configurations'].append(conf)
|
|
1080
|
1080
|
kwargs['menu_experiments'] = 'active'
|
|
1081
|
1081
|
|
|
1082
|
1082
|
###### SIDEBAR ######
|
|
1083
|
1083
|
kwargs.update(sidebar(experiment=experiment))
|
|
1084
|
1084
|
|
|
1085
|
1085
|
return render(request, 'experiment_summary.html', kwargs)
|
|
1086
|
1086
|
|
|
1087
|
1087
|
|
|
1088
|
1088
|
@login_required
|
|
1089
|
1089
|
def experiment_verify(request, id_exp):
|
|
1090
|
1090
|
|
|
1091
|
1091
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
1092
|
1092
|
experiment_data = experiment.parms_to_dict()
|
|
1093
|
1093
|
configurations = Configuration.objects.filter(
|
|
1094
|
1094
|
experiment=experiment, type=0)
|
|
1095
|
1095
|
|
|
1096
|
1096
|
kwargs = {}
|
|
1097
|
1097
|
|
|
1098
|
1098
|
kwargs['experiment_keys'] = ['template',
|
|
1099
|
1099
|
'radar_system', 'name', 'start_time', 'end_time']
|
|
1100
|
1100
|
kwargs['experiment'] = experiment
|
|
1101
|
1101
|
|
|
1102
|
1102
|
kwargs['configuration_keys'] = ['name', 'device__ip_address',
|
|
1103
|
1103
|
'device__port_address', 'device__status']
|
|
1104
|
1104
|
kwargs['configurations'] = configurations
|
|
1105
|
1105
|
kwargs['experiment_data'] = experiment_data
|
|
1106
|
1106
|
|
|
1107
|
1107
|
kwargs['title'] = 'Verify Experiment'
|
|
1108
|
1108
|
kwargs['suptitle'] = 'Parameters'
|
|
1109
|
1109
|
|
|
1110
|
1110
|
kwargs['button'] = 'Update'
|
|
1111
|
1111
|
|
|
1112
|
1112
|
jars_conf = False
|
|
1113
|
1113
|
rc_conf = False
|
|
1114
|
1114
|
dds_conf = False
|
|
1115
|
1115
|
|
|
1116
|
1116
|
for configuration in configurations:
|
|
1117
|
1117
|
#-------------------- JARS -----------------------:
|
|
1118
|
1118
|
if configuration.device.device_type.name == 'jars':
|
|
1119
|
1119
|
jars_conf = True
|
|
1120
|
1120
|
jars = configuration
|
|
1121
|
1121
|
kwargs['jars_conf'] = jars_conf
|
|
1122
|
1122
|
filter_parms = json.loads(jars.filter_parms)
|
|
1123
|
1123
|
kwargs['filter_parms'] = filter_parms
|
|
1124
|
1124
|
#--Sampling Frequency
|
|
1125
|
1125
|
clock = filter_parms['clock']
|
|
1126
|
1126
|
filter_2 = filter_parms['cic_2']
|
|
1127
|
1127
|
filter_5 = filter_parms['cic_5']
|
|
1128
|
1128
|
filter_fir = filter_parms['fir']
|
|
1129
|
1129
|
samp_freq_jars = clock/filter_2/filter_5/filter_fir
|
|
1130
|
1130
|
|
|
1131
|
1131
|
kwargs['samp_freq_jars'] = samp_freq_jars
|
|
1132
|
1132
|
kwargs['jars'] = configuration
|
|
1133
|
1133
|
|
|
1134
|
1134
|
#--------------------- RC ----------------------:
|
|
1135
|
1135
|
if configuration.device.device_type.name == 'rc' and not configuration.mix:
|
|
1136
|
1136
|
rc_conf = True
|
|
1137
|
1137
|
rc = configuration
|
|
1138
|
1138
|
|
|
1139
|
1139
|
rc_parms = configuration.parms_to_dict()
|
|
1140
|
1140
|
|
|
1141
|
1141
|
win_lines = rc.get_lines(line_type__name='windows')
|
|
1142
|
1142
|
if win_lines:
|
|
1143
|
1143
|
dh = json.loads(win_lines[0].params)['params'][0]['resolution']
|
|
1144
|
1144
|
#--Sampling Frequency
|
|
1145
|
1145
|
samp_freq_rc = 0.15/dh
|
|
1146
|
1146
|
kwargs['samp_freq_rc'] = samp_freq_rc
|
|
1147
|
1147
|
|
|
1148
|
1148
|
kwargs['rc_conf'] = rc_conf
|
|
1149
|
1149
|
kwargs['rc'] = configuration
|
|
1150
|
1150
|
|
|
1151
|
1151
|
#-------------------- DDS ----------------------:
|
|
1152
|
1152
|
if configuration.device.device_type.name == 'dds':
|
|
1153
|
1153
|
dds_conf = True
|
|
1154
|
1154
|
dds = configuration
|
|
1155
|
1155
|
dds_parms = configuration.parms_to_dict()
|
|
1156
|
1156
|
|
|
1157
|
1157
|
kwargs['dds_conf'] = dds_conf
|
|
1158
|
1158
|
kwargs['dds'] = configuration
|
|
1159
|
1159
|
|
|
1160
|
1160
|
#------------Validation------------:
|
|
1161
|
1161
|
#Clock
|
|
1162
|
1162
|
if dds_conf and rc_conf and jars_conf:
|
|
1163
|
1163
|
if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) and float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']):
|
|
1164
|
1164
|
messages.warning(request, "Devices don't have the same clock.")
|
|
1165
|
1165
|
elif rc_conf and jars_conf:
|
|
1166
|
1166
|
if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']):
|
|
1167
|
1167
|
messages.warning(request, "Devices don't have the same clock.")
|
|
1168
|
1168
|
elif rc_conf and dds_conf:
|
|
1169
|
1169
|
if float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']):
|
|
1170
|
1170
|
messages.warning(request, "Devices don't have the same clock.")
|
|
1171
|
1171
|
if float(samp_freq_rc) != float(dds_parms['configurations']['byId'][str(dds.pk)]['frequencyA']):
|
|
1172
|
1172
|
messages.warning(
|
|
1173
|
1173
|
request, "Devices don't have the same Frequency A.")
|
|
1174
|
1174
|
|
|
1175
|
1175
|
#------------POST METHOD------------:
|
|
1176
|
1176
|
if request.method == 'POST':
|
|
1177
|
1177
|
if request.POST['suggest_clock']:
|
|
1178
|
1178
|
try:
|
|
1179
|
1179
|
suggest_clock = float(request.POST['suggest_clock'])
|
|
1180
|
1180
|
except:
|
|
1181
|
1181
|
messages.warning(request, "Invalid value in CLOCK IN.")
|
|
1182
|
1182
|
return redirect('url_verify_experiment', id_exp=experiment.id)
|
|
1183
|
1183
|
else:
|
|
1184
|
1184
|
suggest_clock = ""
|
|
1185
|
1185
|
if suggest_clock:
|
|
1186
|
1186
|
if rc_conf:
|
|
1187
|
1187
|
rc.clock_in = suggest_clock
|
|
1188
|
1188
|
rc.save()
|
|
1189
|
1189
|
if jars_conf:
|
|
1190
|
1190
|
filter_parms = jars.filter_parms
|
|
1191
|
1191
|
filter_parms = ast.literal_eval(filter_parms)
|
|
1192
|
1192
|
filter_parms['clock'] = suggest_clock
|
|
1193
|
1193
|
jars.filter_parms = json.dumps(filter_parms)
|
|
1194
|
1194
|
jars.save()
|
|
1195
|
1195
|
kwargs['filter_parms'] = filter_parms
|
|
1196
|
1196
|
if dds_conf:
|
|
1197
|
1197
|
dds.clock = suggest_clock
|
|
1198
|
1198
|
dds.save()
|
|
1199
|
1199
|
|
|
1200
|
1200
|
if request.POST['suggest_frequencyA']:
|
|
1201
|
1201
|
try:
|
|
1202
|
1202
|
suggest_frequencyA = float(request.POST['suggest_frequencyA'])
|
|
1203
|
1203
|
except:
|
|
1204
|
1204
|
messages.warning(request, "Invalid value in FREQUENCY A.")
|
|
1205
|
1205
|
return redirect('url_verify_experiment', id_exp=experiment.id)
|
|
1206
|
1206
|
else:
|
|
1207
|
1207
|
suggest_frequencyA = ""
|
|
1208
|
1208
|
if suggest_frequencyA:
|
|
1209
|
1209
|
if jars_conf:
|
|
1210
|
1210
|
filter_parms = jars.filter_parms
|
|
1211
|
1211
|
filter_parms = ast.literal_eval(filter_parms)
|
|
1212
|
1212
|
filter_parms['fch'] = suggest_frequencyA
|
|
1213
|
1213
|
jars.filter_parms = json.dumps(filter_parms)
|
|
1214
|
1214
|
jars.save()
|
|
1215
|
1215
|
kwargs['filter_parms'] = filter_parms
|
|
1216
|
1216
|
if dds_conf:
|
|
1217
|
1217
|
dds.frequencyA_Mhz = request.POST['suggest_frequencyA']
|
|
1218
|
1218
|
dds.save()
|
|
1219
|
1219
|
|
|
1220
|
1220
|
kwargs['menu_experiments'] = 'active'
|
|
1221
|
1221
|
kwargs.update(sidebar(experiment=experiment))
|
|
1222
|
1222
|
return render(request, 'experiment_verify.html', kwargs)
|
|
1223
|
1223
|
|
|
1224
|
1224
|
|
|
1225
|
1225
|
def parse_mix_result(s):
|
|
1226
|
1226
|
|
|
1227
|
1227
|
values = s.split('-')
|
|
1228
|
1228
|
html = 'EXP MOD OPE DELAY MASK\r\n'
|
|
1229
|
1229
|
|
|
1230
|
1230
|
if not values or values[0] in ('', ' '):
|
|
1231
|
1231
|
return mark_safe(html)
|
|
1232
|
1232
|
|
|
1233
|
1233
|
for i, value in enumerate(values):
|
|
1234
|
1234
|
if not value:
|
|
1235
|
1235
|
continue
|
|
1236
|
1236
|
pk, mode, operation, delay, mask = value.split('|')
|
|
1237
|
1237
|
conf = RCConfiguration.objects.get(pk=pk)
|
|
1238
|
1238
|
if i == 0:
|
|
1239
|
1239
|
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format(
|
|
1240
|
1240
|
conf.name,
|
|
1241
|
1241
|
mode,
|
|
1242
|
1242
|
' ',
|
|
1243
|
1243
|
delay,
|
|
1244
|
1244
|
mask)
|
|
1245
|
1245
|
else:
|
|
1246
|
1246
|
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format(
|
|
1247
|
1247
|
conf.name,
|
|
1248
|
1248
|
mode,
|
|
1249
|
1249
|
operation,
|
|
1250
|
1250
|
delay,
|
|
1251
|
1251
|
mask)
|
|
1252
|
1252
|
|
|
1253
|
1253
|
return mark_safe(html)
|
|
1254
|
1254
|
|
|
1255
|
1255
|
|
|
1256
|
1256
|
def parse_mask(l):
|
|
1257
|
1257
|
|
|
1258
|
1258
|
values = []
|
|
1259
|
1259
|
|
|
1260
|
1260
|
for x in range(16):
|
|
1261
|
1261
|
if '{}'.format(x) in l:
|
|
1262
|
1262
|
values.append(1)
|
|
1263
|
1263
|
else:
|
|
1264
|
1264
|
values.append(0)
|
|
1265
|
1265
|
|
|
1266
|
1266
|
values.reverse()
|
|
1267
|
1267
|
|
|
1268
|
1268
|
return int(''.join([str(x) for x in values]), 2)
|
|
1269
|
1269
|
|
|
1270
|
1270
|
|
|
1271
|
1271
|
def dev_confs(request):
|
|
1272
|
1272
|
|
|
1273
|
1273
|
page = request.GET.get('page')
|
|
1274
|
1274
|
order = ('-programmed_date', )
|
|
1275
|
1275
|
filters = request.GET.copy()
|
|
1276
|
1276
|
if 'my configurations' in filters:
|
|
1277
|
1277
|
filters.pop('my configurations', None)
|
|
1278
|
1278
|
filters['mine'] = request.user.id
|
|
1279
|
1279
|
kwargs = get_paginator(Configuration, page, order, filters)
|
|
1280
|
1280
|
fields = ['tags', 'template', 'historical']
|
|
1281
|
1281
|
if request.user.is_authenticated:
|
|
1282
|
1282
|
fields.append('my configurations')
|
|
1283
|
1283
|
form = FilterForm(initial=request.GET, extra_fields=fields)
|
|
1284
|
1284
|
kwargs['keys'] = ['name', 'experiment',
|
|
1285
|
1285
|
'type', 'programmed_date', 'actions']
|
|
1286
|
1286
|
kwargs['title'] = 'Configuration'
|
|
1287
|
1287
|
kwargs['suptitle'] = 'List'
|
|
1288
|
1288
|
kwargs['no_sidebar'] = True
|
|
1289
|
1289
|
kwargs['form'] = form
|
|
1290
|
1290
|
kwargs['add_url'] = reverse('url_add_dev_conf', args=[0])
|
|
1291
|
1291
|
filters = request.GET.copy()
|
|
1292
|
1292
|
filters.pop('page', None)
|
|
1293
|
1293
|
kwargs['q'] = urlencode(filters)
|
|
1294
|
1294
|
kwargs['menu_configurations'] = 'active'
|
|
1295
|
1295
|
|
|
1296
|
1296
|
return render(request, 'base_list.html', kwargs)
|
|
1297
|
1297
|
|
|
1298
|
1298
|
|
|
1299
|
1299
|
def dev_conf(request, id_conf):
|
|
1300
|
1300
|
|
|
1301
|
1301
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1302
|
1302
|
|
|
1303
|
1303
|
return redirect(conf.get_absolute_url())
|
|
1304
|
1304
|
|
|
1305
|
1305
|
|
|
1306
|
1306
|
@login_required
|
|
1307
|
1307
|
def dev_conf_new(request, id_exp=0, id_dev=0):
|
|
1308
|
1308
|
|
|
1309
|
1309
|
if not is_developer(request.user):
|
|
1310
|
1310
|
messages.error(
|
|
1311
|
1311
|
request, 'Developer required, to create new configurations')
|
|
1312
|
1312
|
return redirect('index')
|
|
1313
|
1313
|
|
|
1314
|
1314
|
initial = {}
|
|
1315
|
1315
|
kwargs = {}
|
|
1316
|
1316
|
|
|
1317
|
1317
|
if id_exp != 0:
|
|
1318
|
1318
|
initial['experiment'] = id_exp
|
|
1319
|
1319
|
|
|
1320
|
1320
|
if id_dev != 0:
|
|
1321
|
1321
|
initial['device'] = id_dev
|
|
1322
|
1322
|
|
|
1323
|
1323
|
if request.method == 'GET':
|
|
1324
|
1324
|
|
|
1325
|
1325
|
if id_dev:
|
|
1326
|
1326
|
kwargs['button'] = 'Create'
|
|
1327
|
1327
|
device = Device.objects.get(pk=id_dev)
|
|
1328
|
1328
|
DevConfForm = CONF_FORMS[device.device_type.name]
|
|
1329
|
1329
|
initial['name'] = request.GET['name']
|
|
1330
|
1330
|
form = DevConfForm(initial=initial)
|
|
1331
|
1331
|
else:
|
|
1332
|
1332
|
if 'template' in request.GET:
|
|
1333
|
1333
|
if request.GET['template'] == '0':
|
|
1334
|
1334
|
choices = [(conf.pk, '{}'.format(conf))
|
|
1335
|
1335
|
for conf in Configuration.objects.filter(template=True)]
|
|
1336
|
1336
|
form = NewForm(initial={'create_from': 2},
|
|
1337
|
1337
|
template_choices=choices)
|
|
1338
|
1338
|
else:
|
|
1339
|
1339
|
kwargs['button'] = 'Create'
|
|
1340
|
1340
|
conf = Configuration.objects.get(
|
|
1341
|
1341
|
pk=request.GET['template'])
|
|
1342
|
1342
|
id_dev = conf.device.pk
|
|
1343
|
1343
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1344
|
1344
|
form = DevConfForm(instance=conf,
|
|
1345
|
1345
|
initial={'name': '{}_{:%y%m%d}'.format(conf.name, datetime.now()),
|
|
1346
|
1346
|
'template': False,
|
|
1347
|
1347
|
'experiment': id_exp})
|
|
1348
|
1348
|
elif 'blank' in request.GET:
|
|
1349
|
1349
|
kwargs['button'] = 'Create'
|
|
1350
|
1350
|
form = ConfigurationForm(initial=initial)
|
|
1351
|
1351
|
else:
|
|
1352
|
1352
|
form = NewForm()
|
|
1353
|
1353
|
|
|
1354
|
1354
|
if request.method == 'POST':
|
|
1355
|
1355
|
|
|
1356
|
1356
|
device = Device.objects.get(pk=request.POST['device'])
|
|
1357
|
1357
|
DevConfForm = CONF_FORMS[device.device_type.name]
|
|
1358
|
1358
|
|
|
1359
|
1359
|
form = DevConfForm(request.POST)
|
|
1360
|
1360
|
kwargs['button'] = 'Create'
|
|
1361
|
1361
|
if form.is_valid():
|
|
1362
|
1362
|
conf = form.save(commit=False)
|
|
1363
|
1363
|
conf.author = request.user
|
|
1364
|
1364
|
conf.save()
|
|
1365
|
1365
|
|
|
1366
|
1366
|
if 'template' in request.GET and conf.device.device_type.name == 'rc':
|
|
1367
|
1367
|
lines = RCLine.objects.filter(
|
|
1368
|
1368
|
rc_configuration=request.GET['template'])
|
|
1369
|
1369
|
for line in lines:
|
|
1370
|
1370
|
line.clone(rc_configuration=conf)
|
|
1371
|
1371
|
|
|
1372
|
1372
|
new_lines = conf.get_lines()
|
|
1373
|
1373
|
for line in new_lines:
|
|
1374
|
1374
|
line_params = json.loads(line.params)
|
|
1375
|
1375
|
if 'TX_ref' in line_params:
|
|
1376
|
1376
|
ref_line = RCLine.objects.get(pk=line_params['TX_ref'])
|
|
1377
|
1377
|
line_params['TX_ref'] = ['{}'.format(
|
|
1378
|
1378
|
l.pk) for l in new_lines if l.get_name() == ref_line.get_name()][0]
|
|
1379
|
1379
|
line.params = json.dumps(line_params)
|
|
1380
|
1380
|
line.save()
|
|
1381
|
1381
|
elif conf.device.device_type.name == 'rc':
|
|
1382
|
1382
|
clk = RCClock(rc_configuration=conf)
|
|
1383
|
1383
|
clk.save()
|
|
1384
|
1384
|
|
|
1385
|
1385
|
return redirect('url_dev_conf', id_conf=conf.pk)
|
|
1386
|
1386
|
|
|
1387
|
1387
|
kwargs['id_exp'] = id_exp
|
|
1388
|
1388
|
kwargs['form'] = form
|
|
1389
|
1389
|
kwargs['title'] = 'Configuration'
|
|
1390
|
1390
|
kwargs['suptitle'] = 'New'
|
|
1391
|
1391
|
kwargs['menu_configurations'] = 'active'
|
|
1392
|
1392
|
|
|
1393
|
1393
|
if id_dev != 0:
|
|
1394
|
1394
|
device = Device.objects.get(pk=id_dev)
|
|
1395
|
1395
|
kwargs['device'] = device.device_type.name
|
|
1396
|
1396
|
print(id_exp)
|
|
1397
|
1397
|
return render(request, 'dev_conf_edit.html', kwargs)
|
|
1398
|
1398
|
|
|
1399
|
1399
|
|
|
1400
|
1400
|
@login_required
|
|
1401
|
1401
|
def dev_conf_edit(request, id_conf):
|
|
1402
|
1402
|
|
|
1403
|
1403
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1404
|
1404
|
|
|
1405
|
1405
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1406
|
1406
|
|
|
1407
|
1407
|
if request.method == 'GET':
|
|
1408
|
1408
|
form = DevConfForm(instance=conf)
|
|
1409
|
1409
|
|
|
1410
|
1410
|
if request.method == 'POST':
|
|
1411
|
1411
|
form = DevConfForm(request.POST, instance=conf)
|
|
1412
|
1412
|
|
|
1413
|
1413
|
if form.is_valid():
|
|
1414
|
1414
|
form.save()
|
|
1415
|
1415
|
return redirect('url_dev_conf', id_conf=id_conf)
|
|
1416
|
1416
|
|
|
1417
|
1417
|
kwargs = {}
|
|
1418
|
1418
|
kwargs['form'] = form
|
|
1419
|
1419
|
kwargs['title'] = 'Device Configuration'
|
|
1420
|
1420
|
kwargs['suptitle'] = 'Edit'
|
|
1421
|
1421
|
kwargs['button'] = 'Update'
|
|
1422
|
1422
|
kwargs['menu_configurations'] = 'active'
|
|
1423
|
1423
|
|
|
1424
|
1424
|
###### SIDEBAR ######
|
|
1425
|
1425
|
kwargs.update(sidebar(conf=conf))
|
|
1426
|
1426
|
|
|
1427
|
1427
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
1428
|
1428
|
|
|
1429
|
1429
|
|
|
1430
|
1430
|
@login_required
|
|
1431
|
1431
|
def dev_conf_start(request, id_conf):
|
|
1432
|
1432
|
|
|
1433
|
1433
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1434
|
1434
|
|
|
1435
|
1435
|
if conf.start_device():
|
|
1436
|
1436
|
messages.success(request, conf.message)
|
|
1437
|
1437
|
else:
|
|
1438
|
1438
|
messages.error(request, conf.message)
|
|
1439
|
1439
|
|
|
1440
|
1440
|
#conf.status_device()
|
|
1441
|
1441
|
|
|
1442
|
1442
|
return redirect(conf.get_absolute_url())
|
|
1443
|
1443
|
|
|
1444
|
1444
|
|
|
1445
|
1445
|
@login_required
|
|
1446
|
1446
|
def dev_conf_stop(request, id_conf):
|
|
1447
|
1447
|
|
|
1448
|
1448
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1449
|
1449
|
|
|
1450
|
1450
|
if conf.stop_device():
|
|
1451
|
1451
|
messages.success(request, conf.message)
|
|
1452
|
1452
|
else:
|
|
1453
|
1453
|
messages.error(request, conf.message)
|
|
1454
|
1454
|
|
|
1455
|
1455
|
#conf.status_device()
|
|
1456
|
1456
|
|
|
1457
|
1457
|
return redirect(conf.get_absolute_url())
|
|
1458
|
1458
|
|
|
1459
|
1459
|
|
|
1460
|
1460
|
@login_required
|
|
1461
|
1461
|
def dev_conf_status(request, id_conf):
|
|
1462
|
1462
|
|
|
1463
|
1463
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1464
|
1464
|
|
|
1465
|
1465
|
conf_active = Configuration.objects.filter(pk=conf.device.conf_active).first()
|
|
1466
|
1466
|
if conf_active!=conf:
|
|
1467
|
1467
|
url = '#' if conf_active is None else conf_active.get_absolute_url()
|
|
1468
|
1468
|
label = 'None' if conf_active is None else conf_active.label
|
|
1469
|
1469
|
messages.warning(
|
|
1470
|
1470
|
request,
|
|
1471
|
1471
|
mark_safe('The current configuration has not been written to device, the active configuration is <a href="{}">{}</a>'.format(
|
|
1472
|
1472
|
url,
|
|
1473
|
1473
|
label
|
|
1474
|
1474
|
))
|
|
1475
|
1475
|
)
|
|
1476
|
1476
|
|
|
1477
|
1477
|
return redirect(conf.get_absolute_url())
|
|
1478
|
1478
|
|
|
1479
|
1479
|
if conf.status_device():
|
|
1480
|
1480
|
messages.success(request, conf.message)
|
|
1481
|
1481
|
else:
|
|
1482
|
1482
|
messages.error(request, conf.message)
|
|
1483
|
1483
|
|
|
1484
|
1484
|
return redirect(conf.get_absolute_url())
|
|
1485
|
1485
|
|
|
1486
|
1486
|
|
|
1487
|
1487
|
@login_required
|
|
1488
|
1488
|
def dev_conf_reset(request, id_conf):
|
|
1489
|
1489
|
|
|
1490
|
1490
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1491
|
1491
|
|
|
1492
|
1492
|
if conf.reset_device():
|
|
1493
|
1493
|
messages.success(request, conf.message)
|
|
1494
|
1494
|
else:
|
|
1495
|
1495
|
messages.error(request, conf.message)
|
|
1496
|
1496
|
|
|
1497
|
1497
|
return redirect(conf.get_absolute_url())
|
|
1498
|
1498
|
|
|
1499
|
1499
|
|
|
1500
|
1500
|
@login_required
|
|
1501
|
1501
|
def dev_conf_write(request, id_conf):
|
|
1502
|
1502
|
|
|
1503
|
1503
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1504
|
1504
|
|
|
1505
|
1505
|
if request.method == 'POST':
|
|
1506
|
1506
|
if conf.write_device():
|
|
1507
|
1507
|
conf.device.conf_active = conf.pk
|
|
1508
|
1508
|
conf.device.save()
|
|
1509
|
1509
|
messages.success(request, conf.message)
|
|
1510
|
1510
|
if has_been_modified(conf):
|
|
1511
|
1511
|
conf.clone(type=1, template=False)
|
|
1512
|
1512
|
else:
|
|
1513
|
1513
|
messages.error(request, conf.message)
|
|
1514
|
1514
|
|
|
1515
|
1515
|
return redirect(get_object_or_404(Configuration, pk=id_conf).get_absolute_url())
|
|
1516
|
1516
|
|
|
1517
|
1517
|
kwargs = {
|
|
1518
|
1518
|
'title': 'Write Configuration',
|
|
1519
|
1519
|
'suptitle': conf.label,
|
|
1520
|
1520
|
'message': 'Are you sure yo want to write this {} configuration?'.format(conf.device),
|
|
1521
|
1521
|
'delete': False
|
|
1522
|
1522
|
}
|
|
1523
|
1523
|
kwargs['menu_configurations'] = 'active'
|
|
1524
|
1524
|
|
|
1525
|
1525
|
return render(request, 'confirm.html', kwargs)
|
|
1526
|
1526
|
|
|
1527
|
1527
|
|
|
1528
|
1528
|
@login_required
|
|
1529
|
1529
|
def dev_conf_read(request, id_conf):
|
|
1530
|
1530
|
|
|
1531
|
1531
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1532
|
1532
|
|
|
1533
|
1533
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1534
|
1534
|
|
|
1535
|
1535
|
if request.method == 'GET':
|
|
1536
|
1536
|
|
|
1537
|
1537
|
parms = conf.read_device()
|
|
1538
|
1538
|
#conf.status_device()
|
|
1539
|
1539
|
|
|
1540
|
1540
|
if not parms:
|
|
1541
|
1541
|
messages.error(request, conf.message)
|
|
1542
|
1542
|
return redirect(conf.get_absolute_url())
|
|
1543
|
1543
|
|
|
1544
|
1544
|
form = DevConfForm(initial=parms, instance=conf)
|
|
1545
|
1545
|
|
|
1546
|
1546
|
if request.method == 'POST':
|
|
1547
|
1547
|
form = DevConfForm(request.POST, instance=conf)
|
|
1548
|
1548
|
|
|
1549
|
1549
|
if form.is_valid():
|
|
1550
|
1550
|
form.save()
|
|
1551
|
1551
|
return redirect(conf.get_absolute_url())
|
|
1552
|
1552
|
|
|
1553
|
1553
|
messages.error(request, "Parameters could not be saved")
|
|
1554
|
1554
|
|
|
1555
|
1555
|
kwargs = {}
|
|
1556
|
1556
|
kwargs['id_dev'] = conf.id
|
|
1557
|
1557
|
kwargs['form'] = form
|
|
1558
|
1558
|
kwargs['title'] = 'Device Configuration'
|
|
1559
|
1559
|
kwargs['suptitle'] = 'Parameters read from device'
|
|
1560
|
1560
|
kwargs['button'] = 'Save'
|
|
1561
|
1561
|
|
|
1562
|
1562
|
###### SIDEBAR ######
|
|
1563
|
1563
|
kwargs.update(sidebar(conf=conf))
|
|
1564
|
1564
|
|
|
1565
|
1565
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
1566
|
1566
|
|
|
1567
|
1567
|
|
|
1568
|
1568
|
@login_required
|
|
1569
|
1569
|
def dev_conf_import(request, id_conf):
|
|
1570
|
1570
|
|
|
1571
|
1571
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1572
|
1572
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1573
|
1573
|
|
|
1574
|
1574
|
if request.method == 'GET':
|
|
1575
|
1575
|
file_form = UploadFileForm()
|
|
1576
|
1576
|
|
|
1577
|
1577
|
if request.method == 'POST':
|
|
1578
|
1578
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
1579
|
1579
|
|
|
1580
|
1580
|
if file_form.is_valid():
|
|
1581
|
1581
|
|
|
1582
|
1582
|
data = conf.import_from_file(request.FILES['file'])
|
|
1583
|
1583
|
parms = Params(data=data).get_conf(
|
|
1584
|
1584
|
dtype=conf.device.device_type.name)
|
|
1585
|
1585
|
|
|
1586
|
1586
|
if parms:
|
|
1587
|
1587
|
|
|
1588
|
1588
|
form = DevConfForm(initial=parms, instance=conf)
|
|
1589
|
1589
|
|
|
1590
|
1590
|
kwargs = {}
|
|
1591
|
1591
|
kwargs['id_dev'] = conf.id
|
|
1592
|
1592
|
kwargs['form'] = form
|
|
1593
|
1593
|
kwargs['title'] = 'Device Configuration'
|
|
1594
|
1594
|
kwargs['suptitle'] = 'Parameters imported'
|
|
1595
|
1595
|
kwargs['button'] = 'Save'
|
|
1596
|
1596
|
kwargs['action'] = conf.get_absolute_url_edit()
|
|
1597
|
1597
|
kwargs['previous'] = conf.get_absolute_url()
|
|
1598
|
1598
|
|
|
1599
|
1599
|
###### SIDEBAR ######
|
|
1600
|
1600
|
kwargs.update(sidebar(conf=conf))
|
|
1601
|
1601
|
|
|
1602
|
1602
|
messages.success(
|
|
1603
|
1603
|
request, "Parameters imported from: '%s'." % request.FILES['file'].name)
|
|
1604
|
1604
|
|
|
1605
|
1605
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
1606
|
1606
|
|
|
1607
|
1607
|
messages.error(request, "Could not import parameters from file")
|
|
1608
|
1608
|
|
|
1609
|
1609
|
kwargs = {}
|
|
1610
|
1610
|
kwargs['id_dev'] = conf.id
|
|
1611
|
1611
|
kwargs['title'] = 'Device Configuration'
|
|
1612
|
1612
|
kwargs['form'] = file_form
|
|
1613
|
1613
|
kwargs['suptitle'] = 'Importing file'
|
|
1614
|
1614
|
kwargs['button'] = 'Import'
|
|
1615
|
1615
|
kwargs['menu_configurations'] = 'active'
|
|
1616
|
1616
|
|
|
1617
|
1617
|
kwargs.update(sidebar(conf=conf))
|
|
1618
|
1618
|
|
|
1619
|
1619
|
return render(request, 'dev_conf_import.html', kwargs)
|
|
1620
|
1620
|
|
|
1621
|
1621
|
|
|
1622
|
1622
|
@login_required
|
|
1623
|
1623
|
def dev_conf_export(request, id_conf):
|
|
1624
|
1624
|
|
|
1625
|
1625
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1626
|
1626
|
|
|
1627
|
1627
|
if request.method == 'GET':
|
|
1628
|
1628
|
file_form = DownloadFileForm(conf.device.device_type.name)
|
|
1629
|
1629
|
|
|
1630
|
1630
|
if request.method == 'POST':
|
|
1631
|
1631
|
file_form = DownloadFileForm(
|
|
1632
|
1632
|
conf.device.device_type.name, request.POST)
|
|
1633
|
1633
|
|
|
1634
|
1634
|
if file_form.is_valid():
|
|
1635
|
1635
|
fields = conf.export_to_file(
|
|
1636
|
1636
|
format=file_form.cleaned_data['format'])
|
|
1637
|
1637
|
if not fields['content']:
|
|
1638
|
1638
|
messages.error(request, conf.message)
|
|
1639
|
1639
|
return redirect(conf.get_absolute_url_export())
|
|
1640
|
1640
|
response = HttpResponse(content_type=fields['content_type'])
|
|
1641
|
1641
|
response['Content-Disposition'] = 'attachment; filename="%s"' % fields['filename']
|
|
1642
|
1642
|
response.write(fields['content'])
|
|
1643
|
1643
|
|
|
1644
|
1644
|
return response
|
|
1645
|
1645
|
|
|
1646
|
1646
|
messages.error(request, "Could not export parameters")
|
|
1647
|
1647
|
|
|
1648
|
1648
|
kwargs = {}
|
|
1649
|
1649
|
kwargs['id_dev'] = conf.id
|
|
1650
|
1650
|
kwargs['title'] = 'Device Configuration'
|
|
1651
|
1651
|
kwargs['form'] = file_form
|
|
1652
|
1652
|
kwargs['suptitle'] = 'Exporting file'
|
|
1653
|
1653
|
kwargs['button'] = 'Export'
|
|
1654
|
1654
|
kwargs['menu_configurations'] = 'active'
|
|
1655
|
1655
|
|
|
1656
|
1656
|
return render(request, 'dev_conf_export.html', kwargs)
|
|
1657
|
1657
|
|
|
1658
|
1658
|
|
|
1659
|
1659
|
@login_required
|
|
1660
|
1660
|
def dev_conf_delete(request, id_conf):
|
|
1661
|
1661
|
|
|
1662
|
1662
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1663
|
1663
|
|
|
1664
|
1664
|
if request.method == 'POST':
|
|
1665
|
1665
|
if is_developer(request.user):
|
|
1666
|
1666
|
conf.delete()
|
|
1667
|
1667
|
return redirect('url_dev_confs')
|
|
1668
|
1668
|
|
|
1669
|
1669
|
messages.error(request, 'Not enough permission to delete this object')
|
|
1670
|
1670
|
return redirect(conf.get_absolute_url())
|
|
1671
|
1671
|
|
|
1672
|
1672
|
kwargs = {
|
|
1673
|
1673
|
'title': 'Delete',
|
|
1674
|
1674
|
'suptitle': 'Configuration',
|
|
1675
|
1675
|
'object': conf,
|
|
1676
|
1676
|
'delete': True
|
|
1677
|
1677
|
}
|
|
1678
|
1678
|
kwargs['menu_configurations'] = 'active'
|
|
1679
|
1679
|
|
|
1680
|
1680
|
return render(request, 'confirm.html', kwargs)
|
|
1681
|
1681
|
|
|
1682
|
1682
|
|
|
1683
|
1683
|
def sidebar(**kwargs):
|
|
1684
|
1684
|
|
|
1685
|
1685
|
side_data = {}
|
|
1686
|
1686
|
|
|
1687
|
1687
|
conf = kwargs.get('conf', None)
|
|
1688
|
1688
|
experiment = kwargs.get('experiment', None)
|
|
1689
|
1689
|
|
|
1690
|
1690
|
if not experiment:
|
|
1691
|
1691
|
experiment = conf.experiment
|
|
1692
|
1692
|
|
|
1693
|
1693
|
if experiment:
|
|
1694
|
1694
|
side_data['experiment'] = experiment
|
|
1695
|
1695
|
campaign = experiment.campaign_set.all()
|
|
1696
|
1696
|
if campaign:
|
|
1697
|
1697
|
side_data['campaign'] = campaign[0]
|
|
1698
|
1698
|
experiments = campaign[0].experiments.all().order_by('name')
|
|
1699
|
1699
|
else:
|
|
1700
|
1700
|
experiments = [experiment]
|
|
1701
|
1701
|
configurations = experiment.configuration_set.filter(type=0)
|
|
1702
|
1702
|
side_data['side_experiments'] = experiments
|
|
1703
|
1703
|
side_data['side_configurations'] = configurations.order_by(
|
|
1704
|
1704
|
'device__device_type__name')
|
|
1705
|
1705
|
|
|
1706
|
1706
|
return side_data
|
|
1707
|
1707
|
|
|
1708
|
|
|
|
1709
|
1708
|
def get_paginator(model, page, order, filters={}, n=8):
|
|
1710
|
|
|
|
1711
|
1709
|
kwargs = {}
|
|
1712
|
1710
|
query = Q()
|
|
1713
|
1711
|
if isinstance(filters, QueryDict):
|
|
1714
|
1712
|
filters = filters.dict()
|
|
1715
|
|
[filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')]
|
|
|
1713
|
copy_filters=filters.copy()
|
|
|
1714
|
[filters.pop(key) for key in copy_filters.keys() if copy_filters[key] in (' ', ' ')]
|
|
1716
|
1715
|
filters.pop('page', None)
|
|
1717
|
1716
|
|
|
1718
|
1717
|
fields = [f.name for f in model._meta.get_fields()]
|
|
1719
|
1718
|
|
|
1720
|
|
if 'template' in filters:
|
|
|
1719
|
if 'template' in copy_filters:
|
|
1721
|
1720
|
filters['template'] = True
|
|
1722
|
|
if 'historical' in filters:
|
|
|
1721
|
if 'historical' in copy_filters:
|
|
1723
|
1722
|
filters.pop('historical')
|
|
1724
|
1723
|
filters['type'] = 1
|
|
1725
|
1724
|
elif 'type' in fields:
|
|
1726
|
|
filters['type'] = 0
|
|
1727
|
|
if 'start_date' in filters:
|
|
1728
|
|
filters['start_date__gte'] = filters.pop('start_date')
|
|
1729
|
|
if 'end_date' in filters:
|
|
1730
|
|
filters['start_date__lte'] = filters.pop('end_date')
|
|
1731
|
|
if 'tags' in filters:
|
|
1732
|
|
tags = filters.pop('tags')
|
|
|
1725
|
filters['type'] = 0
|
|
|
1726
|
if 'start_date' in copy_filters:
|
|
|
1727
|
filters['start_date__gte'] =filters.pop('start_date')
|
|
|
1728
|
if 'end_date' in copy_filters:
|
|
|
1729
|
filters['start_date__lte'] =filters.pop('end_date')
|
|
|
1730
|
if 'tags' in copy_filters:
|
|
|
1731
|
tags =filters.pop('tags')
|
|
1733
|
1732
|
if 'tags' in fields:
|
|
1734
|
1733
|
query = query | Q(tags__icontains=tags)
|
|
1735
|
1734
|
if 'label' in fields:
|
|
1736
|
1735
|
query = query | Q(label__icontains=tags)
|
|
1737
|
1736
|
if 'location' in fields:
|
|
1738
|
1737
|
query = query | Q(location__name__icontains=tags)
|
|
1739
|
1738
|
if 'device' in fields:
|
|
1740
|
1739
|
query = query | Q(device__device_type__name__icontains=tags)
|
|
1741
|
1740
|
query = query | Q(device__location__name__icontains=tags)
|
|
1742
|
1741
|
if 'device_type' in fields:
|
|
1743
|
1742
|
query = query | Q(device_type__name__icontains=tags)
|
|
1744
|
1743
|
|
|
1745
|
|
if 'mine' in filters:
|
|
1746
|
|
filters['author_id'] = filters['mine']
|
|
1747
|
|
filters.pop('mine')
|
|
|
1744
|
if 'mine' in copy_filters:
|
|
|
1745
|
filters['author_id'] =filters['mine']
|
|
|
1746
|
filters.pop('mine')
|
|
1748
|
1747
|
object_list = model.objects.filter(query, **filters).order_by(*order)
|
|
1749
|
1748
|
paginator = Paginator(object_list, n)
|
|
1750
|
1749
|
|
|
1751
|
1750
|
try:
|
|
1752
|
1751
|
objects = paginator.page(page)
|
|
1753
|
1752
|
except PageNotAnInteger:
|
|
1754
|
1753
|
objects = paginator.page(1)
|
|
1755
|
1754
|
except EmptyPage:
|
|
1756
|
1755
|
objects = paginator.page(paginator.num_pages)
|
|
1757
|
1756
|
|
|
1758
|
1757
|
kwargs['objects'] = objects
|
|
1759
|
1758
|
kwargs['offset'] = (int(page)-1)*n if page else 0
|
|
1760
|
1759
|
|
|
1761
|
1760
|
return kwargs
|
|
1762
|
1761
|
|
|
|
1762
|
# def get_paginator(model, page, order, filters={}, n=8):
|
|
|
1763
|
# kwargs = {}
|
|
|
1764
|
# query = Q()
|
|
|
1765
|
# if isinstance(filters, QueryDict):
|
|
|
1766
|
# filters = filters.dict()
|
|
|
1767
|
# [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')]
|
|
|
1768
|
# filters.pop('page', None)
|
|
|
1769
|
|
|
|
1770
|
# fields = [f.name for f in model._meta.get_fields()]
|
|
|
1771
|
|
|
|
1772
|
# if 'template' in filters:
|
|
|
1773
|
# filters['template'] = True
|
|
|
1774
|
# if 'historical' in filters:
|
|
|
1775
|
# filters.pop('historical')
|
|
|
1776
|
# filters['type'] = 1
|
|
|
1777
|
# elif 'type' in fields:
|
|
|
1778
|
# filters['type'] = 0
|
|
|
1779
|
# if 'start_date' in filters:
|
|
|
1780
|
# filters['start_date__gte'] = filters.pop('start_date')
|
|
|
1781
|
# if 'end_date' in filters:
|
|
|
1782
|
# filters['start_date__lte'] = filters.pop('end_date')
|
|
|
1783
|
# if 'tags' in filters:
|
|
|
1784
|
# tags = filters.pop('tags')
|
|
|
1785
|
# if 'tags' in fields:
|
|
|
1786
|
# query = query | Q(tags__icontains=tags)
|
|
|
1787
|
# if 'label' in fields:
|
|
|
1788
|
# query = query | Q(label__icontains=tags)
|
|
|
1789
|
# if 'location' in fields:
|
|
|
1790
|
# query = query | Q(location__name__icontains=tags)
|
|
|
1791
|
# if 'device' in fields:
|
|
|
1792
|
# query = query | Q(device__device_type__name__icontains=tags)
|
|
|
1793
|
# query = query | Q(device__location__name__icontains=tags)
|
|
|
1794
|
# if 'device_type' in fields:
|
|
|
1795
|
# query = query | Q(device_type__name__icontains=tags)
|
|
|
1796
|
|
|
|
1797
|
# if 'mine' in filters:
|
|
|
1798
|
# filters['author_id'] = filters['mine']
|
|
|
1799
|
# filters.pop('mine')
|
|
|
1800
|
# object_list = model.objects.filter(query, **filters).order_by(*order)
|
|
|
1801
|
# paginator = Paginator(object_list, n)
|
|
|
1802
|
|
|
|
1803
|
# try:
|
|
|
1804
|
# objects = paginator.page(page)
|
|
|
1805
|
# except PageNotAnInteger:
|
|
|
1806
|
# objects = paginator.page(1)
|
|
|
1807
|
# except EmptyPage:
|
|
|
1808
|
# objects = paginator.page(paginator.num_pages)
|
|
|
1809
|
|
|
|
1810
|
# kwargs['objects'] = objects
|
|
|
1811
|
# kwargs['offset'] = (int(page)-1)*n if page else 0
|
|
|
1812
|
|
|
|
1813
|
# return kwargs
|
|
|
1814
|
|
|
1763
|
1815
|
|
|
1764
|
1816
|
def operation(request, id_camp=None):
|
|
1765
|
1817
|
|
|
1766
|
1818
|
kwargs = {}
|
|
1767
|
1819
|
kwargs['title'] = 'Radars Operation'
|
|
1768
|
1820
|
kwargs['no_sidebar'] = True
|
|
1769
|
1821
|
kwargs['menu_operation'] = 'active'
|
|
1770
|
1822
|
campaigns = Campaign.objects.filter(start_date__lte=datetime.now(),
|
|
1771
|
1823
|
end_date__gte=datetime.now()).order_by('-start_date')
|
|
1772
|
1824
|
|
|
1773
|
1825
|
if id_camp:
|
|
1774
|
1826
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
1775
|
1827
|
form = OperationForm(
|
|
1776
|
1828
|
initial={'campaign': campaign.id}, campaigns=campaigns)
|
|
1777
|
1829
|
kwargs['campaign'] = campaign
|
|
1778
|
1830
|
else:
|
|
1779
|
1831
|
# form = OperationForm(campaigns=campaigns)
|
|
1780
|
1832
|
kwargs['campaigns'] = campaigns
|
|
1781
|
1833
|
return render(request, 'operation.html', kwargs)
|
|
1782
|
1834
|
|
|
1783
|
1835
|
#---Experiment
|
|
1784
|
1836
|
keys = ['id', 'name', 'start_time', 'end_time', 'status']
|
|
1785
|
1837
|
kwargs['experiment_keys'] = keys[1:]
|
|
1786
|
1838
|
kwargs['experiments'] = experiments
|
|
1787
|
1839
|
#---Radar
|
|
1788
|
1840
|
kwargs['locations'] = campaign.get_experiments_by_radar()
|
|
1789
|
1841
|
kwargs['form'] = form
|
|
1790
|
1842
|
|
|
1791
|
1843
|
return render(request, 'operation.html', kwargs)
|
|
1792
|
1844
|
|
|
1793
|
1845
|
|
|
1794
|
1846
|
@login_required
|
|
1795
|
1847
|
def radar_start(request, id_camp, id_radar):
|
|
1796
|
1848
|
|
|
1797
|
1849
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
1798
|
1850
|
experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
|
|
1799
|
1851
|
now = datetime.now()
|
|
1800
|
1852
|
|
|
1801
|
1853
|
for exp in experiments:
|
|
1802
|
1854
|
#app.control.revoke(exp.task)
|
|
1803
|
1855
|
print("----------------------")
|
|
1804
|
1856
|
print("status:->", exp.status)
|
|
1805
|
1857
|
start = datetime.combine(datetime.now().date(), exp.start_time)
|
|
1806
|
1858
|
end = datetime.combine(datetime.now().date(), exp.end_time)
|
|
1807
|
1859
|
print("start exp: ",exp.start_time)
|
|
1808
|
1860
|
print("end exp: ",exp.end_time)
|
|
1809
|
1861
|
|
|
1810
|
1862
|
print("start comb: ",start)
|
|
1811
|
1863
|
print("end comb: ",end)
|
|
1812
|
1864
|
print(is_aware(start))
|
|
1813
|
1865
|
print("start camp",campaign.start_date)
|
|
1814
|
1866
|
print("end camp",campaign.end_date)
|
|
1815
|
1867
|
print(is_aware(campaign.start_date))
|
|
1816
|
1868
|
if end < start:
|
|
1817
|
1869
|
end += timedelta(1)
|
|
1818
|
1870
|
|
|
1819
|
1871
|
if exp.status == 2:
|
|
1820
|
1872
|
messages.warning(
|
|
1821
|
1873
|
request, 'Experiment {} already running'.format(exp))
|
|
1822
|
1874
|
#continue
|
|
1823
|
1875
|
|
|
1824
|
1876
|
if exp.status == 3:
|
|
1825
|
1877
|
messages.warning(
|
|
1826
|
1878
|
request, 'Experiment {} already programmed'.format(exp))
|
|
1827
|
1879
|
#continue
|
|
1828
|
1880
|
|
|
1829
|
1881
|
if exp.status == 1:
|
|
1830
|
1882
|
messages.warning(
|
|
1831
|
1883
|
request, 'Experiment {} stopped'.format(exp))
|
|
1832
|
1884
|
#continue
|
|
1833
|
1885
|
|
|
1834
|
1886
|
if start > campaign.end_date:
|
|
1835
|
1887
|
messages.warning(
|
|
1836
|
1888
|
request, 'Experiment {} out of date'.format(exp))
|
|
1837
|
1889
|
|
|
1838
|
1890
|
#app.control.revoke(exp.task)
|
|
1839
|
1891
|
print("Llego luego del revoke")
|
|
1840
|
1892
|
if now >= start and now <= end:
|
|
1841
|
1893
|
|
|
1842
|
1894
|
print("Caso now > start and < end -- (1)")
|
|
1843
|
1895
|
|
|
1844
|
1896
|
# -------------------------------------------
|
|
1845
|
1897
|
|
|
1846
|
1898
|
# task = task_start.delay(exp.id)
|
|
1847
|
1899
|
# exp.task = task.id
|
|
1848
|
1900
|
# exp.status = task.get()
|
|
1849
|
1901
|
# -------------------------------------------
|
|
1850
|
1902
|
|
|
1851
|
1903
|
#exp.status = task.wait()
|
|
1852
|
1904
|
|
|
1853
|
1905
|
if exp.status == 0:
|
|
1854
|
1906
|
messages.error(request, 'Experiment {} not start'.format(exp))
|
|
1855
|
1907
|
if exp.status == 2:
|
|
1856
|
1908
|
messages.success(request, 'Experiment {} started'.format(exp))
|
|
1857
|
1909
|
elif now < start:
|
|
1858
|
1910
|
print("Caso now <= start -- (2)",exp.pk)
|
|
1859
|
1911
|
#task = task_start.apply_async((exp.pk, ), eta=start)#start+timedelta(hours=5))
|
|
1860
|
1912
|
# task = task_start.apply_async((exp.pk, ), eta=start+timedelta(hours=5))#)
|
|
1861
|
1913
|
# exp.task = task.id
|
|
1862
|
1914
|
# exp.status = 3
|
|
1863
|
1915
|
messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start))
|
|
1864
|
1916
|
else:
|
|
1865
|
1917
|
print("Caso now > end -- (3)")
|
|
1866
|
1918
|
exp.status = 4
|
|
1867
|
1919
|
messages.warning(
|
|
1868
|
1920
|
request, 'Experiment {} out of date'.format(exp))
|
|
1869
|
1921
|
|
|
1870
|
1922
|
exp.save()
|
|
1871
|
1923
|
|
|
1872
|
1924
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1873
|
1925
|
|
|
1874
|
1926
|
|
|
1875
|
1927
|
@login_required
|
|
1876
|
1928
|
def radar_stop(request, id_camp, id_radar):
|
|
1877
|
1929
|
|
|
1878
|
1930
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
1879
|
1931
|
experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
|
|
1880
|
1932
|
print("Ingreso en stop radar_stop")
|
|
1881
|
1933
|
#for exp in experiments:
|
|
1882
|
1934
|
|
|
1883
|
1935
|
# if exp.task:
|
|
1884
|
1936
|
# print("Ingreso antes de revoke stop")
|
|
1885
|
1937
|
# app.control.revoke(exp.task)
|
|
1886
|
1938
|
|
|
1887
|
1939
|
|
|
1888
|
1940
|
# if exp.status == 2: #status 2 es started
|
|
1889
|
1941
|
# print("llama a exp.stop")
|
|
1890
|
1942
|
# exp.stop()
|
|
1891
|
1943
|
# messages.warning(request, 'Experiment {} stopped'.format(exp))
|
|
1892
|
1944
|
# exp.status = 1
|
|
1893
|
1945
|
# exp.save()
|
|
1894
|
1946
|
|
|
1895
|
1947
|
#return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1896
|
1948
|
|
|
1897
|
1949
|
|
|
1898
|
1950
|
@login_required
|
|
1899
|
1951
|
def radar_refresh(request, id_camp, id_radar):
|
|
1900
|
1952
|
|
|
1901
|
1953
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
1902
|
1954
|
experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
|
|
1903
|
1955
|
|
|
1904
|
1956
|
i = app.control.inspect()
|
|
1905
|
1957
|
print("inspect",i)
|
|
1906
|
1958
|
print(i.scheduled())
|
|
1907
|
1959
|
print(i.scheduled().values())
|
|
1908
|
1960
|
scheduled = list(i.scheduled().values())[0]
|
|
1909
|
1961
|
revoked = list(i.revoked().values())[0]
|
|
1910
|
1962
|
|
|
1911
|
1963
|
# for exp in experiments:
|
|
1912
|
1964
|
# if exp.task in revoked:
|
|
1913
|
1965
|
# exp.status = 1
|
|
1914
|
1966
|
# elif exp.task in [t['request']['id'] for t in scheduled if 'task_stop' in t['request']['name']]:
|
|
1915
|
1967
|
# exp.status = 2
|
|
1916
|
1968
|
# elif exp.task in [t['request']['id'] for t in scheduled if 'task_start' in t['request']['name']]:
|
|
1917
|
1969
|
# exp.status = 3
|
|
1918
|
1970
|
# else:
|
|
1919
|
1971
|
# exp.status = 4
|
|
1920
|
1972
|
# exp.save()
|
|
1921
|
1973
|
# return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1922
|
1974
|
|
|
1923
|
1975
|
#@login_required
|
|
1924
|
1976
|
# def revoke_tasks(request, id_camp):
|
|
1925
|
1977
|
|
|
1926
|
1978
|
# i = app.control.inspect()
|
|
1927
|
1979
|
# scheduled = list(i.scheduled().values())[0]
|
|
1928
|
1980
|
# revoked = list(i.revoked().values())[0]
|
|
1929
|
1981
|
|
|
1930
|
1982
|
# for t in scheduled:
|
|
1931
|
1983
|
# if t['request']['id'] in revoked:
|
|
1932
|
1984
|
# continue
|
|
1933
|
1985
|
# app.control.revoke(t['request']['id'])
|
|
1934
|
1986
|
# exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0])
|
|
1935
|
1987
|
# eta = t['eta']
|
|
1936
|
1988
|
# #task = t['request']['name'].split('.')[-1]
|
|
1937
|
1989
|
# messages.warning(request, 'Scheduled {} at {} for experiment {} revoked'.format(task, eta, exp.name))
|
|
1938
|
1990
|
|
|
1939
|
1991
|
# return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1940
|
1992
|
|
|
1941
|
1993
|
# @login_required
|
|
1942
|
1994
|
# def show_tasks(request, id_camp):
|
|
1943
|
1995
|
|
|
1944
|
1996
|
# i = app.control.inspect()
|
|
1945
|
1997
|
# scheduled = list(i.scheduled().values())[0]
|
|
1946
|
1998
|
# revoked = list(i.revoked().values())[0]
|
|
1947
|
1999
|
|
|
1948
|
2000
|
# for t in scheduled:
|
|
1949
|
2001
|
# if t['request']['id'] in revoked:
|
|
1950
|
2002
|
# continue
|
|
1951
|
2003
|
# exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0])
|
|
1952
|
2004
|
# eta = t['eta']
|
|
1953
|
2005
|
# #task = t['request']['name'].split('.')[-1]
|
|
1954
|
2006
|
# #messages.success(request, 'Task {} scheduled at {} for experiment {}'.format(task, eta, exp.name))
|
|
1955
|
2007
|
|
|
1956
|
2008
|
# return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1957
|
2009
|
|
|
1958
|
2010
|
def real_time(request):
|
|
1959
|
2011
|
|
|
1960
|
2012
|
graphic_path = "/home/fiorella/Pictures/catwbeanie.jpg"
|
|
1961
|
2013
|
|
|
1962
|
2014
|
kwargs = {}
|
|
1963
|
2015
|
kwargs['title'] = 'CLAIRE'
|
|
1964
|
2016
|
kwargs['suptitle'] = 'Real Time'
|
|
1965
|
2017
|
kwargs['no_sidebar'] = True
|
|
1966
|
2018
|
kwargs['graphic_path'] = graphic_path
|
|
1967
|
2019
|
kwargs['graphic1_path'] = 'http://www.bluemaize.net/im/girls-accessories/shark-beanie-11.jpg'
|
|
1968
|
2020
|
|
|
1969
|
2021
|
return render(request, 'real_time.html', kwargs)
|
|
1970
|
2022
|
|
|
1971
|
2023
|
def theme(request, theme):
|
|
1972
|
2024
|
|
|
1973
|
2025
|
user = request.user
|
|
1974
|
2026
|
user.profile.theme = theme
|
|
1975
|
2027
|
user.save()
|
|
1976
|
2028
|
return redirect('index')
|