@@ -37,6 +37,7 class CGSConfiguration(Configuration): | |||||
37 | parameters = {} |
|
37 | parameters = {} | |
38 |
|
38 | |||
39 | parameters['device_id'] = self.device.id |
|
39 | parameters['device_id'] = self.device.id | |
|
40 | parameters['device_type'] = self.device.device_type.name | |||
40 |
|
41 | |||
41 | if self.freq0 == None or self.freq0 == '': |
|
42 | if self.freq0 == None or self.freq0 == '': | |
42 | parameters['freq0'] = 0 |
|
43 | parameters['freq0'] = 0 |
@@ -74,6 +74,7 class DDSConfiguration(Configuration): | |||||
74 | parameters = {} |
|
74 | parameters = {} | |
75 |
|
75 | |||
76 | parameters['device_id'] = self.device.id |
|
76 | parameters['device_id'] = self.device.id | |
|
77 | parameters['device_type'] = self.device.device_type.name | |||
77 |
|
78 | |||
78 | parameters['clock'] = float(self.clock) |
|
79 | parameters['clock'] = float(self.clock) | |
79 | parameters['multiplier'] = int(self.multiplier) |
|
80 | parameters['multiplier'] = int(self.multiplier) |
@@ -112,6 +112,7 class JARSConfiguration(Configuration): | |||||
112 |
|
112 | |||
113 | parameters['device_id'] = self.device.id |
|
113 | parameters['device_id'] = self.device.id | |
114 | parameters['name'] = self.name |
|
114 | parameters['name'] = self.name | |
|
115 | parameters['device_type'] = self.device.device_type.name | |||
115 | #parameters['rc'] = self.rc.name |
|
116 | #parameters['rc'] = self.rc.name | |
116 | parameters['exp_type'] = self.exp_type |
|
117 | parameters['exp_type'] = self.exp_type | |
117 | parameters['exptype'] = EXPERIMENT_TYPE[self.exp_type][1] |
|
118 | parameters['exptype'] = EXPERIMENT_TYPE[self.exp_type][1] |
@@ -465,23 +465,12 class Experiment(models.Model): | |||||
465 |
|
465 | |||
466 | import json |
|
466 | import json | |
467 |
|
467 | |||
468 | configurations = Configuration.objects.filter(experiment=self) |
|
468 | configurations = Configuration.objects.filter(experiment=self).filter(type=0) | |
469 | conf_parameters = {} |
|
469 | conf_parameters = {} | |
470 | parameters={} |
|
470 | parameters={} | |
471 |
|
471 | |||
472 | for configuration in configurations: |
|
472 | for configuration in configurations: | |
473 | if 'cgs' in configuration.device.device_type.name: |
|
473 | conf_parameters[configuration.name] = configuration.parms_to_dict() | |
474 | conf_parameters['cgs'] = configuration.parms_to_dict() |
|
|||
475 | if 'dds' in configuration.device.device_type.name: |
|
|||
476 | conf_parameters['dds'] = configuration.parms_to_dict() |
|
|||
477 | if 'rc' in configuration.device.device_type.name: |
|
|||
478 | conf_parameters['rc'] = configuration.parms_to_dict() |
|
|||
479 | if 'jars' in configuration.device.device_type.name: |
|
|||
480 | conf_parameters['jars'] = configuration.parms_to_dict() |
|
|||
481 | if 'usrp' in configuration.device.device_type.name: |
|
|||
482 | conf_parameters['usrp'] = configuration.parms_to_dict() |
|
|||
483 | if 'abs' in configuration.device.device_type.name: |
|
|||
484 | conf_parameters['abs'] = configuration.parms_to_dict() |
|
|||
485 |
|
474 | |||
486 | parameters['configurations'] = conf_parameters |
|
475 | parameters['configurations'] = conf_parameters | |
487 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") |
|
476 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") | |
@@ -512,54 +501,35 class Experiment(models.Model): | |||||
512 | if configurations: |
|
501 | if configurations: | |
513 |
|
|
502 | for configuration in configurations: | |
514 |
|
|
503 | configuration.delete() | |
515 |
|
504 | #If device is missing. | ||
516 |
for conf |
|
505 | for configuration in parms['configurations']: | |
517 | #--For ABS Device: |
|
506 | try: | |
518 | #--For USRP Device: |
|
507 | device = Device.objects.filter(device_type__name=parms['configurations'][configuration]['device_type'])[0] | |
519 | #--For JARS Device: |
|
508 | except: | |
520 | if conf_type == 'jars': |
|
509 | return {'Error': 'Device is not in database. Please create new '+str(parms['configurations'][configuration]['device_type'])+ ' device.'} | |
521 | device = get_object_or_404(Device, pk=parms['configurations']['jars']['device_id']) |
|
510 | ||
522 | DevConfModel = CONF_MODELS[conf_type] |
|
511 | for configuration in parms['configurations']: | |
523 | confjars_form = DevConfModel( |
|
512 | device = Device.objects.filter(device_type__name=parms['configurations'][configuration]['device_type'])[0] | |
524 | experiment = self, |
|
513 | if parms['configurations'][configuration]['device_type'] == 'rc': | |
525 | name = 'JARS', |
|
514 | if bool(parms['configurations'][configuration]['mix']) == False: | |
526 | device=device, |
|
515 | DevConfModel = CONF_MODELS[parms['configurations'][configuration]['device_type']] | |
527 | ) |
|
516 | new_conf = DevConfModel( | |
528 | confjars_form.dict_to_parms(parms['configurations']['jars']) |
|
|||
529 | confjars_form.save() |
|
|||
530 | #--For RC Device: |
|
|||
531 | if conf_type == 'rc': |
|
|||
532 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) |
|
|||
533 | DevConfModel = CONF_MODELS[conf_type] |
|
|||
534 | confrc_form = DevConfModel( |
|
|||
535 | experiment = self, |
|
|||
536 | name = 'RC', |
|
|||
537 | device=device, |
|
|||
538 | ) |
|
|||
539 | confrc_form.dict_to_parms(parms['configurations']['rc']) |
|
|||
540 | confrc_form.save() |
|
|||
541 | #--For DDS Device: |
|
|||
542 | if conf_type == 'dds': |
|
|||
543 | device = get_object_or_404(Device, pk=parms['configurations']['dds']['device_id']) |
|
|||
544 | DevConfModel = CONF_MODELS[conf_type] |
|
|||
545 | confdds_form = DevConfModel( |
|
|||
546 |
|
|
517 | experiment = self, | |
547 |
|
|
518 | name = configuration, | |
548 |
|
|
519 | device = device, | |
549 |
|
|
520 | ) | |
550 |
|
|
521 | new_conf.dict_to_parms(parms['configurations'][configuration]) | |
551 |
|
|
522 | new_conf.save() | |
552 | #--For CGS Device: |
|
523 | else: | |
553 | if conf_type == 'cgs': |
|
524 | DevConfModel = CONF_MODELS[parms['configurations'][configuration]['device_type']] | |
554 | device = get_object_or_404(Device, pk=parms['configurations']['cgs']['device_id']) |
|
525 | new_conf = DevConfModel( | |
555 | DevConfModel = CONF_MODELS[conf_type] |
|
|||
556 | confcgs_form = DevConfModel( |
|
|||
557 |
|
|
526 | experiment = self, | |
558 |
|
|
527 | name = configuration, | |
559 |
|
|
528 | device = device, | |
560 |
|
|
529 | ) | |
561 |
|
|
530 | new_conf.dict_to_parms(parms['configurations'][configuration]) | |
562 |
|
|
531 | new_conf.save() | |
|
532 | ||||
563 |
|
533 | |||
564 | location = Location.objects.get(name = parms['radar']) |
|
534 | location = Location.objects.get(name = parms['radar']) | |
565 | self.name = parms['experiment'] |
|
535 | self.name = parms['experiment'] |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -684,7 +684,7 def experiment_import(request, id_exp): | |||||
684 |
|
684 | |||
685 | if request.method == 'POST': |
|
685 | if request.method == 'POST': | |
686 | file_form = UploadFileForm(request.POST, request.FILES) |
|
686 | file_form = UploadFileForm(request.POST, request.FILES) | |
687 | print 'aqui 1' |
|
687 | ||
688 | if file_form.is_valid(): |
|
688 | if file_form.is_valid(): | |
689 |
|
689 | |||
690 | parms = experiment.import_from_file(request.FILES['file']) |
|
690 | parms = experiment.import_from_file(request.FILES['file']) | |
@@ -693,6 +693,10 def experiment_import(request, id_exp): | |||||
693 |
|
693 | |||
694 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) |
|
694 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) | |
695 |
|
695 | |||
|
696 | if new_exp.__class__.__name__=='dict': | |||
|
697 | messages.error(request, new_exp['Error'] ) | |||
|
698 | return redirect(experiment.get_absolute_url_import()) | |||
|
699 | ||||
696 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
700 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
697 |
|
701 | |||
698 | return redirect(new_exp.get_absolute_url_edit()) |
|
702 | return redirect(new_exp.get_absolute_url_edit()) |
@@ -136,7 +136,7 class RCConfiguration(Configuration): | |||||
136 | ''' |
|
136 | ''' | |
137 |
|
137 | |||
138 |
ignored = ('parameters', 'type', |
|
138 | ignored = ('parameters', 'type','polymorphic_ctype', 'configuration_ptr', | |
139 | 'created_date', 'programmed_date') |
|
139 | 'created_date', 'programmed_date', 'mix') | |
140 |
|
140 | |||
141 | data = {} |
|
141 | data = {} | |
142 | for field in self._meta.fields: |
|
142 | for field in self._meta.fields: | |
@@ -145,7 +145,9 class RCConfiguration(Configuration): | |||||
145 | data[field.name] = '{}'.format(field.value_from_object(self)) |
|
145 | data[field.name] = '{}'.format(field.value_from_object(self)) | |
146 |
|
146 | |||
147 | data['device_id'] = data.pop('device') |
|
147 | data['device_id'] = data.pop('device') | |
|
148 | data['device_type'] = self.device.device_type.name | |||
148 | data['lines'] = [] |
|
149 | data['lines'] = [] | |
|
150 | data['mix'] = self.mix | |||
149 |
|
151 | |||
150 | for line in self.get_lines(): |
|
152 | for line in self.get_lines(): | |
151 | line_data = json.loads(line.params) |
|
153 | line_data = json.loads(line.params) |
General Comments 0
You need to be logged in to leave comments.
Login now