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