@@ -0,0 +1,96 | |||||
|
1 | ||||
|
2 | import ast | |||
|
3 | import json | |||
|
4 | from itertools import chain | |||
|
5 | ||||
|
6 | from django import forms | |||
|
7 | from django.utils.safestring import mark_safe | |||
|
8 | from django.utils.encoding import force_unicode | |||
|
9 | from django.utils.html import conditional_escape | |||
|
10 | ||||
|
11 | ||||
|
12 | class SpectralWidget(forms.widgets.TextInput): | |||
|
13 | ||||
|
14 | def render(self, label, value, attrs=None): | |||
|
15 | ||||
|
16 | disabled = 'disabled' if attrs.get('disabled', False) else '' | |||
|
17 | name = attrs.get('name', label) | |||
|
18 | if '[' in value: | |||
|
19 | value = ast.literal_eval(value) | |||
|
20 | ||||
|
21 | codes = value | |||
|
22 | if not isinstance(value, list): | |||
|
23 | if len(value) > 1: | |||
|
24 | text='' | |||
|
25 | for val in value: | |||
|
26 | text = text+str(val)+',' | |||
|
27 | codes=text | |||
|
28 | else: | |||
|
29 | codes=value+"," | |||
|
30 | ||||
|
31 | html = '''<textarea rows="5" {0} class="form-control" id="id_{1}" name="{2}" style="white-space:nowrap; overflow:scroll;">{3}</textarea> | |||
|
32 | <input type="text" class="col-md-1 col-no-padding" id="num1" value=0> | |||
|
33 | <input type="text" class="col-md-1 col-no-padding" id="num2" value=0> | |||
|
34 | <button type="button" class="button" id="add_spectral_button"> Add </button> | |||
|
35 | <button type="button" class="button" id="all_spectral_button"> All </button> | |||
|
36 | <button type="button" class="button" id="self_spectral_button"> Self </button> | |||
|
37 | <button type="button" class="button" id="cross_spectral_button"> Cross </button> | |||
|
38 | <button type="button" class="button" id="delete_spectral_button"> Delete </button> | |||
|
39 | '''.format(disabled, label, name, codes) | |||
|
40 | ||||
|
41 | script = ''' | |||
|
42 | <script type="text/javascript"> | |||
|
43 | $(document).ready(function () {{ | |||
|
44 | ||||
|
45 | var spectral_number1 = $("#num1").val(); | |||
|
46 | var spectral_number2 = $("#num2").val(); | |||
|
47 | ||||
|
48 | ||||
|
49 | $("#all_spectral_button").click(function(){{ | |||
|
50 | alert(spectral_comb) | |||
|
51 | }}); | |||
|
52 | ||||
|
53 | $("#add_spectral_button").click(function(){{ | |||
|
54 | var spectral_comb = $("#id_spectral").val(); | |||
|
55 | var spectral_number1 = $("#num1").val(); | |||
|
56 | var spectral_number2 = $("#num2").val(); | |||
|
57 | var str = spectral_number1+", "+spectral_number2; | |||
|
58 | //not to duplicate | |||
|
59 | var n = spectral_comb.search(str); | |||
|
60 | if (n==-1){ | |||
|
61 | $("#id_spectral").val(spectral_comb+"["+$("#num1").val()+", "+$("#num2").val()+"],") | |||
|
62 | } | |||
|
63 | }}); | |||
|
64 | ||||
|
65 | $("#delete_spectral_button").click(function(){{ | |||
|
66 | var spectral_comb = $("#id_spectral").val(); | |||
|
67 | var spectral_number1 = $("#num1").val(); | |||
|
68 | var spectral_number2 = $("#num2").val(); | |||
|
69 | var str = spectral_number1+", "+spectral_number2; | |||
|
70 | var n = spectral_comb.search(str); | |||
|
71 | if (n==-1){ | |||
|
72 | ||||
|
73 | } | |||
|
74 | else { | |||
|
75 | n= spectral_comb.length; | |||
|
76 | if (n<8){ | |||
|
77 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |||
|
78 | var txt = spectral_comb.replace(tuple,''); | |||
|
79 | } | |||
|
80 | else { | |||
|
81 | var tuple = ",["+$("#num1").val()+", "+$("#num2").val()+"]" | |||
|
82 | var txt = spectral_comb.replace(tuple,''); | |||
|
83 | } | |||
|
84 | $("#id_spectral").val(txt) | |||
|
85 | ||||
|
86 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |||
|
87 | var txt = spectral_comb.replace(tuple,''); | |||
|
88 | $("#id_spectral").val(txt) | |||
|
89 | } | |||
|
90 | }}); | |||
|
91 | ||||
|
92 | }}); | |||
|
93 | </script> | |||
|
94 | ''' | |||
|
95 | ||||
|
96 | return mark_safe(html+script) No newline at end of file |
@@ -1,29 +1,31 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from apps.main.models import Device, Experiment |
|
2 | from apps.main.models import Device, Experiment | |
3 | from .models import JARSConfiguration |
|
3 | from .models import JARSConfiguration | |
|
4 | from .widgets import SpectralWidget | |||
4 |
|
5 | |||
5 | class JARSConfigurationForm(forms.ModelForm): |
|
6 | class JARSConfigurationForm(forms.ModelForm): | |
6 | def __init__(self, *args, **kwargs): |
|
7 | def __init__(self, *args, **kwargs): | |
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) |
|
8 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) | |
8 | instance = getattr(self, 'instance', None) |
|
9 | instance = getattr(self, 'instance', None) | |
9 |
|
10 | |||
10 | if instance and instance.pk: |
|
11 | if instance and instance.pk: | |
11 | devices = Device.objects.filter(device_type__name='jars') |
|
12 | devices = Device.objects.filter(device_type__name='jars') | |
12 |
|
13 | |||
13 | if instance.experiment: |
|
14 | if instance.experiment: | |
14 | experiments = Experiment.objects.filter(pk=instance.experiment.id) |
|
15 | experiments = Experiment.objects.filter(pk=instance.experiment.id) | |
15 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] |
|
16 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] | |
16 |
|
17 | |||
17 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
18 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
|
19 | self.fields['spectral'].widget = SpectralWidget() | |||
18 |
|
20 | |||
19 | #-------------JARS Configuration needs an Experiment----------------- |
|
21 | #-------------JARS Configuration needs an Experiment----------------- | |
20 | def clean(self): |
|
22 | def clean(self): | |
21 | cleaned_data = super(JARSConfigurationForm, self).clean() |
|
23 | cleaned_data = super(JARSConfigurationForm, self).clean() | |
22 | experiment = cleaned_data.get('experiment') |
|
24 | experiment = cleaned_data.get('experiment') | |
23 | if experiment == None: |
|
25 | if experiment == None: | |
24 | msg = "Error: Jars Configuration needs an Experiment" |
|
26 | msg = "Error: Jars Configuration needs an Experiment" | |
25 | self.add_error('experiment', msg) |
|
27 | self.add_error('experiment', msg) | |
26 |
|
28 | |||
27 | class Meta: |
|
29 | class Meta: | |
28 | model = JARSConfiguration |
|
30 | model = JARSConfiguration | |
29 | exclude = ('type', 'parameters', 'status') No newline at end of file |
|
31 | exclude = ('type', 'parameters', 'status') |
@@ -1,95 +1,95 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
3 | from django.core.validators import MinValueValidator, MaxValueValidator | |
4 |
|
4 | |||
5 | from apps.rc.models import RCConfiguration |
|
5 | from apps.rc.models import RCConfiguration | |
6 | # Create your models here. |
|
6 | # Create your models here. | |
7 |
|
7 | |||
8 | EXPERIMENT_TYPE = ( |
|
8 | EXPERIMENT_TYPE = ( | |
9 | (0, 'RAW_DATA'), |
|
9 | (0, 'RAW_DATA'), | |
10 | (1, 'PDATA'), |
|
10 | (1, 'PDATA'), | |
11 | ) |
|
11 | ) | |
12 |
|
12 | |||
13 | DATA_TYPE = ( |
|
13 | DATA_TYPE = ( | |
14 | (0, 'SHORT'), |
|
14 | (0, 'SHORT'), | |
15 | (1, 'FLOAT'), |
|
15 | (1, 'FLOAT'), | |
16 | ) |
|
16 | ) | |
17 |
|
17 | |||
18 | class JARSfilter(models.Model): |
|
18 | class JARSfilter(models.Model): | |
19 |
|
19 | |||
20 | name = models.CharField(max_length=60, unique=True, default='') |
|
20 | name = models.CharField(max_length=60, unique=True, default='') | |
21 | filter_fir = models.PositiveIntegerField(verbose_name='FIR Filter',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) |
|
21 | filter_fir = models.PositiveIntegerField(verbose_name='FIR Filter',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) | |
22 | filter_2 = models.PositiveIntegerField(verbose_name='Filter 2',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) |
|
22 | filter_2 = models.PositiveIntegerField(verbose_name='Filter 2',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) | |
23 | filter_5 = models.PositiveIntegerField(verbose_name='Filter 5',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) |
|
23 | filter_5 = models.PositiveIntegerField(verbose_name='Filter 5',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) | |
24 |
|
24 | |||
25 | class Meta: |
|
25 | class Meta: | |
26 | db_table = 'jars_filters' |
|
26 | db_table = 'jars_filters' | |
27 | #ordering = ['channel'] |
|
27 | #ordering = ['channel'] | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | class JARSConfiguration(Configuration): |
|
30 | class JARSConfiguration(Configuration): | |
31 |
|
31 | |||
32 | ADC_RESOLUTION = 8 |
|
32 | ADC_RESOLUTION = 8 | |
33 | PCI_DIO_BUSWIDTH = 32 |
|
33 | PCI_DIO_BUSWIDTH = 32 | |
34 | HEADER_VERSION = 1103 |
|
34 | HEADER_VERSION = 1103 | |
35 | BEGIN_ON_START = True |
|
35 | BEGIN_ON_START = True | |
36 | REFRESH_RATE = 1 |
|
36 | REFRESH_RATE = 1 | |
37 |
|
37 | |||
38 | rc = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE, null=True) |
|
38 | rc = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE, null=True) | |
39 | exp_type = models.PositiveIntegerField(verbose_name='Experiment Type', choices=EXPERIMENT_TYPE, default=0) |
|
39 | exp_type = models.PositiveIntegerField(verbose_name='Experiment Type', choices=EXPERIMENT_TYPE, default=0) | |
40 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) |
|
40 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) | |
41 | channels_number = models.PositiveIntegerField(verbose_name='Number of Channels', validators=[MinValueValidator(1), MaxValueValidator(8)], default = 5) |
|
41 | channels_number = models.PositiveIntegerField(verbose_name='Number of Channels', validators=[MinValueValidator(1), MaxValueValidator(8)], default = 5) | |
42 | channels = models.CharField(verbose_name='Channels', max_length=15, default = '1,2,3,4,5') |
|
42 | channels = models.CharField(verbose_name='Channels', max_length=15, default = '1,2,3,4,5') | |
43 | rd_directory = models.CharField(verbose_name='Raw Data Directory', max_length=40, default='', blank=True, null=True) |
|
43 | rd_directory = models.CharField(verbose_name='Raw Data Directory', max_length=40, default='', blank=True, null=True) | |
44 | raw_data_blocks = models.PositiveIntegerField(verbose_name='Raw Data Blocks', validators=[MaxValueValidator(5000)], default=120) |
|
44 | raw_data_blocks = models.PositiveIntegerField(verbose_name='Raw Data Blocks', validators=[MaxValueValidator(5000)], default=120) | |
45 | data_type = models.PositiveIntegerField(verbose_name='Data Type', choices=DATA_TYPE, default=0) |
|
45 | data_type = models.PositiveIntegerField(verbose_name='Data Type', choices=DATA_TYPE, default=0) | |
46 | acq_profiles = models.PositiveIntegerField(verbose_name='Acquired Profiles', validators=[MaxValueValidator(5000)], default=400) |
|
46 | acq_profiles = models.PositiveIntegerField(verbose_name='Acquired Profiles', validators=[MaxValueValidator(5000)], default=400) | |
47 | profiles_block = models.PositiveIntegerField(verbose_name='Profiles Per Block', validators=[MaxValueValidator(5000)], default=400) |
|
47 | profiles_block = models.PositiveIntegerField(verbose_name='Profiles Per Block', validators=[MaxValueValidator(5000)], default=400) | |
48 | fftpoints = models.PositiveIntegerField(verbose_name='FFT Points',default=16) |
|
48 | fftpoints = models.PositiveIntegerField(verbose_name='FFT Points',default=16) | |
49 | incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default = 30) |
|
49 | incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default = 30) | |
50 | filter = models.ForeignKey(JARSfilter, on_delete=models.CASCADE, null=True, blank=True) |
|
50 | filter = models.ForeignKey(JARSfilter, on_delete=models.CASCADE, null=True, blank=True) | |
51 | spectral_number = models.PositiveIntegerField(verbose_name='# Spectral Combinations',validators=[MinValueValidator(1)], null=True, blank=True) |
|
51 | spectral_number = models.PositiveIntegerField(verbose_name='# Spectral Combinations',validators=[MinValueValidator(1)], null=True, blank=True) | |
52 |
spectral = models.CharField(verbose_name='Combinations', max_length= |
|
52 | spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0,0]') | |
53 | create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True) |
|
53 | create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True) | |
54 | include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=True) |
|
54 | include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=True) | |
55 | acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True) |
|
55 | acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True) | |
56 | view_raw_data = models.BooleanField(verbose_name='View Raw Data', default=True) |
|
56 | view_raw_data = models.BooleanField(verbose_name='View Raw Data', default=True) | |
57 | save_ch_dc = models.BooleanField(verbose_name='Save Channels DC', default=True) |
|
57 | save_ch_dc = models.BooleanField(verbose_name='Save Channels DC', default=True) | |
58 |
|
58 | |||
59 | class Meta: |
|
59 | class Meta: | |
60 | db_table = 'jars_configurations' |
|
60 | db_table = 'jars_configurations' | |
61 |
|
61 | |||
62 | def parms_to_dict(self): |
|
62 | def parms_to_dict(self): | |
63 |
|
63 | |||
64 | parameters = {} |
|
64 | parameters = {} | |
65 |
|
65 | |||
66 | parameters['name'] = self.name |
|
66 | parameters['name'] = self.name | |
67 | parameters['rc'] = self.rc.name |
|
67 | parameters['rc'] = self.rc.name | |
68 | parameters['exp_type'] = self.exp_type |
|
68 | parameters['exp_type'] = self.exp_type | |
69 | parameters['cards_number'] = self.cards_number |
|
69 | parameters['cards_number'] = self.cards_number | |
70 | parameters['channels_number'] = self.channels_number |
|
70 | parameters['channels_number'] = self.channels_number | |
71 | parameters['channels'] = self.channels |
|
71 | parameters['channels'] = self.channels | |
72 | parameters['rd_directory'] = self.rd_directory |
|
72 | parameters['rd_directory'] = self.rd_directory | |
73 | parameters['raw_data_blocks'] = self.raw_data_blocks |
|
73 | parameters['raw_data_blocks'] = self.raw_data_blocks | |
74 | parameters['data_type'] = self.data_type |
|
74 | parameters['data_type'] = self.data_type | |
75 | parameters['acq_profiles'] = self.acq_profiles |
|
75 | parameters['acq_profiles'] = self.acq_profiles | |
76 | parameters['profiles_block'] = self.profiles_block |
|
76 | parameters['profiles_block'] = self.profiles_block | |
77 | parameters['filter'] = self.filter.name |
|
77 | parameters['filter'] = self.filter.name | |
78 | parameters['create_directory'] = bool(self.create_directory) |
|
78 | parameters['create_directory'] = bool(self.create_directory) | |
79 | parameters['include_expname'] = bool(self.include_expname) |
|
79 | parameters['include_expname'] = bool(self.include_expname) | |
80 | parameters['acq_link'] = bool(self.acq_link) |
|
80 | parameters['acq_link'] = bool(self.acq_link) | |
81 | parameters['view_raw_data'] = bool(self.view_raw_data) |
|
81 | parameters['view_raw_data'] = bool(self.view_raw_data) | |
82 |
|
82 | |||
83 | return parameters |
|
83 | return parameters | |
84 |
|
84 | |||
85 | def dict_to_parms(self, parameters): |
|
85 | def dict_to_parms(self, parameters): | |
86 | return |
|
86 | return | |
87 |
|
87 | |||
88 | def status_device(self): |
|
88 | def status_device(self): | |
89 | return |
|
89 | return | |
90 |
|
90 | |||
91 | def read_device(self): |
|
91 | def read_device(self): | |
92 | return |
|
92 | return | |
93 |
|
93 | |||
94 | def write_device(self): |
|
94 | def write_device(self): | |
95 | return No newline at end of file |
|
95 | return |
General Comments 0
You need to be logged in to leave comments.
Login now