@@ -694,7 +694,7 def experiment_mix(request, id_exp): | |||
|
694 | 694 | if 'operation' in request.POST: |
|
695 | 695 | operation = MIX_OPERATIONS[request.POST['operation']] |
|
696 | 696 | else: |
|
697 |
operation = ' |
|
|
697 | operation = ' ' | |
|
698 | 698 | |
|
699 | 699 | mode = MIX_MODES[request.POST['mode']] |
|
700 | 700 | |
@@ -767,7 +767,7 def parse_mix_result(s): | |||
|
767 | 767 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
768 | 768 | conf.name, |
|
769 | 769 | mode, |
|
770 |
' |
|
|
770 | ' ', | |
|
771 | 771 | delay, |
|
772 | 772 | mask) |
|
773 | 773 | else: |
@@ -847,7 +847,8 def dev_conf_new(request, id_exp=0, id_dev=0): | |||
|
847 | 847 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
848 | 848 | form = DevConfForm(instance=conf, |
|
849 | 849 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), |
|
850 |
'template': False |
|
|
850 | 'template': False, | |
|
851 | 'experiment':id_exp}) | |
|
851 | 852 | elif 'blank' in request.GET: |
|
852 | 853 | kwargs['button'] = 'Create' |
|
853 | 854 | form = ConfigurationForm(initial=initial) |
@@ -865,7 +866,7 def dev_conf_new(request, id_exp=0, id_dev=0): | |||
|
865 | 866 | conf = form.save() |
|
866 | 867 | |
|
867 | 868 | if 'template' in request.GET and conf.device.device_type.name=='rc': |
|
868 |
lines = RCLine.objects.filter(rc_configuration=request.GET['template']) |
|
|
869 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |
|
869 | 870 | for line in lines: |
|
870 | 871 | line.clone(rc_configuration=conf) |
|
871 | 872 |
@@ -74,7 +74,7 class RCConfigurationForm(forms.ModelForm): | |||
|
74 | 74 | self.fields['time_after'].label = mark_safe(self.fields['time_after'].label) |
|
75 | 75 | |
|
76 | 76 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): |
|
77 |
self.fields['experiment'].widget.attrs[' |
|
|
77 | self.fields['experiment'].widget.attrs['readonly'] = True | |
|
78 | 78 | |
|
79 | 79 | class Meta: |
|
80 | 80 | model = RCConfiguration |
@@ -92,6 +92,12 class RCConfigurationForm(forms.ModelForm): | |||
|
92 | 92 | |
|
93 | 93 | return form_data |
|
94 | 94 | |
|
95 | def save(self): | |
|
96 | conf = super(RCConfigurationForm, self).save() | |
|
97 | conf.total_units = conf.ipp*conf.ntx*conf.km2unit | |
|
98 | conf.save() | |
|
99 | return conf | |
|
100 | ||
|
95 | 101 | |
|
96 | 102 | class RCMixConfigurationForm(forms.Form): |
|
97 | 103 |
@@ -353,7 +353,7 class RCConfiguration(Configuration): | |||
|
353 | 353 | from bokeh.resources import CDN |
|
354 | 354 | from bokeh.embed import components |
|
355 | 355 | from bokeh.mpl import to_bokeh |
|
356 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool | |
|
356 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool | |
|
357 | 357 | |
|
358 | 358 | lines = self.get_lines() |
|
359 | 359 | |
@@ -371,7 +371,8 class RCConfiguration(Configuration): | |||
|
371 | 371 | |
|
372 | 372 | labels.reverse() |
|
373 | 373 | ax.set_yticklabels(labels) |
|
374 | plot = to_bokeh(fig, use_pandas=False) | |
|
374 | ax.set_xlabel = 'Units' | |
|
375 | plot = to_bokeh(fig, use_pandas=False) | |
|
375 | 376 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] |
|
376 | 377 | |
|
377 | 378 | return components(plot, CDN) |
@@ -538,7 +539,7 class RCLine(models.Model): | |||
|
538 | 539 | ipp = self.rc_configuration.ipp |
|
539 | 540 | ntx = self.rc_configuration.ntx |
|
540 | 541 | ipp_u = int(ipp*km2unit) |
|
541 | total = ipp_u*ntx | |
|
542 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units | |
|
542 | 543 | y = [] |
|
543 | 544 | |
|
544 | 545 | if self.line_type.name=='tr': |
@@ -576,6 +577,9 class RCLine(models.Model): | |||
|
576 | 577 | |
|
577 | 578 | y.extend(y_tx) |
|
578 | 579 | |
|
580 | self.pulses = unicode(y) | |
|
581 | y = self.array_to_points(self.pulses_as_array()) | |
|
582 | ||
|
579 | 583 | elif self.line_type.name=='tx': |
|
580 | 584 | params = json.loads(self.params) |
|
581 | 585 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
@@ -663,7 +667,7 class RCLine(models.Model): | |||
|
663 | 667 | |
|
664 | 668 | elif self.line_type.name=='mix': |
|
665 | 669 | values = self.rc_configuration.parameters.split('-') |
|
666 |
confs = RCConfiguration.objects. |
|
|
670 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] | |
|
667 | 671 | modes = [value.split('|')[1] for value in values] |
|
668 | 672 | ops = [value.split('|')[2] for value in values] |
|
669 | 673 | delays = [value.split('|')[3] for value in values] |
@@ -671,9 +675,9 class RCLine(models.Model): | |||
|
671 | 675 | mask = list('{:8b}'.format(int(masks[0]))) |
|
672 | 676 | mask.reverse() |
|
673 | 677 | if mask[self.channel] in ('0', '', ' '): |
|
674 | y = np.zeros(total, dtype=np.int8) | |
|
678 | y = np.zeros(confs[0].total_units, dtype=np.int8) | |
|
675 | 679 | else: |
|
676 |
y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() |
|
|
680 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() | |
|
677 | 681 | |
|
678 | 682 | for i in range(1, len(values)): |
|
679 | 683 | mask = list('{:8b}'.format(int(masks[i]))) |
@@ -681,32 +685,39 class RCLine(models.Model): | |||
|
681 | 685 | |
|
682 | 686 | if mask[self.channel] in ('0', '', ' '): |
|
683 | 687 | continue |
|
684 |
Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() |
|
|
688 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() | |
|
685 | 689 | delay = float(delays[i])*km2unit |
|
686 | 690 | |
|
687 |
if |
|
|
688 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): | |
|
689 | y_temp = np.empty_like(Y) | |
|
690 |
y_temp |
|
|
691 |
y_temp[delay |
|
|
692 | elif delay+len(Y)>len(y): | |
|
693 |
|
|
|
694 |
y_new |
|
|
695 |
y = y |
|
|
696 | y_temp = np.zeros(delay+len(Y), dtype=np.int8) | |
|
697 |
y_temp |
|
|
698 | elif delay+len(Y)==len(y): | |
|
699 |
|
|
|
700 |
y_temp |
|
|
701 | ||
|
702 | if ops[i]=='OR': | |
|
703 | y = y | y_temp | |
|
704 | elif ops[i]=='XOR': | |
|
705 |
|
|
|
706 |
|
|
|
707 |
y = y |
|
|
708 |
elif ops[i]==' |
|
|
709 |
y = y |
|
|
691 | if modes[i]=='P': | |
|
692 | if delay>0: | |
|
693 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): | |
|
694 | y_temp = np.empty_like(Y) | |
|
695 | y_temp[:delay] = 0 | |
|
696 | y_temp[delay:] = Y[:-delay] | |
|
697 | elif delay+len(Y)>len(y): | |
|
698 | y_new = np.zeros(delay+len(Y), dtype=np.int8) | |
|
699 | y_new[:len(y)] = y | |
|
700 | y = y_new | |
|
701 | y_temp = np.zeros(delay+len(Y), dtype=np.int8) | |
|
702 | y_temp[-len(Y):] = Y | |
|
703 | elif delay+len(Y)==len(y): | |
|
704 | y_temp = np.zeros(delay+len(Y)) | |
|
705 | y_temp[-len(Y):] = Y | |
|
706 | elif delay+len(Y)<len(y): | |
|
707 | y_temp = np.zeros(len(y), dtype=np.int8) | |
|
708 | y_temp[delay:delay+len(Y)] = Y | |
|
709 | ||
|
710 | if ops[i]=='OR': | |
|
711 | y = y | y_temp | |
|
712 | elif ops[i]=='XOR': | |
|
713 | y = y ^ y_temp | |
|
714 | elif ops[i]=='AND': | |
|
715 | y = y & y_temp | |
|
716 | elif ops[i]=='NAND': | |
|
717 | y = y & ~y_temp | |
|
718 | else: | |
|
719 | print len(y), len(Y) | |
|
720 | y = np.concatenate([y, Y]) | |
|
710 | 721 | |
|
711 | 722 | total = len(y) |
|
712 | 723 | y = self.array_to_points(y) |
@@ -718,7 +729,7 class RCLine(models.Model): | |||
|
718 | 729 | self.rc_configuration.total_units = total |
|
719 | 730 | self.rc_configuration.save() |
|
720 | 731 | |
|
721 | self.pulses = y | |
|
732 | self.pulses = unicode(y) | |
|
722 | 733 | self.save() |
|
723 | 734 | |
|
724 | 735 | @staticmethod |
@@ -9,6 +9,10 | |||
|
9 | 9 | |
|
10 | 10 | {% block content %} |
|
11 | 11 | <div id="div_plot">{{div}}</div> |
|
12 | <br> | |
|
13 | <div class="col-md-2">1 Km =</div><div class="col-md-3">{{units}} Units</div> | |
|
14 | <br> | |
|
15 | <div class="col-md-2">1 Unit=</div><div class="col-md-3">{{kms}} Km</div> | |
|
12 | 16 | {% endblock %} |
|
13 | 17 | |
|
14 | 18 | {% block extra-js%} |
@@ -327,7 +327,7 def import_file(request, conf_id): | |||
|
327 | 327 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
328 | 328 | if request.method=='POST': |
|
329 | 329 | form = RCImportForm(request.POST, request.FILES) |
|
330 | if form.is_valid(): | |
|
330 | if form.is_valid(): | |
|
331 | 331 | try: |
|
332 | 332 | conf.update_from_file(request.FILES['file_name']) |
|
333 | 333 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
@@ -362,6 +362,8 def plot_pulses(request, conf_id): | |||
|
362 | 362 | kwargs['suptitle'] = conf.name |
|
363 | 363 | kwargs['div'] = mark_safe(div) |
|
364 | 364 | kwargs['script'] = mark_safe(script) |
|
365 | kwargs['units'] = conf.km2unit | |
|
366 | kwargs['kms'] = 1/conf.km2unit | |
|
365 | 367 | |
|
366 | 368 | if 'json' in request.GET: |
|
367 | 369 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") |
@@ -29,7 +29,11 class KmUnitWidget(forms.widgets.TextInput): | |||
|
29 | 29 | if 'line' in attrs: |
|
30 | 30 | label += '_{0}'.format(attrs['line'].pk) |
|
31 | 31 | |
|
32 | html = '<div class="col-md-12 col-no-padding"><div class="col-md-5 col-no-padding"><input type="text" {0} class="form-control" id="id_{1}" name="{2}" value="{3}"></div><div class="col-md-1 col-no-padding">Km</div><div class="col-md-5 col-no-padding"><input type="text" {4} class="form-control" id="id_{5}_unit" value="{6}"></div><div class="col-md-1 col-no-padding">Units</div></div><br>'.format(disabled, label, name, value, disabled, label, unit) | |
|
32 | html = '''<div class="col-md-12 col-no-padding"> | |
|
33 | <div class="col-md-5 col-no-padding"><input type="number" step="any" {0} class="form-control" id="id_{1}" name="{2}" value="{3}"></div> | |
|
34 | <div class="col-md-1 col-no-padding">Km</div> | |
|
35 | <div class="col-md-5 col-no-padding"><input type="number" {4} class="form-control" id="id_{5}_unit" value="{6}"></div> | |
|
36 | <div class="col-md-1 col-no-padding">Units</div></div><br>'''.format(disabled, label, name, value, disabled, label, unit) | |
|
33 | 37 | |
|
34 | 38 | script = '''<script type="text/javascript"> |
|
35 | 39 | $(document).ready(function () {{ |
@@ -77,7 +81,7 class UnitKmWidget(forms.widgets.TextInput): | |||
|
77 | 81 | html = '''<div class="col-md-12 col-no-padding"> |
|
78 | 82 | <div class="col-md-5 col-no-padding"><input type="number" {0} class="form-control" id="id_{1}_unit" name="{2}" value="{3}"></div> |
|
79 | 83 | <div class="col-md-1 col-no-padding">Units</div> |
|
80 | <div class="col-md-5 col-no-padding"><input type="number" {4} class="form-control" id="id_{5}" value="{6}"></div> | |
|
84 | <div class="col-md-5 col-no-padding"><input type="number" step="any" {4} class="form-control" id="id_{5}" value="{6}"></div> | |
|
81 | 85 | <div class="col-md-1 col-no-padding">Km</div></div>'''.format(disabled, label, name, value, disabled, label, km) |
|
82 | 86 | |
|
83 | 87 | script = '''<script type="text/javascript"> |
@@ -117,11 +121,11 class KmUnitHzWidget(forms.widgets.TextInput): | |||
|
117 | 121 | label += '_{0}'.format(attrs['line'].pk) |
|
118 | 122 | |
|
119 | 123 | html = '''<div class="col-md-12 col-no-padding"> |
|
120 | <div class="col-md-3 col-no-padding"><input type="number" {0} class="form-control" id="id_{1}" name="{2}" value="{3}"></div> | |
|
124 | <div class="col-md-3 col-no-padding"><input type="number" step="any" {0} class="form-control" id="id_{1}" name="{2}" value="{3}"></div> | |
|
121 | 125 | <div class="col-md-1 col-no-padding">Km</div> |
|
122 | 126 | <div class="col-md-3 col-no-padding"><input type="number" {4} class="form-control" id="id_{1}_unit" value="{5}"></div> |
|
123 | 127 | <div class="col-md-1 col-no-padding">Units</div> |
|
124 | <div class="col-md-3 col-no-padding"><input type="number" {4} class="form-control" id="id_{1}_hz" value="{6}"></div> | |
|
128 | <div class="col-md-3 col-no-padding"><input type="number" step="any" {4} class="form-control" id="id_{1}_hz" value="{6}"></div> | |
|
125 | 129 | <div class="col-md-1 col-no-padding">Hz</div> |
|
126 | 130 | </div>'''.format(disabled, label, name, value, disabled, unit, hz) |
|
127 | 131 | |
@@ -168,11 +172,11 class KmUnitDcWidget(forms.widgets.TextInput): | |||
|
168 | 172 | dc = float(json.loads(attrs['line'].params)['pulse_width'])*100/attrs['line'].rc_configuration.ipp |
|
169 | 173 | |
|
170 | 174 | html = '''<div class="col-md-12 col-no-padding"> |
|
171 | <div class="col-md-3 col-no-padding"><input type="number" {0} class="form-control" id="id_{1}" name="{2}" value="{3}"></div> | |
|
175 | <div class="col-md-3 col-no-padding"><input type="number" step="any" {0} class="form-control" id="id_{1}" name="{2}" value="{3}"></div> | |
|
172 | 176 | <div class="col-md-1 col-no-padding">Km</div> |
|
173 | 177 | <div class="col-md-3 col-no-padding"><input type="number" {4} class="form-control" id="id_{1}_unit" value="{5}"></div> |
|
174 | 178 | <div class="col-md-1 col-no-padding">Units</div> |
|
175 | <div class="col-md-3 col-no-padding"><input type="number" {4} class="form-control" id="id_{1}_dc" value="{6}"></div> | |
|
179 | <div class="col-md-3 col-no-padding"><input type="number" step="any" {4} class="form-control" id="id_{1}_dc" value="{6}"></div> | |
|
176 | 180 | <div class="col-md-1 col-no-padding">DC[%]</div> |
|
177 | 181 | </div>'''.format(disabled, label, name, value, disabled, unit, dc) |
|
178 | 182 |
General Comments 0
You need to be logged in to leave comments.
Login now