@@ -1,11 +1,13 | |||
|
1 | [ | |
|
1 | [[ | |
|
2 | 2 | {"fields": {"name": "JRO", "description": ""}, "model": "main.location", "pk": 1}, |
|
3 | 3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, |
|
4 | 4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, |
|
5 | 5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, |
|
6 | {"fields": {"name": "CLAIRE", "description": ""}, "model": "main.location", "pk": 4}, | |
|
6 | 7 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, |
|
7 | 8 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, |
|
8 | 9 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, |
|
9 | 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 | 1 | from django import forms |
|
2 | 2 | from django.utils.safestring import mark_safe |
|
3 | from .models import Device, Experiment, Campaign, Location | |
|
4 | from apps.main.models import Configuration | |
|
3 | from apps.main.models import Device, Experiment, Campaign, Location, Configuration | |
|
5 | 4 | from django.template.defaultfilters import default |
|
6 | 5 | |
|
7 | 6 | FILE_FORMAT = ( |
@@ -80,6 +79,12 class ExperimentForm(forms.ModelForm): | |||
|
80 | 79 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
81 | 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 | 88 | class Meta: |
|
84 | 89 | model = Experiment |
|
85 | 90 | exclude = ['status'] |
@@ -106,10 +111,6 class ConfigurationForm(forms.ModelForm): | |||
|
106 | 111 | model = Configuration |
|
107 | 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 | 114 | class UploadFileForm(forms.Form): |
|
114 | 115 | |
|
115 | 116 | file = forms.FileField() |
@@ -188,5 +189,5 class ChangeIpForm(forms.Form): | |||
|
188 | 189 | ip_address = forms.GenericIPAddressField() |
|
189 | 190 | mask = forms.GenericIPAddressField(initial='255.255.255.0') |
|
190 | 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 | 4 | import requests |
|
5 | import time | |
|
3 | 6 | from datetime import datetime |
|
4 | from django.template.base import kwarg_re | |
|
5 | 7 | |
|
6 | 8 | try: |
|
7 | 9 | from polymorphic.models import PolymorphicModel |
|
8 | 10 | except: |
|
9 | 11 | from polymorphic import PolymorphicModel |
|
10 | 12 | |
|
13 | from django.template.base import kwarg_re | |
|
11 | 14 | from django.db import models |
|
12 | 15 | from django.core.urlresolvers import reverse |
|
16 | from django.core.validators import MinValueValidator, MaxValueValidator | |
|
13 | 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 | 21 | from devices.dds import api as dds_api |
|
22 | from devices.dds import data as dds_data | |
|
16 | 23 | |
|
17 | EXP_STATES = ( | |
|
18 | (0,'Error'), #RED | |
|
19 | (1,'Configured'), #BLUE | |
|
20 | (2,'Running'), #GREEN | |
|
21 | (3,'Scheduled'), #YELLOW | |
|
22 | (4,'Not Configured'), #WHITE | |
|
24 | ||
|
25 | DEV_PORTS = { | |
|
26 | 'rc' : 2000, | |
|
27 | 'dds' : 2000, | |
|
28 | 'jars' : 2000, | |
|
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 |
|
|
|
26 |
(0, ' |
|
|
27 |
(1, ' |
|
|
42 | EXPERIMENT_TYPE = ( | |
|
43 | (0, 'RAW_DATA'), | |
|
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 | 54 | DEV_STATES = ( |
@@ -45,23 +69,18 DEV_TYPES = ( | |||
|
45 | 69 | ('abs', 'Automatic Beam Switching'), |
|
46 | 70 | ) |
|
47 | 71 | |
|
48 | DEV_PORTS = { | |
|
49 | 'rc' : 2000, | |
|
50 | 'dds' : 2000, | |
|
51 | 'jars' : 2000, | |
|
52 | 'usrp' : 2000, | |
|
53 | 'cgs' : 8080, | |
|
54 | 'abs' : 8080 | |
|
55 | } | |
|
56 | ||
|
57 | RADAR_STATES = ( | |
|
58 | (0, 'No connected'), | |
|
59 | (1, 'Connected'), | |
|
60 | (2, 'Configured'), | |
|
61 | (3, 'Running'), | |
|
62 | (4, 'Scheduled'), | |
|
72 | EXP_STATES = ( | |
|
73 | (0,'Error'), #RED | |
|
74 | (1,'Configured'), #BLUE | |
|
75 | (2,'Running'), #GREEN | |
|
76 | (3,'Scheduled'), #YELLOW | |
|
77 | (4,'Not Configured'), #WHITE | |
|
63 | 78 | ) |
|
64 | 79 | |
|
80 | CONF_TYPES = ( | |
|
81 | (0, 'Active'), | |
|
82 | (1, 'Historical'), | |
|
83 | ) | |
|
65 | 84 | |
|
66 | 85 | class Location(models.Model): |
|
67 | 86 | |
@@ -136,7 +155,7 class Device(models.Model): | |||
|
136 | 155 | |
|
137 | 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 | 160 | if self.device_type.name=='dds': |
|
142 | 161 | try: |
@@ -157,11 +176,22 class Device(models.Model): | |||
|
157 | 176 | return False |
|
158 | 177 | |
|
159 | 178 | elif self.device_type.name=='rc': |
|
160 | payload = {'ip': ip_address, | |
|
161 | 'dns': kwargs.get('dns', '8.8.8.8'), | |
|
162 | 'gateway': gateway, | |
|
163 | 'subnet': mask} | |
|
164 | req = requests.post(self.url('changeip'), data=payload) | |
|
179 | headers = {'content-type': "application/json", | |
|
180 | 'cache-control': "no-cache"} | |
|
181 | ||
|
182 | ip = [int(x) for x in ip_address.split('.')] | |
|
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 | 195 | try: |
|
166 | 196 | answer = req.json() |
|
167 | 197 | if answer['changeip']=='ok': |
@@ -199,73 +229,61 class Campaign(models.Model): | |||
|
199 | 229 | else: |
|
200 | 230 | return u'{}'.format(self.name) |
|
201 | 231 | |
|
202 |
def |
|
|
203 | ||
|
204 | import json | |
|
232 | def jsonify(self): | |
|
205 | 233 | |
|
206 |
|
|
|
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 | |
|
234 | data = {} | |
|
214 | 235 | |
|
236 | ignored = ('template') | |
|
215 | 237 | |
|
216 | parameters['experiments'] = exp_parameters | |
|
217 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
|
218 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
|
219 | parameters['campaign'] = self.__str__() | |
|
220 | parameters['tags'] =self.tags | |
|
238 | for field in self._meta.fields: | |
|
239 | if field.name in ignored: | |
|
240 | continue | |
|
241 | data[field.name] = field.value_from_object(self) | |
|
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': | |
|
235 | parms = json.loads(fp.read()) | |
|
236 | ||
|
237 | return parms | |
|
263 | return params.data | |
|
238 | 264 | |
|
239 | 265 | def dict_to_parms(self, parms, CONF_MODELS): |
|
240 | 266 | |
|
241 | 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 | 269 | if experiments: |
|
249 | 270 | for experiment in experiments: |
|
250 | 271 | experiment.delete() |
|
251 | 272 | |
|
252 |
for |
|
|
253 | location = Location.objects.get(name = parms['experiments'][parms_exp]['radar']) | |
|
254 | new_exp = Experiment( | |
|
255 | name = parms['experiments'][parms_exp]['experiment'], | |
|
256 | location = location, | |
|
257 | start_time = parms['experiments'][parms_exp]['start_time'], | |
|
258 | end_time = parms['experiments'][parms_exp]['end_time'], | |
|
259 | ) | |
|
260 | new_exp.save() | |
|
261 | new_exp.dict_to_parms(parms['experiments'][parms_exp],CONF_MODELS) | |
|
262 | new_exp.save() | |
|
263 | ||
|
264 |
|
|
|
265 |
|
|
|
266 | self.end_date = parms['end_date'] | |
|
267 | self.tags = parms['tags'] | |
|
268 | self.experiments.add(new_exp) | |
|
273 | for id_exp in parms['experiments']['allIds']: | |
|
274 | exp_parms = parms['experiments']['byId'][id_exp] | |
|
275 | dum = (datetime.now() - datetime(1970, 1, 1)).total_seconds() | |
|
276 | exp = Experiment(name='{}'.format(dum)) | |
|
277 | exp.save() | |
|
278 | exp.dict_to_parms(parms, CONF_MODELS, id_exp=id_exp) | |
|
279 | self.experiments.add(exp) | |
|
280 | ||
|
281 | camp_parms = parms['campaigns']['byId'][parms['campaigns']['allIds'][0]] | |
|
282 | ||
|
283 | self.name = '{}-{}'.format(camp_parms['name'], datetime.now().strftime('%y%m%d')) | |
|
284 | self.start_date = camp_parms['start_date'] | |
|
285 | self.end_date = camp_parms['end_date'] | |
|
286 | self.tags = camp_parms['tags'] | |
|
269 | 287 |
|
|
270 | 288 | |
|
271 | 289 | return self |
@@ -326,6 +344,25 class Experiment(models.Model): | |||
|
326 | 344 | else: |
|
327 | 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 | 366 | @property |
|
330 | 367 | def radar_system(self): |
|
331 | 368 | return self.location |
@@ -353,27 +390,24 class Experiment(models.Model): | |||
|
353 | 390 | |
|
354 | 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 | 394 | #Only Configured Devices. |
|
358 | 395 | for conf in confs: |
|
359 | if conf.device.device_type.name == 'rc': | |
|
360 | continue | |
|
361 | #if conf.device.status in [0,4]: | |
|
362 |
|
|
|
363 | # return result | |
|
364 | for conf in confs: | |
|
365 | if conf.device.device_type.name == 'rc': | |
|
366 |
|
|
|
367 |
|
|
|
368 | pass#conf.write_device() | |
|
369 |
|
|
|
370 |
|
|
|
371 | #Start Device | |
|
372 | for conf in confs: | |
|
373 | if conf.device.device_type.name == 'rc': | |
|
374 | continue | |
|
375 | print 'start: '#conf.start_device() | |
|
376 | print conf | |
|
396 | dev_status = conf.device.status | |
|
397 | if dev_status in [0,4]: | |
|
398 | result = 0 | |
|
399 | return result | |
|
400 | else: | |
|
401 | if conf.device.device_type.name != 'jars': | |
|
402 | conf.write_device() | |
|
403 | time.sleep(1) | |
|
404 | print conf.device.name+' has started...' | |
|
405 | else: | |
|
406 | conf.stop_device() | |
|
407 | conf.write_device() | |
|
408 | conf.start_device() | |
|
409 | print conf.device.name+' has started...' | |
|
410 | ||
|
377 | 411 | return result |
|
378 | 412 | |
|
379 | 413 | |
@@ -385,33 +419,22 class Experiment(models.Model): | |||
|
385 | 419 | |
|
386 | 420 | result = 1 |
|
387 | 421 | |
|
388 |
confs = Configuration.objects.filter(experiment=self).order_by(' |
|
|
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 | |
|
422 | confs = Configuration.objects.filter(experiment=self).filter(type = 0).order_by('device__device_type__sequence') | |
|
403 | 423 | |
|
404 | 424 | for conf in confs: |
|
405 | if conf.device.device_type.name == 'jars': | |
|
406 | #conf.stop_device() | |
|
407 | confs=confs.exclude(device__device_type__name='jars') | |
|
408 |
|
|
|
425 | dev_status = conf.device.status | |
|
426 | if dev_status in [0,4]: | |
|
427 | result = 0 | |
|
428 | return result | |
|
409 | 429 | |
|
430 | #Stop Device | |
|
431 | confs=confs.exclude(device__device_type__name='cgs') | |
|
410 | 432 | for conf in confs: |
|
411 |
if conf.device.device_type.name |
|
|
412 |
con |
|
|
413 | print 'start: '#conf.stop_device() | |
|
414 | print conf | |
|
433 | if conf.device.device_type.name != 'rc': | |
|
434 | conf.stop_device() | |
|
435 | else: | |
|
436 | conf.reset_device() | |
|
437 | print conf.device.name+' has stopped...' | |
|
415 | 438 | |
|
416 | 439 | return result |
|
417 | 440 | |
@@ -451,79 +474,48 class Experiment(models.Model): | |||
|
451 | 474 | |
|
452 | 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 |
|
|
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): | |
|
480 | configurations = Configuration.objects.filter(experiment=self, type=0) | |
|
473 | 481 | |
|
474 | import os, json | |
|
475 | ||
|
476 | parms = {} | |
|
477 | ||
|
478 | path, ext = os.path.splitext(fp.name) | |
|
479 | ||
|
480 | if ext == '.json': | |
|
481 | parms = json.loads(fp.read().decode('utf-8')) | |
|
482 | for conf in configurations: | |
|
483 | params.add(conf.jsonify(), 'configurations') | |
|
484 | if conf.device.device_type.name=='rc': | |
|
485 | for line in conf.get_lines(): | |
|
486 | params.add(line.jsonify(), 'lines') | |
|
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 | 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 | 499 | if configurations: |
|
490 | 500 | for configuration in configurations: |
|
491 | 501 | configuration.delete() |
|
492 | #If device is missing. | |
|
493 |
for conf |
|
|
494 | try: | |
|
495 |
|
|
|
496 | except: | |
|
497 | return {'Error': 'Device is not in database. Please create new '+str(parms['configurations'][configuration]['device_type'])+ ' device.'} | |
|
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( | |
|
502 | ||
|
503 | for id_conf in exp_parms['configurations']: | |
|
504 | conf_parms = parms['configurations']['byId'][id_conf] | |
|
505 | device = Device.objects.filter(device_type__name=conf_parms['device_type'])[0] | |
|
506 | model = CONF_MODELS[conf_parms['device_type']] | |
|
507 | conf = model( | |
|
514 | 508 |
|
|
515 | name = configuration, | |
|
516 | 509 |
|
|
517 | 510 | ) |
|
518 |
|
|
|
519 | new_conf.save() | |
|
511 | conf.dict_to_parms(parms, id=id_conf) | |
|
520 | 512 | |
|
521 | 513 | |
|
522 |
location = Location.objects.get(name |
|
|
523 | self.name = parms['experiment'] | |
|
514 | location, created = Location.objects.get_or_create(name=exp_parms['location']) | |
|
515 | self.name = '{}-{}'.format(exp_parms['name'], datetime.now().strftime('%y%m%d')) | |
|
524 | 516 |
self.location |
|
525 | self.start_time = parms['start_time'] | |
|
526 |
self.end_time |
|
|
517 | self.start_time = exp_parms['start_time'] | |
|
518 | self.end_time = exp_parms['end_time'] | |
|
527 | 519 | self.save() |
|
528 | 520 | |
|
529 | 521 | return self |
@@ -581,6 +573,37 class Configuration(PolymorphicModel): | |||
|
581 | 573 | else: |
|
582 | 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 | 607 | def clone(self, **kwargs): |
|
585 | 608 | |
|
586 | 609 | self.pk = None |
@@ -594,12 +617,14 class Configuration(PolymorphicModel): | |||
|
594 | 617 | |
|
595 | 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(): | |
|
600 | parameters[key] = getattr(self, key) | |
|
623 | if self.device.device_type.name=='rc': | |
|
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 | 629 | def parms_to_text(self): |
|
605 | 630 | |
@@ -611,17 +636,28 class Configuration(PolymorphicModel): | |||
|
611 | 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({}): | |
|
617 | return | |
|
641 | params = Params(parameters) | |
|
618 | 642 | |
|
619 | for key in parameters.keys(): | |
|
620 | setattr(self, key, parameters[key]) | |
|
643 | if id: | |
|
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 | 662 | content_type = '' |
|
627 | 663 | |
@@ -632,7 +668,7 class Configuration(PolymorphicModel): | |||
|
632 | 668 | |
|
633 | 669 | if format == 'binary': |
|
634 | 670 | content_type = 'application/octet-stream' |
|
635 |
filename = '%s_%s. |
|
|
671 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
|
636 | 672 | content = self.parms_to_binary() |
|
637 | 673 | |
|
638 | 674 | if not content_type: |
@@ -649,8 +685,6 class Configuration(PolymorphicModel): | |||
|
649 | 685 | |
|
650 | 686 | def import_from_file(self, fp): |
|
651 | 687 | |
|
652 | import os, json | |
|
653 | ||
|
654 | 688 | parms = {} |
|
655 | 689 | |
|
656 | 690 | path, ext = os.path.splitext(fp.name) |
@@ -658,6 +692,13 class Configuration(PolymorphicModel): | |||
|
658 | 692 | if ext == '.json': |
|
659 | 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 | 702 | return parms |
|
662 | 703 | |
|
663 | 704 | def status_device(self): |
@@ -479,7 +479,7 def campaign_export(request, id_camp): | |||
|
479 | 479 | |
|
480 | 480 | response = HttpResponse(content_type=content_type) |
|
481 | 481 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
482 | response.write(content) | |
|
482 | response.write(json.dumps(content, indent=2)) | |
|
483 | 483 | |
|
484 | 484 | return response |
|
485 | 485 | |
@@ -496,16 +496,8 def campaign_import(request, id_camp): | |||
|
496 | 496 | file_form = UploadFileForm(request.POST, request.FILES) |
|
497 | 497 | |
|
498 | 498 | if file_form.is_valid(): |
|
499 | ||
|
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 | ||
|
499 | new_camp = campaign.dict_to_parms(json.load(request.FILES['file']), CONF_MODELS) | |
|
507 | 500 |
|
|
508 | ||
|
509 | 501 |
|
|
510 | 502 | |
|
511 | 503 | messages.error(request, "Could not import parameters from file") |
@@ -543,12 +535,12 def experiments(request): | |||
|
543 | 535 | def experiment(request, id_exp): |
|
544 | 536 | |
|
545 | 537 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
546 | #experiment.get_status() | |
|
538 | ||
|
547 | 539 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
548 | 540 | |
|
549 | 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 | 544 | kwargs['experiment'] = experiment |
|
553 | 545 | |
|
554 | 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 | 573 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
582 | 574 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
583 | 575 | form = ExperimentForm(instance=exp, |
|
584 |
initial={'name': '{} |
|
|
576 | initial={'name': '{}_{:%y%m%d}'.format(exp.name, datetime.now()), | |
|
585 | 577 | 'template': False}) |
|
586 | 578 | elif 'blank' in request.GET: |
|
587 | 579 | kwargs['button'] = 'Create' |
@@ -668,7 +660,7 def experiment_export(request, id_exp): | |||
|
668 | 660 | |
|
669 | 661 | response = HttpResponse(content_type=content_type) |
|
670 | 662 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
671 | response.write(content) | |
|
663 | response.write(json.dumps(content, indent=2)) | |
|
672 | 664 | |
|
673 | 665 | return response |
|
674 | 666 | |
@@ -686,19 +678,8 def experiment_import(request, id_exp): | |||
|
686 | 678 | file_form = UploadFileForm(request.POST, request.FILES) |
|
687 | 679 | |
|
688 | 680 | if file_form.is_valid(): |
|
689 | ||
|
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 | ||
|
681 | new_exp = experiment.dict_to_parms(json.load(request.FILES['file']), CONF_MODELS) | |
|
700 | 682 |
|
|
701 | ||
|
702 | 683 |
|
|
703 | 684 | |
|
704 | 685 | messages.error(request, "Could not import parameters from file") |
@@ -717,32 +698,19 def experiment_import(request, id_exp): | |||
|
717 | 698 | @user_passes_test(lambda u:u.is_staff) |
|
718 | 699 | def experiment_start(request, id_exp): |
|
719 | 700 | |
|
720 | exp = get_object_or_404(Experiment, pk=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()) | |
|
701 | def experiment_start(request, id_exp): | |
|
732 | 702 | |
|
733 | exp.get_status() | |
|
703 | exp = get_object_or_404(Experiment, pk=id_exp) | |
|
734 | 704 | |
|
735 | 705 | if exp.status == 2: |
|
736 |
messages.warning(request, 'Experiment {} already runn |
|
|
706 | messages.warning(request, 'Experiment {} already runnnig'.format(exp)) | |
|
737 | 707 | else: |
|
738 | task = task_start.delay(exp.pk) | |
|
739 | exp.status = task.wait() | |
|
740 | ||
|
708 | exp.status = exp.start() | |
|
741 | 709 | if exp.status==0: |
|
742 | 710 | messages.error(request, 'Experiment {} not start'.format(exp)) |
|
743 | 711 | if exp.status==2: |
|
744 | 712 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
745 | task_status.delay(exp.pk) #background get_status function | |
|
713 | ||
|
746 | 714 | exp.save() |
|
747 | 715 | |
|
748 | 716 | return redirect(exp.get_absolute_url()) |
@@ -752,24 +720,26 def experiment_start(request, id_exp): | |||
|
752 | 720 | def experiment_stop(request, id_exp): |
|
753 | 721 | |
|
754 | 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 | 724 | if exp.status == 2: |
|
763 | task = task_stop.delay(exp.pk) | |
|
764 | exp.status = task.wait() | |
|
765 | messages.warning(request, 'Experiment {} stopped'.format(exp)) | |
|
725 | exp.status = exp.stop() | |
|
766 | 726 | exp.save() |
|
727 | messages.success(request, 'Experiment {} stopped'.format(exp)) | |
|
767 | 728 | else: |
|
768 | 729 | messages.error(request, 'Experiment {} not running'.format(exp)) |
|
769 | 730 | |
|
770 | 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 | 743 | @user_passes_test(lambda u:u.is_staff) |
|
774 | 744 | def experiment_mix(request, id_exp): |
|
775 | 745 | |
@@ -882,7 +852,7 def experiment_summary(request, id_exp): | |||
|
882 | 852 | |
|
883 | 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 | 856 | kwargs['experiment'] = experiment |
|
887 | 857 | |
|
888 | 858 | kwargs['configurations'] = [] |
@@ -892,8 +862,15 def experiment_summary(request, id_exp): | |||
|
892 | 862 | |
|
893 | 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 | 870 | jars_conf = False |
|
896 | 871 | rc_conf = False |
|
872 | code_id = 0 | |
|
873 | tx_line = {} | |
|
897 | 874 | |
|
898 | 875 | for configuration in configurations: |
|
899 | 876 | |
@@ -907,6 +884,9 def experiment_summary(request, id_exp): | |||
|
907 | 884 | configuration.tx_lines = [] |
|
908 | 885 | |
|
909 | 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 | 890 | line = {'name':tx_line.get_name()} |
|
911 | 891 | tx_params = json.loads(tx_line.params) |
|
912 | 892 | line['width'] = tx_params['pulse_width'] |
@@ -922,6 +902,7 def experiment_summary(request, id_exp): | |||
|
922 | 902 | |
|
923 | 903 | for code_line in configuration.get_lines(line_type__name='codes'): |
|
924 | 904 | code_params = json.loads(code_line.params) |
|
905 | code_id = code_params['code'] | |
|
925 | 906 | if tx_line.pk==int(code_params['TX_ref']): |
|
926 | 907 | line['codes'] = '{}:{}'.format(RCLineCode.objects.get(pk=code_params['code']), |
|
927 | 908 | '-'.join(code_params['codes'])) |
@@ -930,12 +911,16 def experiment_summary(request, id_exp): | |||
|
930 | 911 | win_params = json.loads(windows_line.params) |
|
931 | 912 | if tx_line.pk==int(win_params['TX_ref']): |
|
932 | 913 | windows = '' |
|
914 | nsa = win_params['params'][0]['number_of_samples'] | |
|
933 | 915 | for i, params in enumerate(win_params['params']): |
|
934 | 916 | windows += 'W{}: Ho={first_height} km DH={resolution} km NSA={number_of_samples}<br>'.format(i, **params) |
|
935 | 917 | line['windows'] = mark_safe(windows) |
|
936 | 918 | |
|
937 | 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 | 924 | #-------------------- JARS -----------------------: |
|
940 | 925 | if configuration.device.device_type.name == 'jars': |
|
941 | 926 | jars_conf = True |
@@ -946,34 +931,71 def experiment_summary(request, id_exp): | |||
|
946 | 931 | filter_parms = configuration.filter_parms |
|
947 | 932 | filter_parms = ast.literal_eval(filter_parms) |
|
948 | 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 | 941 | kwargs['configurations'].append(configuration) |
|
952 | 942 | |
|
953 | 943 | |
|
954 | 944 | #------ RC & JARS ------: |
|
955 | ipp = 937.5 # | |
|
956 | nsa = 200# | |
|
957 | dh = 1.5 # | |
|
958 | channels_number = 5 # | |
|
959 | ||
|
960 | 945 | if rc_conf and jars_conf: |
|
946 | #RC filter values: | |
|
947 | ||
|
961 | 948 | if exp_type == 0: #Short |
|
962 | bytes = 2 | |
|
963 | b = nsa*2*bytes*channels_number | |
|
949 | bytes_ = 2 | |
|
950 | b = nsa*2*bytes_*channels_number | |
|
964 | 951 | else: #Float |
|
965 | bytes = 4 | |
|
952 | bytes_ = 4 | |
|
966 | 953 | channels = channels_number + spectral_number |
|
967 | b = nsa*2*bytes*fftpoints*channels | |
|
968 | ||
|
969 | ipps = (ipp*pow(10,-6))/0.15 | |
|
970 | GB = 1048576.0*1024.0 | |
|
971 |
|
|
|
972 | rate = b/ipps | |
|
973 | rate = rate *(1/GB)*(Hour) | |
|
974 | kwargs['rate'] = str(rate)+" GB/h" | |
|
954 | b = nsa*2*bytes_*fftpoints*channels | |
|
955 | ||
|
956 | codes_num = 7 | |
|
957 | if code_id == 2: | |
|
958 | codes_num = 7 | |
|
959 | elif code_id == 12: | |
|
960 | codes_num = 15 | |
|
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 | 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 | 1000 | ###### SIDEBAR ###### |
|
979 | 1001 | kwargs.update(sidebar(experiment=experiment)) |
@@ -985,7 +1007,7 def experiment_summary(request, id_exp): | |||
|
985 | 1007 | def experiment_verify(request, id_exp): |
|
986 | 1008 | |
|
987 | 1009 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
988 |
experiment_data = |
|
|
1010 | experiment_data = experiment.parms_to_dict() | |
|
989 | 1011 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
990 | 1012 | |
|
991 | 1013 | kwargs = {} |
@@ -1012,14 +1034,14 def experiment_verify(request, id_exp): | |||
|
1012 | 1034 | jars_conf = True |
|
1013 | 1035 | jars = configuration |
|
1014 | 1036 | kwargs['jars_conf'] = jars_conf |
|
1015 |
filter_parms = |
|
|
1037 | filter_parms = jars.filter_parms | |
|
1016 | 1038 | filter_parms = ast.literal_eval(filter_parms) |
|
1017 | 1039 | kwargs['filter_parms'] = filter_parms |
|
1018 | 1040 | #--Sampling Frequency |
|
1019 | clock = filter_parms['clock'] | |
|
1020 | filter_2 = filter_parms['filter_2'] | |
|
1021 | filter_5 = filter_parms['filter_5'] | |
|
1022 | filter_fir = filter_parms['filter_fir'] | |
|
1041 | clock = eval(filter_parms['clock']) | |
|
1042 | filter_2 = eval(filter_parms['filter_2']) | |
|
1043 | filter_5 = eval(filter_parms['filter_5']) | |
|
1044 | filter_fir = eval(filter_parms['filter_fir']) | |
|
1023 | 1045 | samp_freq_jars = clock/filter_2/filter_5/filter_fir |
|
1024 | 1046 | |
|
1025 | 1047 | kwargs['samp_freq_jars'] = samp_freq_jars |
@@ -1055,15 +1077,15 def experiment_verify(request, id_exp): | |||
|
1055 | 1077 | #------------Validation------------: |
|
1056 | 1078 | #Clock |
|
1057 | 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 | 1081 | messages.warning(request, "Devices don't have the same clock.") |
|
1060 | 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 | 1084 | messages.warning(request, "Devices don't have the same clock.") |
|
1063 | 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 | 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 | 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 | 1250 | id_dev = conf.device.pk |
|
1229 | 1251 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1230 | 1252 | form = DevConfForm(instance=conf, |
|
1231 |
initial={'name': '{} |
|
|
1253 | initial={'name': '{}_{:%y%m%d}'.format(conf.name, datetime.now()), | |
|
1232 | 1254 | 'template': False, |
|
1233 | 1255 | 'experiment':id_exp}) |
|
1234 | 1256 | elif 'blank' in request.GET: |
@@ -1252,6 +1274,15 def dev_conf_new(request, id_exp=0, id_dev=0): | |||
|
1252 | 1274 | for line in lines: |
|
1253 | 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 | 1286 | if conf.device.device_type.name=='jars': |
|
1256 | 1287 | conf.add_parms_to_filter() |
|
1257 | 1288 | |
@@ -1342,6 +1373,19 def dev_conf_status(request, id_conf): | |||
|
1342 | 1373 | |
|
1343 | 1374 | |
|
1344 | 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 | 1389 | def dev_conf_write(request, id_conf): |
|
1346 | 1390 | |
|
1347 | 1391 | conf = get_object_or_404(Configuration, pk=id_conf) |
@@ -1409,10 +1453,11 def dev_conf_import(request, id_conf): | |||
|
1409 | 1453 | |
|
1410 | 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 | 1459 | if parms: |
|
1415 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
|
1460 | ||
|
1416 | 1461 | form = DevConfForm(initial=parms, instance=conf) |
|
1417 | 1462 | |
|
1418 | 1463 | kwargs = {} |
@@ -1427,6 +1472,8 def dev_conf_import(request, id_conf): | |||
|
1427 | 1472 | ###### SIDEBAR ###### |
|
1428 | 1473 | kwargs.update(sidebar(conf=conf)) |
|
1429 | 1474 | |
|
1475 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
|
1476 | ||
|
1430 | 1477 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1431 | 1478 | |
|
1432 | 1479 | messages.error(request, "Could not import parameters from file") |
General Comments 0
You need to be logged in to leave comments.
Login now