##// END OF EJS Templates
Task #99: Modulo web del JARS...
Fiorella Quino -
r130:36666b44dc7e
parent child
Show More
@@ -1,95 +1,95
1 1 from django.db import models
2 2 from apps.main.models import Configuration
3 3 from django.core.validators import MinValueValidator, MaxValueValidator
4 4
5 5 from apps.rc.models import RCConfiguration
6 6 # Create your models here.
7 7
8 8 EXPERIMENT_TYPE = (
9 9 (0, 'RAW_DATA'),
10 10 (1, 'PDATA'),
11 11 )
12 12
13 13 DATA_TYPE = (
14 14 (0, 'SHORT'),
15 15 (1, 'FLOAT'),
16 16 )
17 17
18 18 class JARSfilter(models.Model):
19 19
20 20 name = models.CharField(max_length=60, unique=True, default='')
21 21 filter_fir = models.PositiveIntegerField(verbose_name='FIR Filter',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1)
22 22 filter_2 = models.PositiveIntegerField(verbose_name='Filter 2',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1)
23 23 filter_5 = models.PositiveIntegerField(verbose_name='Filter 5',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1)
24 24
25 25 class Meta:
26 26 db_table = 'jars_filters'
27 27 #ordering = ['channel']
28 28
29 29
30 30 class JARSConfiguration(Configuration):
31 31
32 32 ADC_RESOLUTION = 8
33 33 PCI_DIO_BUSWIDTH = 32
34 34 HEADER_VERSION = 1103
35 35 BEGIN_ON_START = True
36 36 REFRESH_RATE = 1
37 37
38 38 rc = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE, null=True)
39 39 exp_type = models.PositiveIntegerField(verbose_name='Experiment Type', choices=EXPERIMENT_TYPE, default=0)
40 40 cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1)
41 41 channels_number = models.PositiveIntegerField(verbose_name='Number of Channels', validators=[MinValueValidator(1), MaxValueValidator(8)], default = 5)
42 42 channels = models.CharField(verbose_name='Channels', max_length=15, default = '1,2,3,4,5')
43 43 rd_directory = models.CharField(verbose_name='Raw Data Directory', max_length=40, default='', blank=True, null=True)
44 44 raw_data_blocks = models.PositiveIntegerField(verbose_name='Raw Data Blocks', validators=[MaxValueValidator(5000)], default=120)
45 45 data_type = models.PositiveIntegerField(verbose_name='Data Type', choices=DATA_TYPE, default=0)
46 46 acq_profiles = models.PositiveIntegerField(verbose_name='Acquired Profiles', validators=[MaxValueValidator(5000)], default=400)
47 47 profiles_block = models.PositiveIntegerField(verbose_name='Profiles Per Block', validators=[MaxValueValidator(5000)], default=400)
48 48 fftpoints = models.PositiveIntegerField(verbose_name='FFT Points',default=16)
49 49 incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default = 30)
50 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)
52 spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0,0]')
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],')
53 53 create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True)
54 54 include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=True)
55 55 acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True)
56 56 view_raw_data = models.BooleanField(verbose_name='View Raw Data', default=True)
57 57 save_ch_dc = models.BooleanField(verbose_name='Save Channels DC', default=True)
58 58
59 59 class Meta:
60 60 db_table = 'jars_configurations'
61 61
62 62 def parms_to_dict(self):
63 63
64 64 parameters = {}
65 65
66 66 parameters['name'] = self.name
67 67 parameters['rc'] = self.rc.name
68 68 parameters['exp_type'] = self.exp_type
69 69 parameters['cards_number'] = self.cards_number
70 70 parameters['channels_number'] = self.channels_number
71 71 parameters['channels'] = self.channels
72 72 parameters['rd_directory'] = self.rd_directory
73 73 parameters['raw_data_blocks'] = self.raw_data_blocks
74 74 parameters['data_type'] = self.data_type
75 75 parameters['acq_profiles'] = self.acq_profiles
76 76 parameters['profiles_block'] = self.profiles_block
77 77 parameters['filter'] = self.filter.name
78 78 parameters['create_directory'] = bool(self.create_directory)
79 79 parameters['include_expname'] = bool(self.include_expname)
80 80 parameters['acq_link'] = bool(self.acq_link)
81 81 parameters['view_raw_data'] = bool(self.view_raw_data)
82 82
83 83 return parameters
84 84
85 85 def dict_to_parms(self, parameters):
86 86 return
87 87
88 88 def status_device(self):
89 89 return
90 90
91 91 def read_device(self):
92 92 return
93 93
94 94 def write_device(self):
95 95 return No newline at end of file
@@ -1,103 +1,134
1 1 {% extends "dev_conf_edit.html" %}
2 2 {% load bootstrap3 %}
3 3 {% load static %}
4 4 {% load main_tags %}
5 5
6 6 {% block extra-js%}
7 7 <script type="text/javascript">
8 8
9 9 $(document).ready(function() {
10 10 var type = $("#id_exp_type").val();
11 11 spectral_number = $("#id_spectral_number")
12 12 spectral = $("#id_spectral")
13 13 fftpoints = $("#id_fftpoints")
14 14 save_ch_dc = $("#id_save_ch_dc")
15 15 add_spec_button = $("#add_spectral_button")
16 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 21 if (type == 0) {
18 22 $(spectral_number).attr('readonly', true);
19 23 $(spectral).attr('readonly', true);
20 24 $(fftpoints).attr('readonly', true);
21 25 $(save_ch_dc).attr('disabled', true);
22 26 $(save_ch_dc).attr('readonly', true);
23 27 $(add_spec_button).attr('disabled', true);
24 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 33 else {
28 34 $(spectral_number).attr('readonly', false);
29 35 $(spectral).attr('readonly', false);
30 36 $(fftpoints).attr('readonly', false);
31 37 $(save_ch_dc).attr('disabled', false);
32 38 $(save_ch_dc).attr('readonly', false);
33 39 $(add_spec_button).attr('disabled', false);
34 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 47 $("#id_exp_type").change(function() {
39 48 var type = $("#id_exp_type").val();
40 49 spectral_number = $("#id_spectral_number")
41 50 spectral = $("#id_spectral")
42 51 fftpoints = $("#id_fftpoints")
43 52 save_ch_dc = $("#id_save_ch_dc")
44 53 add_spec_button = $("#add_spectral_button")
45 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 59 if (type == 0) {
47 60 $(spectral_number).attr('readonly', true);
48 61 $(spectral).attr('readonly', true);
49 62 $(fftpoints).attr('readonly', true);
50 63 $(save_ch_dc).attr('disabled', true);
51 64 $(save_ch_dc).attr('readonly', true);
52 65 $(add_spec_button).attr('disabled', true);
53 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 71 else {
57 72 $(spectral_number).attr('readonly', false);
58 73 $(spectral).attr('readonly', false);
59 74 $(fftpoints).attr('readonly', false);
60 75 $(save_ch_dc).attr('disabled', false);
61 76 $(save_ch_dc).attr('readonly', false);
62 77 $(add_spec_button).attr('disabled', false);
63 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 94 $("#id_channels_number").on('change', function() {
68 95 updateChannelsNumber();
69 96 });
70 97
71 function updateChannelsNumber() {
72 98
73 var channels_number = $("#id_channels_number").val();
74 channels = $("#id_channels")
99 $("#id_spectral").on('change', function() {
100 updateSpectralNumber();
101 });
75 102
76 if (channels_number == 1) {
77 $(channels).val('1')
78 }
79 else if (channels_number == 2){
80 $(channels).val('1,2')
81 }
82 else if (channels_number == 3){
83 $(channels).val('1,2,3')
84 }
85 else if (channels_number == 4){
86 $(channels).val('1,2,3,4')
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
87 111 }
88 else if (channels_number == 5){
89 $(channels).val('1,2,3,4,5')
90 112 }
91 else if (channels_number == 6){
92 $(channels).val('1,2,3,4,5,6')
113 $("#id_spectral_number").val(cont)
93 114 }
94 else if (channels_number == 7){
95 $(channels).val('1,2,3,5,6,7')
115
116
117 function updateChannelsNumber() {
118
119 var channels_number = $("#id_channels_number").val();
120 channels = $("#id_channels")
121 sequence = ""
122
123 for (i = 1; i <= channels_number; i++) {
124 if (i==1){
125 sequence = i.toString()
96 126 }
97 127 else {
98 $(channels).val('1,2,3,4,5,6,7,8')
128 sequence = sequence + "," + i.toString()
99 129 }
100
130 }
131 $(channels).val(sequence)
101 132 }
102 133 </script>
103 134 {% endblock %} No newline at end of file
@@ -1,96 +1,164
1 1
2 2 import ast
3 3 import json
4 4 from itertools import chain
5 5
6 6 from django import forms
7 7 from django.utils.safestring import mark_safe
8 8 from django.utils.encoding import force_unicode
9 9 from django.utils.html import conditional_escape
10 10
11 11
12 12 class SpectralWidget(forms.widgets.TextInput):
13 13
14 14 def render(self, label, value, attrs=None):
15 15
16 16 disabled = 'disabled' if attrs.get('disabled', False) else ''
17 17 name = attrs.get('name', label)
18 18 if '[' in value:
19 if value[len(value)-1] == ",":
20 value = ast.literal_eval(value)
21 else:
22 value = value + ","
19 23 value = ast.literal_eval(value)
20 24
21 25 codes = value
22 26 if not isinstance(value, list):
23 if len(value) > 1:
24 27 text=''
28 #lista = []
29 #if len(value) > 1:
25 30 for val in value:
26 31 text = text+str(val)+','
32 #lista.append(val)
27 33 codes=text
28 34 else:
29 codes=value+","
35 codes=''
30 36
31 37 html = '''<textarea rows="5" {0} class="form-control" id="id_{1}" name="{2}" style="white-space:nowrap; overflow:scroll;">{3}</textarea>
32 38 <input type="text" class="col-md-1 col-no-padding" id="num1" value=0>
33 39 <input type="text" class="col-md-1 col-no-padding" id="num2" value=0>
34 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 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 45 '''.format(disabled, label, name, codes)
40 46
41 47 script = '''
42 48 <script type="text/javascript">
43 49 $(document).ready(function () {{
44 50
45 51 var spectral_number1 = $("#num1").val();
46 52 var spectral_number2 = $("#num2").val();
47 53
48 54
49 55 $("#all_spectral_button").click(function(){{
50 alert(spectral_comb)
56 var sequence1 = selfSpectral()
57 var sequence2 = crossSpectral()
58 $("#id_spectral").val(sequence1+sequence2)
59 updateSpectralNumber()
51 60 }});
52 61
62
53 63 $("#add_spectral_button").click(function(){{
54 64 var spectral_comb = $("#id_spectral").val();
55 65 var spectral_number1 = $("#num1").val();
56 66 var spectral_number2 = $("#num2").val();
57 67 var str = spectral_number1+", "+spectral_number2;
58 68 //not to duplicate
59 69 var n = spectral_comb.search(str);
60 70 if (n==-1){
61 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 131 $("#delete_spectral_button").click(function(){{
66 132 var spectral_comb = $("#id_spectral").val();
67 133 var spectral_number1 = $("#num1").val();
68 134 var spectral_number2 = $("#num2").val();
69 135 var str = spectral_number1+", "+spectral_number2;
70 136 var n = spectral_comb.search(str);
71 137 if (n==-1){
72 138
73 139 }
74 140 else {
75 141 n= spectral_comb.length;
76 142 if (n<8){
77 143 var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"],"
78 144 var txt = spectral_comb.replace(tuple,'');
79 145 }
80 146 else {
81 147 var tuple = ",["+$("#num1").val()+", "+$("#num2").val()+"]"
82 148 var txt = spectral_comb.replace(tuple,'');
83 149 }
84 150 $("#id_spectral").val(txt)
85 151
86 152 var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"],"
87 153 var txt = spectral_comb.replace(tuple,'');
88 154 $("#id_spectral").val(txt)
89 155 }
156 updateSpectralNumber()
90 157 }});
91 158
159
92 160 }});
93 161 </script>
94 162 '''
95 163
96 164 return mark_safe(html+script) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now