@@ -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 |
|
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)], |
|
51 | spectral_number = models.PositiveIntegerField(verbose_name='# Spectral Combinations',validators=[MinValueValidator(1)], default=1) | |
52 | spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0,0]') |
|
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 |
@@ -1,103 +1,134 | |||||
1 | {% extends "dev_conf_edit.html" %} |
|
1 | {% extends "dev_conf_edit.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 |
|
5 | |||
6 | {% block extra-js%} |
|
6 | {% block extra-js%} | |
7 | <script type="text/javascript"> |
|
7 | <script type="text/javascript"> | |
8 |
|
8 | |||
9 | $(document).ready(function() { |
|
9 | $(document).ready(function() { | |
10 | var type = $("#id_exp_type").val(); |
|
10 | var type = $("#id_exp_type").val(); | |
11 | spectral_number = $("#id_spectral_number") |
|
11 | spectral_number = $("#id_spectral_number") | |
12 | spectral = $("#id_spectral") |
|
12 | spectral = $("#id_spectral") | |
13 | fftpoints = $("#id_fftpoints") |
|
13 | fftpoints = $("#id_fftpoints") | |
14 | save_ch_dc = $("#id_save_ch_dc") |
|
14 | save_ch_dc = $("#id_save_ch_dc") | |
15 | add_spec_button = $("#add_spectral_button") |
|
15 | add_spec_button = $("#add_spectral_button") | |
16 | del_spec_button = $("#delete_spectral_button") |
|
16 | del_spec_button = $("#delete_spectral_button") | |
|
17 | sel_spec_button = $("#self_spectral_button") | |||
|
18 | cro_spec_button = $("#cross_spectral_button") | |||
|
19 | all_spec_button = $("#all_spectral_button") | |||
|
20 | ||||
17 | if (type == 0) { |
|
21 | if (type == 0) { | |
18 | $(spectral_number).attr('readonly', true); |
|
22 | $(spectral_number).attr('readonly', true); | |
19 | $(spectral).attr('readonly', true); |
|
23 | $(spectral).attr('readonly', true); | |
20 | $(fftpoints).attr('readonly', true); |
|
24 | $(fftpoints).attr('readonly', true); | |
21 | $(save_ch_dc).attr('disabled', true); |
|
25 | $(save_ch_dc).attr('disabled', true); | |
22 | $(save_ch_dc).attr('readonly', true); |
|
26 | $(save_ch_dc).attr('readonly', true); | |
23 | $(add_spec_button).attr('disabled', true); |
|
27 | $(add_spec_button).attr('disabled', true); | |
24 | $(del_spec_button).attr('disabled', true); |
|
28 | $(del_spec_button).attr('disabled', true); | |
25 |
|
29 | $(sel_spec_button).attr('disabled', true); | ||
|
30 | $(cro_spec_button).attr('disabled', true); | |||
|
31 | $(all_spec_button).attr('disabled', true); | |||
26 | } |
|
32 | } | |
27 | else { |
|
33 | else { | |
28 | $(spectral_number).attr('readonly', false); |
|
34 | $(spectral_number).attr('readonly', false); | |
29 | $(spectral).attr('readonly', false); |
|
35 | $(spectral).attr('readonly', false); | |
30 | $(fftpoints).attr('readonly', false); |
|
36 | $(fftpoints).attr('readonly', false); | |
31 | $(save_ch_dc).attr('disabled', false); |
|
37 | $(save_ch_dc).attr('disabled', false); | |
32 | $(save_ch_dc).attr('readonly', false); |
|
38 | $(save_ch_dc).attr('readonly', false); | |
33 | $(add_spec_button).attr('disabled', false); |
|
39 | $(add_spec_button).attr('disabled', false); | |
34 | $(del_spec_button).attr('disabled', false); |
|
40 | $(del_spec_button).attr('disabled', false); | |
|
41 | $(sel_spec_button).attr('disabled', false); | |||
|
42 | $(cro_spec_button).attr('disabled', false); | |||
|
43 | $(all_spec_button).attr('disabled', false); | |||
35 | } |
|
44 | } | |
36 | }); |
|
45 | }); | |
37 |
|
46 | |||
38 | $("#id_exp_type").change(function() { |
|
47 | $("#id_exp_type").change(function() { | |
39 | var type = $("#id_exp_type").val(); |
|
48 | var type = $("#id_exp_type").val(); | |
40 | spectral_number = $("#id_spectral_number") |
|
49 | spectral_number = $("#id_spectral_number") | |
41 | spectral = $("#id_spectral") |
|
50 | spectral = $("#id_spectral") | |
42 | fftpoints = $("#id_fftpoints") |
|
51 | fftpoints = $("#id_fftpoints") | |
43 | save_ch_dc = $("#id_save_ch_dc") |
|
52 | save_ch_dc = $("#id_save_ch_dc") | |
44 | add_spec_button = $("#add_spectral_button") |
|
53 | add_spec_button = $("#add_spectral_button") | |
45 | del_spec_button = $("#delete_spectral_button") |
|
54 | del_spec_button = $("#delete_spectral_button") | |
|
55 | sel_spec_button = $("#self_spectral_button") | |||
|
56 | cro_spec_button = $("#cross_spectral_button") | |||
|
57 | all_spec_button = $("#all_spectral_button") | |||
|
58 | ||||
46 | if (type == 0) { |
|
59 | if (type == 0) { | |
47 | $(spectral_number).attr('readonly', true); |
|
60 | $(spectral_number).attr('readonly', true); | |
48 | $(spectral).attr('readonly', true); |
|
61 | $(spectral).attr('readonly', true); | |
49 | $(fftpoints).attr('readonly', true); |
|
62 | $(fftpoints).attr('readonly', true); | |
50 | $(save_ch_dc).attr('disabled', true); |
|
63 | $(save_ch_dc).attr('disabled', true); | |
51 | $(save_ch_dc).attr('readonly', true); |
|
64 | $(save_ch_dc).attr('readonly', true); | |
52 | $(add_spec_button).attr('disabled', true); |
|
65 | $(add_spec_button).attr('disabled', true); | |
53 | $(del_spec_button).attr('disabled', true); |
|
66 | $(del_spec_button).attr('disabled', true); | |
54 |
|
67 | $(sel_spec_button).attr('disabled', true); | ||
|
68 | $(cro_spec_button).attr('disabled', true); | |||
|
69 | $(all_spec_button).attr('disabled', true); | |||
55 | } |
|
70 | } | |
56 | else { |
|
71 | else { | |
57 | $(spectral_number).attr('readonly', false); |
|
72 | $(spectral_number).attr('readonly', false); | |
58 | $(spectral).attr('readonly', false); |
|
73 | $(spectral).attr('readonly', false); | |
59 | $(fftpoints).attr('readonly', false); |
|
74 | $(fftpoints).attr('readonly', false); | |
60 | $(save_ch_dc).attr('disabled', false); |
|
75 | $(save_ch_dc).attr('disabled', false); | |
61 | $(save_ch_dc).attr('readonly', false); |
|
76 | $(save_ch_dc).attr('readonly', false); | |
62 | $(add_spec_button).attr('disabled', false); |
|
77 | $(add_spec_button).attr('disabled', false); | |
63 | $(del_spec_button).attr('disabled', false); |
|
78 | $(del_spec_button).attr('disabled', false); | |
|
79 | $(sel_spec_button).attr('disabled', false); | |||
|
80 | $(cro_spec_button).attr('disabled', false); | |||
|
81 | $(all_spec_button).attr('disabled', false); | |||
64 | } |
|
82 | } | |
65 | }); |
|
83 | }); | |
66 |
|
84 | |||
|
85 | ||||
|
86 | $("#id_cards_number").on('change', function() { | |||
|
87 | var cards_number = $("#id_cards_number").val(); | |||
|
88 | channels_number = $("#id_channels_number") | |||
|
89 | $(channels_number).val(cards_number*2) | |||
|
90 | updateChannelsNumber(); | |||
|
91 | }); | |||
|
92 | ||||
|
93 | ||||
67 | $("#id_channels_number").on('change', function() { |
|
94 | $("#id_channels_number").on('change', function() { | |
68 | updateChannelsNumber(); |
|
95 | updateChannelsNumber(); | |
69 | }); |
|
96 | }); | |
70 |
|
97 | |||
|
98 | ||||
|
99 | $("#id_spectral").on('change', function() { | |||
|
100 | updateSpectralNumber(); | |||
|
101 | }); | |||
|
102 | ||||
|
103 | ||||
|
104 | function updateSpectralNumber(){ | |||
|
105 | var spectral_comb = $("#id_spectral").val(); | |||
|
106 | var num = spectral_comb.length; | |||
|
107 | var cont = 0 | |||
|
108 | for (i = 0; i < num; i++) { | |||
|
109 | if (spectral_comb[i] == "]"){ | |||
|
110 | cont = cont + 1 | |||
|
111 | } | |||
|
112 | } | |||
|
113 | $("#id_spectral_number").val(cont) | |||
|
114 | } | |||
|
115 | ||||
|
116 | ||||
71 | function updateChannelsNumber() { |
|
117 | function updateChannelsNumber() { | |
72 |
|
118 | |||
73 | var channels_number = $("#id_channels_number").val(); |
|
119 | var channels_number = $("#id_channels_number").val(); | |
74 | channels = $("#id_channels") |
|
120 | channels = $("#id_channels") | |
|
121 | sequence = "" | |||
75 |
|
122 | |||
76 |
|
|
123 | for (i = 1; i <= channels_number; i++) { | |
77 | $(channels).val('1') |
|
124 | if (i==1){ | |
78 | } |
|
125 | sequence = i.toString() | |
79 | else if (channels_number == 2){ |
|
126 | } | |
80 | $(channels).val('1,2') |
|
127 | else{ | |
81 | } |
|
128 | sequence = sequence + "," + i.toString() | |
82 | else if (channels_number == 3){ |
|
129 | } | |
83 | $(channels).val('1,2,3') |
|
|||
84 | } |
|
|||
85 | else if (channels_number == 4){ |
|
|||
86 | $(channels).val('1,2,3,4') |
|
|||
87 | } |
|
130 | } | |
88 | else if (channels_number == 5){ |
|
131 | $(channels).val(sequence) | |
89 | $(channels).val('1,2,3,4,5') |
|
|||
90 | } |
|
|||
91 | else if (channels_number == 6){ |
|
|||
92 | $(channels).val('1,2,3,4,5,6') |
|
|||
93 | } |
|
|||
94 | else if (channels_number == 7){ |
|
|||
95 | $(channels).val('1,2,3,5,6,7') |
|
|||
96 | } |
|
|||
97 | else { |
|
|||
98 | $(channels).val('1,2,3,4,5,6,7,8') |
|
|||
99 | } |
|
|||
100 |
|
||||
101 | } |
|
132 | } | |
102 | </script> |
|
133 | </script> | |
103 | {% endblock %} No newline at end of file |
|
134 | {% endblock %} |
@@ -1,96 +1,164 | |||||
1 |
|
1 | |||
2 | import ast |
|
2 | import ast | |
3 | import json |
|
3 | import json | |
4 | from itertools import chain |
|
4 | from itertools import chain | |
5 |
|
5 | |||
6 | from django import forms |
|
6 | from django import forms | |
7 | from django.utils.safestring import mark_safe |
|
7 | from django.utils.safestring import mark_safe | |
8 | from django.utils.encoding import force_unicode |
|
8 | from django.utils.encoding import force_unicode | |
9 | from django.utils.html import conditional_escape |
|
9 | from django.utils.html import conditional_escape | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | class SpectralWidget(forms.widgets.TextInput): |
|
12 | class SpectralWidget(forms.widgets.TextInput): | |
13 |
|
13 | |||
14 | def render(self, label, value, attrs=None): |
|
14 | def render(self, label, value, attrs=None): | |
15 |
|
15 | |||
16 | disabled = 'disabled' if attrs.get('disabled', False) else '' |
|
16 | disabled = 'disabled' if attrs.get('disabled', False) else '' | |
17 | name = attrs.get('name', label) |
|
17 | name = attrs.get('name', label) | |
18 | if '[' in value: |
|
18 | if '[' in value: | |
19 |
value |
|
19 | if value[len(value)-1] == ",": | |
|
20 | value = ast.literal_eval(value) | |||
|
21 | else: | |||
|
22 | value = value + "," | |||
|
23 | value = ast.literal_eval(value) | |||
20 |
|
24 | |||
21 | codes = value |
|
25 | codes = value | |
22 | if not isinstance(value, list): |
|
26 | if not isinstance(value, list): | |
23 | if len(value) > 1: |
|
27 | text='' | |
24 |
|
|
28 | #lista = [] | |
25 |
|
|
29 | #if len(value) > 1: | |
26 | text = text+str(val)+',' |
|
30 | for val in value: | |
|
31 | text = text+str(val)+',' | |||
|
32 | #lista.append(val) | |||
27 | codes=text |
|
33 | codes=text | |
28 | else: |
|
34 | else: | |
29 |
codes= |
|
35 | codes='' | |
30 |
|
36 | |||
31 | html = '''<textarea rows="5" {0} class="form-control" id="id_{1}" name="{2}" style="white-space:nowrap; overflow:scroll;">{3}</textarea> |
|
37 | 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> |
|
38 | <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> |
|
39 | <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> |
|
40 | <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> |
|
41 | <button type="button" class="button" id="delete_spectral_button"> Delete </button> | |
|
42 | <button type="button" class="button pull-right" id="cross_spectral_button"> Cross </button> | |||
|
43 | <button type="button" class="button pull-right" id="self_spectral_button"> Self </button> | |||
|
44 | <button type="button" class="button pull-right" id="all_spectral_button"> All </button> | |||
39 | '''.format(disabled, label, name, codes) |
|
45 | '''.format(disabled, label, name, codes) | |
40 |
|
46 | |||
41 | script = ''' |
|
47 | script = ''' | |
42 | <script type="text/javascript"> |
|
48 | <script type="text/javascript"> | |
43 | $(document).ready(function () {{ |
|
49 | $(document).ready(function () {{ | |
44 |
|
50 | |||
45 | var spectral_number1 = $("#num1").val(); |
|
51 | var spectral_number1 = $("#num1").val(); | |
46 | var spectral_number2 = $("#num2").val(); |
|
52 | var spectral_number2 = $("#num2").val(); | |
47 |
|
53 | |||
48 |
|
54 | |||
49 | $("#all_spectral_button").click(function(){{ |
|
55 | $("#all_spectral_button").click(function(){{ | |
50 |
|
|
56 | var sequence1 = selfSpectral() | |
|
57 | var sequence2 = crossSpectral() | |||
|
58 | $("#id_spectral").val(sequence1+sequence2) | |||
|
59 | updateSpectralNumber() | |||
51 | }}); |
|
60 | }}); | |
52 |
|
61 | |||
|
62 | ||||
53 | $("#add_spectral_button").click(function(){{ |
|
63 | $("#add_spectral_button").click(function(){{ | |
54 | var spectral_comb = $("#id_spectral").val(); |
|
64 | var spectral_comb = $("#id_spectral").val(); | |
55 | var spectral_number1 = $("#num1").val(); |
|
65 | var spectral_number1 = $("#num1").val(); | |
56 | var spectral_number2 = $("#num2").val(); |
|
66 | var spectral_number2 = $("#num2").val(); | |
57 | var str = spectral_number1+", "+spectral_number2; |
|
67 | var str = spectral_number1+", "+spectral_number2; | |
58 | //not to duplicate |
|
68 | //not to duplicate | |
59 | var n = spectral_comb.search(str); |
|
69 | var n = spectral_comb.search(str); | |
60 | if (n==-1){ |
|
70 | if (n==-1){ | |
61 | $("#id_spectral").val(spectral_comb+"["+$("#num1").val()+", "+$("#num2").val()+"],") |
|
71 | $("#id_spectral").val(spectral_comb+"["+$("#num1").val()+", "+$("#num2").val()+"],") | |
62 |
} |
|
72 | } | |
|
73 | updateSpectralNumber() | |||
|
74 | }}); | |||
|
75 | ||||
|
76 | ||||
|
77 | $("#self_spectral_button").click(function(){{ | |||
|
78 | var sequence = selfSpectral() | |||
|
79 | $("#id_spectral").val(sequence) | |||
|
80 | ||||
|
81 | updateSpectralNumber() | |||
63 | }}); |
|
82 | }}); | |
64 |
|
83 | |||
|
84 | $("#cross_spectral_button").click(function(){{ | |||
|
85 | var sequence = crossSpectral() | |||
|
86 | $("#id_spectral").val(sequence) | |||
|
87 | ||||
|
88 | updateSpectralNumber() | |||
|
89 | }}); | |||
|
90 | ||||
|
91 | ||||
|
92 | function selfSpectral() { | |||
|
93 | var channels = $("#id_channels").val(); | |||
|
94 | var n = (channels.length)-1; | |||
|
95 | var num = parseInt(channels[n]); | |||
|
96 | sequence = "" | |||
|
97 | for (i = 0; i < num; i++) { | |||
|
98 | sequence = sequence + "[" + i.toString() + ", " + i.toString() + "]," | |||
|
99 | } | |||
|
100 | return sequence | |||
|
101 | } | |||
|
102 | ||||
|
103 | ||||
|
104 | function crossSpectral() { | |||
|
105 | var channels = $("#id_channels").val(); | |||
|
106 | var n = (channels.length)-1; | |||
|
107 | var num = parseInt(channels[n]); | |||
|
108 | sequence = "" | |||
|
109 | for (i = 0; i < num; i++) { | |||
|
110 | for (j = i+1; j < num; j++) { | |||
|
111 | sequence = sequence + "[" + i.toString() + ", " + j.toString() + "]," | |||
|
112 | } | |||
|
113 | } | |||
|
114 | return sequence | |||
|
115 | } | |||
|
116 | ||||
|
117 | ||||
|
118 | function updateSpectralNumber(){ | |||
|
119 | var spectral_comb = $("#id_spectral").val(); | |||
|
120 | var num = spectral_comb.length; | |||
|
121 | var cont = 0 | |||
|
122 | for (i = 0; i < num; i++) { | |||
|
123 | if (spectral_comb[i] == "]"){ | |||
|
124 | cont = cont + 1 | |||
|
125 | } | |||
|
126 | } | |||
|
127 | $("#id_spectral_number").val(cont) | |||
|
128 | } | |||
|
129 | ||||
|
130 | ||||
65 | $("#delete_spectral_button").click(function(){{ |
|
131 | $("#delete_spectral_button").click(function(){{ | |
66 | var spectral_comb = $("#id_spectral").val(); |
|
132 | var spectral_comb = $("#id_spectral").val(); | |
67 | var spectral_number1 = $("#num1").val(); |
|
133 | var spectral_number1 = $("#num1").val(); | |
68 | var spectral_number2 = $("#num2").val(); |
|
134 | var spectral_number2 = $("#num2").val(); | |
69 | var str = spectral_number1+", "+spectral_number2; |
|
135 | var str = spectral_number1+", "+spectral_number2; | |
70 | var n = spectral_comb.search(str); |
|
136 | var n = spectral_comb.search(str); | |
71 | if (n==-1){ |
|
137 | if (n==-1){ | |
72 |
|
138 | |||
73 | } |
|
139 | } | |
74 | else { |
|
140 | else { | |
75 | n= spectral_comb.length; |
|
141 | n= spectral_comb.length; | |
76 | if (n<8){ |
|
142 | if (n<8){ | |
77 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," |
|
143 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |
78 | var txt = spectral_comb.replace(tuple,''); |
|
144 | var txt = spectral_comb.replace(tuple,''); | |
79 | } |
|
145 | } | |
80 | else { |
|
146 | else { | |
81 | var tuple = ",["+$("#num1").val()+", "+$("#num2").val()+"]" |
|
147 | var tuple = ",["+$("#num1").val()+", "+$("#num2").val()+"]" | |
82 | var txt = spectral_comb.replace(tuple,''); |
|
148 | var txt = spectral_comb.replace(tuple,''); | |
83 | } |
|
149 | } | |
84 | $("#id_spectral").val(txt) |
|
150 | $("#id_spectral").val(txt) | |
85 |
|
151 | |||
86 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," |
|
152 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |
87 | var txt = spectral_comb.replace(tuple,''); |
|
153 | var txt = spectral_comb.replace(tuple,''); | |
88 | $("#id_spectral").val(txt) |
|
154 | $("#id_spectral").val(txt) | |
89 |
} |
|
155 | } | |
|
156 | updateSpectralNumber() | |||
90 | }}); |
|
157 | }}); | |
91 |
|
158 | |||
|
159 | ||||
92 | }}); |
|
160 | }}); | |
93 | </script> |
|
161 | </script> | |
94 | ''' |
|
162 | ''' | |
95 |
|
163 | |||
96 | return mark_safe(html+script) No newline at end of file |
|
164 | return mark_safe(html+script) |
General Comments 0
You need to be logged in to leave comments.
Login now