@@ -50,13 +50,14 class CampaignForm(forms.ModelForm): | |||||
50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
51 | self.fields['description'].widget.attrs = {'rows': 2} |
|
51 | self.fields['description'].widget.attrs = {'rows': 2} | |
52 |
|
52 | |||
53 | if self.instance: |
|
53 | if self.instance.pk: | |
54 | self.fields['experiments'].queryset |= self.instance.experiments.all() |
|
54 | self.fields['experiments'].queryset |= self.instance.experiments.all() | |
55 |
|
55 | |||
56 | class Meta: |
|
56 | class Meta: | |
57 | model = Campaign |
|
57 | model = Campaign | |
58 | exclude = [''] |
|
58 | exclude = [''] | |
59 |
|
|
59 | ||
|
60 | ||||
60 | class ExperimentForm(forms.ModelForm): |
|
61 | class ExperimentForm(forms.ModelForm): | |
61 |
|
62 | |||
62 | def __init__(self, *args, **kwargs): |
|
63 | def __init__(self, *args, **kwargs): |
@@ -35,6 +35,7 DEV_STATES = ( | |||||
35 | DEV_TYPES = ( |
|
35 | DEV_TYPES = ( | |
36 | ('', 'Select a device type'), |
|
36 | ('', 'Select a device type'), | |
37 | ('rc', 'Radar Controller'), |
|
37 | ('rc', 'Radar Controller'), | |
|
38 | ('rc_mix', 'Radar Controller (Mix)'), | |||
38 | ('dds', 'Direct Digital Synthesizer'), |
|
39 | ('dds', 'Direct Digital Synthesizer'), | |
39 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
40 | ('jars', 'Jicamarca Radar Acquisition System'), | |
40 | ('usrp', 'Universal Software Radio Peripheral'), |
|
41 | ('usrp', 'Universal Software Radio Peripheral'), | |
@@ -44,6 +45,7 DEV_TYPES = ( | |||||
44 |
|
45 | |||
45 | DEV_PORTS = { |
|
46 | DEV_PORTS = { | |
46 | 'rc' : 2000, |
|
47 | 'rc' : 2000, | |
|
48 | 'rc_mix': 2000, | |||
47 | 'dds' : 2000, |
|
49 | 'dds' : 2000, | |
48 | 'jars' : 2000, |
|
50 | 'jars' : 2000, | |
49 | 'usrp' : 2000, |
|
51 | 'usrp' : 2000, | |
@@ -290,7 +292,7 class Configuration(PolymorphicModel): | |||||
290 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
292 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
291 |
|
293 | |||
292 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
294 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
293 | device = models.ForeignKey(Device, on_delete=models.CASCADE) |
|
295 | device = models.ForeignKey(Device, null=True, on_delete=models.CASCADE) | |
294 |
|
296 | |||
295 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
297 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
296 |
|
298 | |||
@@ -306,12 +308,7 class Configuration(PolymorphicModel): | |||||
306 |
|
308 | |||
307 | def __unicode__(self): |
|
309 | def __unicode__(self): | |
308 |
|
310 | |||
309 | if self.experiment: |
|
311 | return u'[%s]: %s' % (self.device.name, self.name) | |
310 | return u'[%s, %s]: %s' % (self.experiment.name, |
|
|||
311 | self.device.name, |
|
|||
312 | self.name) |
|
|||
313 | else: |
|
|||
314 | return u'%s' % self.device.name |
|
|||
315 |
|
312 | |||
316 | def clone(self, **kwargs): |
|
313 | def clone(self, **kwargs): | |
317 |
|
314 |
@@ -18,13 +18,12 | |||||
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
19 | <ul class="dropdown-menu" role="menu"> |
|
19 | <ul class="dropdown-menu" role="menu"> | |
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
21 |
<li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove |
|
21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
24 | {% block extra-menu-actions %} |
|
24 | {% block extra-menu-actions %} | |
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 | <li><a>----------------</a></li> |
|
26 | <li><a>----------------</a></li> | |
27 | <li><a href="#"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Mix Experiments</a></li> |
|
|||
28 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
27 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
29 | {% if not no_play %} |
|
28 | {% if not no_play %} | |
30 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
29 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
@@ -15,6 +15,7 | |||||
15 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
15 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
16 | <ul class="dropdown-menu" role="menu"> |
|
16 | <ul class="dropdown-menu" role="menu"> | |
17 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
17 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
|
18 | <li><a href="{% url 'url_delete_dev_conf' dev_conf.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |||
18 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
19 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
19 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
20 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
20 | {% block extra-menu-actions %} |
|
21 | {% block extra-menu-actions %} |
@@ -18,13 +18,14 | |||||
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
19 | <ul class="dropdown-menu" role="menu"> |
|
19 | <ul class="dropdown-menu" role="menu"> | |
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
21 |
<li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove |
|
21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
24 | {% block extra-menu-actions %} |
|
24 | {% block extra-menu-actions %} | |
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 | <li><a>----------------</a></li> |
|
26 | <li><a>----------------</a></li> | |
27 |
<li><a href=" |
|
27 | <li><a href="{% url 'url_mix_experiment' experiment.id %}"><span class="glyphicon glyphicon-random" aria-hidden="true"></span> Mix RC Configurations </a></li> | |
|
28 | <li><a href="{% url 'url_add_dev_conf' experiment.id %}"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> | |||
28 | </ul> |
|
29 | </ul> | |
29 | </span> |
|
30 | </span> | |
30 | {% endblock %} |
|
31 | {% endblock %} | |
@@ -65,7 +66,6 | |||||
65 | </tr> |
|
66 | </tr> | |
66 | {% endfor %} |
|
67 | {% endfor %} | |
67 |
</table> |
|
68 | </table> | |
68 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
|||
69 | </div> |
|
69 | </div> | |
70 | </div> |
|
70 | </div> | |
71 | </div> |
|
71 | </div> |
@@ -4,6 +4,10 | |||||
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
|
7 | <style type="text/css"> | |||
|
8 | .tabuled {font-family: Courier New} | |||
|
9 | .check-inline {display: inline} | |||
|
10 | </style> | |||
7 | {% endblock %} |
|
11 | {% endblock %} | |
8 |
|
12 | |||
9 | {% block extra-js%} |
|
13 | {% block extra-js%} | |
@@ -11,4 +15,12 | |||||
11 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
15 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> | |
12 | <script src="{% static 'js/cr.js' %}"></script> |
|
16 | <script src="{% static 'js/cr.js' %}"></script> | |
13 |
|
17 | |||
|
18 | <script type="text/javascript"> | |||
|
19 | ||||
|
20 | $("#bt_Delete").click(function() { | |||
|
21 | document.location = "{% url 'url_delete_mix_experiment' id_exp %}"; | |||
|
22 | }); | |||
|
23 | ||||
|
24 | </script> | |||
|
25 | ||||
14 | {% endblock %} No newline at end of file |
|
26 | {% endblock %} |
@@ -22,6 +22,8 def title(s): | |||||
22 | def value(instance, key): |
|
22 | def value(instance, key): | |
23 |
|
23 | |||
24 | item = instance |
|
24 | item = instance | |
|
25 | if key=='name': | |||
|
26 | return '%s' % item | |||
25 | for my_key in key.split("__"): |
|
27 | for my_key in key.split("__"): | |
26 | item = attr(item, my_key) |
|
28 | item = attr(item, my_key) | |
27 |
|
29 |
@@ -26,6 +26,8 urlpatterns = ( | |||||
26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), | |
27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), | |
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), | |
|
29 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), | |||
|
30 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), | |||
29 |
|
31 | |||
30 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
32 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
31 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
33 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
@@ -1,4 +1,5 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
|
2 | from django.utils.safestring import mark_safe | |||
2 | from django.http import HttpResponseRedirect |
|
3 | from django.http import HttpResponseRedirect | |
3 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
4 | from django.contrib import messages |
|
5 | from django.contrib import messages | |
@@ -10,7 +11,7 from apps.cgs.forms import CGSConfigurationForm | |||||
10 | from apps.jars.forms import JARSConfigurationForm |
|
11 | from apps.jars.forms import JARSConfigurationForm | |
11 | from apps.usrp.forms import USRPConfigurationForm |
|
12 | from apps.usrp.forms import USRPConfigurationForm | |
12 | from apps.abs.forms import ABSConfigurationForm |
|
13 | from apps.abs.forms import ABSConfigurationForm | |
13 | from apps.rc.forms import RCConfigurationForm |
|
14 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm | |
14 | from apps.dds.forms import DDSConfigurationForm |
|
15 | from apps.dds.forms import DDSConfigurationForm | |
15 |
|
16 | |||
16 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
17 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
@@ -18,13 +19,14 from apps.cgs.models import CGSConfiguration | |||||
18 | from apps.jars.models import JARSConfiguration |
|
19 | from apps.jars.models import JARSConfiguration | |
19 | from apps.usrp.models import USRPConfiguration |
|
20 | from apps.usrp.models import USRPConfiguration | |
20 | from apps.abs.models import ABSConfiguration |
|
21 | from apps.abs.models import ABSConfiguration | |
21 | from apps.rc.models import RCConfiguration |
|
22 | from apps.rc.models import RCConfiguration, RCLine, RCLineType | |
22 | from apps.dds.models import DDSConfiguration |
|
23 | from apps.dds.models import DDSConfiguration | |
23 |
|
24 | |||
24 | # Create your views here. |
|
25 | # Create your views here. | |
25 |
|
26 | |||
26 | CONF_FORMS = { |
|
27 | CONF_FORMS = { | |
27 | 'rc': RCConfigurationForm, |
|
28 | 'rc': RCConfigurationForm, | |
|
29 | 'rc_mix': RCMixConfigurationForm, | |||
28 | 'dds': DDSConfigurationForm, |
|
30 | 'dds': DDSConfigurationForm, | |
29 | 'jars': JARSConfigurationForm, |
|
31 | 'jars': JARSConfigurationForm, | |
30 | 'cgs': CGSConfigurationForm, |
|
32 | 'cgs': CGSConfigurationForm, | |
@@ -41,6 +43,13 CONF_MODELS = { | |||||
41 | 'usrp': USRPConfiguration, |
|
43 | 'usrp': USRPConfiguration, | |
42 | } |
|
44 | } | |
43 |
|
45 | |||
|
46 | MIX_MODES = { | |||
|
47 | '0': 'OR', | |||
|
48 | '1': 'XOR', | |||
|
49 | '2': 'AND', | |||
|
50 | '3': 'NAND' | |||
|
51 | } | |||
|
52 | ||||
44 |
|
53 | |||
45 | def index(request): |
|
54 | def index(request): | |
46 | kwargs = {} |
|
55 | kwargs = {} | |
@@ -446,7 +455,7 def experiment(request, id_exp): | |||||
446 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
455 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] | |
447 | kwargs['experiment'] = experiment |
|
456 | kwargs['experiment'] = experiment | |
448 |
|
457 | |||
449 |
kwargs['configuration_keys'] = [' |
|
458 | kwargs['configuration_keys'] = ['name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
450 | kwargs['configurations'] = configurations |
|
459 | kwargs['configurations'] = configurations | |
451 |
|
460 | |||
452 | kwargs['title'] = 'Experiment' |
|
461 | kwargs['title'] = 'Experiment' | |
@@ -564,13 +573,150 def experiment_export(request, id_exp): | |||||
564 | return response |
|
573 | return response | |
565 |
|
574 | |||
566 |
|
575 | |||
|
576 | def experiment_mix(request, id_exp): | |||
|
577 | ||||
|
578 | experiment = get_object_or_404(Experiment, pk=id_exp) | |||
|
579 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, | |||
|
580 | mix=False)] | |||
|
581 | ||||
|
582 | if len(rc_confs)<2: | |||
|
583 | messages.warning(request, 'You need at least two RC Configurations to make a mix') | |||
|
584 | return redirect(experiment.get_absolute_url()) | |||
|
585 | ||||
|
586 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) | |||
|
587 | ||||
|
588 | if mix_confs: | |||
|
589 | mix = mix_confs[0] | |||
|
590 | else: | |||
|
591 | mix = RCConfiguration(experiment=experiment, | |||
|
592 | device=rc_confs[0].device, | |||
|
593 | ipp=rc_confs[0].ipp, | |||
|
594 | clock_in=rc_confs[0].clock_in, | |||
|
595 | clock_divider=rc_confs[0].clock_divider, | |||
|
596 | mix=True, | |||
|
597 | parameters='') | |||
|
598 | mix.save() | |||
|
599 | ||||
|
600 | line_type = RCLineType.objects.get(name='mix') | |||
|
601 | for i in range(len(rc_confs[0].get_lines())): | |||
|
602 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |||
|
603 | line.save() | |||
|
604 | ||||
|
605 | initial = {'name': mix.name, | |||
|
606 | 'result': parse_mix_result(mix.parameters), | |||
|
607 | 'delay': 0, | |||
|
608 | 'mask': [0,1,2,3,4,5,6,7] | |||
|
609 | } | |||
|
610 | ||||
|
611 | if request.method=='GET': | |||
|
612 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |||
|
613 | ||||
|
614 | if request.method=='POST': | |||
|
615 | ||||
|
616 | result = mix.parameters | |||
|
617 | ||||
|
618 | if '{}|'.format(request.POST['experiment']) in result: | |||
|
619 | messages.error(request, 'Configuration already added') | |||
|
620 | else: | |||
|
621 | if result: | |||
|
622 | result = '{}-{}|{}|{}|{}'.format(mix.parameters, | |||
|
623 | request.POST['experiment'], | |||
|
624 | MIX_MODES[request.POST['operation']], | |||
|
625 | float(request.POST['delay']), | |||
|
626 | parse_mask(request.POST.getlist('mask')) | |||
|
627 | ) | |||
|
628 | else: | |||
|
629 | result = '{}|{}|{}|{}'.format(request.POST['experiment'], | |||
|
630 | MIX_MODES[request.POST['operation']], | |||
|
631 | float(request.POST['delay']), | |||
|
632 | parse_mask(request.POST.getlist('mask')) | |||
|
633 | ) | |||
|
634 | ||||
|
635 | mix.parameters = result | |||
|
636 | mix.name = request.POST['name'] | |||
|
637 | mix.save() | |||
|
638 | mix.update_pulses() | |||
|
639 | ||||
|
640 | ||||
|
641 | initial['result'] = parse_mix_result(result) | |||
|
642 | initial['name'] = mix.name | |||
|
643 | ||||
|
644 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |||
|
645 | ||||
|
646 | ||||
|
647 | kwargs = { | |||
|
648 | 'title': 'Experiment', | |||
|
649 | 'suptitle': 'Mix Configurations', | |||
|
650 | 'form' : form, | |||
|
651 | 'extra_button': 'Delete', | |||
|
652 | 'button': 'Add', | |||
|
653 | 'cancel': 'Back', | |||
|
654 | 'previous': experiment.get_absolute_url(), | |||
|
655 | 'id_exp':id_exp, | |||
|
656 | ||||
|
657 | } | |||
|
658 | ||||
|
659 | return render(request, 'experiment_mix.html', kwargs) | |||
|
660 | ||||
|
661 | ||||
|
662 | def experiment_mix_delete(request, id_exp): | |||
|
663 | ||||
|
664 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |||
|
665 | values = conf.parameters.split('-') | |||
|
666 | conf.parameters = '-'.join(values[:-1]) | |||
|
667 | conf.save() | |||
|
668 | ||||
|
669 | return redirect('url_mix_experiment', id_exp=id_exp) | |||
|
670 | ||||
|
671 | ||||
|
672 | def parse_mix_result(s): | |||
|
673 | ||||
|
674 | values = s.split('-') | |||
|
675 | html = '' | |||
|
676 | ||||
|
677 | ||||
|
678 | for i, value in enumerate(values): | |||
|
679 | if not value: | |||
|
680 | continue | |||
|
681 | pk, mode, delay, mask = value.split('|') | |||
|
682 | conf = RCConfiguration.objects.get(pk=pk) | |||
|
683 | if i==0: | |||
|
684 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( | |||
|
685 | conf.name[:18], | |||
|
686 | '---', | |||
|
687 | delay, | |||
|
688 | mask) | |||
|
689 | else: | |||
|
690 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( | |||
|
691 | conf.name[:18], | |||
|
692 | mode, | |||
|
693 | delay, | |||
|
694 | mask) | |||
|
695 | ||||
|
696 | return mark_safe(html) | |||
|
697 | ||||
|
698 | def parse_mask(l): | |||
|
699 | ||||
|
700 | values = [] | |||
|
701 | ||||
|
702 | for x in range(8): | |||
|
703 | if '{}'.format(x) in l: | |||
|
704 | values.append(1) | |||
|
705 | else: | |||
|
706 | values.append(0) | |||
|
707 | ||||
|
708 | values.reverse() | |||
|
709 | ||||
|
710 | return int(''.join([str(x) for x in values]), 2) | |||
|
711 | ||||
|
712 | ||||
567 | def dev_confs(request): |
|
713 | def dev_confs(request): | |
568 |
|
714 | |||
569 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
715 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
570 |
|
716 | |||
571 | kwargs = {} |
|
717 | kwargs = {} | |
572 |
|
718 | |||
573 | kwargs['configuration_keys'] = ['device', 'experiment', 'type', 'programmed_date'] |
|
719 | kwargs['configuration_keys'] = ['device', 'name', 'experiment', 'type', 'programmed_date'] | |
574 | kwargs['configurations'] = configurations |
|
720 | kwargs['configurations'] = configurations | |
575 |
|
721 | |||
576 | kwargs['title'] = 'Configuration' |
|
722 | kwargs['title'] = 'Configuration' | |
@@ -589,6 +735,7 def dev_conf(request, id_conf): | |||||
589 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
735 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
590 |
|
736 | |||
591 | initial = {} |
|
737 | initial = {} | |
|
738 | kwargs = {} | |||
592 |
|
739 | |||
593 | if id_exp<>0: |
|
740 | if id_exp<>0: | |
594 | initial['experiment'] = id_exp |
|
741 | initial['experiment'] = id_exp | |
@@ -597,13 +744,30 def dev_conf_new(request, id_exp=0, id_dev=0): | |||||
597 | initial['device'] = id_dev |
|
744 | initial['device'] = id_dev | |
598 |
|
745 | |||
599 | if request.method == 'GET': |
|
746 | if request.method == 'GET': | |
600 | if id_dev==0: |
|
747 | ||
601 | form = ConfigurationForm(initial=initial) |
|
748 | if id_dev: | |
602 | else: |
|
749 | kwargs['button'] = 'Create' | |
603 | device = Device.objects.get(pk=id_dev) |
|
750 | device = Device.objects.get(pk=id_dev) | |
604 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
751 | DevConfForm = CONF_FORMS[device.device_type.name] | |
605 |
|
752 | initial['name'] = request.GET['name'] | ||
606 | form = DevConfForm(initial=initial) |
|
753 | form = DevConfForm(initial=initial) | |
|
754 | else: | |||
|
755 | if 'template' in request.GET: | |||
|
756 | if request.GET['template']=='0': | |||
|
757 | form = NewForm(initial={'create_from':2}, | |||
|
758 | template_choices=Configuration.objects.filter(template=True).values_list('id', 'name')) | |||
|
759 | else: | |||
|
760 | kwargs['button'] = 'Create' | |||
|
761 | conf = Configuration.objects.get(pk=request.GET['template']) | |||
|
762 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |||
|
763 | form = DevConfForm(instance=conf, | |||
|
764 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), | |||
|
765 | 'template': False}) | |||
|
766 | elif 'blank' in request.GET: | |||
|
767 | kwargs['button'] = 'Create' | |||
|
768 | form = ConfigurationForm(initial=initial) | |||
|
769 | else: | |||
|
770 | form = NewForm() | |||
607 |
|
771 | |||
608 | if request.method == 'POST': |
|
772 | if request.method == 'POST': | |
609 |
|
773 | |||
@@ -613,16 +777,21 def dev_conf_new(request, id_exp=0, id_dev=0): | |||||
613 | form = DevConfForm(request.POST) |
|
777 | form = DevConfForm(request.POST) | |
614 |
|
778 | |||
615 | if form.is_valid(): |
|
779 | if form.is_valid(): | |
616 |
|
|
780 | conf = form.save() | |
|
781 | ||||
|
782 | if 'template' in request.GET and conf.device.device_type.name=='rc': | |||
|
783 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |||
|
784 | for line in lines: | |||
|
785 | line.clone(rc_configuration=conf) | |||
|
786 | ||||
|
787 | return redirect('url_dev_conf', id_conf=conf.pk) | |||
617 |
|
788 | |||
618 | return redirect('url_dev_confs') |
|
|||
619 |
|
|
789 | ||
620 | kwargs = {} |
|
|||
621 | kwargs['id_exp'] = id_exp |
|
790 | kwargs['id_exp'] = id_exp | |
622 | kwargs['form'] = form |
|
791 | kwargs['form'] = form | |
623 | kwargs['title'] = 'Configuration' |
|
792 | kwargs['title'] = 'Configuration' | |
624 | kwargs['suptitle'] = 'New' |
|
793 | kwargs['suptitle'] = 'New' | |
625 | kwargs['button'] = 'Create' |
|
794 | ||
626 |
|
795 | |||
627 | if id_dev != 0: |
|
796 | if id_dev != 0: | |
628 | device = Device.objects.get(pk=id_dev) |
|
797 | device = Device.objects.get(pk=id_dev) |
General Comments 0
You need to be logged in to leave comments.
Login now