diff --git a/apps/main/views.py b/apps/main/views.py index 3fa78cb..a27ffd9 100644 --- a/apps/main/views.py +++ b/apps/main/views.py @@ -694,7 +694,7 @@ def experiment_mix(request, id_exp): if 'operation' in request.POST: operation = MIX_OPERATIONS[request.POST['operation']] else: - operation = '---' + operation = ' ' mode = MIX_MODES[request.POST['mode']] @@ -767,7 +767,7 @@ def parse_mix_result(s): html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( conf.name, mode, - '---', + ' ', delay, mask) else: @@ -847,7 +847,8 @@ def dev_conf_new(request, id_exp=0, id_dev=0): DevConfForm = CONF_FORMS[conf.device.device_type.name] form = DevConfForm(instance=conf, initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), - 'template': False}) + 'template': False, + 'experiment':id_exp}) elif 'blank' in request.GET: kwargs['button'] = 'Create' form = ConfigurationForm(initial=initial) @@ -865,7 +866,7 @@ def dev_conf_new(request, id_exp=0, id_dev=0): conf = form.save() if 'template' in request.GET and conf.device.device_type.name=='rc': - lines = RCLine.objects.filter(rc_configuration=request.GET['template']) + lines = RCLine.objects.filter(rc_configuration=request.GET['template']) for line in lines: line.clone(rc_configuration=conf) diff --git a/apps/rc/forms.py b/apps/rc/forms.py index ca86665..02b1172 100644 --- a/apps/rc/forms.py +++ b/apps/rc/forms.py @@ -74,7 +74,7 @@ class RCConfigurationForm(forms.ModelForm): self.fields['time_after'].label = mark_safe(self.fields['time_after'].label) if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): - self.fields['experiment'].widget.attrs['disabled'] = 'disabled' + self.fields['experiment'].widget.attrs['readonly'] = True class Meta: model = RCConfiguration @@ -92,6 +92,12 @@ class RCConfigurationForm(forms.ModelForm): return form_data + def save(self): + conf = super(RCConfigurationForm, self).save() + conf.total_units = conf.ipp*conf.ntx*conf.km2unit + conf.save() + return conf + class RCMixConfigurationForm(forms.Form): diff --git a/apps/rc/models.py b/apps/rc/models.py index 2f70cca..ed766c1 100644 --- a/apps/rc/models.py +++ b/apps/rc/models.py @@ -353,7 +353,7 @@ class RCConfiguration(Configuration): from bokeh.resources import CDN from bokeh.embed import components from bokeh.mpl import to_bokeh - from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool + from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool lines = self.get_lines() @@ -371,7 +371,8 @@ class RCConfiguration(Configuration): labels.reverse() ax.set_yticklabels(labels) - plot = to_bokeh(fig, use_pandas=False) + ax.set_xlabel = 'Units' + plot = to_bokeh(fig, use_pandas=False) plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] return components(plot, CDN) @@ -538,7 +539,7 @@ class RCLine(models.Model): ipp = self.rc_configuration.ipp ntx = self.rc_configuration.ntx ipp_u = int(ipp*km2unit) - total = ipp_u*ntx + total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units y = [] if self.line_type.name=='tr': @@ -576,6 +577,9 @@ class RCLine(models.Model): y.extend(y_tx) + self.pulses = unicode(y) + y = self.array_to_points(self.pulses_as_array()) + elif self.line_type.name=='tx': params = json.loads(self.params) delays = [float(d)*km2unit for d in params['delays'].split(',') if d] @@ -663,7 +667,7 @@ class RCLine(models.Model): elif self.line_type.name=='mix': values = self.rc_configuration.parameters.split('-') - confs = RCConfiguration.objects.filter(pk__in=[value.split('|')[0] for value in values]) + confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] modes = [value.split('|')[1] for value in values] ops = [value.split('|')[2] for value in values] delays = [value.split('|')[3] for value in values] @@ -671,9 +675,9 @@ class RCLine(models.Model): mask = list('{:8b}'.format(int(masks[0]))) mask.reverse() if mask[self.channel] in ('0', '', ' '): - y = np.zeros(total, dtype=np.int8) + y = np.zeros(confs[0].total_units, dtype=np.int8) else: - y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() + y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() for i in range(1, len(values)): mask = list('{:8b}'.format(int(masks[i]))) @@ -681,32 +685,39 @@ class RCLine(models.Model): if mask[self.channel] in ('0', '', ' '): continue - Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() + Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() delay = float(delays[i])*km2unit - if delay>0: - if delaylen(y): - y_new = np.zeros(delay+len(Y), dtype=np.int8) - y_new[:len(y)] = y - y = y_new - y_temp = np.zeros(delay+len(Y), dtype=np.int8) - y_temp[-len(Y):] = Y - elif delay+len(Y)==len(y): - y_temp = np.zeros(delay+len(Y)) - y_temp[-len(Y):] = Y - - if ops[i]=='OR': - y = y | y_temp - elif ops[i]=='XOR': - y = y ^ y_temp - elif ops[i]=='AND': - y = y & y_temp - elif ops[i]=='NAND': - y = y & ~y_temp + if modes[i]=='P': + if delay>0: + if delaylen(y): + y_new = np.zeros(delay+len(Y), dtype=np.int8) + y_new[:len(y)] = y + y = y_new + y_temp = np.zeros(delay+len(Y), dtype=np.int8) + y_temp[-len(Y):] = Y + elif delay+len(Y)==len(y): + y_temp = np.zeros(delay+len(Y)) + y_temp[-len(Y):] = Y + elif delay+len(Y){{div}} +
+
1 Km =
{{units}} Units
+
+
1 Unit=
{{kms}} Km
{% endblock %} {% block extra-js%} diff --git a/apps/rc/views.py b/apps/rc/views.py index 995cea2..b68b740 100644 --- a/apps/rc/views.py +++ b/apps/rc/views.py @@ -327,7 +327,7 @@ def import_file(request, conf_id): conf = get_object_or_404(RCConfiguration, pk=conf_id) if request.method=='POST': form = RCImportForm(request.POST, request.FILES) - if form.is_valid(): + if form.is_valid(): try: conf.update_from_file(request.FILES['file_name']) messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) @@ -362,6 +362,8 @@ def plot_pulses(request, conf_id): kwargs['suptitle'] = conf.name kwargs['div'] = mark_safe(div) kwargs['script'] = mark_safe(script) + kwargs['units'] = conf.km2unit + kwargs['kms'] = 1/conf.km2unit if 'json' in request.GET: return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") diff --git a/apps/rc/widgets.py b/apps/rc/widgets.py index a725541..d865ecf 100644 --- a/apps/rc/widgets.py +++ b/apps/rc/widgets.py @@ -29,7 +29,11 @@ class KmUnitWidget(forms.widgets.TextInput): if 'line' in attrs: label += '_{0}'.format(attrs['line'].pk) - html = '
Km
Units

'.format(disabled, label, name, value, disabled, label, unit) + html = '''
+
+
Km
+
+
Units

'''.format(disabled, label, name, value, disabled, label, unit) script = '''