@@ -1,11 +1,13 | |||||
1 | [ |
|
1 | [[ | |
2 | {"fields": {"name": "JRO", "description": ""}, "model": "main.location", "pk": 1}, |
|
2 | {"fields": {"name": "JRO", "description": ""}, "model": "main.location", "pk": 1}, | |
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, |
|
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, | |
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, |
|
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, | |
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, |
|
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, | |
|
6 | {"fields": {"name": "CLAIRE", "description": ""}, "model": "main.location", "pk": 4}, | |||
6 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, |
|
7 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, | |
7 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, |
|
8 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, | |
8 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, |
|
9 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, | |
9 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4}, |
|
10 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4}, | |
10 | {"fields": {"name": "abs", "description": ""}, "model": "main.devicetype", "pk": 5} |
|
11 | {"fields": {"name": "abs", "description": ""}, "model": "main.devicetype", "pk": 5}, | |
|
12 | {"fields": {"password": "pbkdf2_sha256$24000$6RRL7xETgdgN$ORRPhrITZKzTTZHCm8T+Er6ght415kYKeU7QP3rry5M=", "last_login": null, "is_superuser": true, "username": "admin", "first_name": "", "last_name": "", "email": "admin@admin.com", "is_staff": true, "is_active": true, "date_joined": "2017-01-12T16:10:24.383", "groups": [], "user_permissions": []}, "model": "auth.user", "pk": 1} | |||
11 | ] |
|
13 | ] |
@@ -1,7 +1,6 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 | from .models import Device, Experiment, Campaign, Location |
|
3 | from apps.main.models import Device, Experiment, Campaign, Location, Configuration | |
4 | from apps.main.models import Configuration |
|
|||
5 | from django.template.defaultfilters import default |
|
4 | from django.template.defaultfilters import default | |
6 |
|
5 | |||
7 | FILE_FORMAT = ( |
|
6 | FILE_FORMAT = ( | |
@@ -80,6 +79,12 class ExperimentForm(forms.ModelForm): | |||||
80 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
79 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
81 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
80 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
82 |
|
81 | |||
|
82 | def save(self): | |||
|
83 | exp = super(ExperimentForm, self).save() | |||
|
84 | exp.name = exp.name.replace(' ', '') | |||
|
85 | exp.save() | |||
|
86 | return exp | |||
|
87 | ||||
83 | class Meta: |
|
88 | class Meta: | |
84 | model = Experiment |
|
89 | model = Experiment | |
85 | exclude = ['status'] |
|
90 | exclude = ['status'] | |
@@ -106,10 +111,6 class ConfigurationForm(forms.ModelForm): | |||||
106 | model = Configuration |
|
111 | model = Configuration | |
107 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
112 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
108 |
|
113 | |||
109 | #class DeviceTypeForm(forms.Form): |
|
|||
110 | # device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
|||
111 |
|
||||
112 |
|
||||
113 | class UploadFileForm(forms.Form): |
|
114 | class UploadFileForm(forms.Form): | |
114 |
|
115 | |||
115 | file = forms.FileField() |
|
116 | file = forms.FileField() | |
@@ -188,5 +189,5 class ChangeIpForm(forms.Form): | |||||
188 | ip_address = forms.GenericIPAddressField() |
|
189 | ip_address = forms.GenericIPAddressField() | |
189 | mask = forms.GenericIPAddressField(initial='255.255.255.0') |
|
190 | mask = forms.GenericIPAddressField(initial='255.255.255.0') | |
190 | gateway = forms.GenericIPAddressField(initial='0.0.0.0') |
|
191 | gateway = forms.GenericIPAddressField(initial='0.0.0.0') | |
191 |
|
192 | dns = forms.GenericIPAddressField(initial='0.0.0.0') | ||
192 |
|
193 |
@@ -1,30 +1,54 | |||||
1 |
|
1 | |||
|
2 | import os | |||
|
3 | import json | |||
2 | import requests |
|
4 | import requests | |
|
5 | import time | |||
3 | from datetime import datetime |
|
6 | from datetime import datetime | |
4 | from django.template.base import kwarg_re |
|
|||
5 |
|
7 | |||
6 | try: |
|
8 | try: | |
7 | from polymorphic.models import PolymorphicModel |
|
9 | from polymorphic.models import PolymorphicModel | |
8 | except: |
|
10 | except: | |
9 | from polymorphic import PolymorphicModel |
|
11 | from polymorphic import PolymorphicModel | |
10 |
|
12 | |||
|
13 | from django.template.base import kwarg_re | |||
11 | from django.db import models |
|
14 | from django.db import models | |
12 | from django.core.urlresolvers import reverse |
|
15 | from django.core.urlresolvers import reverse | |
|
16 | from django.core.validators import MinValueValidator, MaxValueValidator | |||
13 | from django.shortcuts import get_object_or_404 |
|
17 | from django.shortcuts import get_object_or_404 | |
14 |
|
18 | |||
|
19 | from apps.main.utils import Params | |||
|
20 | from apps.rc.utils import RCFile | |||
15 | from devices.dds import api as dds_api |
|
21 | from devices.dds import api as dds_api | |
|
22 | from devices.dds import data as dds_data | |||
16 |
|
23 | |||
17 | EXP_STATES = ( |
|
24 | ||
18 | (0,'Error'), #RED |
|
25 | DEV_PORTS = { | |
19 | (1,'Configured'), #BLUE |
|
26 | 'rc' : 2000, | |
20 | (2,'Running'), #GREEN |
|
27 | 'dds' : 2000, | |
21 | (3,'Scheduled'), #YELLOW |
|
28 | 'jars' : 2000, | |
22 | (4,'Not Configured'), #WHITE |
|
29 | 'usrp' : 2000, | |
|
30 | 'cgs' : 8080, | |||
|
31 | 'abs' : 8080 | |||
|
32 | } | |||
|
33 | ||||
|
34 | RADAR_STATES = ( | |||
|
35 | (0, 'No connected'), | |||
|
36 | (1, 'Connected'), | |||
|
37 | (2, 'Configured'), | |||
|
38 | (3, 'Running'), | |||
|
39 | (4, 'Scheduled'), | |||
23 | ) |
|
40 | ) | |
24 |
|
41 | |||
25 |
|
|
42 | EXPERIMENT_TYPE = ( | |
26 |
(0, ' |
|
43 | (0, 'RAW_DATA'), | |
27 |
(1, ' |
|
44 | (1, 'PDATA'), | |
|
45 | ) | |||
|
46 | ||||
|
47 | DECODE_TYPE = ( | |||
|
48 | (0, 'None'), | |||
|
49 | (1, 'TimeDomain'), | |||
|
50 | (2, 'FreqDomain'), | |||
|
51 | (3, 'InvFreqDomain'), | |||
28 | ) |
|
52 | ) | |
29 |
|
53 | |||
30 | DEV_STATES = ( |
|
54 | DEV_STATES = ( | |
@@ -45,23 +69,18 DEV_TYPES = ( | |||||
45 | ('abs', 'Automatic Beam Switching'), |
|
69 | ('abs', 'Automatic Beam Switching'), | |
46 | ) |
|
70 | ) | |
47 |
|
71 | |||
48 | DEV_PORTS = { |
|
72 | EXP_STATES = ( | |
49 | 'rc' : 2000, |
|
73 | (0,'Error'), #RED | |
50 | 'dds' : 2000, |
|
74 | (1,'Configured'), #BLUE | |
51 | 'jars' : 2000, |
|
75 | (2,'Running'), #GREEN | |
52 | 'usrp' : 2000, |
|
76 | (3,'Scheduled'), #YELLOW | |
53 | 'cgs' : 8080, |
|
77 | (4,'Not Configured'), #WHITE | |
54 | 'abs' : 8080 |
|
|||
55 | } |
|
|||
56 |
|
||||
57 | RADAR_STATES = ( |
|
|||
58 | (0, 'No connected'), |
|
|||
59 | (1, 'Connected'), |
|
|||
60 | (2, 'Configured'), |
|
|||
61 | (3, 'Running'), |
|
|||
62 | (4, 'Scheduled'), |
|
|||
63 | ) |
|
78 | ) | |
64 |
|
79 | |||
|
80 | CONF_TYPES = ( | |||
|
81 | (0, 'Active'), | |||
|
82 | (1, 'Historical'), | |||
|
83 | ) | |||
65 |
|
84 | |||
66 | class Location(models.Model): |
|
85 | class Location(models.Model): | |
67 |
|
86 | |||
@@ -136,7 +155,7 class Device(models.Model): | |||||
136 |
|
155 | |||
137 | return reverse('url_device', args=[str(self.id)]) |
|
156 | return reverse('url_device', args=[str(self.id)]) | |
138 |
|
157 | |||
139 | def change_ip(self, ip_address, mask, gateway, **kwargs): |
|
158 | def change_ip(self, ip_address, mask, gateway, dns, **kwargs): | |
140 |
|
159 | |||
141 | if self.device_type.name=='dds': |
|
160 | if self.device_type.name=='dds': | |
142 | try: |
|
161 | try: | |
@@ -157,11 +176,22 class Device(models.Model): | |||||
157 | return False |
|
176 | return False | |
158 |
|
177 | |||
159 | elif self.device_type.name=='rc': |
|
178 | elif self.device_type.name=='rc': | |
160 | payload = {'ip': ip_address, |
|
179 | headers = {'content-type': "application/json", | |
161 | 'dns': kwargs.get('dns', '8.8.8.8'), |
|
180 | 'cache-control': "no-cache"} | |
162 | 'gateway': gateway, |
|
181 | ||
163 | 'subnet': mask} |
|
182 | ip = [int(x) for x in ip_address.split('.')] | |
164 | req = requests.post(self.url('changeip'), data=payload) |
|
183 | dns = [int(x) for x in dns.split('.')] | |
|
184 | gateway = [int(x) for x in gateway.split('.')] | |||
|
185 | subnet = [int(x) for x in mask.split('.')] | |||
|
186 | ||||
|
187 | payload = { | |||
|
188 | "ip": ip, | |||
|
189 | "dns": dns, | |||
|
190 | "gateway": gateway, | |||
|
191 | "subnet": subnet | |||
|
192 | } | |||
|
193 | ||||
|
194 | req = requests.post(self.url('changeip'), data=json.dumps(payload), headers=headers) | |||
165 | try: |
|
195 | try: | |
166 | answer = req.json() |
|
196 | answer = req.json() | |
167 | if answer['changeip']=='ok': |
|
197 | if answer['changeip']=='ok': | |
@@ -199,73 +229,61 class Campaign(models.Model): | |||||
199 | else: |
|
229 | else: | |
200 | return u'{}'.format(self.name) |
|
230 | return u'{}'.format(self.name) | |
201 |
|
231 | |||
202 |
def |
|
232 | def jsonify(self): | |
203 |
|
||||
204 | import json |
|
|||
205 |
|
233 | |||
206 |
|
|
234 | data = {} | |
207 | exp_parameters = {} |
|
|||
208 | experiments = Experiment.objects.filter(campaign = self) |
|
|||
209 |
|
||||
210 | i=1 |
|
|||
211 | for experiment in experiments: |
|
|||
212 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) |
|
|||
213 | i += 1 |
|
|||
214 |
|
235 | |||
|
236 | ignored = ('template') | |||
215 |
|
237 | |||
216 | parameters['experiments'] = exp_parameters |
|
238 | for field in self._meta.fields: | |
217 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") |
|
239 | if field.name in ignored: | |
218 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") |
|
240 | continue | |
219 | parameters['campaign'] = self.__str__() |
|
241 | data[field.name] = field.value_from_object(self) | |
220 | parameters['tags'] =self.tags |
|
|||
221 |
|
242 | |||
222 | parameters = json.dumps(parameters, indent=2, sort_keys=False) |
|
243 | data['start_date'] = data['start_date'].strftime('%Y-%m-%d') | |
|
244 | data['end_date'] = data['end_date'].strftime('%Y-%m-%d') | |||
223 |
|
245 | |||
224 |
return |
|
246 | return data | |
225 |
|
247 | |||
226 | def import_from_file(self, fp): |
|
248 | def parms_to_dict(self): | |
227 |
|
249 | |||
228 | import os, json |
|
250 | params = Params() | |
|
251 | params.add(self.jsonify(), 'campaigns') | |||
229 |
|
252 | |||
230 | parms = {} |
|
253 | for exp in Experiment.objects.filter(campaign = self): | |
|
254 | params.add(exp.jsonify(), 'experiments') | |||
|
255 | configurations = Configuration.objects.filter(experiment=exp, type=0) | |||
231 |
|
256 | |||
232 | path, ext = os.path.splitext(fp.name) |
|
257 | for conf in configurations: | |
|
258 | params.add(conf.jsonify(), 'configurations') | |||
|
259 | if conf.device.device_type.name=='rc': | |||
|
260 | for line in conf.get_lines(): | |||
|
261 | params.add(line.jsonify(), 'lines') | |||
233 |
|
262 | |||
234 | if ext == '.json': |
|
263 | return params.data | |
235 | parms = json.loads(fp.read()) |
|
|||
236 |
|
||||
237 | return parms |
|
|||
238 |
|
264 | |||
239 | def dict_to_parms(self, parms, CONF_MODELS): |
|
265 | def dict_to_parms(self, parms, CONF_MODELS): | |
240 |
|
266 | |||
241 | experiments = Experiment.objects.filter(campaign = self) |
|
267 | experiments = Experiment.objects.filter(campaign = self) | |
242 | configurations = Configuration.objects.filter(experiment = experiments) |
|
|||
243 |
|
||||
244 | if configurations: |
|
|||
245 | for configuration in configurations: |
|
|||
246 | configuration.delete() |
|
|||
247 |
|
268 | |||
248 | if experiments: |
|
269 | if experiments: | |
249 | for experiment in experiments: |
|
270 | for experiment in experiments: | |
250 | experiment.delete() |
|
271 | experiment.delete() | |
251 |
|
272 | |||
252 |
for |
|
273 | for id_exp in parms['experiments']['allIds']: | |
253 | location = Location.objects.get(name = parms['experiments'][parms_exp]['radar']) |
|
274 | exp_parms = parms['experiments']['byId'][id_exp] | |
254 | new_exp = Experiment( |
|
275 | dum = (datetime.now() - datetime(1970, 1, 1)).total_seconds() | |
255 | name = parms['experiments'][parms_exp]['experiment'], |
|
276 | exp = Experiment(name='{}'.format(dum)) | |
256 | location = location, |
|
277 | exp.save() | |
257 | start_time = parms['experiments'][parms_exp]['start_time'], |
|
278 | exp.dict_to_parms(parms, CONF_MODELS, id_exp=id_exp) | |
258 | end_time = parms['experiments'][parms_exp]['end_time'], |
|
279 | self.experiments.add(exp) | |
259 | ) |
|
280 | ||
260 | new_exp.save() |
|
281 | camp_parms = parms['campaigns']['byId'][parms['campaigns']['allIds'][0]] | |
261 | new_exp.dict_to_parms(parms['experiments'][parms_exp],CONF_MODELS) |
|
282 | ||
262 | new_exp.save() |
|
283 | self.name = '{}-{}'.format(camp_parms['name'], datetime.now().strftime('%y%m%d')) | |
263 |
|
284 | self.start_date = camp_parms['start_date'] | ||
264 |
|
|
285 | self.end_date = camp_parms['end_date'] | |
265 |
|
|
286 | self.tags = camp_parms['tags'] | |
266 | self.end_date = parms['end_date'] |
|
|||
267 | self.tags = parms['tags'] |
|
|||
268 | self.experiments.add(new_exp) |
|
|||
269 |
|
|
287 | self.save() | |
270 |
|
288 | |||
271 | return self |
|
289 | return self | |
@@ -326,6 +344,25 class Experiment(models.Model): | |||||
326 | else: |
|
344 | else: | |
327 | return u'%s' % (self.name) |
|
345 | return u'%s' % (self.name) | |
328 |
|
346 | |||
|
347 | def jsonify(self): | |||
|
348 | ||||
|
349 | data = {} | |||
|
350 | ||||
|
351 | ignored = ('template') | |||
|
352 | ||||
|
353 | for field in self._meta.fields: | |||
|
354 | if field.name in ignored: | |||
|
355 | continue | |||
|
356 | data[field.name] = field.value_from_object(self) | |||
|
357 | ||||
|
358 | data['start_time'] = data['start_time'].strftime('%H:%M:%S') | |||
|
359 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') | |||
|
360 | data['location'] = self.location.name | |||
|
361 | data['configurations'] = ['{}'.format(conf.pk) for | |||
|
362 | conf in Configuration.objects.filter(experiment=self)] | |||
|
363 | ||||
|
364 | return data | |||
|
365 | ||||
329 | @property |
|
366 | @property | |
330 | def radar_system(self): |
|
367 | def radar_system(self): | |
331 | return self.location |
|
368 | return self.location | |
@@ -353,27 +390,24 class Experiment(models.Model): | |||||
353 |
|
390 | |||
354 | result = 2 |
|
391 | result = 2 | |
355 |
|
392 | |||
356 | confs = Configuration.objects.filter(experiment=self).order_by('device__device_type__sequence') |
|
393 | confs = Configuration.objects.filter(experiment=self).filter(type = 0).order_by('-device__device_type__sequence') | |
357 | #Only Configured Devices. |
|
394 | #Only Configured Devices. | |
358 | for conf in confs: |
|
395 | for conf in confs: | |
359 | if conf.device.device_type.name == 'rc': |
|
396 | dev_status = conf.device.status | |
360 | continue |
|
397 | if dev_status in [0,4]: | |
361 | #if conf.device.status in [0,4]: |
|
398 | result = 0 | |
362 |
|
|
399 | return result | |
363 | # return result |
|
400 | else: | |
364 | for conf in confs: |
|
401 | if conf.device.device_type.name != 'jars': | |
365 | if conf.device.device_type.name == 'rc': |
|
402 | conf.write_device() | |
366 |
|
|
403 | time.sleep(1) | |
367 |
|
|
404 | print conf.device.name+' has started...' | |
368 | pass#conf.write_device() |
|
405 | else: | |
369 |
|
|
406 | conf.stop_device() | |
370 |
|
|
407 | conf.write_device() | |
371 | #Start Device |
|
408 | conf.start_device() | |
372 | for conf in confs: |
|
409 | print conf.device.name+' has started...' | |
373 | if conf.device.device_type.name == 'rc': |
|
410 | ||
374 | continue |
|
|||
375 | print 'start: '#conf.start_device() |
|
|||
376 | print conf |
|
|||
377 | return result |
|
411 | return result | |
378 |
|
412 | |||
379 |
|
413 | |||
@@ -385,33 +419,22 class Experiment(models.Model): | |||||
385 |
|
419 | |||
386 | result = 1 |
|
420 | result = 1 | |
387 |
|
421 | |||
388 |
confs = Configuration.objects.filter(experiment=self).order_by(' |
|
422 | confs = Configuration.objects.filter(experiment=self).filter(type = 0).order_by('device__device_type__sequence') | |
389 | #Only Running Devices. |
|
|||
390 | for conf in confs: |
|
|||
391 | if conf.device.device_type.name == 'rc': |
|
|||
392 | continue |
|
|||
393 | #if conf.device.status in [0,4]: |
|
|||
394 | # result = 0 |
|
|||
395 | # return result |
|
|||
396 |
|
||||
397 | #Stop Device |
|
|||
398 | for conf in confs: |
|
|||
399 | if conf.device.device_type.name == 'dds': |
|
|||
400 | #conf.stop_device() |
|
|||
401 | confs=confs.exclude(device__device_type__name='dds') |
|
|||
402 | break |
|
|||
403 |
|
423 | |||
404 | for conf in confs: |
|
424 | for conf in confs: | |
405 | if conf.device.device_type.name == 'jars': |
|
425 | dev_status = conf.device.status | |
406 | #conf.stop_device() |
|
426 | if dev_status in [0,4]: | |
407 | confs=confs.exclude(device__device_type__name='jars') |
|
427 | result = 0 | |
408 |
|
|
428 | return result | |
409 |
|
429 | |||
|
430 | #Stop Device | |||
|
431 | confs=confs.exclude(device__device_type__name='cgs') | |||
410 | for conf in confs: |
|
432 | for conf in confs: | |
411 |
if conf.device.device_type.name |
|
433 | if conf.device.device_type.name != 'rc': | |
412 |
con |
|
434 | conf.stop_device() | |
413 | print 'start: '#conf.stop_device() |
|
435 | else: | |
414 | print conf |
|
436 | conf.reset_device() | |
|
437 | print conf.device.name+' has stopped...' | |||
415 |
|
438 | |||
416 | return result |
|
439 | return result | |
417 |
|
440 | |||
@@ -451,79 +474,48 class Experiment(models.Model): | |||||
451 |
|
474 | |||
452 | def parms_to_dict(self): |
|
475 | def parms_to_dict(self): | |
453 |
|
476 | |||
454 | import json |
|
477 | params = Params() | |
|
478 | params.add(self.jsonify(), 'experiments') | |||
455 |
|
479 | |||
456 |
configurations = Configuration.objects.filter(experiment=self |
|
480 | configurations = Configuration.objects.filter(experiment=self, type=0) | |
457 | conf_parameters = {} |
|
|||
458 | parameters={} |
|
|||
459 |
|
||||
460 | for configuration in configurations: |
|
|||
461 | conf_parameters[configuration.name] = configuration.parms_to_dict() |
|
|||
462 |
|
||||
463 | parameters['configurations'] = conf_parameters |
|
|||
464 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") |
|
|||
465 | parameters['start_time'] = self.start_time.strftime("%H:%M:%S") |
|
|||
466 | parameters['radar'] = self.radar_system.name |
|
|||
467 | parameters['experiment'] = self.name |
|
|||
468 | parameters = json.dumps(parameters, indent=2) |
|
|||
469 |
|
||||
470 | return parameters |
|
|||
471 |
|
||||
472 | def import_from_file(self, fp): |
|
|||
473 |
|
481 | |||
474 | import os, json |
|
482 | for conf in configurations: | |
475 |
|
483 | params.add(conf.jsonify(), 'configurations') | ||
476 | parms = {} |
|
484 | if conf.device.device_type.name=='rc': | |
477 |
|
485 | for line in conf.get_lines(): | ||
478 | path, ext = os.path.splitext(fp.name) |
|
486 | params.add(line.jsonify(), 'lines') | |
479 |
|
||||
480 | if ext == '.json': |
|
|||
481 | parms = json.loads(fp.read().decode('utf-8')) |
|
|||
482 |
|
487 | |||
483 | return parms |
|
488 | return params.data | |
484 |
|
489 | |||
485 | def dict_to_parms(self, parms, CONF_MODELS): |
|
490 | def dict_to_parms(self, parms, CONF_MODELS, id_exp=None): | |
486 |
|
491 | |||
487 | configurations = Configuration.objects.filter(experiment=self) |
|
492 | configurations = Configuration.objects.filter(experiment=self) | |
488 |
|
493 | |||
|
494 | if id_exp is not None: | |||
|
495 | exp_parms = parms['experiments']['byId'][id_exp] | |||
|
496 | else: | |||
|
497 | exp_parms = parms['experiments']['byId'][parms['experiments']['allIds'][0]] | |||
|
498 | ||||
489 | if configurations: |
|
499 | if configurations: | |
490 | for configuration in configurations: |
|
500 | for configuration in configurations: | |
491 | configuration.delete() |
|
501 | configuration.delete() | |
492 | #If device is missing. |
|
502 | ||
493 |
for conf |
|
503 | for id_conf in exp_parms['configurations']: | |
494 | try: |
|
504 | conf_parms = parms['configurations']['byId'][id_conf] | |
495 |
|
|
505 | device = Device.objects.filter(device_type__name=conf_parms['device_type'])[0] | |
496 | except: |
|
506 | model = CONF_MODELS[conf_parms['device_type']] | |
497 | return {'Error': 'Device is not in database. Please create new '+str(parms['configurations'][configuration]['device_type'])+ ' device.'} |
|
507 | conf = model( | |
498 |
|
||||
499 | for configuration in parms['configurations']: |
|
|||
500 | device = Device.objects.filter(device_type__name=parms['configurations'][configuration]['device_type'])[0] |
|
|||
501 | if parms['configurations'][configuration]['device_type'] == 'rc': |
|
|||
502 | if bool(parms['configurations'][configuration]['mix']) == False: |
|
|||
503 | DevConfModel = CONF_MODELS[parms['configurations'][configuration]['device_type']] |
|
|||
504 | new_conf = DevConfModel( |
|
|||
505 | experiment = self, |
|
|||
506 | name = configuration, |
|
|||
507 | device = device, |
|
|||
508 | ) |
|
|||
509 | new_conf.dict_to_parms(parms['configurations'][configuration]) |
|
|||
510 | new_conf.save() |
|
|||
511 | else: |
|
|||
512 | DevConfModel = CONF_MODELS[parms['configurations'][configuration]['device_type']] |
|
|||
513 | new_conf = DevConfModel( |
|
|||
514 |
|
|
508 | experiment = self, | |
515 | name = configuration, |
|
|||
516 |
|
|
509 | device = device, | |
517 | ) |
|
510 | ) | |
518 |
|
|
511 | conf.dict_to_parms(parms, id=id_conf) | |
519 | new_conf.save() |
|
|||
520 |
|
512 | |||
521 |
|
513 | |||
522 |
location = Location.objects.get(name |
|
514 | location, created = Location.objects.get_or_create(name=exp_parms['location']) | |
523 | self.name = parms['experiment'] |
|
515 | self.name = '{}-{}'.format(exp_parms['name'], datetime.now().strftime('%y%m%d')) | |
524 |
self.location |
|
516 | self.location = location | |
525 | self.start_time = parms['start_time'] |
|
517 | self.start_time = exp_parms['start_time'] | |
526 |
self.end_time |
|
518 | self.end_time = exp_parms['end_time'] | |
527 | self.save() |
|
519 | self.save() | |
528 |
|
520 | |||
529 | return self |
|
521 | return self | |
@@ -581,6 +573,37 class Configuration(PolymorphicModel): | |||||
581 | else: |
|
573 | else: | |
582 | return u'{} {}'.format(device, self.name) |
|
574 | return u'{} {}'.format(device, self.name) | |
583 |
|
575 | |||
|
576 | def jsonify(self): | |||
|
577 | ||||
|
578 | data = {} | |||
|
579 | ||||
|
580 | ignored = ('type', 'polymorphic_ctype', 'configuration_ptr', | |||
|
581 | 'created_date', 'programmed_date', 'template', 'device', | |||
|
582 | 'experiment') | |||
|
583 | ||||
|
584 | for field in self._meta.fields: | |||
|
585 | if field.name in ignored: | |||
|
586 | continue | |||
|
587 | data[field.name] = field.value_from_object(self) | |||
|
588 | ||||
|
589 | data['device_type'] = self.device.device_type.name | |||
|
590 | ||||
|
591 | if self.device.device_type.name == 'rc': | |||
|
592 | data['lines'] = ['{}'.format(line.pk) for line in self.get_lines()] | |||
|
593 | data['delays'] = self.get_delays() | |||
|
594 | data['pulses'] = self.get_pulses() | |||
|
595 | ||||
|
596 | elif self.device.device_type.name == 'jars': | |||
|
597 | data['decode_type'] = DECODE_TYPE[self.decode_data][1] | |||
|
598 | ||||
|
599 | elif self.device.device_type.name == 'dds': | |||
|
600 | data['frequencyA_Mhz'] = float(data['frequencyA_Mhz']) | |||
|
601 | data['frequencyB_Mhz'] = float(data['frequencyB_Mhz']) | |||
|
602 | data['phaseA'] = dds_data.phase_to_binary(data['phaseA_degrees']) | |||
|
603 | data['phaseB'] = dds_data.phase_to_binary(data['phaseB_degrees']) | |||
|
604 | ||||
|
605 | return data | |||
|
606 | ||||
584 | def clone(self, **kwargs): |
|
607 | def clone(self, **kwargs): | |
585 |
|
608 | |||
586 | self.pk = None |
|
609 | self.pk = None | |
@@ -594,12 +617,14 class Configuration(PolymorphicModel): | |||||
594 |
|
617 | |||
595 | def parms_to_dict(self): |
|
618 | def parms_to_dict(self): | |
596 |
|
619 | |||
597 |
param |
|
620 | params = Params() | |
|
621 | params.add(self.jsonify(), 'configurations') | |||
598 |
|
622 | |||
599 | for key in self.__dict__.keys(): |
|
623 | if self.device.device_type.name=='rc': | |
600 | parameters[key] = getattr(self, key) |
|
624 | for line in self.get_lines(): | |
|
625 | params.add(line.jsonify(), 'lines') | |||
601 |
|
626 | |||
602 |
return param |
|
627 | return params.data | |
603 |
|
628 | |||
604 | def parms_to_text(self): |
|
629 | def parms_to_text(self): | |
605 |
|
630 | |||
@@ -611,17 +636,28 class Configuration(PolymorphicModel): | |||||
611 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) |
|
636 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
612 |
|
637 | |||
613 |
|
638 | |||
614 | def dict_to_parms(self, parameters): |
|
639 | def dict_to_parms(self, parameters, id=None): | |
615 |
|
640 | |||
616 | if type(parameters) != type({}): |
|
641 | params = Params(parameters) | |
617 | return |
|
|||
618 |
|
642 | |||
619 | for key in parameters.keys(): |
|
643 | if id: | |
620 | setattr(self, key, parameters[key]) |
|
644 | data = params.get_conf(id_conf=id) | |
|
645 | else: | |||
|
646 | data = params.get_conf(dtype=self.device.device_type.name) | |||
621 |
|
647 | |||
622 | def export_to_file(self, format="json"): |
|
648 | if data['device_type']=='rc': | |
|
649 | self.clean_lines() | |||
|
650 | lines = data.pop('lines', None) | |||
|
651 | for line_id in lines: | |||
|
652 | pass | |||
623 |
|
653 | |||
624 | import json |
|
654 | for key, value in data.items(): | |
|
655 | if key not in ('id', 'device_type'): | |||
|
656 | setattr(self, key, value) | |||
|
657 | ||||
|
658 | self.save() | |||
|
659 | ||||
|
660 | def export_to_file(self, format="json"): | |||
625 |
|
661 | |||
626 | content_type = '' |
|
662 | content_type = '' | |
627 |
|
663 | |||
@@ -632,7 +668,7 class Configuration(PolymorphicModel): | |||||
632 |
|
668 | |||
633 | if format == 'binary': |
|
669 | if format == 'binary': | |
634 | content_type = 'application/octet-stream' |
|
670 | content_type = 'application/octet-stream' | |
635 |
filename = '%s_%s. |
|
671 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
636 | content = self.parms_to_binary() |
|
672 | content = self.parms_to_binary() | |
637 |
|
673 | |||
638 | if not content_type: |
|
674 | if not content_type: | |
@@ -649,8 +685,6 class Configuration(PolymorphicModel): | |||||
649 |
|
685 | |||
650 | def import_from_file(self, fp): |
|
686 | def import_from_file(self, fp): | |
651 |
|
687 | |||
652 | import os, json |
|
|||
653 |
|
||||
654 | parms = {} |
|
688 | parms = {} | |
655 |
|
689 | |||
656 | path, ext = os.path.splitext(fp.name) |
|
690 | path, ext = os.path.splitext(fp.name) | |
@@ -658,6 +692,13 class Configuration(PolymorphicModel): | |||||
658 | if ext == '.json': |
|
692 | if ext == '.json': | |
659 | parms = json.load(fp) |
|
693 | parms = json.load(fp) | |
660 |
|
694 | |||
|
695 | if ext == '.dds': | |||
|
696 | lines = fp.readlines() | |||
|
697 | parms = dds_data.text_to_dict(lines) | |||
|
698 | ||||
|
699 | if ext == '.racp': | |||
|
700 | parms = RCFile(fp).to_dict() | |||
|
701 | ||||
661 | return parms |
|
702 | return parms | |
662 |
|
703 | |||
663 | def status_device(self): |
|
704 | def status_device(self): |
@@ -479,7 +479,7 def campaign_export(request, id_camp): | |||||
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(content) |
|
482 | response.write(json.dumps(content, indent=2)) | |
483 |
|
483 | |||
484 | return response |
|
484 | return response | |
485 |
|
485 | |||
@@ -496,16 +496,8 def campaign_import(request, id_camp): | |||||
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 |
|
499 | new_camp = campaign.dict_to_parms(json.load(request.FILES['file']), CONF_MODELS) | ||
500 | parms = campaign.import_from_file(request.FILES['file']) |
|
|||
501 |
|
||||
502 | if parms: |
|
|||
503 | parms['name'] = parms['campaign'] |
|
|||
504 |
|
||||
505 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) |
|
|||
506 |
|
||||
507 |
|
|
500 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
508 |
|
||||
509 |
|
|
501 | return redirect(new_camp.get_absolute_url_edit()) | |
510 |
|
502 | |||
511 | messages.error(request, "Could not import parameters from file") |
|
503 | messages.error(request, "Could not import parameters from file") | |
@@ -543,12 +535,12 def experiments(request): | |||||
543 | def experiment(request, id_exp): |
|
535 | def experiment(request, id_exp): | |
544 |
|
536 | |||
545 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
537 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
546 | #experiment.get_status() |
|
538 | ||
547 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
539 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
548 |
|
540 | |||
549 | kwargs = {} |
|
541 | kwargs = {} | |
550 |
|
542 | |||
551 | kwargs['experiment_keys'] = ['radar_system', 'name', 'start_time', 'end_time'] |
|
543 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'freq', 'start_time', 'end_time'] | |
552 | kwargs['experiment'] = experiment |
|
544 | kwargs['experiment'] = experiment | |
553 |
|
545 | |||
554 | 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'] | |
@@ -581,7 +573,7 def experiment_new(request, id_camp=None): | |||||
581 | 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'] | |
582 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
574 | exp=Experiment.objects.get(pk=request.GET['template']) | |
583 | form = ExperimentForm(instance=exp, |
|
575 | form = ExperimentForm(instance=exp, | |
584 |
initial={'name': '{} |
|
576 | initial={'name': '{}_{:%y%m%d}'.format(exp.name, datetime.now()), | |
585 | 'template': False}) |
|
577 | 'template': False}) | |
586 | elif 'blank' in request.GET: |
|
578 | elif 'blank' in request.GET: | |
587 | kwargs['button'] = 'Create' |
|
579 | kwargs['button'] = 'Create' | |
@@ -668,7 +660,7 def experiment_export(request, id_exp): | |||||
668 |
|
660 | |||
669 | response = HttpResponse(content_type=content_type) |
|
661 | response = HttpResponse(content_type=content_type) | |
670 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
662 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
671 | response.write(content) |
|
663 | response.write(json.dumps(content, indent=2)) | |
672 |
|
664 | |||
673 | return response |
|
665 | return response | |
674 |
|
666 | |||
@@ -686,19 +678,8 def experiment_import(request, id_exp): | |||||
686 | file_form = UploadFileForm(request.POST, request.FILES) |
|
678 | file_form = UploadFileForm(request.POST, request.FILES) | |
687 |
|
679 | |||
688 | if file_form.is_valid(): |
|
680 | if file_form.is_valid(): | |
689 |
|
681 | new_exp = experiment.dict_to_parms(json.load(request.FILES['file']), CONF_MODELS) | ||
690 | parms = experiment.import_from_file(request.FILES['file']) |
|
|||
691 |
|
||||
692 | if parms: |
|
|||
693 |
|
||||
694 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) |
|
|||
695 |
|
||||
696 | if new_exp.__class__.__name__=='dict': |
|
|||
697 | messages.error(request, new_exp['Error'] ) |
|
|||
698 | return redirect(experiment.get_absolute_url_import()) |
|
|||
699 |
|
||||
700 |
|
|
682 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
701 |
|
||||
702 |
|
|
683 | return redirect(new_exp.get_absolute_url_edit()) | |
703 |
|
684 | |||
704 | messages.error(request, "Could not import parameters from file") |
|
685 | messages.error(request, "Could not import parameters from file") | |
@@ -717,32 +698,19 def experiment_import(request, id_exp): | |||||
717 | @user_passes_test(lambda u:u.is_staff) |
|
698 | @user_passes_test(lambda u:u.is_staff) | |
718 | def experiment_start(request, id_exp): |
|
699 | def experiment_start(request, id_exp): | |
719 |
|
700 | |||
720 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
701 | def experiment_start(request, id_exp): | |
721 |
|
||||
722 | confs = Configuration.objects.filter(experiment=exp, type=0) |
|
|||
723 | if not confs: |
|
|||
724 | messages.error(request, 'Experiment not running. No Device Configurations detected.') |
|
|||
725 | return redirect(exp.get_absolute_url()) |
|
|||
726 |
|
||||
727 | for conf in confs: |
|
|||
728 | conf.status_device() |
|
|||
729 | if conf.device.status != 2: |
|
|||
730 | messages.error(request, 'Experiment not running. Configuration {} state: '.format(conf) + DEV_STATES[conf.device.status][1]) |
|
|||
731 | return redirect(exp.get_absolute_url()) |
|
|||
732 |
|
702 | |||
733 | exp.get_status() |
|
703 | exp = get_object_or_404(Experiment, pk=id_exp) | |
734 |
|
704 | |||
735 | if exp.status == 2: |
|
705 | if exp.status == 2: | |
736 |
messages.warning(request, 'Experiment {} already runn |
|
706 | messages.warning(request, 'Experiment {} already runnnig'.format(exp)) | |
737 | else: |
|
707 | else: | |
738 | task = task_start.delay(exp.pk) |
|
708 | exp.status = exp.start() | |
739 | exp.status = task.wait() |
|
|||
740 |
|
||||
741 | if exp.status==0: |
|
709 | if exp.status==0: | |
742 | messages.error(request, 'Experiment {} not start'.format(exp)) |
|
710 | messages.error(request, 'Experiment {} not start'.format(exp)) | |
743 | if exp.status==2: |
|
711 | if exp.status==2: | |
744 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
712 | messages.success(request, 'Experiment {} started'.format(exp)) | |
745 | task_status.delay(exp.pk) #background get_status function |
|
713 | ||
746 | exp.save() |
|
714 | exp.save() | |
747 |
|
715 | |||
748 | return redirect(exp.get_absolute_url()) |
|
716 | return redirect(exp.get_absolute_url()) | |
@@ -752,24 +720,26 def experiment_start(request, id_exp): | |||||
752 | def experiment_stop(request, id_exp): |
|
720 | def experiment_stop(request, id_exp): | |
753 |
|
721 | |||
754 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
722 | exp = get_object_or_404(Experiment, pk=id_exp) | |
755 | confs = Configuration.objects.filter(experiment=exp, type=0) |
|
|||
756 | if not confs: |
|
|||
757 | messages.error(request, 'No Device Configurations detected.') |
|
|||
758 | return redirect(exp.get_absolute_url()) |
|
|||
759 |
|
||||
760 | exp.get_status() |
|
|||
761 |
|
723 | |||
762 | if exp.status == 2: |
|
724 | if exp.status == 2: | |
763 | task = task_stop.delay(exp.pk) |
|
725 | exp.status = exp.stop() | |
764 | exp.status = task.wait() |
|
|||
765 | messages.warning(request, 'Experiment {} stopped'.format(exp)) |
|
|||
766 | exp.save() |
|
726 | exp.save() | |
|
727 | messages.success(request, 'Experiment {} stopped'.format(exp)) | |||
767 | else: |
|
728 | else: | |
768 | messages.error(request, 'Experiment {} not running'.format(exp)) |
|
729 | messages.error(request, 'Experiment {} not running'.format(exp)) | |
769 |
|
730 | |||
770 | return redirect(exp.get_absolute_url()) |
|
731 | return redirect(exp.get_absolute_url()) | |
771 |
|
732 | |||
772 |
|
733 | |||
|
734 | def experiment_status(request, id_exp): | |||
|
735 | ||||
|
736 | exp = get_object_or_404(Experiment, pk=id_exp) | |||
|
737 | ||||
|
738 | exp.get_status() | |||
|
739 | ||||
|
740 | return redirect(exp.get_absolute_url()) | |||
|
741 | ||||
|
742 | ||||
773 | @user_passes_test(lambda u:u.is_staff) |
|
743 | @user_passes_test(lambda u:u.is_staff) | |
774 | def experiment_mix(request, id_exp): |
|
744 | def experiment_mix(request, id_exp): | |
775 |
|
745 | |||
@@ -882,7 +852,7 def experiment_summary(request, id_exp): | |||||
882 |
|
852 | |||
883 | kwargs = {} |
|
853 | kwargs = {} | |
884 |
|
854 | |||
885 | kwargs['experiment_keys'] = ['radar_system', 'name', 'start_time', 'end_time'] |
|
855 | kwargs['experiment_keys'] = ['radar_system', 'name', 'freq', 'start_time', 'end_time'] | |
886 | kwargs['experiment'] = experiment |
|
856 | kwargs['experiment'] = experiment | |
887 |
|
857 | |||
888 | kwargs['configurations'] = [] |
|
858 | kwargs['configurations'] = [] | |
@@ -892,8 +862,15 def experiment_summary(request, id_exp): | |||||
892 |
|
862 | |||
893 | kwargs['button'] = 'Verify Parameters' |
|
863 | kwargs['button'] = 'Verify Parameters' | |
894 |
|
864 | |||
|
865 | c_vel = 3.0*(10**8) #m/s | |||
|
866 | ope_freq = experiment.freq*(10**6) #1/s | |||
|
867 | radar_lambda = c_vel/ope_freq #m | |||
|
868 | kwargs['radar_lambda'] = radar_lambda | |||
|
869 | ||||
895 | jars_conf = False |
|
870 | jars_conf = False | |
896 | rc_conf = False |
|
871 | rc_conf = False | |
|
872 | code_id = 0 | |||
|
873 | tx_line = {} | |||
897 |
|
874 | |||
898 | for configuration in configurations: |
|
875 | for configuration in configurations: | |
899 |
|
876 | |||
@@ -907,6 +884,9 def experiment_summary(request, id_exp): | |||||
907 | configuration.tx_lines = [] |
|
884 | configuration.tx_lines = [] | |
908 |
|
885 | |||
909 | for tx_line in lines: |
|
886 | for tx_line in lines: | |
|
887 | if tx_line.get_name()[-1] == 'A': | |||
|
888 | txa_line = tx_line | |||
|
889 | txa_params = json.loads(txa_line.params) | |||
910 | line = {'name':tx_line.get_name()} |
|
890 | line = {'name':tx_line.get_name()} | |
911 | tx_params = json.loads(tx_line.params) |
|
891 | tx_params = json.loads(tx_line.params) | |
912 | line['width'] = tx_params['pulse_width'] |
|
892 | line['width'] = tx_params['pulse_width'] | |
@@ -922,6 +902,7 def experiment_summary(request, id_exp): | |||||
922 |
|
902 | |||
923 | for code_line in configuration.get_lines(line_type__name='codes'): |
|
903 | for code_line in configuration.get_lines(line_type__name='codes'): | |
924 | code_params = json.loads(code_line.params) |
|
904 | code_params = json.loads(code_line.params) | |
|
905 | code_id = code_params['code'] | |||
925 | if tx_line.pk==int(code_params['TX_ref']): |
|
906 | if tx_line.pk==int(code_params['TX_ref']): | |
926 | line['codes'] = '{}:{}'.format(RCLineCode.objects.get(pk=code_params['code']), |
|
907 | line['codes'] = '{}:{}'.format(RCLineCode.objects.get(pk=code_params['code']), | |
927 | '-'.join(code_params['codes'])) |
|
908 | '-'.join(code_params['codes'])) | |
@@ -930,12 +911,16 def experiment_summary(request, id_exp): | |||||
930 | win_params = json.loads(windows_line.params) |
|
911 | win_params = json.loads(windows_line.params) | |
931 | if tx_line.pk==int(win_params['TX_ref']): |
|
912 | if tx_line.pk==int(win_params['TX_ref']): | |
932 | windows = '' |
|
913 | windows = '' | |
|
914 | nsa = win_params['params'][0]['number_of_samples'] | |||
933 | for i, params in enumerate(win_params['params']): |
|
915 | for i, params in enumerate(win_params['params']): | |
934 | windows += 'W{}: Ho={first_height} km DH={resolution} km NSA={number_of_samples}<br>'.format(i, **params) |
|
916 | windows += 'W{}: Ho={first_height} km DH={resolution} km NSA={number_of_samples}<br>'.format(i, **params) | |
935 | line['windows'] = mark_safe(windows) |
|
917 | line['windows'] = mark_safe(windows) | |
936 |
|
918 | |||
937 | configuration.tx_lines.append(line) |
|
919 | configuration.tx_lines.append(line) | |
938 |
|
920 | |||
|
921 | if txa_line: | |||
|
922 | kwargs['duty_cycle'] = float(txa_params['pulse_width'])/ipp*100 | |||
|
923 | ||||
939 | #-------------------- JARS -----------------------: |
|
924 | #-------------------- JARS -----------------------: | |
940 | if configuration.device.device_type.name == 'jars': |
|
925 | if configuration.device.device_type.name == 'jars': | |
941 | jars_conf = True |
|
926 | jars_conf = True | |
@@ -946,34 +931,71 def experiment_summary(request, id_exp): | |||||
946 | filter_parms = configuration.filter_parms |
|
931 | filter_parms = configuration.filter_parms | |
947 | filter_parms = ast.literal_eval(filter_parms) |
|
932 | filter_parms = ast.literal_eval(filter_parms) | |
948 | spectral_number = configuration.spectral_number |
|
933 | spectral_number = configuration.spectral_number | |
|
934 | acq_profiles = configuration.acq_profiles | |||
|
935 | cohe_integr = configuration.cohe_integr | |||
|
936 | profiles_block = configuration.profiles_block | |||
949 |
|
937 | |||
|
938 | if filter_parms.__class__.__name__=='str': | |||
|
939 | filter_parms = eval(filter_parms) | |||
950 |
|
940 | |||
951 | kwargs['configurations'].append(configuration) |
|
941 | kwargs['configurations'].append(configuration) | |
952 |
|
942 | |||
953 |
|
943 | |||
954 | #------ RC & JARS ------: |
|
944 | #------ RC & JARS ------: | |
955 | ipp = 937.5 # |
|
|||
956 | nsa = 200# |
|
|||
957 | dh = 1.5 # |
|
|||
958 | channels_number = 5 # |
|
|||
959 |
|
||||
960 | if rc_conf and jars_conf: |
|
945 | if rc_conf and jars_conf: | |
|
946 | #RC filter values: | |||
|
947 | ||||
961 | if exp_type == 0: #Short |
|
948 | if exp_type == 0: #Short | |
962 | bytes = 2 |
|
949 | bytes_ = 2 | |
963 | b = nsa*2*bytes*channels_number |
|
950 | b = nsa*2*bytes_*channels_number | |
964 | else: #Float |
|
951 | else: #Float | |
965 | bytes = 4 |
|
952 | bytes_ = 4 | |
966 | channels = channels_number + spectral_number |
|
953 | channels = channels_number + spectral_number | |
967 | b = nsa*2*bytes*fftpoints*channels |
|
954 | b = nsa*2*bytes_*fftpoints*channels | |
968 |
|
955 | |||
969 | ipps = (ipp*pow(10,-6))/0.15 |
|
956 | codes_num = 7 | |
970 | GB = 1048576.0*1024.0 |
|
957 | if code_id == 2: | |
971 |
|
|
958 | codes_num = 7 | |
972 | rate = b/ipps |
|
959 | elif code_id == 12: | |
973 | rate = rate *(1/GB)*(Hour) |
|
960 | codes_num = 15 | |
974 | kwargs['rate'] = str(rate)+" GB/h" |
|
961 | ||
|
962 | #Jars filter values: | |||
|
963 | try: | |||
|
964 | clock = eval(filter_parms['clock']) | |||
|
965 | filter_2 = eval(filter_parms['filter_2']) | |||
|
966 | filter_5 = eval(filter_parms['filter_5']) | |||
|
967 | filter_fir = eval(filter_parms['filter_fir']) | |||
|
968 | except: | |||
|
969 | clock = float(filter_parms['clock']) | |||
|
970 | filter_2 = int(filter_parms['filter_2']) | |||
|
971 | filter_5 = int(filter_parms['filter_5']) | |||
|
972 | filter_fir = int(filter_parms['filter_fir']) | |||
|
973 | Fs_MHz = clock/(filter_2*filter_5*filter_fir) | |||
|
974 | ||||
|
975 | #Jars values: | |||
|
976 | IPP_units = ipp/0.15*Fs_MHz | |||
|
977 | IPP_us = IPP_units / Fs_MHz | |||
|
978 | IPP_s = IPP_units / (Fs_MHz * (10**6)) | |||
|
979 | Ts = 1/(Fs_MHz*(10**6)) | |||
|
980 | ||||
|
981 | #Values | |||
|
982 | Va = radar_lambda/(4*Ts*cohe_integr) | |||
|
983 | rate_bh = ((nsa-codes_num)*channels_number*2*bytes_/IPP_us)*(36*(10**8)/cohe_integr) | |||
|
984 | rate_gh = rate_bh/(1024*1024*1024) | |||
|
985 | kwargs['rate_bh'] = str(rate_bh) + " (Bytes/h)" | |||
|
986 | kwargs['rate_gh'] = str(rate_gh)+" (GBytes/h)" | |||
|
987 | kwargs['va'] = Va | |||
|
988 | kwargs['time_per_block'] = IPP_s * profiles_block * cohe_integr | |||
|
989 | kwargs['acqtime'] = IPP_s * acq_profiles | |||
|
990 | kwargs['vrange'] = 3/(2*IPP_s*cohe_integr) | |||
|
991 | ||||
975 | else: |
|
992 | else: | |
976 | kwargs['rate'] = '' |
|
993 | kwargs['rate_bh'] = '' | |
|
994 | kwargs['rate_gh'] = '' | |||
|
995 | kwargs['va'] = '' | |||
|
996 | kwargs['time_per_block'] = '' | |||
|
997 | kwargs['acqtime'] = '' | |||
|
998 | kwargs['vrange'] = '' | |||
977 |
|
999 | |||
978 | ###### SIDEBAR ###### |
|
1000 | ###### SIDEBAR ###### | |
979 | kwargs.update(sidebar(experiment=experiment)) |
|
1001 | kwargs.update(sidebar(experiment=experiment)) | |
@@ -985,7 +1007,7 def experiment_summary(request, id_exp): | |||||
985 | def experiment_verify(request, id_exp): |
|
1007 | def experiment_verify(request, id_exp): | |
986 |
|
1008 | |||
987 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
1009 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
988 |
experiment_data = |
|
1010 | experiment_data = experiment.parms_to_dict() | |
989 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
1011 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
990 |
|
1012 | |||
991 | kwargs = {} |
|
1013 | kwargs = {} | |
@@ -1012,14 +1034,14 def experiment_verify(request, id_exp): | |||||
1012 | jars_conf = True |
|
1034 | jars_conf = True | |
1013 | jars = configuration |
|
1035 | jars = configuration | |
1014 | kwargs['jars_conf'] = jars_conf |
|
1036 | kwargs['jars_conf'] = jars_conf | |
1015 |
filter_parms = |
|
1037 | filter_parms = jars.filter_parms | |
1016 | filter_parms = ast.literal_eval(filter_parms) |
|
1038 | filter_parms = ast.literal_eval(filter_parms) | |
1017 | kwargs['filter_parms'] = filter_parms |
|
1039 | kwargs['filter_parms'] = filter_parms | |
1018 | #--Sampling Frequency |
|
1040 | #--Sampling Frequency | |
1019 | clock = filter_parms['clock'] |
|
1041 | clock = eval(filter_parms['clock']) | |
1020 | filter_2 = filter_parms['filter_2'] |
|
1042 | filter_2 = eval(filter_parms['filter_2']) | |
1021 | filter_5 = filter_parms['filter_5'] |
|
1043 | filter_5 = eval(filter_parms['filter_5']) | |
1022 | filter_fir = filter_parms['filter_fir'] |
|
1044 | filter_fir = eval(filter_parms['filter_fir']) | |
1023 | samp_freq_jars = clock/filter_2/filter_5/filter_fir |
|
1045 | samp_freq_jars = clock/filter_2/filter_5/filter_fir | |
1024 |
|
1046 | |||
1025 | kwargs['samp_freq_jars'] = samp_freq_jars |
|
1047 | kwargs['samp_freq_jars'] = samp_freq_jars | |
@@ -1055,15 +1077,15 def experiment_verify(request, id_exp): | |||||
1055 | #------------Validation------------: |
|
1077 | #------------Validation------------: | |
1056 | #Clock |
|
1078 | #Clock | |
1057 | if dds_conf and rc_conf and jars_conf: |
|
1079 | if dds_conf and rc_conf and jars_conf: | |
1058 | if float(filter_parms['clock']) != float(rc_parms['clock_in']) and float(rc_parms['clock_in']) != float(dds_parms['clock']): |
|
1080 | 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']): | |
1059 | messages.warning(request, "Devices don't have the same clock.") |
|
1081 | messages.warning(request, "Devices don't have the same clock.") | |
1060 | elif rc_conf and jars_conf: |
|
1082 | elif rc_conf and jars_conf: | |
1061 | if float(filter_parms['clock']) != float(rc_parms['clock_in']): |
|
1083 | if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']): | |
1062 | messages.warning(request, "Devices don't have the same clock.") |
|
1084 | messages.warning(request, "Devices don't have the same clock.") | |
1063 | elif rc_conf and dds_conf: |
|
1085 | elif rc_conf and dds_conf: | |
1064 | if float(rc_parms['clock_in']) != float(dds_parms['clock']): |
|
1086 | if float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']): | |
1065 | messages.warning(request, "Devices don't have the same clock.") |
|
1087 | messages.warning(request, "Devices don't have the same clock.") | |
1066 | if float(samp_freq_rc) != float(dds_parms['frequencyA']): |
|
1088 | if float(samp_freq_rc) != float(dds_parms['configurations']['byId'][str(dds.pk)]['frequencyA']): | |
1067 | messages.warning(request, "Devices don't have the same Frequency A.") |
|
1089 | messages.warning(request, "Devices don't have the same Frequency A.") | |
1068 |
|
1090 | |||
1069 |
|
1091 | |||
@@ -1228,7 +1250,7 def dev_conf_new(request, id_exp=0, id_dev=0): | |||||
1228 | id_dev = conf.device.pk |
|
1250 | id_dev = conf.device.pk | |
1229 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1251 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1230 | form = DevConfForm(instance=conf, |
|
1252 | form = DevConfForm(instance=conf, | |
1231 |
initial={'name': '{} |
|
1253 | initial={'name': '{}_{:%y%m%d}'.format(conf.name, datetime.now()), | |
1232 | 'template': False, |
|
1254 | 'template': False, | |
1233 | 'experiment':id_exp}) |
|
1255 | 'experiment':id_exp}) | |
1234 | elif 'blank' in request.GET: |
|
1256 | elif 'blank' in request.GET: | |
@@ -1252,6 +1274,15 def dev_conf_new(request, id_exp=0, id_dev=0): | |||||
1252 | for line in lines: |
|
1274 | for line in lines: | |
1253 | line.clone(rc_configuration=conf) |
|
1275 | line.clone(rc_configuration=conf) | |
1254 |
|
1276 | |||
|
1277 | new_lines = conf.get_lines() | |||
|
1278 | for line in new_lines: | |||
|
1279 | line_params = json.loads(line.params) | |||
|
1280 | if 'TX_ref' in line_params: | |||
|
1281 | ref_line = RCLine.objects.get(pk=line_params['TX_ref']) | |||
|
1282 | line_params['TX_ref'] = ['{}'.format(l.pk) for l in new_lines if l.get_name()==ref_line.get_name()][0] | |||
|
1283 | line.params = json.dumps(line_params) | |||
|
1284 | line.save() | |||
|
1285 | ||||
1255 | if conf.device.device_type.name=='jars': |
|
1286 | if conf.device.device_type.name=='jars': | |
1256 | conf.add_parms_to_filter() |
|
1287 | conf.add_parms_to_filter() | |
1257 |
|
1288 | |||
@@ -1342,6 +1373,19 def dev_conf_status(request, id_conf): | |||||
1342 |
|
1373 | |||
1343 |
|
1374 | |||
1344 | @user_passes_test(lambda u:u.is_staff) |
|
1375 | @user_passes_test(lambda u:u.is_staff) | |
|
1376 | def dev_conf_reset(request, id_conf): | |||
|
1377 | ||||
|
1378 | conf = get_object_or_404(Configuration, pk=id_conf) | |||
|
1379 | ||||
|
1380 | if conf.reset_device(): | |||
|
1381 | messages.success(request, conf.message) | |||
|
1382 | else: | |||
|
1383 | messages.error(request, conf.message) | |||
|
1384 | ||||
|
1385 | return redirect(conf.get_absolute_url()) | |||
|
1386 | ||||
|
1387 | ||||
|
1388 | @user_passes_test(lambda u:u.is_staff) | |||
1345 | def dev_conf_write(request, id_conf): |
|
1389 | def dev_conf_write(request, id_conf): | |
1346 |
|
1390 | |||
1347 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1391 | conf = get_object_or_404(Configuration, pk=id_conf) | |
@@ -1409,10 +1453,11 def dev_conf_import(request, id_conf): | |||||
1409 |
|
1453 | |||
1410 | if file_form.is_valid(): |
|
1454 | if file_form.is_valid(): | |
1411 |
|
1455 | |||
1412 |
|
|
1456 | data = conf.import_from_file(request.FILES['file']) | |
|
1457 | parms = Params(data=data).get_conf(dtype=conf.device.device_type.name) | |||
1413 |
|
1458 | |||
1414 | if parms: |
|
1459 | if parms: | |
1415 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
1460 | ||
1416 | form = DevConfForm(initial=parms, instance=conf) |
|
1461 | form = DevConfForm(initial=parms, instance=conf) | |
1417 |
|
1462 | |||
1418 | kwargs = {} |
|
1463 | kwargs = {} | |
@@ -1427,6 +1472,8 def dev_conf_import(request, id_conf): | |||||
1427 | ###### SIDEBAR ###### |
|
1472 | ###### SIDEBAR ###### | |
1428 | kwargs.update(sidebar(conf=conf)) |
|
1473 | kwargs.update(sidebar(conf=conf)) | |
1429 |
|
1474 | |||
|
1475 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |||
|
1476 | ||||
1430 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1477 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1431 |
|
1478 | |||
1432 | messages.error(request, "Could not import parameters from file") |
|
1479 | messages.error(request, "Could not import parameters from file") |
General Comments 0
You need to be logged in to leave comments.
Login now