The requested changes are too big and content was truncated. Show full diff
@@ -1,940 +1,940 | |||||
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.urlresolvers import reverse |
|
3 | from django.core.urlresolvers import reverse | |
4 | # Create your models here. |
|
4 | # Create your models here. | |
5 |
|
5 | |||
6 | import ast |
|
6 | import ast | |
7 | import socket |
|
7 | import socket | |
8 | import json |
|
8 | import json | |
9 | import requests |
|
9 | import requests | |
10 | import struct |
|
10 | import struct | |
11 | import sys, time |
|
11 | import sys, time | |
12 |
|
12 | |||
13 | import multiprocessing |
|
13 | import multiprocessing | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | antenna_default = json.dumps({ |
|
16 | antenna_default = json.dumps({ | |
17 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
17 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
18 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
18 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
19 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
19 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
20 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
20 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
21 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
21 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], | |
22 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
22 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], | |
23 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
23 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], | |
24 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] |
|
24 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] | |
25 | ] |
|
25 | ] | |
26 | , |
|
26 | , | |
27 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
27 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
28 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
28 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
29 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
29 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
30 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
30 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
31 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
31 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], | |
32 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
32 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], | |
33 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
33 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], | |
34 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], |
|
34 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], | |
35 | }) |
|
35 | }) | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | tx_default = json.dumps({ |
|
38 | tx_default = json.dumps({ | |
39 | "up": [[1,1,1,1,0,0,0,0], |
|
39 | "up": [[1,1,1,1,0,0,0,0], | |
40 | [1,1,1,1,0,0,0,0], |
|
40 | [1,1,1,1,0,0,0,0], | |
41 | [1,1,1,1,0,0,0,0], |
|
41 | [1,1,1,1,0,0,0,0], | |
42 | [1,1,1,1,0,0,0,0], |
|
42 | [1,1,1,1,0,0,0,0], | |
43 | [0,0,0,0,1,1,1,1], |
|
43 | [0,0,0,0,1,1,1,1], | |
44 | [0,0,0,0,1,1,1,1], |
|
44 | [0,0,0,0,1,1,1,1], | |
45 | [0,0,0,0,1,1,1,1], |
|
45 | [0,0,0,0,1,1,1,1], | |
46 | [0,0,0,0,1,1,1,1]], |
|
46 | [0,0,0,0,1,1,1,1]], | |
47 |
|
47 | |||
48 | "down": [[1,1,1,1,0,0,0,0], |
|
48 | "down": [[1,1,1,1,0,0,0,0], | |
49 | [1,1,1,1,0,0,0,0], |
|
49 | [1,1,1,1,0,0,0,0], | |
50 | [1,1,1,1,0,0,0,0], |
|
50 | [1,1,1,1,0,0,0,0], | |
51 | [1,1,1,1,0,0,0,0], |
|
51 | [1,1,1,1,0,0,0,0], | |
52 | [0,0,0,0,1,1,1,1], |
|
52 | [0,0,0,0,1,1,1,1], | |
53 | [0,0,0,0,1,1,1,1], |
|
53 | [0,0,0,0,1,1,1,1], | |
54 | [0,0,0,0,1,1,1,1], |
|
54 | [0,0,0,0,1,1,1,1], | |
55 | [0,0,0,0,1,1,1,1]], |
|
55 | [0,0,0,0,1,1,1,1]], | |
56 | }) |
|
56 | }) | |
57 |
|
57 | |||
58 | rx_default = json.dumps({ |
|
58 | rx_default = json.dumps({ | |
59 | "up": [[1,1,1,1,0,0,0,0], |
|
59 | "up": [[1,1,1,1,0,0,0,0], | |
60 | [1,1,1,1,0,0,0,0], |
|
60 | [1,1,1,1,0,0,0,0], | |
61 | [1,1,1,1,0,0,0,0], |
|
61 | [1,1,1,1,0,0,0,0], | |
62 | [1,1,1,1,0,0,0,0], |
|
62 | [1,1,1,1,0,0,0,0], | |
63 | [0,0,0,0,1,1,1,1], |
|
63 | [0,0,0,0,1,1,1,1], | |
64 | [0,0,0,0,1,1,1,1], |
|
64 | [0,0,0,0,1,1,1,1], | |
65 | [0,0,0,0,1,1,1,1], |
|
65 | [0,0,0,0,1,1,1,1], | |
66 | [0,0,0,0,1,1,1,1]], |
|
66 | [0,0,0,0,1,1,1,1]], | |
67 |
|
67 | |||
68 | "down": [[1,1,1,1,0,0,0,0], |
|
68 | "down": [[1,1,1,1,0,0,0,0], | |
69 | [1,1,1,1,0,0,0,0], |
|
69 | [1,1,1,1,0,0,0,0], | |
70 | [1,1,1,1,0,0,0,0], |
|
70 | [1,1,1,1,0,0,0,0], | |
71 | [1,1,1,1,0,0,0,0], |
|
71 | [1,1,1,1,0,0,0,0], | |
72 | [0,0,0,0,1,1,1,1], |
|
72 | [0,0,0,0,1,1,1,1], | |
73 | [0,0,0,0,1,1,1,1], |
|
73 | [0,0,0,0,1,1,1,1], | |
74 | [0,0,0,0,1,1,1,1], |
|
74 | [0,0,0,0,1,1,1,1], | |
75 | [0,0,0,0,1,1,1,1]], |
|
75 | [0,0,0,0,1,1,1,1]], | |
76 | }) |
|
76 | }) | |
77 |
|
77 | |||
78 | conf_default = {} |
|
78 | conf_default = {} | |
79 | status_default = {} |
|
79 | status_default = {} | |
80 | for i in range(1,65): |
|
80 | for i in range(1,65): | |
81 | conf_default[str(i)] = "" |
|
81 | conf_default[str(i)] = "" | |
82 | status_default[str(i)] = 0 |
|
82 | status_default[str(i)] = 0 | |
83 |
|
83 | |||
84 | ues_default = json.dumps({ |
|
84 | ues_default = json.dumps({ | |
85 | "up": [0.533333,0.00000,1.06667,0.00000], |
|
85 | "up": [0.533333,0.00000,1.06667,0.00000], | |
86 | "down": [0.533333,0.00000,1.06667,0.00000] |
|
86 | "down": [0.533333,0.00000,1.06667,0.00000] | |
87 | }) |
|
87 | }) | |
88 |
|
88 | |||
89 | onlyrx_default = json.dumps({ |
|
89 | onlyrx_default = json.dumps({ | |
90 | "up": False, |
|
90 | "up": False, | |
91 | "down": False |
|
91 | "down": False | |
92 | }) |
|
92 | }) | |
93 |
|
93 | |||
94 | def up_convertion(cadena): |
|
94 | def up_convertion(cadena): | |
95 | valores = [] |
|
95 | valores = [] | |
96 | for c in cadena: |
|
96 | for c in cadena: | |
97 | if c == 1.0: valores=valores+['000'] |
|
97 | if c == 1.0: valores=valores+['000'] | |
98 | if c == 2.0: valores=valores+['001'] |
|
98 | if c == 2.0: valores=valores+['001'] | |
99 | if c == 3.0: valores=valores+['010'] |
|
99 | if c == 3.0: valores=valores+['010'] | |
100 | if c == 0.0: valores=valores+['011'] |
|
100 | if c == 0.0: valores=valores+['011'] | |
101 | if c == 0.5: valores=valores+['100'] |
|
101 | if c == 0.5: valores=valores+['100'] | |
102 | if c == 1.5: valores=valores+['101'] |
|
102 | if c == 1.5: valores=valores+['101'] | |
103 | if c == 2.5: valores=valores+['110'] |
|
103 | if c == 2.5: valores=valores+['110'] | |
104 | if c == 3.5: valores=valores+['111'] |
|
104 | if c == 3.5: valores=valores+['111'] | |
105 |
|
105 | |||
106 | return valores |
|
106 | return valores | |
107 |
|
107 | |||
108 | def up_conv_bits(value): |
|
108 | def up_conv_bits(value): | |
109 |
|
109 | |||
110 | if value == 1.0: bits="000" |
|
110 | if value == 1.0: bits="000" | |
111 | if value == 2.0: bits="001" |
|
111 | if value == 2.0: bits="001" | |
112 | if value == 3.0: bits="010" |
|
112 | if value == 3.0: bits="010" | |
113 | if value == 0.0: bits="011" |
|
113 | if value == 0.0: bits="011" | |
114 | if value == 0.5: bits="100" |
|
114 | if value == 0.5: bits="100" | |
115 | if value == 1.5: bits="101" |
|
115 | if value == 1.5: bits="101" | |
116 | if value == 2.5: bits="110" |
|
116 | if value == 2.5: bits="110" | |
117 | if value == 3.5: bits="111" |
|
117 | if value == 3.5: bits="111" | |
118 |
|
118 | |||
119 | return bits |
|
119 | return bits | |
120 |
|
120 | |||
121 | def down_convertion(cadena): |
|
121 | def down_convertion(cadena): | |
122 | valores = [] |
|
122 | valores = [] | |
123 | for c in cadena: |
|
123 | for c in cadena: | |
124 | if c == 1.0: valores=valores+['000'] |
|
124 | if c == 1.0: valores=valores+['000'] | |
125 | if c == 2.0: valores=valores+['001'] |
|
125 | if c == 2.0: valores=valores+['001'] | |
126 | if c == 3.0: valores=valores+['010'] |
|
126 | if c == 3.0: valores=valores+['010'] | |
127 | if c == 0.0: valores=valores+['011'] |
|
127 | if c == 0.0: valores=valores+['011'] | |
128 | if c == 0.5: valores=valores+['100'] |
|
128 | if c == 0.5: valores=valores+['100'] | |
129 | if c == 1.5: valores=valores+['101'] |
|
129 | if c == 1.5: valores=valores+['101'] | |
130 | if c == 2.5: valores=valores+['110'] |
|
130 | if c == 2.5: valores=valores+['110'] | |
131 | if c == 3.5: valores=valores+['111'] |
|
131 | if c == 3.5: valores=valores+['111'] | |
132 |
|
132 | |||
133 | return valores |
|
133 | return valores | |
134 |
|
134 | |||
135 | def down_conv_bits(value): |
|
135 | def down_conv_bits(value): | |
136 |
|
136 | |||
137 | if value == 1.0: bits="000" |
|
137 | if value == 1.0: bits="000" | |
138 | if value == 2.0: bits="001" |
|
138 | if value == 2.0: bits="001" | |
139 | if value == 3.0: bits="010" |
|
139 | if value == 3.0: bits="010" | |
140 | if value == 0.0: bits="011" |
|
140 | if value == 0.0: bits="011" | |
141 | if value == 0.5: bits="100" |
|
141 | if value == 0.5: bits="100" | |
142 | if value == 1.5: bits="101" |
|
142 | if value == 1.5: bits="101" | |
143 | if value == 2.5: bits="110" |
|
143 | if value == 2.5: bits="110" | |
144 | if value == 3.5: bits="111" |
|
144 | if value == 3.5: bits="111" | |
145 |
|
145 | |||
146 | return bits |
|
146 | return bits | |
147 |
|
147 | |||
148 | def ip2position(module_number): |
|
148 | def ip2position(module_number): | |
149 | j=0 |
|
149 | j=0 | |
150 | i=0 |
|
150 | i=0 | |
151 | for x in range(0,module_number-1): |
|
151 | for x in range(0,module_number-1): | |
152 | j=j+1 |
|
152 | j=j+1 | |
153 | if j==8: |
|
153 | if j==8: | |
154 | i=i+1 |
|
154 | i=i+1 | |
155 | j=0 |
|
155 | j=0 | |
156 |
|
156 | |||
157 | pos = [i,j] |
|
157 | pos = [i,j] | |
158 | return pos |
|
158 | return pos | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | def change_beam_for_multiprocessing(module): |
|
161 | def change_beam_for_multiprocessing(module): | |
162 |
|
162 | |||
163 | for i in range (1,50): |
|
163 | for i in range (1,50): | |
164 | beam_pos = 0 |
|
164 | beam_pos = 0 | |
165 | module_address = ('192.168.1.'+str(module), 5500) |
|
165 | module_address = ('192.168.1.'+str(module), 5500) | |
166 | header = 'JROABSCeCnModCnMod0100000' |
|
166 | header = 'JROABSCeCnModCnMod0100000' | |
167 | numbers = len(str(beam_pos)) |
|
167 | numbers = len(str(beam_pos)) | |
168 | function = 'CHGB' |
|
168 | function = 'CHGB' | |
169 |
|
169 | |||
170 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
170 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
171 |
|
171 | |||
172 | # Create the datagram socket |
|
172 | # Create the datagram socket | |
173 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
173 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
174 | sock.connect(module_address) |
|
174 | sock.connect(module_address) | |
175 |
|
175 | |||
176 | sock.send(message_tx) |
|
176 | sock.send(message_tx) | |
177 | #t = sock.recv(1024) |
|
177 | #t = sock.recv(1024) | |
178 | sock.close() |
|
178 | sock.close() | |
179 | sock = None |
|
179 | sock = None | |
180 |
|
180 | |||
181 |
|
181 | |||
182 | time.sleep(0.2) |
|
182 | time.sleep(0.2) | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | beam_pos = 1 |
|
185 | beam_pos = 1 | |
186 | numbers = len(str(beam_pos)) |
|
186 | numbers = len(str(beam_pos)) | |
187 |
|
187 | |||
188 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
188 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
189 |
|
189 | |||
190 | # Create the datagram socket |
|
190 | # Create the datagram socket | |
191 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
191 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
192 | sock.connect(module_address) |
|
192 | sock.connect(module_address) | |
193 | sock.send(message_tx) |
|
193 | sock.send(message_tx) | |
194 | sock.close() |
|
194 | sock.close() | |
195 | sock = None |
|
195 | sock = None | |
196 |
|
196 | |||
197 | time.sleep(0.2) |
|
197 | time.sleep(0.2) | |
198 |
|
198 | |||
199 |
|
199 | |||
200 |
|
200 | |||
201 | class ABSConfiguration(Configuration): |
|
201 | class ABSConfiguration(Configuration): | |
202 | beams = models.CharField(verbose_name='Beams', max_length=20000, default="{}") |
|
202 | beams = models.CharField(verbose_name='Beams', max_length=20000, default="{}") | |
203 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default)) |
|
203 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default)) | |
204 |
|
204 | |||
205 | class Meta: |
|
205 | class Meta: | |
206 | db_table = 'abs_configurations' |
|
206 | db_table = 'abs_configurations' | |
207 |
|
207 | |||
208 | def get_absolute_url_plot(self): |
|
208 | def get_absolute_url_plot(self): | |
209 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) |
|
209 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) | |
210 |
|
210 | |||
211 |
|
211 | |||
212 | def parms_to_dict(self): |
|
212 | def parms_to_dict(self): | |
213 |
|
213 | |||
214 | parameters = {} |
|
214 | parameters = {} | |
215 |
|
215 | |||
216 | parameters['device_id'] = self.device.id |
|
216 | parameters['device_id'] = self.device.id | |
217 | parameters['name'] = self.name |
|
217 | parameters['name'] = self.name | |
218 | parameters['beams'] = {} |
|
218 | parameters['beams'] = {} | |
219 |
|
219 | |||
220 | beams = ast.literal_eval(self.beams) |
|
220 | beams = ast.literal_eval(self.beams) | |
221 | b=1 |
|
221 | b=1 | |
222 | for beam in beams: |
|
222 | for beam in beams: | |
223 | absbeam = ABSBeam.objects.get(pk=beams[beam]) |
|
223 | absbeam = ABSBeam.objects.get(pk=beams[beam]) | |
224 | parameters['beams']['beam'+str(b)] = absbeam.parms_to_dict() |
|
224 | parameters['beams']['beam'+str(b)] = absbeam.parms_to_dict() | |
225 | b+=1 |
|
225 | b+=1 | |
226 |
|
226 | |||
227 | return parameters |
|
227 | return parameters | |
228 |
|
228 | |||
229 |
|
229 | |||
230 | def module_conf(self, module_num, beams): |
|
230 | def module_conf(self, module_num, beams): | |
231 | """ |
|
231 | """ | |
232 | This function creates beam configurations for one abs module. |
|
232 | This function creates beam configurations for one abs module. | |
233 | """ |
|
233 | """ | |
234 | ip_address = self.device.ip_address |
|
234 | ip_address = self.device.ip_address | |
235 | ip_address = ip_address.split('.') |
|
235 | ip_address = ip_address.split('.') | |
236 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
236 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) | |
237 | dot = '.' |
|
237 | dot = '.' | |
238 | module_ip = dot.join(module_seq)+'.'+str(module_num) |
|
238 | module_ip = dot.join(module_seq)+'.'+str(module_num) | |
239 | module_port = self.device.port_address |
|
239 | module_port = self.device.port_address | |
240 | write_route = 'http://'+module_ip+':'+str(module_port)+'/configure' |
|
240 | write_route = 'http://'+module_ip+':'+str(module_port)+'/configure' | |
241 |
|
241 | |||
242 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' |
|
242 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' | |
243 | module = 'ABS_'+str(module_num) |
|
243 | module = 'ABS_'+str(module_num) | |
244 | bs = {} |
|
244 | bs = {} | |
245 | i=1 |
|
245 | i=1 | |
246 | #beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', |
|
246 | #beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', | |
247 | # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} |
|
247 | # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} | |
248 | for beam in beams: |
|
248 | for beam in beams: | |
249 | bs[i] = beam.module_6bits(module_num) |
|
249 | bs[i] = beam.module_6bits(module_num) | |
250 | i=i+1 |
|
250 | i=i+1 | |
251 |
|
251 | |||
252 | beams = bs |
|
252 | beams = bs | |
253 |
|
253 | |||
254 | parameters = {} |
|
254 | parameters = {} | |
255 | parameters['header'] = header |
|
255 | parameters['header'] = header | |
256 | parameters['module'] = module |
|
256 | parameters['module'] = module | |
257 | parameters['beams'] = json.dumps(beams) |
|
257 | parameters['beams'] = json.dumps(beams) | |
258 |
|
258 | |||
259 | answer = '' |
|
259 | answer = '' | |
260 |
|
260 | |||
261 | try: |
|
261 | try: | |
262 | r_write = requests.post(write_route, parameters, timeout=0.5) |
|
262 | r_write = requests.post(write_route, parameters, timeout=0.5) | |
263 | answer = r_write.json() |
|
263 | answer = r_write.json() | |
264 | self.message = answer['message'] |
|
264 | self.message = answer['message'] | |
265 | except: |
|
265 | except: | |
266 | self.message = "Could not write ABS parameters" |
|
266 | self.message = "Could not write ABS parameters" | |
267 | return 0 |
|
267 | return 0 | |
268 | return 1 |
|
268 | return 1 | |
269 |
|
269 | |||
270 |
|
270 | |||
271 | def read_module(self, module): |
|
271 | def read_module(self, module): | |
272 |
|
272 | |||
273 | """ |
|
273 | """ | |
274 | Read out-bits (up-down) of 1 abs module NOT for Configuration |
|
274 | Read out-bits (up-down) of 1 abs module NOT for Configuration | |
275 | """ |
|
275 | """ | |
276 |
|
276 | |||
277 | parameters = {} |
|
277 | parameters = {} | |
278 | ip_address = self.device.ip_address |
|
278 | ip_address = self.device.ip_address | |
279 | ip_address = ip_address.split('.') |
|
279 | ip_address = ip_address.split('.') | |
280 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
280 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) | |
281 | dot = '.' |
|
281 | dot = '.' | |
282 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
282 | module_ip = dot.join(module_seq)+'.'+str(module) | |
283 | module_port = self.device.port_address |
|
283 | module_port = self.device.port_address | |
284 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' |
|
284 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' | |
285 |
|
285 | |||
286 |
print |
|
286 | print(read_route) | |
287 |
|
287 | |||
288 | answer = '' |
|
288 | answer = '' | |
289 | module_bits = '' |
|
289 | module_bits = '' | |
290 |
|
290 | |||
291 | try: |
|
291 | try: | |
292 | r_write = requests.get(read_route, timeout=0.7) |
|
292 | r_write = requests.get(read_route, timeout=0.7) | |
293 | answer = r_write.json() |
|
293 | answer = r_write.json() | |
294 | message = answer['message'] |
|
294 | message = answer['message'] | |
295 | module_bits = answer['allbits'] |
|
295 | module_bits = answer['allbits'] | |
296 | except: |
|
296 | except: | |
297 | message = "Could not read ABS parameters" |
|
297 | message = "Could not read ABS parameters" | |
298 | return 0 |
|
298 | return 0 | |
299 |
|
299 | |||
300 | return module_bits |
|
300 | return module_bits | |
301 |
|
301 | |||
302 |
|
302 | |||
303 | def write_device(self): |
|
303 | def write_device(self): | |
304 | """ |
|
304 | """ | |
305 | This function sends the beams list to every abs module. |
|
305 | This function sends the beams list to every abs module. | |
306 | """ |
|
306 | """ | |
307 |
|
307 | |||
308 | beams_list = ast.literal_eval(self.beams) |
|
308 | beams_list = ast.literal_eval(self.beams) | |
309 | beams = [] |
|
309 | beams = [] | |
310 |
|
310 | |||
311 | for bl in range(1,len(beams_list)+1): |
|
311 | for bl in range(1,len(beams_list)+1): | |
312 | b = ABSBeam.objects.get(pk=beams_list['beam'+str(bl)]) |
|
312 | b = ABSBeam.objects.get(pk=beams_list['beam'+str(bl)]) | |
313 | beams.append(b) |
|
313 | beams.append(b) | |
314 |
|
314 | |||
315 | #---Write each abs module--- |
|
315 | #---Write each abs module--- | |
316 | beams_status = ast.literal_eval(self.module_status) |
|
316 | beams_status = ast.literal_eval(self.module_status) | |
317 | for i in range(62,65): |
|
317 | for i in range(62,65): | |
318 | try: |
|
318 | try: | |
319 | self.module_conf(i, beams) |
|
319 | self.module_conf(i, beams) | |
320 | beams_status[str(i)] = 1 |
|
320 | beams_status[str(i)] = 1 | |
321 | self.module_status = json.dumps(beams_status) |
|
321 | self.module_status = json.dumps(beams_status) | |
322 | self.save() |
|
322 | self.save() | |
323 | #self.module_conf(63,beams) |
|
323 | #self.module_conf(63,beams) | |
324 | #beams_status[str(63)] = 1 |
|
324 | #beams_status[str(63)] = 1 | |
325 | #self.module_status = json.dumps(beams_status) |
|
325 | #self.module_status = json.dumps(beams_status) | |
326 | except: |
|
326 | except: | |
327 | beams_status[str(i)] = 0 |
|
327 | beams_status[str(i)] = 0 | |
328 | self.module_status = json.dumps(beams_status) |
|
328 | self.module_status = json.dumps(beams_status) | |
329 | self.save() |
|
329 | self.save() | |
330 | #return 0 |
|
330 | #return 0 | |
331 |
|
331 | |||
332 | #self.device.status = 1 |
|
332 | #self.device.status = 1 | |
333 | self.save() |
|
333 | self.save() | |
334 | return 1 |
|
334 | return 1 | |
335 |
|
335 | |||
336 |
|
336 | |||
337 | def write_module(self, module): |
|
337 | def write_module(self, module): | |
338 |
|
338 | |||
339 | """ |
|
339 | """ | |
340 | Send configuration to one abs module |
|
340 | Send configuration to one abs module | |
341 | """ |
|
341 | """ | |
342 |
|
342 | |||
343 | parameters = {} |
|
343 | parameters = {} | |
344 | ip_address = self.abs_conf.device.ip_address |
|
344 | ip_address = self.abs_conf.device.ip_address | |
345 | ip_address = ip_address.split('.') |
|
345 | ip_address = ip_address.split('.') | |
346 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
346 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) | |
347 | dot = '.' |
|
347 | dot = '.' | |
348 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
348 | module_ip = dot.join(module_seq)+'.'+str(module) | |
349 | module_port = self.abs_conf.device.port_address |
|
349 | module_port = self.abs_conf.device.port_address | |
350 | write_route = 'http://'+module_ip+':'+str(module_port)+'/configure' |
|
350 | write_route = 'http://'+module_ip+':'+str(module_port)+'/configure' | |
351 |
|
351 | |||
352 | #print write_route |
|
352 | #print write_route | |
353 |
|
353 | |||
354 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' |
|
354 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' | |
355 | module = 'ABS_'+str(module) |
|
355 | module = 'ABS_'+str(module) | |
356 | beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', |
|
356 | beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', | |
357 | 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} |
|
357 | 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} | |
358 |
|
358 | |||
359 | parameters['header'] = header |
|
359 | parameters['header'] = header | |
360 | parameters['module'] = module |
|
360 | parameters['module'] = module | |
361 | parameters['beams'] = json.dumps(beams) |
|
361 | parameters['beams'] = json.dumps(beams) | |
362 |
|
362 | |||
363 | answer = '' |
|
363 | answer = '' | |
364 |
|
364 | |||
365 | try: |
|
365 | try: | |
366 | r_write = requests.post(write_route, parameters, timeout=0.5) |
|
366 | r_write = requests.post(write_route, parameters, timeout=0.5) | |
367 | answer = r_write.json() |
|
367 | answer = r_write.json() | |
368 | self.message = answer['message'] |
|
368 | self.message = answer['message'] | |
369 | except: |
|
369 | except: | |
370 | self.message = "Could not write ABS parameters" |
|
370 | self.message = "Could not write ABS parameters" | |
371 | return 0 |
|
371 | return 0 | |
372 |
|
372 | |||
373 |
|
373 | |||
374 | #self.device.status = int(answer['status']) |
|
374 | #self.device.status = int(answer['status']) | |
375 |
|
375 | |||
376 | return 1 |
|
376 | return 1 | |
377 |
|
377 | |||
378 |
|
378 | |||
379 | def beam_selector(self, module, beam_pos): |
|
379 | def beam_selector(self, module, beam_pos): | |
380 | """ |
|
380 | """ | |
381 | This function selects the beam number for one absmodule. |
|
381 | This function selects the beam number for one absmodule. | |
382 | """ |
|
382 | """ | |
383 |
|
383 | |||
384 | if beam_pos > 0: |
|
384 | if beam_pos > 0: | |
385 | beam_pos = beam_pos - 1 |
|
385 | beam_pos = beam_pos - 1 | |
386 | else: |
|
386 | else: | |
387 | beam_pos = 0 |
|
387 | beam_pos = 0 | |
388 |
|
388 | |||
389 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
389 | #El indice del apunte debe ser menor que el numero total de apuntes | |
390 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
390 | #El servidor tcp en el embebido comienza a contar desde 0 | |
391 | beams_list = ast.literal_eval(self.beams) |
|
391 | beams_list = ast.literal_eval(self.beams) | |
392 | if len(beams_list) < beam_pos: |
|
392 | if len(beams_list) < beam_pos: | |
393 | return 0 |
|
393 | return 0 | |
394 |
|
394 | |||
395 | flag = 1 |
|
395 | flag = 1 | |
396 | if beam_pos>9: |
|
396 | if beam_pos>9: | |
397 | flag = 2 |
|
397 | flag = 2 | |
398 |
|
398 | |||
399 | module_address = ('192.168.1.'+str(module), 5500) |
|
399 | module_address = ('192.168.1.'+str(module), 5500) | |
400 | header = 'JROABSCeCnModCnMod0100000' |
|
400 | header = 'JROABSCeCnModCnMod0100000' | |
401 | numbers = len(str(beam_pos)) |
|
401 | numbers = len(str(beam_pos)) | |
402 | function = 'CHGB' |
|
402 | function = 'CHGB' | |
403 |
|
403 | |||
404 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
404 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
405 |
|
405 | |||
406 | # Create the datagram socket |
|
406 | # Create the datagram socket | |
407 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
407 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
408 | #sock.connect(module_address) |
|
408 | #sock.connect(module_address) | |
409 | try: |
|
409 | try: | |
410 | sock.connect(module_address) |
|
410 | sock.connect(module_address) | |
411 | sock.send(message_tx) |
|
411 | sock.send(message_tx) | |
412 | sock.close() |
|
412 | sock.close() | |
413 |
print |
|
413 | print("Writing abs module:"+module_address[0]+"...") | |
414 | except: |
|
414 | except: | |
415 | sock = None |
|
415 | sock = None | |
416 |
print |
|
416 | print("Problem writing abs module:"+module_address[0]) | |
417 | return 0 |
|
417 | return 0 | |
418 |
|
418 | |||
419 | return 1 |
|
419 | return 1 | |
420 |
|
420 | |||
421 |
|
421 | |||
422 | def change_beam(self, beam_pos): |
|
422 | def change_beam(self, beam_pos): | |
423 | """ |
|
423 | """ | |
424 | This function selects the beam number for all absmodules. |
|
424 | This function selects the beam number for all absmodules. | |
425 | """ |
|
425 | """ | |
426 | for i in range(1,65): |
|
426 | for i in range(1,65): | |
427 | try: |
|
427 | try: | |
428 | self.beam_selector(i,beam_pos) |
|
428 | self.beam_selector(i,beam_pos) | |
429 | except: |
|
429 | except: | |
430 |
print |
|
430 | print("Problem with module: 192.168.1."+str(i)) | |
431 | self.message = "Problem with module: 192.168.1."+str(i) |
|
431 | self.message = "Problem with module: 192.168.1."+str(i) | |
432 | #return 0 |
|
432 | #return 0 | |
433 | return 1 |
|
433 | return 1 | |
434 |
|
434 | |||
435 |
|
435 | |||
436 | def send_beam_num(self, beam_pos): |
|
436 | def send_beam_num(self, beam_pos): | |
437 | """ |
|
437 | """ | |
438 | This function connects to a multicast group and sends the beam number |
|
438 | This function connects to a multicast group and sends the beam number | |
439 | to all abs modules. |
|
439 | to all abs modules. | |
440 | """ |
|
440 | """ | |
441 |
|
441 | |||
442 | if beam_pos > 0: |
|
442 | if beam_pos > 0: | |
443 | beam_pos = beam_pos - 1 |
|
443 | beam_pos = beam_pos - 1 | |
444 | else: |
|
444 | else: | |
445 | beam_pos = 0 |
|
445 | beam_pos = 0 | |
446 |
|
446 | |||
447 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
447 | #El indice del apunte debe ser menor que el numero total de apuntes | |
448 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
448 | #El servidor tcp en el embebido comienza a contar desde 0 | |
449 | beams_list = ast.literal_eval(self.beams) |
|
449 | beams_list = ast.literal_eval(self.beams) | |
450 | if len(beams_list) < beam_pos: |
|
450 | if len(beams_list) < beam_pos: | |
451 | return 0 |
|
451 | return 0 | |
452 |
|
452 | |||
453 | flag = 1 |
|
453 | flag = 1 | |
454 | if beam_pos>9: |
|
454 | if beam_pos>9: | |
455 | flag = 2 |
|
455 | flag = 2 | |
456 |
|
456 | |||
457 | header = 'JROABSCeCnModCnMod0100000' |
|
457 | header = 'JROABSCeCnModCnMod0100000' | |
458 | flag = str(flag) |
|
458 | flag = str(flag) | |
459 | function = 'CHGB' |
|
459 | function = 'CHGB' | |
460 | message_tx = header+flag+function+str(beam_pos)+'0' |
|
460 | message_tx = header+flag+function+str(beam_pos)+'0' | |
461 |
|
461 | |||
462 | multicast_group = '224.3.29.71' |
|
462 | multicast_group = '224.3.29.71' | |
463 | server_address = ('',10000) |
|
463 | server_address = ('',10000) | |
464 |
|
464 | |||
465 | # Create the socket |
|
465 | # Create the socket | |
466 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
466 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
467 | # Bind to the server address |
|
467 | # Bind to the server address | |
468 | sock.bind(server_address) |
|
468 | sock.bind(server_address) | |
469 | # Telling the OS add the socket to the multicast on all interfaces |
|
469 | # Telling the OS add the socket to the multicast on all interfaces | |
470 | group = socket.inet_aton(multicast_group) |
|
470 | group = socket.inet_aton(multicast_group) | |
471 | mreq = struct.pack('4sL', group, socket.INADDR_ANY) |
|
471 | mreq = struct.pack('4sL', group, socket.INADDR_ANY) | |
472 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) |
|
472 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) | |
473 |
|
473 | |||
474 | #print 'sending acknowledgement to all: \n' + message_tx |
|
474 | #print 'sending acknowledgement to all: \n' + message_tx | |
475 | sock.sendto(message_tx, (multicast_group, 10000)) |
|
475 | sock.sendto(message_tx, (multicast_group, 10000)) | |
476 | sock.close() |
|
476 | sock.close() | |
477 | sock = None |
|
477 | sock = None | |
478 |
|
478 | |||
479 | return 1 |
|
479 | return 1 | |
480 |
|
480 | |||
481 | def test1(self): |
|
481 | def test1(self): | |
482 | t1 = time.time() |
|
482 | t1 = time.time() | |
483 | t2 = 0 |
|
483 | t2 = 0 | |
484 | while (t2-t1)<300: |
|
484 | while (t2-t1)<300: | |
485 | t2 = time.time() |
|
485 | t2 = time.time() | |
486 | self.send_beam_num(1) |
|
486 | self.send_beam_num(1) | |
487 | time.sleep(0.04) |
|
487 | time.sleep(0.04) | |
488 | self.send_beam_num(2) |
|
488 | self.send_beam_num(2) | |
489 | time.sleep(0.04) |
|
489 | time.sleep(0.04) | |
490 | return |
|
490 | return | |
491 |
|
491 | |||
492 | def change_procs_test1(self, module): |
|
492 | def change_procs_test1(self, module): | |
493 |
|
493 | |||
494 | for i in range (1,300): |
|
494 | for i in range (1,300): | |
495 | beam_pos = 0 |
|
495 | beam_pos = 0 | |
496 | module_address = ('192.168.1.'+str(module), 5500) |
|
496 | module_address = ('192.168.1.'+str(module), 5500) | |
497 | header = 'JROABSCeCnModCnMod0100000' |
|
497 | header = 'JROABSCeCnModCnMod0100000' | |
498 | numbers = len(str(beam_pos)) |
|
498 | numbers = len(str(beam_pos)) | |
499 | function = 'CHGB' |
|
499 | function = 'CHGB' | |
500 |
|
500 | |||
501 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
501 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
502 |
|
502 | |||
503 | # Create the datagram socket |
|
503 | # Create the datagram socket | |
504 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
504 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
505 | sock.connect(module_address) |
|
505 | sock.connect(module_address) | |
506 |
|
506 | |||
507 | sock.send(message_tx) |
|
507 | sock.send(message_tx) | |
508 | #t = sock.recv(1024) |
|
508 | #t = sock.recv(1024) | |
509 | sock.close() |
|
509 | sock.close() | |
510 | sock = None |
|
510 | sock = None | |
511 |
|
511 | |||
512 |
|
512 | |||
513 | time.sleep(0.2) |
|
513 | time.sleep(0.2) | |
514 |
|
514 | |||
515 |
|
515 | |||
516 | beam_pos = 1 |
|
516 | beam_pos = 1 | |
517 | numbers = len(str(beam_pos)) |
|
517 | numbers = len(str(beam_pos)) | |
518 |
|
518 | |||
519 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
519 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
520 |
|
520 | |||
521 | # Create the datagram socket |
|
521 | # Create the datagram socket | |
522 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
522 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
523 | sock.connect(module_address) |
|
523 | sock.connect(module_address) | |
524 | sock.send(message_tx) |
|
524 | sock.send(message_tx) | |
525 | sock.close() |
|
525 | sock.close() | |
526 | sock = None |
|
526 | sock = None | |
527 |
|
527 | |||
528 | time.sleep(0.2) |
|
528 | time.sleep(0.2) | |
529 |
|
529 | |||
530 |
|
530 | |||
531 | def multi_procs_test1(self): |
|
531 | def multi_procs_test1(self): | |
532 |
|
532 | |||
533 | #if __name__ == "__main__": |
|
533 | #if __name__ == "__main__": | |
534 | size = 10000000 # Number of random numbers to add |
|
534 | size = 10000000 # Number of random numbers to add | |
535 | procs = 65 # (Number-1) of processes to create |
|
535 | procs = 65 # (Number-1) of processes to create | |
536 |
|
536 | |||
537 | # Create a list of jobs and then iterate through |
|
537 | # Create a list of jobs and then iterate through | |
538 | # the number of processes appending each process to |
|
538 | # the number of processes appending each process to | |
539 | # the job list |
|
539 | # the job list | |
540 | jobs = [] |
|
540 | jobs = [] | |
541 | for i in range(62, procs): |
|
541 | for i in range(62, procs): | |
542 |
|
542 | |||
543 | process = multiprocessing.Process(target=self.change_procs_test1,args=(i,)) |
|
543 | process = multiprocessing.Process(target=self.change_procs_test1,args=(i,)) | |
544 | jobs.append(process) |
|
544 | jobs.append(process) | |
545 | #print jobs |
|
545 | #print jobs | |
546 |
|
546 | |||
547 | # Start the processes (i.e. calculate the random number lists) |
|
547 | # Start the processes (i.e. calculate the random number lists) | |
548 | for j in jobs: |
|
548 | for j in jobs: | |
549 | #time.sleep(0.4) |
|
549 | #time.sleep(0.4) | |
550 | #print j |
|
550 | #print j | |
551 | j.start() |
|
551 | j.start() | |
552 |
|
552 | |||
553 | # Ensure all of the processes have finished |
|
553 | # Ensure all of the processes have finished | |
554 | for j in jobs: |
|
554 | for j in jobs: | |
555 | j.join() |
|
555 | j.join() | |
556 |
|
556 | |||
557 |
print |
|
557 | print("List processing complete.") | |
558 | return 1 |
|
558 | return 1 | |
559 |
|
559 | |||
560 |
|
560 | |||
561 | def status_device(self): |
|
561 | def status_device(self): | |
562 |
|
562 | |||
563 | return 1 |
|
563 | return 1 | |
564 |
|
564 | |||
565 |
|
565 | |||
566 |
|
566 | |||
567 | class ABSBeam(models.Model): |
|
567 | class ABSBeam(models.Model): | |
568 |
|
568 | |||
569 | name = models.CharField(max_length=60, default='Beam') |
|
569 | name = models.CharField(max_length=60, default='Beam') | |
570 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) |
|
570 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) | |
571 | abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration') |
|
571 | abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration') | |
572 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) |
|
572 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) | |
573 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) |
|
573 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) | |
574 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') |
|
574 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') | |
575 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') |
|
575 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') | |
576 | modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default)) |
|
576 | modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default)) | |
577 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) |
|
577 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) | |
578 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) |
|
578 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) | |
579 |
|
579 | |||
580 | class Meta: |
|
580 | class Meta: | |
581 | db_table = 'abs_beams' |
|
581 | db_table = 'abs_beams' | |
582 |
|
582 | |||
583 | def __unicode__(self): |
|
583 | def __unicode__(self): | |
584 | return u'%s' % (self.name) |
|
584 | return u'%s' % (self.name) | |
585 |
|
585 | |||
586 | def parms_to_dict(self): |
|
586 | def parms_to_dict(self): | |
587 |
|
587 | |||
588 | #Update data |
|
588 | #Update data | |
589 | self.modules_6bits() |
|
589 | self.modules_6bits() | |
590 |
|
590 | |||
591 | parameters = {} |
|
591 | parameters = {} | |
592 |
|
592 | |||
593 | parameters['name'] = self.name |
|
593 | parameters['name'] = self.name | |
594 | parameters['antenna'] = ast.literal_eval(self.antenna) |
|
594 | parameters['antenna'] = ast.literal_eval(self.antenna) | |
595 | parameters['abs_conf'] = self.abs_conf.name |
|
595 | parameters['abs_conf'] = self.abs_conf.name | |
596 | parameters['tx'] = ast.literal_eval(self.tx) |
|
596 | parameters['tx'] = ast.literal_eval(self.tx) | |
597 | parameters['rx'] = ast.literal_eval(self.rx) |
|
597 | parameters['rx'] = ast.literal_eval(self.rx) | |
598 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") |
|
598 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") | |
599 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") |
|
599 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") | |
600 | parameters['configuration'] = ast.literal_eval(self.modules_conf) |
|
600 | parameters['configuration'] = ast.literal_eval(self.modules_conf) | |
601 | parameters['ues'] = ast.literal_eval(self.ues) |
|
601 | parameters['ues'] = ast.literal_eval(self.ues) | |
602 | parameters['only_rx'] = json.loads(self.only_rx) |
|
602 | parameters['only_rx'] = json.loads(self.only_rx) | |
603 |
|
603 | |||
604 | return parameters |
|
604 | return parameters | |
605 |
|
605 | |||
606 | def dict_to_parms(self, parameters): |
|
606 | def dict_to_parms(self, parameters): | |
607 |
|
607 | |||
608 | self.name = parameters['name'] |
|
608 | self.name = parameters['name'] | |
609 | self.antenna = json.dumps(parameters['antenna']) |
|
609 | self.antenna = json.dumps(parameters['antenna']) | |
610 | #self.abs_conf = parameters['abs_conf'] |
|
610 | #self.abs_conf = parameters['abs_conf'] | |
611 | self.tx = json.dumps(parameters['tx']) |
|
611 | self.tx = json.dumps(parameters['tx']) | |
612 | self.rx = json.dumps(parameters['rx']) |
|
612 | self.rx = json.dumps(parameters['rx']) | |
613 | #parameters['s_time'] |
|
613 | #parameters['s_time'] | |
614 | #parameters['e_time'] |
|
614 | #parameters['e_time'] | |
615 | self.ues = json.dumps(parameters['ues']) |
|
615 | self.ues = json.dumps(parameters['ues']) | |
616 | self.only_rx = json.dumps(parameters['only_rx']) |
|
616 | self.only_rx = json.dumps(parameters['only_rx']) | |
617 |
|
617 | |||
618 | self.modules_6bits() |
|
618 | self.modules_6bits() | |
619 | self.save() |
|
619 | self.save() | |
620 |
|
620 | |||
621 | return parameters |
|
621 | return parameters | |
622 |
|
622 | |||
623 |
|
623 | |||
624 | def change_beam(self, beam_pos=0): |
|
624 | def change_beam(self, beam_pos=0): | |
625 |
|
625 | |||
626 | module_63 = ('192.168.1.63', 5500) |
|
626 | module_63 = ('192.168.1.63', 5500) | |
627 | header = 'JROABSCeCnModCnMod0100000' |
|
627 | header = 'JROABSCeCnModCnMod0100000' | |
628 | numbers = len(str(beam_pos)) |
|
628 | numbers = len(str(beam_pos)) | |
629 | function = 'CHGB' |
|
629 | function = 'CHGB' | |
630 |
|
630 | |||
631 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
631 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
632 |
|
632 | |||
633 | # Create the datagram socket |
|
633 | # Create the datagram socket | |
634 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
634 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
635 | sock.connect(module_63) |
|
635 | sock.connect(module_63) | |
636 | sock.send(message_tx) |
|
636 | sock.send(message_tx) | |
637 | sock.close() |
|
637 | sock.close() | |
638 | return message_tx |
|
638 | return message_tx | |
639 |
|
639 | |||
640 | def change_module_beam(self, module=61,beam_pos=0): |
|
640 | def change_module_beam(self, module=61,beam_pos=0): | |
641 |
|
641 | |||
642 | module_address = ('192.168.1.'+str(module), 5500) |
|
642 | module_address = ('192.168.1.'+str(module), 5500) | |
643 | header = 'JROABSCeCnModCnMod0100000' |
|
643 | header = 'JROABSCeCnModCnMod0100000' | |
644 | numbers = len(str(beam_pos)) |
|
644 | numbers = len(str(beam_pos)) | |
645 | function = 'CHGB' |
|
645 | function = 'CHGB' | |
646 |
|
646 | |||
647 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
647 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' | |
648 |
|
648 | |||
649 | # Create the datagram socket |
|
649 | # Create the datagram socket | |
650 | try: |
|
650 | try: | |
651 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
651 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
652 | sock.connect(module_address) |
|
652 | sock.connect(module_address) | |
653 | sock.send(message_tx) |
|
653 | sock.send(message_tx) | |
654 | sock.close() |
|
654 | sock.close() | |
655 | except: |
|
655 | except: | |
656 | return 0 |
|
656 | return 0 | |
657 | return message_tx |
|
657 | return message_tx | |
658 |
|
658 | |||
659 | def write_device(self): |
|
659 | def write_device(self): | |
660 |
|
660 | |||
661 | parameters = {} |
|
661 | parameters = {} | |
662 |
|
662 | |||
663 | module_ip = '192.168.1.63' |
|
663 | module_ip = '192.168.1.63' | |
664 | write_route = 'http://192.168.1.63:8080/configure' |
|
664 | write_route = 'http://192.168.1.63:8080/configure' | |
665 |
|
665 | |||
666 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' |
|
666 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' | |
667 | module = 'ABS_63' |
|
667 | module = 'ABS_63' | |
668 | beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', |
|
668 | beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', | |
669 | 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} |
|
669 | 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} | |
670 |
|
670 | |||
671 | parameters['header'] = header |
|
671 | parameters['header'] = header | |
672 | parameters['module'] = module |
|
672 | parameters['module'] = module | |
673 | parameters['beams'] = json.dumps(beams) |
|
673 | parameters['beams'] = json.dumps(beams) | |
674 |
|
674 | |||
675 | answer = '' |
|
675 | answer = '' | |
676 |
|
676 | |||
677 | try: |
|
677 | try: | |
678 | r_write = requests.post(write_route, parameters, timeout=0.5) |
|
678 | r_write = requests.post(write_route, parameters, timeout=0.5) | |
679 | answer = r_write.json() |
|
679 | answer = r_write.json() | |
680 | self.message = answer['message'] |
|
680 | self.message = answer['message'] | |
681 | except: |
|
681 | except: | |
682 | self.message = "Could not write ABS parameters" |
|
682 | self.message = "Could not write ABS parameters" | |
683 | return 0 |
|
683 | return 0 | |
684 |
|
684 | |||
685 |
|
685 | |||
686 | #self.device.status = int(answer['status']) |
|
686 | #self.device.status = int(answer['status']) | |
687 |
|
687 | |||
688 | return 1 |
|
688 | return 1 | |
689 |
|
689 | |||
690 |
|
690 | |||
691 |
|
691 | |||
692 | def module_6bits(self, module): |
|
692 | def module_6bits(self, module): | |
693 | """ |
|
693 | """ | |
694 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
694 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module | |
695 | """ |
|
695 | """ | |
696 | if module > 64: |
|
696 | if module > 64: | |
697 | beam_bits = "" |
|
697 | beam_bits = "" | |
698 | return beam_bits |
|
698 | return beam_bits | |
699 |
|
699 | |||
700 | data = ast.literal_eval(self.antenna) |
|
700 | data = ast.literal_eval(self.antenna) | |
701 | up_data = data['antenna_up'] |
|
701 | up_data = data['antenna_up'] | |
702 | down_data = data['antenna_down'] |
|
702 | down_data = data['antenna_down'] | |
703 |
|
703 | |||
704 | pos = ip2position(module) |
|
704 | pos = ip2position(module) | |
705 | up_value = up_data[pos[0]][pos[1]] |
|
705 | up_value = up_data[pos[0]][pos[1]] | |
706 | down_value = down_data[pos[0]][pos[1]] |
|
706 | down_value = down_data[pos[0]][pos[1]] | |
707 |
|
707 | |||
708 | up_bits = up_conv_bits(up_value) |
|
708 | up_bits = up_conv_bits(up_value) | |
709 | down_bits = down_conv_bits(down_value) |
|
709 | down_bits = down_conv_bits(down_value) | |
710 | beam_bits = up_bits+down_bits |
|
710 | beam_bits = up_bits+down_bits | |
711 |
|
711 | |||
712 | return beam_bits |
|
712 | return beam_bits | |
713 |
|
713 | |||
714 | def modules_6bits(self): |
|
714 | def modules_6bits(self): | |
715 | """ |
|
715 | """ | |
716 | This function returns 6bits from every abs module (1-64) in a dict |
|
716 | This function returns 6bits from every abs module (1-64) in a dict | |
717 | """ |
|
717 | """ | |
718 | modules_configuration = ast.literal_eval(self.modules_conf) |
|
718 | modules_configuration = ast.literal_eval(self.modules_conf) | |
719 |
|
719 | |||
720 | for i in range(1,65): |
|
720 | for i in range(1,65): | |
721 | modules_configuration[str(i)] = self.module_6bits(i) |
|
721 | modules_configuration[str(i)] = self.module_6bits(i) | |
722 |
|
722 | |||
723 | self.modules_conf = json.dumps(modules_configuration) |
|
723 | self.modules_conf = json.dumps(modules_configuration) | |
724 | self.save() |
|
724 | self.save() | |
725 |
|
725 | |||
726 | return self.modules_conf |
|
726 | return self.modules_conf | |
727 |
|
727 | |||
728 | def add_beam2list(self): |
|
728 | def add_beam2list(self): | |
729 | """ |
|
729 | """ | |
730 | This function adds a beam to the beams list of ABS Configuration. |
|
730 | This function adds a beam to the beams list of ABS Configuration. | |
731 | """ |
|
731 | """ | |
732 | beams = ast.literal_eval(self.abs_conf.beams) |
|
732 | beams = ast.literal_eval(self.abs_conf.beams) | |
733 | if any(beams): |
|
733 | if any(beams): | |
734 | for beam in beams: |
|
734 | for beam in beams: | |
735 | if beams[beam] == self.id: |
|
735 | if beams[beam] == self.id: | |
736 | return |
|
736 | return | |
737 | i = len(beams)+1 |
|
737 | i = len(beams)+1 | |
738 | beams['beam'+str(i)] = self.id |
|
738 | beams['beam'+str(i)] = self.id | |
739 | else: |
|
739 | else: | |
740 | beams['beam1'] = self.id |
|
740 | beams['beam1'] = self.id | |
741 |
|
741 | |||
742 | self.abs_conf.beams = json.dumps(beams) |
|
742 | self.abs_conf.beams = json.dumps(beams) | |
743 | self.abs_conf.save() |
|
743 | self.abs_conf.save() | |
744 |
|
744 | |||
745 | return |
|
745 | return | |
746 |
|
746 | |||
747 | def remove_beamfromlist(self): |
|
747 | def remove_beamfromlist(self): | |
748 | """ |
|
748 | """ | |
749 | This function removes current beam from the beams list of ABS Configuration. |
|
749 | This function removes current beam from the beams list of ABS Configuration. | |
750 | """ |
|
750 | """ | |
751 | beams = ast.literal_eval(self.abs_conf.beams) |
|
751 | beams = ast.literal_eval(self.abs_conf.beams) | |
752 | dict_position = '' |
|
752 | dict_position = '' | |
753 |
|
753 | |||
754 | if any(beams): |
|
754 | if any(beams): | |
755 | for beam in beams: |
|
755 | for beam in beams: | |
756 | if beams[beam] == self.id: |
|
756 | if beams[beam] == self.id: | |
757 | dict_position = beam |
|
757 | dict_position = beam | |
758 | if dict_position != '': |
|
758 | if dict_position != '': | |
759 | beams.pop(str(dict_position),None) |
|
759 | beams.pop(str(dict_position),None) | |
760 | else: |
|
760 | else: | |
761 | return |
|
761 | return | |
762 |
|
762 | |||
763 | self.abs_conf.beams = json.dumps(beams) |
|
763 | self.abs_conf.beams = json.dumps(beams) | |
764 | self.abs_conf.save() |
|
764 | self.abs_conf.save() | |
765 |
|
765 | |||
766 | return |
|
766 | return | |
767 |
|
767 | |||
768 | @property |
|
768 | @property | |
769 | def get_upvalues(self): |
|
769 | def get_upvalues(self): | |
770 | """ |
|
770 | """ | |
771 | This function reads antenna pattern and show the up-value of one abs module |
|
771 | This function reads antenna pattern and show the up-value of one abs module | |
772 | """ |
|
772 | """ | |
773 |
|
773 | |||
774 | data = ast.literal_eval(self.antenna) |
|
774 | data = ast.literal_eval(self.antenna) | |
775 | up_data = data['antenna_up'] |
|
775 | up_data = data['antenna_up'] | |
776 |
|
776 | |||
777 | up_values = [] |
|
777 | up_values = [] | |
778 | for data in up_data: |
|
778 | for data in up_data: | |
779 | for i in range(0,8): |
|
779 | for i in range(0,8): | |
780 | up_values.append(data[i]) |
|
780 | up_values.append(data[i]) | |
781 |
|
781 | |||
782 | return up_values |
|
782 | return up_values | |
783 |
|
783 | |||
784 | @property |
|
784 | @property | |
785 | def antenna_upvalues(self): |
|
785 | def antenna_upvalues(self): | |
786 | """ |
|
786 | """ | |
787 | This function reads antenna pattern and show the up - values of one abs beam |
|
787 | This function reads antenna pattern and show the up - values of one abs beam | |
788 | in a particular order |
|
788 | in a particular order | |
789 | """ |
|
789 | """ | |
790 | data = ast.literal_eval(self.antenna) |
|
790 | data = ast.literal_eval(self.antenna) | |
791 | up_data = data['antenna_up'] |
|
791 | up_data = data['antenna_up'] | |
792 |
|
792 | |||
793 | return up_data |
|
793 | return up_data | |
794 |
|
794 | |||
795 | @property |
|
795 | @property | |
796 | def antenna_downvalues(self): |
|
796 | def antenna_downvalues(self): | |
797 | """ |
|
797 | """ | |
798 | This function reads antenna pattern and show the down - values of one abs beam |
|
798 | This function reads antenna pattern and show the down - values of one abs beam | |
799 | in a particular order |
|
799 | in a particular order | |
800 | """ |
|
800 | """ | |
801 | data = ast.literal_eval(self.antenna) |
|
801 | data = ast.literal_eval(self.antenna) | |
802 | down_data = data['antenna_down'] |
|
802 | down_data = data['antenna_down'] | |
803 |
|
803 | |||
804 | return down_data |
|
804 | return down_data | |
805 |
|
805 | |||
806 | @property |
|
806 | @property | |
807 | def get_downvalues(self): |
|
807 | def get_downvalues(self): | |
808 | """ |
|
808 | """ | |
809 | This function reads antenna pattern and show the down-value of one abs module |
|
809 | This function reads antenna pattern and show the down-value of one abs module | |
810 | """ |
|
810 | """ | |
811 |
|
811 | |||
812 | data = ast.literal_eval(self.antenna) |
|
812 | data = ast.literal_eval(self.antenna) | |
813 | down_data = data['antenna_down'] |
|
813 | down_data = data['antenna_down'] | |
814 |
|
814 | |||
815 | down_values = [] |
|
815 | down_values = [] | |
816 | for data in down_data: |
|
816 | for data in down_data: | |
817 | for i in range(0,8): |
|
817 | for i in range(0,8): | |
818 | down_values.append(data[i]) |
|
818 | down_values.append(data[i]) | |
819 |
|
819 | |||
820 | return down_values |
|
820 | return down_values | |
821 |
|
821 | |||
822 | @property |
|
822 | @property | |
823 | def get_up_ues(self): |
|
823 | def get_up_ues(self): | |
824 | """ |
|
824 | """ | |
825 | This function shows the up-ues-value of one beam |
|
825 | This function shows the up-ues-value of one beam | |
826 | """ |
|
826 | """ | |
827 | data = ast.literal_eval(self.ues) |
|
827 | data = ast.literal_eval(self.ues) | |
828 | up_ues = data['up'] |
|
828 | up_ues = data['up'] | |
829 |
|
829 | |||
830 | return up_ues |
|
830 | return up_ues | |
831 |
|
831 | |||
832 | @property |
|
832 | @property | |
833 | def get_down_ues(self): |
|
833 | def get_down_ues(self): | |
834 | """ |
|
834 | """ | |
835 | This function shows the down-ues-value of one beam |
|
835 | This function shows the down-ues-value of one beam | |
836 | """ |
|
836 | """ | |
837 | data = ast.literal_eval(self.ues) |
|
837 | data = ast.literal_eval(self.ues) | |
838 | down_ues = data['down'] |
|
838 | down_ues = data['down'] | |
839 |
|
839 | |||
840 | return down_ues |
|
840 | return down_ues | |
841 |
|
841 | |||
842 | @property |
|
842 | @property | |
843 | def get_up_onlyrx(self): |
|
843 | def get_up_onlyrx(self): | |
844 | """ |
|
844 | """ | |
845 | This function shows the up-onlyrx-value of one beam |
|
845 | This function shows the up-onlyrx-value of one beam | |
846 | """ |
|
846 | """ | |
847 | data = json.loads(self.only_rx) |
|
847 | data = json.loads(self.only_rx) | |
848 | up_onlyrx = data['up'] |
|
848 | up_onlyrx = data['up'] | |
849 |
|
849 | |||
850 | return up_onlyrx |
|
850 | return up_onlyrx | |
851 |
|
851 | |||
852 | @property |
|
852 | @property | |
853 | def get_down_onlyrx(self): |
|
853 | def get_down_onlyrx(self): | |
854 | """ |
|
854 | """ | |
855 | This function shows the down-onlyrx-value of one beam |
|
855 | This function shows the down-onlyrx-value of one beam | |
856 | """ |
|
856 | """ | |
857 | data = json.loads(self.only_rx) |
|
857 | data = json.loads(self.only_rx) | |
858 | down_onlyrx = data['down'] |
|
858 | down_onlyrx = data['down'] | |
859 |
|
859 | |||
860 | return down_onlyrx |
|
860 | return down_onlyrx | |
861 |
|
861 | |||
862 | @property |
|
862 | @property | |
863 | def get_tx(self): |
|
863 | def get_tx(self): | |
864 | """ |
|
864 | """ | |
865 | This function shows the tx-values of one beam |
|
865 | This function shows the tx-values of one beam | |
866 | """ |
|
866 | """ | |
867 | data = json.loads(self.tx) |
|
867 | data = json.loads(self.tx) | |
868 |
|
868 | |||
869 | return data |
|
869 | return data | |
870 |
|
870 | |||
871 | @property |
|
871 | @property | |
872 | def get_uptx(self): |
|
872 | def get_uptx(self): | |
873 | """ |
|
873 | """ | |
874 | This function shows the up-tx-values of one beam |
|
874 | This function shows the up-tx-values of one beam | |
875 | """ |
|
875 | """ | |
876 | data = json.loads(self.tx) |
|
876 | data = json.loads(self.tx) | |
877 | up_data = data['up'] |
|
877 | up_data = data['up'] | |
878 |
|
878 | |||
879 | up_values = [] |
|
879 | up_values = [] | |
880 | for data in up_data: |
|
880 | for data in up_data: | |
881 | for i in range(0,8): |
|
881 | for i in range(0,8): | |
882 | up_values.append(data[i]) |
|
882 | up_values.append(data[i]) | |
883 |
|
883 | |||
884 | return up_values |
|
884 | return up_values | |
885 |
|
885 | |||
886 | @property |
|
886 | @property | |
887 | def get_downtx(self): |
|
887 | def get_downtx(self): | |
888 | """ |
|
888 | """ | |
889 | This function shows the down-tx-values of one beam |
|
889 | This function shows the down-tx-values of one beam | |
890 | """ |
|
890 | """ | |
891 | data = json.loads(self.tx) |
|
891 | data = json.loads(self.tx) | |
892 | down_data = data['down'] |
|
892 | down_data = data['down'] | |
893 |
|
893 | |||
894 | down_values = [] |
|
894 | down_values = [] | |
895 | for data in down_data: |
|
895 | for data in down_data: | |
896 | for i in range(0,8): |
|
896 | for i in range(0,8): | |
897 | down_values.append(data[i]) |
|
897 | down_values.append(data[i]) | |
898 |
|
898 | |||
899 | return down_values |
|
899 | return down_values | |
900 |
|
900 | |||
901 |
|
901 | |||
902 |
|
902 | |||
903 | @property |
|
903 | @property | |
904 | def get_rx(self): |
|
904 | def get_rx(self): | |
905 | """ |
|
905 | """ | |
906 | This function shows the rx-values of one beam |
|
906 | This function shows the rx-values of one beam | |
907 | """ |
|
907 | """ | |
908 | data = json.loads(self.rx) |
|
908 | data = json.loads(self.rx) | |
909 |
|
909 | |||
910 | return data |
|
910 | return data | |
911 |
|
911 | |||
912 | @property |
|
912 | @property | |
913 | def get_uprx(self): |
|
913 | def get_uprx(self): | |
914 | """ |
|
914 | """ | |
915 | This function shows the up-rx-values of one beam |
|
915 | This function shows the up-rx-values of one beam | |
916 | """ |
|
916 | """ | |
917 | data = json.loads(self.rx) |
|
917 | data = json.loads(self.rx) | |
918 | up_data = data['up'] |
|
918 | up_data = data['up'] | |
919 |
|
919 | |||
920 | up_values = [] |
|
920 | up_values = [] | |
921 | for data in up_data: |
|
921 | for data in up_data: | |
922 | for i in range(0,8): |
|
922 | for i in range(0,8): | |
923 | up_values.append(data[i]) |
|
923 | up_values.append(data[i]) | |
924 |
|
924 | |||
925 | return up_values |
|
925 | return up_values | |
926 |
|
926 | |||
927 | @property |
|
927 | @property | |
928 | def get_downrx(self): |
|
928 | def get_downrx(self): | |
929 | """ |
|
929 | """ | |
930 | This function shows the down-rx-values of one beam |
|
930 | This function shows the down-rx-values of one beam | |
931 | """ |
|
931 | """ | |
932 | data = json.loads(self.rx) |
|
932 | data = json.loads(self.rx) | |
933 | down_data = data['down'] |
|
933 | down_data = data['down'] | |
934 |
|
934 | |||
935 | down_values = [] |
|
935 | down_values = [] | |
936 | for data in down_data: |
|
936 | for data in down_data: | |
937 | for i in range(0,8): |
|
937 | for i in range(0,8): | |
938 | down_values.append(data[i]) |
|
938 | down_values.append(data[i]) | |
939 |
|
939 | |||
940 | return down_values |
|
940 | return down_values |
@@ -1,15 +1,15 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
3 | import views |
|
3 | from apps.abs import views | |
4 |
|
4 | |||
5 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
6 | url(r'^(?P<id_conf>-?\d+)/$', views.abs_conf, name='url_abs_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', views.abs_conf, name='url_abs_conf'), | |
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.abs_conf_edit, name='url_edit_abs_conf'), |
|
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.abs_conf_edit, name='url_edit_abs_conf'), | |
8 | #url(r'^(?P<id_conf>-?\d+)/read/$', views.dev_conf_read, name='url_read_abs_conf'), |
|
8 | #url(r'^(?P<id_conf>-?\d+)/read/$', views.dev_conf_read, name='url_read_abs_conf'), | |
9 | #url(r'^(?P<id_conf>-?\d+)/import/$', views.dev_conf_import, name='url_import_abs_conf'), |
|
9 | #url(r'^(?P<id_conf>-?\d+)/import/$', views.dev_conf_import, name='url_import_abs_conf'), | |
10 | #url(r'^(?P<id_conf>-?\d+)/export/$', views.dev_conf_export, name='url_export_abs_conf'), |
|
10 | #url(r'^(?P<id_conf>-?\d+)/export/$', views.dev_conf_export, name='url_export_abs_conf'), | |
11 | url(r'^(?P<id_conf>-?\d+)/plot/$', views.plot_patterns, name='url_plot_abs_patterns'), |
|
11 | url(r'^(?P<id_conf>-?\d+)/plot/$', views.plot_patterns, name='url_plot_abs_patterns'), | |
12 | url(r'^(?P<id_conf>-?\d+)/add_beam/$', views.add_beam, name='url_add_abs_beam'), |
|
12 | url(r'^(?P<id_conf>-?\d+)/add_beam/$', views.add_beam, name='url_add_abs_beam'), | |
13 | url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/delete/$', views.remove_beam, name='url_remove_abs_beam'), |
|
13 | url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/delete/$', views.remove_beam, name='url_remove_abs_beam'), | |
14 | url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/edit/$', views.edit_beam, name='url_edit_abs_beam'), |
|
14 | url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/edit/$', views.edit_beam, name='url_edit_abs_beam'), | |
15 | ) |
|
15 | ) |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,1589 +1,1587 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 | from django.http import HttpResponseRedirect |
|
3 | from django.http import HttpResponseRedirect | |
4 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
5 | from django.db.models import Q |
|
5 | from django.db.models import Q | |
6 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
|
6 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | |
7 | from django.contrib import messages |
|
7 | from django.contrib import messages | |
8 | from django.http.request import QueryDict |
|
8 | from django.http.request import QueryDict | |
9 | from datetime import datetime |
|
9 | from datetime import datetime | |
10 |
|
10 | |||
11 | try: |
|
11 | try: | |
12 | from urllib.parse import urlencode |
|
12 | from urllib.parse import urlencode | |
13 | except ImportError: |
|
13 | except ImportError: | |
14 | from urllib import urlencode |
|
14 | from urllib import urlencode | |
15 |
|
15 | |||
16 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
16 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
17 | from .forms import OperationSearchForm, FilterForm |
|
17 | from .forms import OperationSearchForm, FilterForm | |
18 |
|
18 | |||
19 | from apps.rc.forms import RCConfigurationForm |
|
19 | from apps.rc.forms import RCConfigurationForm | |
20 | from apps.dds.forms import DDSConfigurationForm |
|
20 | from apps.dds.forms import DDSConfigurationForm | |
21 | from apps.jars.forms import JARSConfigurationForm |
|
21 | from apps.jars.forms import JARSConfigurationForm | |
22 | from apps.cgs.forms import CGSConfigurationForm |
|
22 | from apps.cgs.forms import CGSConfigurationForm | |
23 | from apps.abs.forms import ABSConfigurationForm |
|
23 | from apps.abs.forms import ABSConfigurationForm | |
24 | from apps.usrp.forms import USRPConfigurationForm |
|
24 | from apps.usrp.forms import USRPConfigurationForm | |
25 |
|
25 | |||
26 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
26 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
27 | from apps.cgs.models import CGSConfiguration |
|
27 | from apps.cgs.models import CGSConfiguration | |
28 | from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE |
|
28 | from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE | |
29 | from apps.usrp.models import USRPConfiguration |
|
29 | from apps.usrp.models import USRPConfiguration | |
30 | from apps.abs.models import ABSConfiguration |
|
30 | from apps.abs.models import ABSConfiguration | |
31 | from apps.rc.models import RCConfiguration, RCLine, RCLineType |
|
31 | from apps.rc.models import RCConfiguration, RCLine, RCLineType | |
32 | from apps.dds.models import DDSConfiguration |
|
32 | from apps.dds.models import DDSConfiguration | |
33 | from django.http.request import QueryDict |
|
33 | from django.http.request import QueryDict | |
34 | #from __builtin__ import False |
|
34 | #from __builtin__ import False | |
35 |
|
35 | |||
36 | # Create your views here. |
|
36 | # Create your views here. | |
37 |
|
37 | |||
38 | CONF_FORMS = { |
|
38 | CONF_FORMS = { | |
39 | 'rc': RCConfigurationForm, |
|
39 | 'rc': RCConfigurationForm, | |
40 | 'dds': DDSConfigurationForm, |
|
40 | 'dds': DDSConfigurationForm, | |
41 | 'jars': JARSConfigurationForm, |
|
41 | 'jars': JARSConfigurationForm, | |
42 | 'cgs': CGSConfigurationForm, |
|
42 | 'cgs': CGSConfigurationForm, | |
43 | 'abs': ABSConfigurationForm, |
|
43 | 'abs': ABSConfigurationForm, | |
44 | 'usrp': USRPConfigurationForm, |
|
44 | 'usrp': USRPConfigurationForm, | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | CONF_MODELS = { |
|
47 | CONF_MODELS = { | |
48 | 'rc': RCConfiguration, |
|
48 | 'rc': RCConfiguration, | |
49 | 'dds': DDSConfiguration, |
|
49 | 'dds': DDSConfiguration, | |
50 | 'jars': JARSConfiguration, |
|
50 | 'jars': JARSConfiguration, | |
51 | 'cgs': CGSConfiguration, |
|
51 | 'cgs': CGSConfiguration, | |
52 | 'abs': ABSConfiguration, |
|
52 | 'abs': ABSConfiguration, | |
53 | 'usrp': USRPConfiguration, |
|
53 | 'usrp': USRPConfiguration, | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | MIX_MODES = { |
|
56 | MIX_MODES = { | |
57 | '0': 'P', |
|
57 | '0': 'P', | |
58 | '1': 'S', |
|
58 | '1': 'S', | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | MIX_OPERATIONS = { |
|
61 | MIX_OPERATIONS = { | |
62 | '0': 'OR', |
|
62 | '0': 'OR', | |
63 | '1': 'XOR', |
|
63 | '1': 'XOR', | |
64 | '2': 'AND', |
|
64 | '2': 'AND', | |
65 | '3': 'NAND', |
|
65 | '3': 'NAND', | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | def index(request): |
|
69 | def index(request): | |
70 | kwargs = {} |
|
70 | kwargs = {} | |
71 |
|
71 | |||
72 | return render(request, 'index.html', kwargs) |
|
72 | return render(request, 'index.html', kwargs) | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | def locations(request): |
|
75 | def locations(request): | |
76 |
|
76 | |||
77 | page = request.GET.get('page') |
|
77 | page = request.GET.get('page') | |
78 | order = ('name',) |
|
78 | order = ('name',) | |
79 |
|
79 | |||
80 | kwargs = get_paginator(Location, page, order) |
|
80 | kwargs = get_paginator(Location, page, order) | |
81 |
|
81 | |||
82 | kwargs['keys'] = ['name', 'description'] |
|
82 | kwargs['keys'] = ['name', 'description'] | |
83 | kwargs['title'] = 'Radar System' |
|
83 | kwargs['title'] = 'Radar System' | |
84 | kwargs['suptitle'] = 'List' |
|
84 | kwargs['suptitle'] = 'List' | |
85 |
|
85 | |||
86 | return render(request, 'base_list.html', kwargs) |
|
86 | return render(request, 'base_list.html', kwargs) | |
87 |
|
87 | |||
88 |
|
88 | |||
89 | def location(request, id_loc): |
|
89 | def location(request, id_loc): | |
90 |
|
90 | |||
91 | location = get_object_or_404(Location, pk=id_loc) |
|
91 | location = get_object_or_404(Location, pk=id_loc) | |
92 |
|
92 | |||
93 | kwargs = {} |
|
93 | kwargs = {} | |
94 | kwargs['location'] = location |
|
94 | kwargs['location'] = location | |
95 | kwargs['location_keys'] = ['name', 'description'] |
|
95 | kwargs['location_keys'] = ['name', 'description'] | |
96 |
|
96 | |||
97 | kwargs['title'] = 'Location' |
|
97 | kwargs['title'] = 'Location' | |
98 | kwargs['suptitle'] = 'Details' |
|
98 | kwargs['suptitle'] = 'Details' | |
99 |
|
99 | |||
100 | return render(request, 'location.html', kwargs) |
|
100 | return render(request, 'location.html', kwargs) | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | def location_new(request): |
|
103 | def location_new(request): | |
104 |
|
104 | |||
105 | if request.method == 'GET': |
|
105 | if request.method == 'GET': | |
106 | form = LocationForm() |
|
106 | form = LocationForm() | |
107 |
|
107 | |||
108 | if request.method == 'POST': |
|
108 | if request.method == 'POST': | |
109 | form = LocationForm(request.POST) |
|
109 | form = LocationForm(request.POST) | |
110 |
|
110 | |||
111 | if form.is_valid(): |
|
111 | if form.is_valid(): | |
112 | form.save() |
|
112 | form.save() | |
113 | return redirect('url_locations') |
|
113 | return redirect('url_locations') | |
114 |
|
114 | |||
115 | kwargs = {} |
|
115 | kwargs = {} | |
116 | kwargs['form'] = form |
|
116 | kwargs['form'] = form | |
117 | kwargs['title'] = 'Radar System' |
|
117 | kwargs['title'] = 'Radar System' | |
118 | kwargs['suptitle'] = 'New' |
|
118 | kwargs['suptitle'] = 'New' | |
119 | kwargs['button'] = 'Create' |
|
119 | kwargs['button'] = 'Create' | |
120 |
|
120 | |||
121 | return render(request, 'base_edit.html', kwargs) |
|
121 | return render(request, 'base_edit.html', kwargs) | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | def location_edit(request, id_loc): |
|
124 | def location_edit(request, id_loc): | |
125 |
|
125 | |||
126 | location = get_object_or_404(Location, pk=id_loc) |
|
126 | location = get_object_or_404(Location, pk=id_loc) | |
127 |
|
127 | |||
128 | if request.method=='GET': |
|
128 | if request.method=='GET': | |
129 | form = LocationForm(instance=location) |
|
129 | form = LocationForm(instance=location) | |
130 |
|
130 | |||
131 | if request.method=='POST': |
|
131 | if request.method=='POST': | |
132 | form = LocationForm(request.POST, instance=location) |
|
132 | form = LocationForm(request.POST, instance=location) | |
133 |
|
133 | |||
134 | if form.is_valid(): |
|
134 | if form.is_valid(): | |
135 | form.save() |
|
135 | form.save() | |
136 | return redirect('url_locations') |
|
136 | return redirect('url_locations') | |
137 |
|
137 | |||
138 | kwargs = {} |
|
138 | kwargs = {} | |
139 | kwargs['form'] = form |
|
139 | kwargs['form'] = form | |
140 | kwargs['title'] = 'Location' |
|
140 | kwargs['title'] = 'Location' | |
141 | kwargs['suptitle'] = 'Edit' |
|
141 | kwargs['suptitle'] = 'Edit' | |
142 | kwargs['button'] = 'Update' |
|
142 | kwargs['button'] = 'Update' | |
143 |
|
143 | |||
144 | return render(request, 'base_edit.html', kwargs) |
|
144 | return render(request, 'base_edit.html', kwargs) | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | def location_delete(request, id_loc): |
|
147 | def location_delete(request, id_loc): | |
148 |
|
148 | |||
149 | location = get_object_or_404(Location, pk=id_loc) |
|
149 | location = get_object_or_404(Location, pk=id_loc) | |
150 |
|
150 | |||
151 | if request.method=='POST': |
|
151 | if request.method=='POST': | |
152 |
|
152 | |||
153 | if request.user.is_staff: |
|
153 | if request.user.is_staff: | |
154 | location.delete() |
|
154 | location.delete() | |
155 | return redirect('url_locations') |
|
155 | return redirect('url_locations') | |
156 |
|
156 | |||
157 | messages.error(request, 'Not enough permission to delete this object') |
|
157 | messages.error(request, 'Not enough permission to delete this object') | |
158 | return redirect(location.get_absolute_url()) |
|
158 | return redirect(location.get_absolute_url()) | |
159 |
|
159 | |||
160 | kwargs = { |
|
160 | kwargs = { | |
161 | 'title': 'Delete', |
|
161 | 'title': 'Delete', | |
162 | 'suptitle': 'Location', |
|
162 | 'suptitle': 'Location', | |
163 | 'object': location, |
|
163 | 'object': location, | |
164 | 'previous': location.get_absolute_url(), |
|
164 | 'previous': location.get_absolute_url(), | |
165 | 'delete': True |
|
165 | 'delete': True | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | return render(request, 'confirm.html', kwargs) |
|
168 | return render(request, 'confirm.html', kwargs) | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | def devices(request): |
|
171 | def devices(request): | |
172 |
|
172 | |||
173 | page = request.GET.get('page') |
|
173 | page = request.GET.get('page') | |
174 | order = ('device_type', 'name') |
|
174 | order = ('device_type', 'name') | |
175 |
|
175 | |||
176 | kwargs = get_paginator(Device, page, order) |
|
176 | kwargs = get_paginator(Device, page, order) | |
177 | kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type'] |
|
177 | kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type'] | |
178 | kwargs['title'] = 'Device' |
|
178 | kwargs['title'] = 'Device' | |
179 | kwargs['suptitle'] = 'List' |
|
179 | kwargs['suptitle'] = 'List' | |
180 |
|
180 | |||
181 | return render(request, 'base_list.html', kwargs) |
|
181 | return render(request, 'base_list.html', kwargs) | |
182 |
|
182 | |||
183 |
|
183 | |||
184 | def device(request, id_dev): |
|
184 | def device(request, id_dev): | |
185 |
|
185 | |||
186 | device = get_object_or_404(Device, pk=id_dev) |
|
186 | device = get_object_or_404(Device, pk=id_dev) | |
187 |
|
187 | |||
188 | kwargs = {} |
|
188 | kwargs = {} | |
189 | kwargs['device'] = device |
|
189 | kwargs['device'] = device | |
190 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
190 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
191 |
|
191 | |||
192 | kwargs['title'] = 'Device' |
|
192 | kwargs['title'] = 'Device' | |
193 | kwargs['suptitle'] = 'Details' |
|
193 | kwargs['suptitle'] = 'Details' | |
194 |
|
194 | |||
195 | return render(request, 'device.html', kwargs) |
|
195 | return render(request, 'device.html', kwargs) | |
196 |
|
196 | |||
197 |
|
197 | |||
198 | def device_new(request): |
|
198 | def device_new(request): | |
199 |
|
199 | |||
200 | if request.method == 'GET': |
|
200 | if request.method == 'GET': | |
201 | form = DeviceForm() |
|
201 | form = DeviceForm() | |
202 |
|
202 | |||
203 | if request.method == 'POST': |
|
203 | if request.method == 'POST': | |
204 | form = DeviceForm(request.POST) |
|
204 | form = DeviceForm(request.POST) | |
205 |
|
205 | |||
206 | if form.is_valid(): |
|
206 | if form.is_valid(): | |
207 | form.save() |
|
207 | form.save() | |
208 | return redirect('url_devices') |
|
208 | return redirect('url_devices') | |
209 |
|
209 | |||
210 | kwargs = {} |
|
210 | kwargs = {} | |
211 | kwargs['form'] = form |
|
211 | kwargs['form'] = form | |
212 | kwargs['title'] = 'Device' |
|
212 | kwargs['title'] = 'Device' | |
213 | kwargs['suptitle'] = 'New' |
|
213 | kwargs['suptitle'] = 'New' | |
214 | kwargs['button'] = 'Create' |
|
214 | kwargs['button'] = 'Create' | |
215 |
|
215 | |||
216 | return render(request, 'base_edit.html', kwargs) |
|
216 | return render(request, 'base_edit.html', kwargs) | |
217 |
|
217 | |||
218 |
|
218 | |||
219 | def device_edit(request, id_dev): |
|
219 | def device_edit(request, id_dev): | |
220 |
|
220 | |||
221 | device = get_object_or_404(Device, pk=id_dev) |
|
221 | device = get_object_or_404(Device, pk=id_dev) | |
222 |
|
222 | |||
223 | if request.method=='GET': |
|
223 | if request.method=='GET': | |
224 | form = DeviceForm(instance=device) |
|
224 | form = DeviceForm(instance=device) | |
225 |
|
225 | |||
226 | if request.method=='POST': |
|
226 | if request.method=='POST': | |
227 | form = DeviceForm(request.POST, instance=device) |
|
227 | form = DeviceForm(request.POST, instance=device) | |
228 |
|
228 | |||
229 | if form.is_valid(): |
|
229 | if form.is_valid(): | |
230 | form.save() |
|
230 | form.save() | |
231 | return redirect(device.get_absolute_url()) |
|
231 | return redirect(device.get_absolute_url()) | |
232 |
|
232 | |||
233 | kwargs = {} |
|
233 | kwargs = {} | |
234 | kwargs['form'] = form |
|
234 | kwargs['form'] = form | |
235 | kwargs['title'] = 'Device' |
|
235 | kwargs['title'] = 'Device' | |
236 | kwargs['suptitle'] = 'Edit' |
|
236 | kwargs['suptitle'] = 'Edit' | |
237 | kwargs['button'] = 'Update' |
|
237 | kwargs['button'] = 'Update' | |
238 |
|
238 | |||
239 | return render(request, 'base_edit.html', kwargs) |
|
239 | return render(request, 'base_edit.html', kwargs) | |
240 |
|
240 | |||
241 |
|
241 | |||
242 | def device_delete(request, id_dev): |
|
242 | def device_delete(request, id_dev): | |
243 |
|
243 | |||
244 | device = get_object_or_404(Device, pk=id_dev) |
|
244 | device = get_object_or_404(Device, pk=id_dev) | |
245 |
|
245 | |||
246 | if request.method=='POST': |
|
246 | if request.method=='POST': | |
247 |
|
247 | |||
248 | if request.user.is_staff: |
|
248 | if request.user.is_staff: | |
249 | device.delete() |
|
249 | device.delete() | |
250 | return redirect('url_devices') |
|
250 | return redirect('url_devices') | |
251 |
|
251 | |||
252 | messages.error(request, 'Not enough permission to delete this object') |
|
252 | messages.error(request, 'Not enough permission to delete this object') | |
253 | return redirect(device.get_absolute_url()) |
|
253 | return redirect(device.get_absolute_url()) | |
254 |
|
254 | |||
255 | kwargs = { |
|
255 | kwargs = { | |
256 | 'title': 'Delete', |
|
256 | 'title': 'Delete', | |
257 | 'suptitle': 'Device', |
|
257 | 'suptitle': 'Device', | |
258 | 'object': device, |
|
258 | 'object': device, | |
259 | 'previous': device.get_absolute_url(), |
|
259 | 'previous': device.get_absolute_url(), | |
260 | 'delete': True |
|
260 | 'delete': True | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | return render(request, 'confirm.html', kwargs) |
|
263 | return render(request, 'confirm.html', kwargs) | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | def campaigns(request): |
|
266 | def campaigns(request): | |
267 |
|
267 | |||
268 | page = request.GET.get('page') |
|
268 | page = request.GET.get('page') | |
269 | order = ('start_date',) |
|
269 | order = ('start_date',) | |
270 | filters = request.GET.copy() |
|
270 | filters = request.GET.copy() | |
271 |
|
271 | |||
272 | kwargs = get_paginator(Campaign, page, order, filters) |
|
272 | kwargs = get_paginator(Campaign, page, order, filters) | |
273 |
|
273 | |||
274 | form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template']) |
|
274 | form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template']) | |
275 | kwargs['keys'] = ['name', 'start_date', 'end_date'] |
|
275 | kwargs['keys'] = ['name', 'start_date', 'end_date'] | |
276 | kwargs['title'] = 'Campaign' |
|
276 | kwargs['title'] = 'Campaign' | |
277 | kwargs['suptitle'] = 'List' |
|
277 | kwargs['suptitle'] = 'List' | |
278 | kwargs['form'] = form |
|
278 | kwargs['form'] = form | |
279 | filters.pop('page', None) |
|
279 | filters.pop('page', None) | |
280 | kwargs['q'] = urlencode(filters) |
|
280 | kwargs['q'] = urlencode(filters) | |
281 |
|
281 | |||
282 | return render(request, 'base_list.html', kwargs) |
|
282 | return render(request, 'base_list.html', kwargs) | |
283 |
|
283 | |||
284 |
|
284 | |||
285 | def campaign(request, id_camp): |
|
285 | def campaign(request, id_camp): | |
286 |
|
286 | |||
287 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
287 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
288 | experiments = Experiment.objects.filter(campaign=campaign) |
|
288 | experiments = Experiment.objects.filter(campaign=campaign) | |
289 |
|
289 | |||
290 | form = CampaignForm(instance=campaign) |
|
290 | form = CampaignForm(instance=campaign) | |
291 |
|
291 | |||
292 | kwargs = {} |
|
292 | kwargs = {} | |
293 | kwargs['campaign'] = campaign |
|
293 | kwargs['campaign'] = campaign | |
294 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
294 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] | |
295 |
|
295 | |||
296 | kwargs['experiments'] = experiments |
|
296 | kwargs['experiments'] = experiments | |
297 | kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time'] |
|
297 | kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time'] | |
298 |
|
298 | |||
299 | kwargs['title'] = 'Campaign' |
|
299 | kwargs['title'] = 'Campaign' | |
300 | kwargs['suptitle'] = 'Details' |
|
300 | kwargs['suptitle'] = 'Details' | |
301 |
|
301 | |||
302 | kwargs['form'] = form |
|
302 | kwargs['form'] = form | |
303 | kwargs['button'] = 'Add Experiment' |
|
303 | kwargs['button'] = 'Add Experiment' | |
304 |
|
304 | |||
305 | return render(request, 'campaign.html', kwargs) |
|
305 | return render(request, 'campaign.html', kwargs) | |
306 |
|
306 | |||
307 |
|
307 | |||
308 | def campaign_new(request): |
|
308 | def campaign_new(request): | |
309 |
|
309 | |||
310 | kwargs = {} |
|
310 | kwargs = {} | |
311 |
|
311 | |||
312 | if request.method == 'GET': |
|
312 | if request.method == 'GET': | |
313 |
|
313 | |||
314 | if 'template' in request.GET: |
|
314 | if 'template' in request.GET: | |
315 | if request.GET['template']=='0': |
|
315 | if request.GET['template']=='0': | |
316 | form = NewForm(initial={'create_from':2}, |
|
316 | form = NewForm(initial={'create_from':2}, | |
317 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
317 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
318 | else: |
|
318 | else: | |
319 | kwargs['button'] = 'Create' |
|
319 | kwargs['button'] = 'Create' | |
320 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
320 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |
321 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
321 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
322 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
322 | camp = Campaign.objects.get(pk=request.GET['template']) | |
323 | form = CampaignForm(instance=camp, |
|
323 | form = CampaignForm(instance=camp, | |
324 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
324 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
325 | 'template':False}) |
|
325 | 'template':False}) | |
326 | elif 'blank' in request.GET: |
|
326 | elif 'blank' in request.GET: | |
327 | kwargs['button'] = 'Create' |
|
327 | kwargs['button'] = 'Create' | |
328 | form = CampaignForm() |
|
328 | form = CampaignForm() | |
329 | else: |
|
329 | else: | |
330 | form = NewForm() |
|
330 | form = NewForm() | |
331 |
|
331 | |||
332 | if request.method == 'POST': |
|
332 | if request.method == 'POST': | |
333 | kwargs['button'] = 'Create' |
|
333 | kwargs['button'] = 'Create' | |
334 | post = request.POST.copy() |
|
334 | post = request.POST.copy() | |
335 | experiments = [] |
|
335 | experiments = [] | |
336 |
|
336 | |||
337 | for id_exp in post.getlist('experiments'): |
|
337 | for id_exp in post.getlist('experiments'): | |
338 | exp = Experiment.objects.get(pk=id_exp) |
|
338 | exp = Experiment.objects.get(pk=id_exp) | |
339 | new_exp = exp.clone(template=False) |
|
339 | new_exp = exp.clone(template=False) | |
340 | experiments.append(new_exp) |
|
340 | experiments.append(new_exp) | |
341 |
|
341 | |||
342 | post.setlist('experiments', []) |
|
342 | post.setlist('experiments', []) | |
343 |
|
343 | |||
344 | form = CampaignForm(post) |
|
344 | form = CampaignForm(post) | |
345 |
|
345 | |||
346 | if form.is_valid(): |
|
346 | if form.is_valid(): | |
347 | campaign = form.save() |
|
347 | campaign = form.save() | |
348 | for exp in experiments: |
|
348 | for exp in experiments: | |
349 | campaign.experiments.add(exp) |
|
349 | campaign.experiments.add(exp) | |
350 | campaign.save() |
|
350 | campaign.save() | |
351 | return redirect('url_campaign', id_camp=campaign.id) |
|
351 | return redirect('url_campaign', id_camp=campaign.id) | |
352 |
|
352 | |||
353 | kwargs['form'] = form |
|
353 | kwargs['form'] = form | |
354 | kwargs['title'] = 'Campaign' |
|
354 | kwargs['title'] = 'Campaign' | |
355 | kwargs['suptitle'] = 'New' |
|
355 | kwargs['suptitle'] = 'New' | |
356 |
|
356 | |||
357 | return render(request, 'campaign_edit.html', kwargs) |
|
357 | return render(request, 'campaign_edit.html', kwargs) | |
358 |
|
358 | |||
359 |
|
359 | |||
360 | def campaign_edit(request, id_camp): |
|
360 | def campaign_edit(request, id_camp): | |
361 |
|
361 | |||
362 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
362 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
363 |
|
363 | |||
364 | if request.method=='GET': |
|
364 | if request.method=='GET': | |
365 | form = CampaignForm(instance=campaign) |
|
365 | form = CampaignForm(instance=campaign) | |
366 |
|
366 | |||
367 | if request.method=='POST': |
|
367 | if request.method=='POST': | |
368 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
368 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
369 | post = request.POST.copy() |
|
369 | post = request.POST.copy() | |
370 | new_exps = post.getlist('experiments') |
|
370 | new_exps = post.getlist('experiments') | |
371 | post.setlist('experiments', []) |
|
371 | post.setlist('experiments', []) | |
372 | form = CampaignForm(post, instance=campaign) |
|
372 | form = CampaignForm(post, instance=campaign) | |
373 |
|
373 | |||
374 | if form.is_valid(): |
|
374 | if form.is_valid(): | |
375 | camp = form.save() |
|
375 | camp = form.save() | |
376 | for id_exp in new_exps: |
|
376 | for id_exp in new_exps: | |
377 | if int(id_exp) in exps: |
|
377 | if int(id_exp) in exps: | |
378 | exps.pop(id_exp) |
|
378 | exps.pop(id_exp) | |
379 | else: |
|
379 | else: | |
380 | exp = Experiment.objects.get(pk=id_exp) |
|
380 | exp = Experiment.objects.get(pk=id_exp) | |
381 | if exp.template: |
|
381 | if exp.template: | |
382 | camp.experiments.add(exp.clone(template=False)) |
|
382 | camp.experiments.add(exp.clone(template=False)) | |
383 | else: |
|
383 | else: | |
384 | camp.experiments.add(exp) |
|
384 | camp.experiments.add(exp) | |
385 |
|
385 | |||
386 | for id_exp in exps: |
|
386 | for id_exp in exps: | |
387 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
387 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
388 |
|
388 | |||
389 | return redirect('url_campaign', id_camp=id_camp) |
|
389 | return redirect('url_campaign', id_camp=id_camp) | |
390 |
|
390 | |||
391 | kwargs = {} |
|
391 | kwargs = {} | |
392 | kwargs['form'] = form |
|
392 | kwargs['form'] = form | |
393 | kwargs['title'] = 'Campaign' |
|
393 | kwargs['title'] = 'Campaign' | |
394 | kwargs['suptitle'] = 'Edit' |
|
394 | kwargs['suptitle'] = 'Edit' | |
395 | kwargs['button'] = 'Update' |
|
395 | kwargs['button'] = 'Update' | |
396 |
|
396 | |||
397 | return render(request, 'campaign_edit.html', kwargs) |
|
397 | return render(request, 'campaign_edit.html', kwargs) | |
398 |
|
398 | |||
399 |
|
399 | |||
400 | def campaign_delete(request, id_camp): |
|
400 | def campaign_delete(request, id_camp): | |
401 |
|
401 | |||
402 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
402 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
403 |
|
403 | |||
404 | if request.method=='POST': |
|
404 | if request.method=='POST': | |
405 | if request.user.is_staff: |
|
405 | if request.user.is_staff: | |
406 |
|
406 | |||
407 | for exp in campaign.experiments.all(): |
|
407 | for exp in campaign.experiments.all(): | |
408 | for conf in Configuration.objects.filter(experiment=exp): |
|
408 | for conf in Configuration.objects.filter(experiment=exp): | |
409 | conf.delete() |
|
409 | conf.delete() | |
410 | exp.delete() |
|
410 | exp.delete() | |
411 | campaign.delete() |
|
411 | campaign.delete() | |
412 |
|
412 | |||
413 | return redirect('url_campaigns') |
|
413 | return redirect('url_campaigns') | |
414 |
|
414 | |||
415 | messages.error(request, 'Not enough permission to delete this object') |
|
415 | messages.error(request, 'Not enough permission to delete this object') | |
416 | return redirect(campaign.get_absolute_url()) |
|
416 | return redirect(campaign.get_absolute_url()) | |
417 |
|
417 | |||
418 | kwargs = { |
|
418 | kwargs = { | |
419 | 'title': 'Delete', |
|
419 | 'title': 'Delete', | |
420 | 'suptitle': 'Campaign', |
|
420 | 'suptitle': 'Campaign', | |
421 | 'object': campaign, |
|
421 | 'object': campaign, | |
422 | 'previous': campaign.get_absolute_url(), |
|
422 | 'previous': campaign.get_absolute_url(), | |
423 | 'delete': True |
|
423 | 'delete': True | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | return render(request, 'confirm.html', kwargs) |
|
426 | return render(request, 'confirm.html', kwargs) | |
427 |
|
427 | |||
428 | def campaign_export(request, id_camp): |
|
428 | def campaign_export(request, id_camp): | |
429 |
|
429 | |||
430 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
430 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
431 | content = campaign.parms_to_dict() |
|
431 | content = campaign.parms_to_dict() | |
432 | content_type = 'application/json' |
|
432 | content_type = 'application/json' | |
433 | filename = '%s_%s.json' %(campaign.name, campaign.id) |
|
433 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
434 |
|
434 | |||
435 | response = HttpResponse(content_type=content_type) |
|
435 | response = HttpResponse(content_type=content_type) | |
436 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
436 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
437 | response.write(content) |
|
437 | response.write(content) | |
438 |
|
438 | |||
439 | return response |
|
439 | return response | |
440 |
|
440 | |||
441 |
|
441 | |||
442 | def campaign_import(request, id_camp): |
|
442 | def campaign_import(request, id_camp): | |
443 |
|
443 | |||
444 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
444 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
445 |
|
445 | |||
446 | if request.method == 'GET': |
|
446 | if request.method == 'GET': | |
447 | file_form = UploadFileForm() |
|
447 | file_form = UploadFileForm() | |
448 |
|
448 | |||
449 | if request.method == 'POST': |
|
449 | if request.method == 'POST': | |
450 | file_form = UploadFileForm(request.POST, request.FILES) |
|
450 | file_form = UploadFileForm(request.POST, request.FILES) | |
451 |
|
451 | |||
452 | if file_form.is_valid(): |
|
452 | if file_form.is_valid(): | |
453 |
|
453 | |||
454 | parms = campaign.import_from_file(request.FILES['file']) |
|
454 | parms = campaign.import_from_file(request.FILES['file']) | |
455 |
|
455 | |||
456 | if parms: |
|
456 | if parms: | |
457 | parms['name'] = parms['campaign'] |
|
457 | parms['name'] = parms['campaign'] | |
458 |
|
458 | |||
459 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) |
|
459 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) | |
460 |
|
460 | |||
461 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
461 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
462 |
|
462 | |||
463 | return redirect(new_camp.get_absolute_url_edit()) |
|
463 | return redirect(new_camp.get_absolute_url_edit()) | |
464 |
|
464 | |||
465 | messages.error(request, "Could not import parameters from file") |
|
465 | messages.error(request, "Could not import parameters from file") | |
466 |
|
466 | |||
467 | kwargs = {} |
|
467 | kwargs = {} | |
468 | kwargs['title'] = 'Campaign' |
|
468 | kwargs['title'] = 'Campaign' | |
469 | kwargs['form'] = file_form |
|
469 | kwargs['form'] = file_form | |
470 | kwargs['suptitle'] = 'Importing file' |
|
470 | kwargs['suptitle'] = 'Importing file' | |
471 | kwargs['button'] = 'Import' |
|
471 | kwargs['button'] = 'Import' | |
472 |
|
472 | |||
473 | return render(request, 'campaign_import.html', kwargs) |
|
473 | return render(request, 'campaign_import.html', kwargs) | |
474 |
|
474 | |||
475 |
|
475 | |||
476 | def experiments(request): |
|
476 | def experiments(request): | |
477 |
|
477 | |||
478 | page = request.GET.get('page') |
|
478 | page = request.GET.get('page') | |
479 | order = ('location',) |
|
479 | order = ('location',) | |
480 | filters = request.GET.copy() |
|
480 | filters = request.GET.copy() | |
481 |
|
481 | |||
482 | kwargs = get_paginator(Experiment, page, order, filters) |
|
482 | kwargs = get_paginator(Experiment, page, order, filters) | |
483 |
|
483 | |||
484 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) |
|
484 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) | |
485 |
|
485 | |||
486 | kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time'] |
|
486 | kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time'] | |
487 | kwargs['title'] = 'Experiment' |
|
487 | kwargs['title'] = 'Experiment' | |
488 | kwargs['suptitle'] = 'List' |
|
488 | kwargs['suptitle'] = 'List' | |
489 | kwargs['form'] = form |
|
489 | kwargs['form'] = form | |
490 | filters.pop('page', None) |
|
490 | filters.pop('page', None) | |
491 | kwargs['q'] = urlencode(filters) |
|
491 | kwargs['q'] = urlencode(filters) | |
492 |
|
492 | |||
493 | return render(request, 'base_list.html', kwargs) |
|
493 | return render(request, 'base_list.html', kwargs) | |
494 |
|
494 | |||
495 |
|
495 | |||
496 | def experiment(request, id_exp): |
|
496 | def experiment(request, id_exp): | |
497 |
|
497 | |||
498 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
498 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
499 |
|
499 | |||
500 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
500 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
501 |
|
501 | |||
502 | kwargs = {} |
|
502 | kwargs = {} | |
503 |
|
503 | |||
504 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] |
|
504 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
505 | kwargs['experiment'] = experiment |
|
505 | kwargs['experiment'] = experiment | |
506 |
|
506 | |||
507 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] |
|
507 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] | |
508 | kwargs['configurations'] = configurations |
|
508 | kwargs['configurations'] = configurations | |
509 |
|
509 | |||
510 | kwargs['title'] = 'Experiment' |
|
510 | kwargs['title'] = 'Experiment' | |
511 | kwargs['suptitle'] = 'Details' |
|
511 | kwargs['suptitle'] = 'Details' | |
512 |
|
512 | |||
513 | kwargs['button'] = 'Add Configuration' |
|
513 | kwargs['button'] = 'Add Configuration' | |
514 |
|
514 | |||
515 | ###### SIDEBAR ###### |
|
515 | ###### SIDEBAR ###### | |
516 | kwargs.update(sidebar(experiment=experiment)) |
|
516 | kwargs.update(sidebar(experiment=experiment)) | |
517 |
|
517 | |||
518 | return render(request, 'experiment.html', kwargs) |
|
518 | return render(request, 'experiment.html', kwargs) | |
519 |
|
519 | |||
520 |
|
520 | |||
521 | def experiment_new(request, id_camp=None): |
|
521 | def experiment_new(request, id_camp=None): | |
522 |
|
522 | |||
523 | kwargs = {} |
|
523 | kwargs = {} | |
524 |
|
524 | |||
525 | if request.method == 'GET': |
|
525 | if request.method == 'GET': | |
526 | if 'template' in request.GET: |
|
526 | if 'template' in request.GET: | |
527 | if request.GET['template']=='0': |
|
527 | if request.GET['template']=='0': | |
528 | form = NewForm(initial={'create_from':2}, |
|
528 | form = NewForm(initial={'create_from':2}, | |
529 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
529 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
530 | else: |
|
530 | else: | |
531 | kwargs['button'] = 'Create' |
|
531 | kwargs['button'] = 'Create' | |
532 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
532 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |
533 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
533 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] | |
534 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
534 | exp=Experiment.objects.get(pk=request.GET['template']) | |
535 | form = ExperimentForm(instance=exp, |
|
535 | form = ExperimentForm(instance=exp, | |
536 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
536 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
537 | 'template': False}) |
|
537 | 'template': False}) | |
538 | elif 'blank' in request.GET: |
|
538 | elif 'blank' in request.GET: | |
539 | kwargs['button'] = 'Create' |
|
539 | kwargs['button'] = 'Create' | |
540 | form = ExperimentForm() |
|
540 | form = ExperimentForm() | |
541 | else: |
|
541 | else: | |
542 | form = NewForm() |
|
542 | form = NewForm() | |
543 |
|
543 | |||
544 | if request.method == 'POST': |
|
544 | if request.method == 'POST': | |
545 | form = ExperimentForm(request.POST) |
|
545 | form = ExperimentForm(request.POST) | |
546 | if form.is_valid(): |
|
546 | if form.is_valid(): | |
547 | experiment = form.save() |
|
547 | experiment = form.save() | |
548 |
|
548 | |||
549 | if 'template' in request.GET: |
|
549 | if 'template' in request.GET: | |
550 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
550 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |
551 | for conf in configurations: |
|
551 | for conf in configurations: | |
552 | conf.clone(experiment=experiment, template=False) |
|
552 | conf.clone(experiment=experiment, template=False) | |
553 |
|
553 | |||
554 | return redirect('url_experiment', id_exp=experiment.id) |
|
554 | return redirect('url_experiment', id_exp=experiment.id) | |
555 |
|
555 | |||
556 | kwargs['form'] = form |
|
556 | kwargs['form'] = form | |
557 | kwargs['title'] = 'Experiment' |
|
557 | kwargs['title'] = 'Experiment' | |
558 | kwargs['suptitle'] = 'New' |
|
558 | kwargs['suptitle'] = 'New' | |
559 |
|
559 | |||
560 | return render(request, 'experiment_edit.html', kwargs) |
|
560 | return render(request, 'experiment_edit.html', kwargs) | |
561 |
|
561 | |||
562 |
|
562 | |||
563 | def experiment_edit(request, id_exp): |
|
563 | def experiment_edit(request, id_exp): | |
564 |
|
564 | |||
565 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
565 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
566 |
|
566 | |||
567 | if request.method == 'GET': |
|
567 | if request.method == 'GET': | |
568 | form = ExperimentForm(instance=experiment) |
|
568 | form = ExperimentForm(instance=experiment) | |
569 |
|
569 | |||
570 | if request.method=='POST': |
|
570 | if request.method=='POST': | |
571 | form = ExperimentForm(request.POST, instance=experiment) |
|
571 | form = ExperimentForm(request.POST, instance=experiment) | |
572 |
|
572 | |||
573 | if form.is_valid(): |
|
573 | if form.is_valid(): | |
574 | experiment = form.save() |
|
574 | experiment = form.save() | |
575 | return redirect('url_experiment', id_exp=experiment.id) |
|
575 | return redirect('url_experiment', id_exp=experiment.id) | |
576 |
|
576 | |||
577 | kwargs = {} |
|
577 | kwargs = {} | |
578 | kwargs['form'] = form |
|
578 | kwargs['form'] = form | |
579 | kwargs['title'] = 'Experiment' |
|
579 | kwargs['title'] = 'Experiment' | |
580 | kwargs['suptitle'] = 'Edit' |
|
580 | kwargs['suptitle'] = 'Edit' | |
581 | kwargs['button'] = 'Update' |
|
581 | kwargs['button'] = 'Update' | |
582 |
|
582 | |||
583 | return render(request, 'experiment_edit.html', kwargs) |
|
583 | return render(request, 'experiment_edit.html', kwargs) | |
584 |
|
584 | |||
585 |
|
585 | |||
586 | def experiment_delete(request, id_exp): |
|
586 | def experiment_delete(request, id_exp): | |
587 |
|
587 | |||
588 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
588 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
589 |
|
589 | |||
590 | if request.method=='POST': |
|
590 | if request.method=='POST': | |
591 | if request.user.is_staff: |
|
591 | if request.user.is_staff: | |
592 | for conf in Configuration.objects.filter(experiment=experiment): |
|
592 | for conf in Configuration.objects.filter(experiment=experiment): | |
593 | conf.delete() |
|
593 | conf.delete() | |
594 | experiment.delete() |
|
594 | experiment.delete() | |
595 | return redirect('url_experiments') |
|
595 | return redirect('url_experiments') | |
596 |
|
596 | |||
597 | messages.error(request, 'Not enough permission to delete this object') |
|
597 | messages.error(request, 'Not enough permission to delete this object') | |
598 | return redirect(experiment.get_absolute_url()) |
|
598 | return redirect(experiment.get_absolute_url()) | |
599 |
|
599 | |||
600 | kwargs = { |
|
600 | kwargs = { | |
601 | 'title': 'Delete', |
|
601 | 'title': 'Delete', | |
602 | 'suptitle': 'Experiment', |
|
602 | 'suptitle': 'Experiment', | |
603 | 'object': experiment, |
|
603 | 'object': experiment, | |
604 | 'previous': experiment.get_absolute_url(), |
|
604 | 'previous': experiment.get_absolute_url(), | |
605 | 'delete': True |
|
605 | 'delete': True | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | return render(request, 'confirm.html', kwargs) |
|
608 | return render(request, 'confirm.html', kwargs) | |
609 |
|
609 | |||
610 |
|
610 | |||
611 | def experiment_export(request, id_exp): |
|
611 | def experiment_export(request, id_exp): | |
612 |
|
612 | |||
613 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
613 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
614 | content = experiment.parms_to_dict() |
|
614 | content = experiment.parms_to_dict() | |
615 | content_type = 'application/json' |
|
615 | content_type = 'application/json' | |
616 | filename = '%s_%s.json' %(experiment.name, experiment.id) |
|
616 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
617 |
|
617 | |||
618 | response = HttpResponse(content_type=content_type) |
|
618 | response = HttpResponse(content_type=content_type) | |
619 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
619 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
620 | response.write(content) |
|
620 | response.write(content) | |
621 |
|
621 | |||
622 | return response |
|
622 | return response | |
623 |
|
623 | |||
624 | def experiment_import(request, id_exp): |
|
624 | def experiment_import(request, id_exp): | |
625 |
|
625 | |||
626 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
626 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
627 | configurations = Configuration.objects.filter(experiment=experiment) |
|
627 | configurations = Configuration.objects.filter(experiment=experiment) | |
628 |
|
628 | |||
629 | if request.method == 'GET': |
|
629 | if request.method == 'GET': | |
630 | file_form = UploadFileForm() |
|
630 | file_form = UploadFileForm() | |
631 |
|
631 | |||
632 | if request.method == 'POST': |
|
632 | if request.method == 'POST': | |
633 | file_form = UploadFileForm(request.POST, request.FILES) |
|
633 | file_form = UploadFileForm(request.POST, request.FILES) | |
634 |
|
634 | |||
635 | if file_form.is_valid(): |
|
635 | if file_form.is_valid(): | |
636 |
|
636 | |||
637 | parms = experiment.import_from_file(request.FILES['file']) |
|
637 | parms = experiment.import_from_file(request.FILES['file']) | |
638 |
|
638 | |||
639 | if parms: |
|
639 | if parms: | |
640 |
|
640 | |||
641 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) |
|
641 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) | |
642 |
|
642 | |||
643 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
643 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
644 |
|
644 | |||
645 | return redirect(new_exp.get_absolute_url_edit()) |
|
645 | return redirect(new_exp.get_absolute_url_edit()) | |
646 |
|
646 | |||
647 | messages.error(request, "Could not import parameters from file") |
|
647 | messages.error(request, "Could not import parameters from file") | |
648 |
|
648 | |||
649 | kwargs = {} |
|
649 | kwargs = {} | |
650 | kwargs['title'] = 'Experiment' |
|
650 | kwargs['title'] = 'Experiment' | |
651 | kwargs['form'] = file_form |
|
651 | kwargs['form'] = file_form | |
652 | kwargs['suptitle'] = 'Importing file' |
|
652 | kwargs['suptitle'] = 'Importing file' | |
653 | kwargs['button'] = 'Import' |
|
653 | kwargs['button'] = 'Import' | |
654 |
|
654 | |||
655 | kwargs.update(sidebar(experiment=experiment)) |
|
655 | kwargs.update(sidebar(experiment=experiment)) | |
656 |
|
656 | |||
657 | return render(request, 'experiment_import.html', kwargs) |
|
657 | return render(request, 'experiment_import.html', kwargs) | |
658 |
|
658 | |||
659 | def experiment_mix(request, id_exp): |
|
659 | def experiment_mix(request, id_exp): | |
660 |
|
660 | |||
661 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
661 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
662 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, |
|
662 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, | |
663 | mix=False)] |
|
663 | mix=False)] | |
664 |
|
664 | |||
665 | if len(rc_confs)<2: |
|
665 | if len(rc_confs)<2: | |
666 | messages.warning(request, 'You need at least two RC Configurations to make a mix') |
|
666 | messages.warning(request, 'You need at least two RC Configurations to make a mix') | |
667 | return redirect(experiment.get_absolute_url()) |
|
667 | return redirect(experiment.get_absolute_url()) | |
668 |
|
668 | |||
669 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) |
|
669 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) | |
670 |
|
670 | |||
671 | if mix_confs: |
|
671 | if mix_confs: | |
672 | mix = mix_confs[0] |
|
672 | mix = mix_confs[0] | |
673 | else: |
|
673 | else: | |
674 | mix = RCConfiguration(experiment=experiment, |
|
674 | mix = RCConfiguration(experiment=experiment, | |
675 | device=rc_confs[0].device, |
|
675 | device=rc_confs[0].device, | |
676 | ipp=rc_confs[0].ipp, |
|
676 | ipp=rc_confs[0].ipp, | |
677 | clock_in=rc_confs[0].clock_in, |
|
677 | clock_in=rc_confs[0].clock_in, | |
678 | clock_divider=rc_confs[0].clock_divider, |
|
678 | clock_divider=rc_confs[0].clock_divider, | |
679 | mix=True, |
|
679 | mix=True, | |
680 | parameters='') |
|
680 | parameters='') | |
681 | mix.save() |
|
681 | mix.save() | |
682 |
|
682 | |||
683 | line_type = RCLineType.objects.get(name='mix') |
|
683 | line_type = RCLineType.objects.get(name='mix') | |
684 | for i in range(len(rc_confs[0].get_lines())): |
|
684 | for i in range(len(rc_confs[0].get_lines())): | |
685 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) |
|
685 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |
686 | line.save() |
|
686 | line.save() | |
687 |
|
687 | |||
688 | initial = {'name': mix.name, |
|
688 | initial = {'name': mix.name, | |
689 | 'result': parse_mix_result(mix.parameters), |
|
689 | 'result': parse_mix_result(mix.parameters), | |
690 | 'delay': 0, |
|
690 | 'delay': 0, | |
691 | 'mask': [0,1,2,3,4,5,6,7] |
|
691 | 'mask': [0,1,2,3,4,5,6,7] | |
692 | } |
|
692 | } | |
693 |
|
693 | |||
694 | if request.method=='GET': |
|
694 | if request.method=='GET': | |
695 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) |
|
695 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |
696 |
|
696 | |||
697 | if request.method=='POST': |
|
697 | if request.method=='POST': | |
698 | result = mix.parameters |
|
698 | result = mix.parameters | |
699 |
|
699 | |||
700 | if '{}|'.format(request.POST['experiment']) in result: |
|
700 | if '{}|'.format(request.POST['experiment']) in result: | |
701 | messages.error(request, 'Configuration already added') |
|
701 | messages.error(request, 'Configuration already added') | |
702 | else: |
|
702 | else: | |
703 | if 'operation' in request.POST: |
|
703 | if 'operation' in request.POST: | |
704 | operation = MIX_OPERATIONS[request.POST['operation']] |
|
704 | operation = MIX_OPERATIONS[request.POST['operation']] | |
705 | else: |
|
705 | else: | |
706 | operation = ' ' |
|
706 | operation = ' ' | |
707 |
|
707 | |||
708 | mode = MIX_MODES[request.POST['mode']] |
|
708 | mode = MIX_MODES[request.POST['mode']] | |
709 |
|
709 | |||
710 | if result: |
|
710 | if result: | |
711 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, |
|
711 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, | |
712 | request.POST['experiment'], |
|
712 | request.POST['experiment'], | |
713 | mode, |
|
713 | mode, | |
714 | operation, |
|
714 | operation, | |
715 | float(request.POST['delay']), |
|
715 | float(request.POST['delay']), | |
716 | parse_mask(request.POST.getlist('mask')) |
|
716 | parse_mask(request.POST.getlist('mask')) | |
717 | ) |
|
717 | ) | |
718 | else: |
|
718 | else: | |
719 | result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'], |
|
719 | result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'], | |
720 | mode, |
|
720 | mode, | |
721 | operation, |
|
721 | operation, | |
722 | float(request.POST['delay']), |
|
722 | float(request.POST['delay']), | |
723 | parse_mask(request.POST.getlist('mask')) |
|
723 | parse_mask(request.POST.getlist('mask')) | |
724 | ) |
|
724 | ) | |
725 |
|
725 | |||
726 | mix.parameters = result |
|
726 | mix.parameters = result | |
727 | mix.name = request.POST['name'] |
|
727 | mix.name = request.POST['name'] | |
728 | mix.save() |
|
728 | mix.save() | |
729 | mix.update_pulses() |
|
729 | mix.update_pulses() | |
730 |
|
730 | |||
731 | initial['result'] = parse_mix_result(result) |
|
731 | initial['result'] = parse_mix_result(result) | |
732 | initial['name'] = mix.name |
|
732 | initial['name'] = mix.name | |
733 |
|
733 | |||
734 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) |
|
734 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |
735 |
|
735 | |||
736 |
|
736 | |||
737 | kwargs = { |
|
737 | kwargs = { | |
738 | 'title': 'Experiment', |
|
738 | 'title': 'Experiment', | |
739 | 'suptitle': 'Mix Configurations', |
|
739 | 'suptitle': 'Mix Configurations', | |
740 | 'form' : form, |
|
740 | 'form' : form, | |
741 | 'extra_button': 'Delete', |
|
741 | 'extra_button': 'Delete', | |
742 | 'button': 'Add', |
|
742 | 'button': 'Add', | |
743 | 'cancel': 'Back', |
|
743 | 'cancel': 'Back', | |
744 | 'previous': experiment.get_absolute_url(), |
|
744 | 'previous': experiment.get_absolute_url(), | |
745 | 'id_exp':id_exp, |
|
745 | 'id_exp':id_exp, | |
746 |
|
746 | |||
747 | } |
|
747 | } | |
748 |
|
748 | |||
749 | return render(request, 'experiment_mix.html', kwargs) |
|
749 | return render(request, 'experiment_mix.html', kwargs) | |
750 |
|
750 | |||
751 |
|
751 | |||
752 | def experiment_mix_delete(request, id_exp): |
|
752 | def experiment_mix_delete(request, id_exp): | |
753 |
|
753 | |||
754 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) |
|
754 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |
755 | values = conf.parameters.split('-') |
|
755 | values = conf.parameters.split('-') | |
756 | conf.parameters = '-'.join(values[:-1]) |
|
756 | conf.parameters = '-'.join(values[:-1]) | |
757 | conf.save() |
|
757 | conf.save() | |
758 |
|
758 | |||
759 | return redirect('url_mix_experiment', id_exp=id_exp) |
|
759 | return redirect('url_mix_experiment', id_exp=id_exp) | |
760 |
|
760 | |||
761 |
|
761 | |||
762 | def experiment_summary(request, id_exp): |
|
762 | def experiment_summary(request, id_exp): | |
763 |
|
763 | |||
764 | import json |
|
764 | import json | |
765 | import ast |
|
765 | import ast | |
766 |
|
766 | |||
767 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
767 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
768 | experiment_data = json.loads(experiment.parms_to_dict()) |
|
768 | experiment_data = json.loads(experiment.parms_to_dict()) | |
769 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
769 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
770 |
|
770 | |||
771 | kwargs = {} |
|
771 | kwargs = {} | |
772 |
|
772 | |||
773 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] |
|
773 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
774 | kwargs['experiment'] = experiment |
|
774 | kwargs['experiment'] = experiment | |
775 |
|
775 | |||
776 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] |
|
776 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] | |
777 | kwargs['configurations'] = configurations |
|
777 | kwargs['configurations'] = configurations | |
778 | kwargs['experiment_data'] = experiment_data |
|
778 | kwargs['experiment_data'] = experiment_data | |
779 |
|
779 | |||
780 | kwargs['title'] = 'Experiment Summary' |
|
780 | kwargs['title'] = 'Experiment Summary' | |
781 | kwargs['suptitle'] = 'Details' |
|
781 | kwargs['suptitle'] = 'Details' | |
782 |
|
782 | |||
783 | kwargs['button'] = 'Verify Parameters' |
|
783 | kwargs['button'] = 'Verify Parameters' | |
784 |
|
784 | |||
785 | jars_conf = False |
|
785 | jars_conf = False | |
786 | rc_conf = False |
|
786 | rc_conf = False | |
787 |
|
787 | |||
788 | for configuration in configurations: |
|
788 | for configuration in configurations: | |
789 | #-------------------- JARS -----------------------: |
|
789 | #-------------------- JARS -----------------------: | |
790 | if configuration.device.device_type.name == 'jars': |
|
790 | if configuration.device.device_type.name == 'jars': | |
791 | jars_conf = True |
|
791 | jars_conf = True | |
792 | kwargs['jars_conf'] = jars_conf |
|
792 | kwargs['jars_conf'] = jars_conf | |
793 | kwargs['exp_type'] = EXPERIMENT_TYPE[configuration.exp_type][1] |
|
793 | kwargs['exp_type'] = EXPERIMENT_TYPE[configuration.exp_type][1] | |
794 | channels_number = configuration.channels_number |
|
794 | channels_number = configuration.channels_number | |
795 | exp_type = configuration.exp_type |
|
795 | exp_type = configuration.exp_type | |
796 | fftpoints = configuration.fftpoints |
|
796 | fftpoints = configuration.fftpoints | |
797 | filter_parms = configuration.filter_parms |
|
797 | filter_parms = configuration.filter_parms | |
798 | filter_parms = ast.literal_eval(filter_parms) |
|
798 | filter_parms = ast.literal_eval(filter_parms) | |
799 | spectral_number = configuration.spectral_number |
|
799 | spectral_number = configuration.spectral_number | |
800 |
|
800 | |||
801 | #--------------------- RC ----------------------: |
|
801 | #--------------------- RC ----------------------: | |
802 | if configuration.device.device_type.name == 'rc': |
|
802 | if configuration.device.device_type.name == 'rc': | |
803 | rc_conf = True |
|
803 | rc_conf = True | |
804 | kwargs['rc_conf'] = rc_conf |
|
804 | kwargs['rc_conf'] = rc_conf | |
805 | rc_lines = experiment_data['configurations']['rc']['lines'] |
|
805 | rc_lines = experiment_data['configurations']['rc']['lines'] | |
806 | ipp = configuration.ipp |
|
806 | ipp = configuration.ipp | |
807 | if experiment_data['configurations']['rc']['mix'] == 'True': |
|
807 | if experiment_data['configurations']['rc']['mix'] == 'True': | |
808 | tx = '' |
|
808 | tx = '' | |
809 | code = '' |
|
809 | code = '' | |
810 | window = '' |
|
810 | window = '' | |
811 | else: |
|
811 | else: | |
812 | code = rc_lines[3]['code'] |
|
812 | code = rc_lines[3]['code'] | |
813 |
|
813 | |||
814 | window_data = rc_lines[6]['params'][0] |
|
814 | window_data = rc_lines[6]['params'][0] | |
815 | h0 = str(window_data['first_height']) |
|
815 | h0 = str(window_data['first_height']) | |
816 | dh = str(window_data['resolution']) |
|
816 | dh = str(window_data['resolution']) | |
817 | nsa = str(window_data['number_of_samples']) |
|
817 | nsa = str(window_data['number_of_samples']) | |
818 | window = 'Ho='+h0+'km\nDH='+dh+'km\nNSA='+nsa |
|
818 | window = 'Ho='+h0+'km\nDH='+dh+'km\nNSA='+nsa | |
819 |
|
819 | |||
820 | tx = '' |
|
820 | tx = '' | |
821 | if float(rc_lines[1]['delays']) == 0: |
|
821 | if float(rc_lines[1]['delays']) == 0: | |
822 | tx = rc_lines[2]['pulse_width'] |
|
822 | tx = rc_lines[2]['pulse_width'] | |
823 | elif float(rc_lines[2]['delays']) == 0: |
|
823 | elif float(rc_lines[2]['delays']) == 0: | |
824 | tx = rc_lines[1]['pulse_width'] |
|
824 | tx = rc_lines[1]['pulse_width'] | |
825 | else: |
|
825 | else: | |
826 | tx = rc_lines[1]['pulse_width']+' | '+rc_lines[2]['pulse_width'] |
|
826 | tx = rc_lines[1]['pulse_width']+' | '+rc_lines[2]['pulse_width'] | |
827 |
|
827 | |||
828 | kwargs['tx'] = tx |
|
828 | kwargs['tx'] = tx | |
829 | kwargs['code'] = code |
|
829 | kwargs['code'] = code | |
830 | kwargs['window'] = window |
|
830 | kwargs['window'] = window | |
831 |
|
831 | |||
832 | #-------------------- DDS -----------------------: |
|
832 | #-------------------- DDS -----------------------: | |
833 | if configuration.device.device_type.name == 'dds': |
|
833 | if configuration.device.device_type.name == 'dds': | |
834 | dds_conf = True |
|
834 | dds_conf = True | |
835 | kwargs['dds_conf'] = dds_conf |
|
835 | kwargs['dds_conf'] = dds_conf | |
836 |
|
836 | |||
837 | #------ RC & JARS ------: |
|
837 | #------ RC & JARS ------: | |
838 | ipp = 937.5 # |
|
838 | ipp = 937.5 # | |
839 | nsa = 200# |
|
839 | nsa = 200# | |
840 | dh = 1.5 # |
|
840 | dh = 1.5 # | |
841 | channels_number = 5 # |
|
841 | channels_number = 5 # | |
842 |
|
842 | |||
843 | if rc_conf and jars_conf: |
|
843 | if rc_conf and jars_conf: | |
844 | if exp_type == 0: #Short |
|
844 | if exp_type == 0: #Short | |
845 | bytes = 2 |
|
845 | bytes = 2 | |
846 | b = nsa*2*bytes*channels_number |
|
846 | b = nsa*2*bytes*channels_number | |
847 | else: #Float |
|
847 | else: #Float | |
848 | bytes = 4 |
|
848 | bytes = 4 | |
849 | channels = channels_number + spectral_number |
|
849 | channels = channels_number + spectral_number | |
850 | b = nsa*2*bytes*fftpoints*channels |
|
850 | b = nsa*2*bytes*fftpoints*channels | |
851 |
|
851 | |||
852 | ipps = (ipp*pow(10,-6))/0.15 |
|
852 | ipps = (ipp*pow(10,-6))/0.15 | |
853 | GB = 1048576.0*1024.0 |
|
853 | GB = 1048576.0*1024.0 | |
854 | Hour = 3600 |
|
854 | Hour = 3600 | |
855 | rate = b/ipps |
|
855 | rate = b/ipps | |
856 | rate = rate *(1/GB)*(Hour) |
|
856 | rate = rate *(1/GB)*(Hour) | |
857 | kwargs['rate'] = str(rate)+" GB/h" |
|
857 | kwargs['rate'] = str(rate)+" GB/h" | |
858 | else: |
|
858 | else: | |
859 | kwargs['rate'] = '' |
|
859 | kwargs['rate'] = '' | |
860 |
|
860 | |||
861 | ###### SIDEBAR ###### |
|
861 | ###### SIDEBAR ###### | |
862 | kwargs.update(sidebar(experiment=experiment)) |
|
862 | kwargs.update(sidebar(experiment=experiment)) | |
863 |
|
863 | |||
864 | return render(request, 'experiment_summary.html', kwargs) |
|
864 | return render(request, 'experiment_summary.html', kwargs) | |
865 |
|
865 | |||
866 | def experiment_verify(request, id_exp): |
|
866 | def experiment_verify(request, id_exp): | |
867 |
|
867 | |||
868 | import json |
|
868 | import json | |
869 | import ast |
|
869 | import ast | |
870 |
|
870 | |||
871 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
871 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
872 | experiment_data = json.loads(experiment.parms_to_dict()) |
|
872 | experiment_data = json.loads(experiment.parms_to_dict()) | |
873 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
873 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
874 |
|
874 | |||
875 | kwargs = {} |
|
875 | kwargs = {} | |
876 |
|
876 | |||
877 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] |
|
877 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
878 | kwargs['experiment'] = experiment |
|
878 | kwargs['experiment'] = experiment | |
879 |
|
879 | |||
880 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] |
|
880 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] | |
881 | kwargs['configurations'] = configurations |
|
881 | kwargs['configurations'] = configurations | |
882 | kwargs['experiment_data'] = experiment_data |
|
882 | kwargs['experiment_data'] = experiment_data | |
883 |
|
883 | |||
884 | kwargs['title'] = 'Verify Experiment' |
|
884 | kwargs['title'] = 'Verify Experiment' | |
885 | kwargs['suptitle'] = 'Parameters' |
|
885 | kwargs['suptitle'] = 'Parameters' | |
886 |
|
886 | |||
887 | kwargs['button'] = 'Update' |
|
887 | kwargs['button'] = 'Update' | |
888 |
|
888 | |||
889 | jars_conf = False |
|
889 | jars_conf = False | |
890 | rc_conf = False |
|
890 | rc_conf = False | |
891 | dds_conf = False |
|
891 | dds_conf = False | |
892 |
|
892 | |||
893 | for configuration in configurations: |
|
893 | for configuration in configurations: | |
894 | #-------------------- JARS -----------------------: |
|
894 | #-------------------- JARS -----------------------: | |
895 | if configuration.device.device_type.name == 'jars': |
|
895 | if configuration.device.device_type.name == 'jars': | |
896 | jars_conf = True |
|
896 | jars_conf = True | |
897 | kwargs['jars_conf'] = jars_conf |
|
897 | kwargs['jars_conf'] = jars_conf | |
898 | filter_parms = configuration.filter_parms |
|
898 | filter_parms = configuration.filter_parms | |
899 | filter_parms = ast.literal_eval(filter_parms) |
|
899 | filter_parms = ast.literal_eval(filter_parms) | |
900 | kwargs['filter_parms'] = filter_parms |
|
900 | kwargs['filter_parms'] = filter_parms | |
901 | #--Sampling Frequency |
|
901 | #--Sampling Frequency | |
902 | clock = filter_parms['clock'] |
|
902 | clock = filter_parms['clock'] | |
903 | filter_2 = filter_parms['filter_2'] |
|
903 | filter_2 = filter_parms['filter_2'] | |
904 | filter_5 = filter_parms['filter_5'] |
|
904 | filter_5 = filter_parms['filter_5'] | |
905 | filter_fir = filter_parms['filter_fir'] |
|
905 | filter_fir = filter_parms['filter_fir'] | |
906 | samp_freq_jars = clock/filter_2/filter_5/filter_fir |
|
906 | samp_freq_jars = clock/filter_2/filter_5/filter_fir | |
907 |
|
907 | |||
908 | kwargs['samp_freq_jars'] = samp_freq_jars |
|
908 | kwargs['samp_freq_jars'] = samp_freq_jars | |
909 | kwargs['jars'] = configuration |
|
909 | kwargs['jars'] = configuration | |
910 |
|
910 | |||
911 | #--------------------- RC ----------------------: |
|
911 | #--------------------- RC ----------------------: | |
912 | if configuration.device.device_type.name == 'rc': |
|
912 | if configuration.device.device_type.name == 'rc': | |
913 | rc_conf = True |
|
913 | rc_conf = True | |
914 | rc_parms = configuration.parms_to_dict() |
|
914 | rc_parms = configuration.parms_to_dict() | |
915 | if rc_parms['mix'] == 'True': |
|
915 | if rc_parms['mix'] == 'True': | |
916 | pass |
|
916 | pass | |
917 | else: |
|
917 | else: | |
918 | rc_lines = rc_parms['lines'] |
|
918 | rc_lines = rc_parms['lines'] | |
919 | dh = rc_lines[6]['params'][0]['resolution'] |
|
919 | dh = rc_lines[6]['params'][0]['resolution'] | |
920 | #--Sampling Frequency |
|
920 | #--Sampling Frequency | |
921 | samp_freq_rc = 0.15/dh |
|
921 | samp_freq_rc = 0.15/dh | |
922 | kwargs['samp_freq_rc'] = samp_freq_rc |
|
922 | kwargs['samp_freq_rc'] = samp_freq_rc | |
923 |
|
923 | |||
924 | kwargs['rc_conf'] = rc_conf |
|
924 | kwargs['rc_conf'] = rc_conf | |
925 | kwargs['rc'] = configuration |
|
925 | kwargs['rc'] = configuration | |
926 |
|
926 | |||
927 | #-------------------- DDS ----------------------: |
|
927 | #-------------------- DDS ----------------------: | |
928 | if configuration.device.device_type.name == 'dds': |
|
928 | if configuration.device.device_type.name == 'dds': | |
929 | dds_conf = True |
|
929 | dds_conf = True | |
930 | dds_parms = configuration.parms_to_dict() |
|
930 | dds_parms = configuration.parms_to_dict() | |
931 |
|
931 | |||
932 | kwargs['dds_conf'] = dds_conf |
|
932 | kwargs['dds_conf'] = dds_conf | |
933 | kwargs['dds'] = configuration |
|
933 | kwargs['dds'] = configuration | |
934 |
|
934 | |||
935 |
|
935 | |||
936 | #------------Validation------------: |
|
936 | #------------Validation------------: | |
937 | #Clock |
|
937 | #Clock | |
938 | if dds_conf and rc_conf and jars_conf: |
|
938 | if dds_conf and rc_conf and jars_conf: | |
939 | if filter_parms['clock'] != rc_parms['clock_in'] and rc_parms['clock_in'] != dds_parms['clock']: |
|
939 | if filter_parms['clock'] != rc_parms['clock_in'] and rc_parms['clock_in'] != dds_parms['clock']: | |
940 | messages.warning(request, "Devices don't have the same clock.") |
|
940 | messages.warning(request, "Devices don't have the same clock.") | |
941 | elif rc_conf and jars_conf: |
|
941 | elif rc_conf and jars_conf: | |
942 | if filter_parms['clock'] != rc_parms['clock_in']: |
|
942 | if filter_parms['clock'] != rc_parms['clock_in']: | |
943 | messages.warning(request, "Devices don't have the same clock.") |
|
943 | messages.warning(request, "Devices don't have the same clock.") | |
944 | elif rc_conf and dds_conf: |
|
944 | elif rc_conf and dds_conf: | |
945 | if rc_parms['clock_in'] != dds_parms['clock']: |
|
945 | if rc_parms['clock_in'] != dds_parms['clock']: | |
946 | messages.warning(request, "Devices don't have the same clock.") |
|
946 | messages.warning(request, "Devices don't have the same clock.") | |
947 | if float(samp_freq_rc) != float(dds_parms['frequencyA']): |
|
947 | if float(samp_freq_rc) != float(dds_parms['frequencyA']): | |
948 | messages.warning(request, "Devices don't have the same Frequency A.") |
|
948 | messages.warning(request, "Devices don't have the same Frequency A.") | |
949 |
|
949 | |||
950 |
|
950 | |||
951 |
|
951 | |||
952 | ###### SIDEBAR ###### |
|
952 | ###### SIDEBAR ###### | |
953 | kwargs.update(sidebar(experiment=experiment)) |
|
953 | kwargs.update(sidebar(experiment=experiment)) | |
954 |
|
954 | |||
955 |
|
955 | |||
956 |
|
956 | |||
957 |
|
957 | |||
958 |
|
958 | |||
959 | return render(request, 'experiment_verify.html', kwargs) |
|
959 | return render(request, 'experiment_verify.html', kwargs) | |
960 |
|
960 | |||
961 |
|
961 | |||
962 | def parse_mix_result(s): |
|
962 | def parse_mix_result(s): | |
963 |
|
963 | |||
964 | values = s.split('-') |
|
964 | values = s.split('-') | |
965 | html = 'EXP MOD OPE DELAY MASK\r\n' |
|
965 | html = 'EXP MOD OPE DELAY MASK\r\n' | |
966 |
|
966 | |||
967 | if not values or values[0] in ('', ' '): |
|
967 | if not values or values[0] in ('', ' '): | |
968 | return mark_safe(html) |
|
968 | return mark_safe(html) | |
969 |
|
969 | |||
970 | for i, value in enumerate(values): |
|
970 | for i, value in enumerate(values): | |
971 | if not value: |
|
971 | if not value: | |
972 | continue |
|
972 | continue | |
973 | pk, mode, operation, delay, mask = value.split('|') |
|
973 | pk, mode, operation, delay, mask = value.split('|') | |
974 | conf = RCConfiguration.objects.get(pk=pk) |
|
974 | conf = RCConfiguration.objects.get(pk=pk) | |
975 | if i==0: |
|
975 | if i==0: | |
976 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
976 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
977 | conf.name, |
|
977 | conf.name, | |
978 | mode, |
|
978 | mode, | |
979 | ' ', |
|
979 | ' ', | |
980 | delay, |
|
980 | delay, | |
981 | mask) |
|
981 | mask) | |
982 | else: |
|
982 | else: | |
983 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
983 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
984 | conf.name, |
|
984 | conf.name, | |
985 | mode, |
|
985 | mode, | |
986 | operation, |
|
986 | operation, | |
987 | delay, |
|
987 | delay, | |
988 | mask) |
|
988 | mask) | |
989 |
|
989 | |||
990 | return mark_safe(html) |
|
990 | return mark_safe(html) | |
991 |
|
991 | |||
992 | def parse_mask(l): |
|
992 | def parse_mask(l): | |
993 |
|
993 | |||
994 | values = [] |
|
994 | values = [] | |
995 |
|
995 | |||
996 | for x in range(8): |
|
996 | for x in range(8): | |
997 | if '{}'.format(x) in l: |
|
997 | if '{}'.format(x) in l: | |
998 | values.append(1) |
|
998 | values.append(1) | |
999 | else: |
|
999 | else: | |
1000 | values.append(0) |
|
1000 | values.append(0) | |
1001 |
|
1001 | |||
1002 | values.reverse() |
|
1002 | values.reverse() | |
1003 |
|
1003 | |||
1004 | return int(''.join([str(x) for x in values]), 2) |
|
1004 | return int(''.join([str(x) for x in values]), 2) | |
1005 |
|
1005 | |||
1006 |
|
1006 | |||
1007 | def dev_confs(request): |
|
1007 | def dev_confs(request): | |
1008 |
|
1008 | |||
1009 |
|
1009 | |||
1010 | page = request.GET.get('page') |
|
1010 | page = request.GET.get('page') | |
1011 | order = ('type', 'device__device_type', 'experiment') |
|
1011 | order = ('type', 'device__device_type', 'experiment') | |
1012 | filters = request.GET.copy() |
|
1012 | filters = request.GET.copy() | |
1013 |
|
1013 | |||
1014 | kwargs = get_paginator(Configuration, page, order, filters) |
|
1014 | kwargs = get_paginator(Configuration, page, order, filters) | |
1015 |
|
1015 | |||
1016 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) |
|
1016 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) | |
1017 | kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] |
|
1017 | kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] | |
1018 | kwargs['title'] = 'Configuration' |
|
1018 | kwargs['title'] = 'Configuration' | |
1019 | kwargs['suptitle'] = 'List' |
|
1019 | kwargs['suptitle'] = 'List' | |
1020 | kwargs['form'] = form |
|
1020 | kwargs['form'] = form | |
1021 | filters.pop('page', None) |
|
1021 | filters.pop('page', None) | |
1022 | kwargs['q'] = urlencode(filters) |
|
1022 | kwargs['q'] = urlencode(filters) | |
1023 |
|
1023 | |||
1024 | return render(request, 'base_list.html', kwargs) |
|
1024 | return render(request, 'base_list.html', kwargs) | |
1025 |
|
1025 | |||
1026 |
|
1026 | |||
1027 | def dev_conf(request, id_conf): |
|
1027 | def dev_conf(request, id_conf): | |
1028 |
|
1028 | |||
1029 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1029 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1030 |
|
1030 | |||
1031 | return redirect(conf.get_absolute_url()) |
|
1031 | return redirect(conf.get_absolute_url()) | |
1032 |
|
1032 | |||
1033 |
|
1033 | |||
1034 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
1034 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
1035 |
|
1035 | |||
1036 | initial = {} |
|
1036 | initial = {} | |
1037 | kwargs = {} |
|
1037 | kwargs = {} | |
1038 |
|
1038 | |||
1039 | if id_exp!=0: |
|
1039 | if id_exp!=0: | |
1040 | initial['experiment'] = id_exp |
|
1040 | initial['experiment'] = id_exp | |
1041 |
|
1041 | |||
1042 | if id_dev!=0: |
|
1042 | if id_dev!=0: | |
1043 | initial['device'] = id_dev |
|
1043 | initial['device'] = id_dev | |
1044 |
|
1044 | |||
1045 | if request.method == 'GET': |
|
1045 | if request.method == 'GET': | |
1046 |
|
1046 | |||
1047 | if id_dev: |
|
1047 | if id_dev: | |
1048 | kwargs['button'] = 'Create' |
|
1048 | kwargs['button'] = 'Create' | |
1049 | device = Device.objects.get(pk=id_dev) |
|
1049 | device = Device.objects.get(pk=id_dev) | |
1050 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
1050 | DevConfForm = CONF_FORMS[device.device_type.name] | |
1051 | initial['name'] = request.GET['name'] |
|
1051 | initial['name'] = request.GET['name'] | |
1052 | form = DevConfForm(initial=initial) |
|
1052 | form = DevConfForm(initial=initial) | |
1053 | else: |
|
1053 | else: | |
1054 | if 'template' in request.GET: |
|
1054 | if 'template' in request.GET: | |
1055 | if request.GET['template']=='0': |
|
1055 | if request.GET['template']=='0': | |
1056 | choices = [(conf.pk, '{}'.format(conf)) for conf in Configuration.objects.filter(template=True)] |
|
1056 | choices = [(conf.pk, '{}'.format(conf)) for conf in Configuration.objects.filter(template=True)] | |
1057 | form = NewForm(initial={'create_from':2}, |
|
1057 | form = NewForm(initial={'create_from':2}, | |
1058 | template_choices=choices) |
|
1058 | template_choices=choices) | |
1059 | else: |
|
1059 | else: | |
1060 | kwargs['button'] = 'Create' |
|
1060 | kwargs['button'] = 'Create' | |
1061 | conf = Configuration.objects.get(pk=request.GET['template']) |
|
1061 | conf = Configuration.objects.get(pk=request.GET['template']) | |
1062 | id_dev = conf.device.pk |
|
1062 | id_dev = conf.device.pk | |
1063 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1063 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1064 | form = DevConfForm(instance=conf, |
|
1064 | form = DevConfForm(instance=conf, | |
1065 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), |
|
1065 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), | |
1066 | 'template': False, |
|
1066 | 'template': False, | |
1067 | 'experiment':id_exp}) |
|
1067 | 'experiment':id_exp}) | |
1068 | elif 'blank' in request.GET: |
|
1068 | elif 'blank' in request.GET: | |
1069 | kwargs['button'] = 'Create' |
|
1069 | kwargs['button'] = 'Create' | |
1070 | form = ConfigurationForm(initial=initial) |
|
1070 | form = ConfigurationForm(initial=initial) | |
1071 | else: |
|
1071 | else: | |
1072 | form = NewForm() |
|
1072 | form = NewForm() | |
1073 |
|
1073 | |||
1074 | if request.method == 'POST': |
|
1074 | if request.method == 'POST': | |
1075 |
|
1075 | |||
1076 | device = Device.objects.get(pk=request.POST['device']) |
|
1076 | device = Device.objects.get(pk=request.POST['device']) | |
1077 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
1077 | DevConfForm = CONF_FORMS[device.device_type.name] | |
1078 |
|
1078 | |||
1079 | form = DevConfForm(request.POST) |
|
1079 | form = DevConfForm(request.POST) | |
1080 | kwargs['button'] = 'Create' |
|
1080 | kwargs['button'] = 'Create' | |
1081 | if form.is_valid(): |
|
1081 | if form.is_valid(): | |
1082 | conf = form.save() |
|
1082 | conf = form.save() | |
1083 |
|
1083 | |||
1084 | if 'template' in request.GET and conf.device.device_type.name=='rc': |
|
1084 | if 'template' in request.GET and conf.device.device_type.name=='rc': | |
1085 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) |
|
1085 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |
1086 | for line in lines: |
|
1086 | for line in lines: | |
1087 | line.clone(rc_configuration=conf) |
|
1087 | line.clone(rc_configuration=conf) | |
1088 |
|
1088 | |||
1089 | if conf.device.device_type.name=='jars': |
|
1089 | if conf.device.device_type.name=='jars': | |
1090 | conf.add_parms_to_filter() |
|
1090 | conf.add_parms_to_filter() | |
1091 |
|
1091 | |||
1092 | return redirect('url_dev_conf', id_conf=conf.pk) |
|
1092 | return redirect('url_dev_conf', id_conf=conf.pk) | |
1093 |
|
1093 | |||
1094 | kwargs['id_exp'] = id_exp |
|
1094 | kwargs['id_exp'] = id_exp | |
1095 | kwargs['form'] = form |
|
1095 | kwargs['form'] = form | |
1096 | kwargs['title'] = 'Configuration' |
|
1096 | kwargs['title'] = 'Configuration' | |
1097 | kwargs['suptitle'] = 'New' |
|
1097 | kwargs['suptitle'] = 'New' | |
1098 |
|
1098 | |||
1099 |
|
1099 | |||
1100 | if id_dev != 0: |
|
1100 | if id_dev != 0: | |
1101 | device = Device.objects.get(pk=id_dev) |
|
1101 | device = Device.objects.get(pk=id_dev) | |
1102 | kwargs['device'] = device.device_type.name |
|
1102 | kwargs['device'] = device.device_type.name | |
1103 |
|
1103 | |||
1104 | return render(request, 'dev_conf_edit.html', kwargs) |
|
1104 | return render(request, 'dev_conf_edit.html', kwargs) | |
1105 |
|
1105 | |||
1106 |
|
1106 | |||
1107 | def dev_conf_edit(request, id_conf): |
|
1107 | def dev_conf_edit(request, id_conf): | |
1108 |
|
1108 | |||
1109 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1109 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1110 |
|
1110 | |||
1111 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1111 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1112 |
|
1112 | |||
1113 | if request.method=='GET': |
|
1113 | if request.method=='GET': | |
1114 | form = DevConfForm(instance=conf) |
|
1114 | form = DevConfForm(instance=conf) | |
1115 |
|
1115 | |||
1116 | if request.method=='POST': |
|
1116 | if request.method=='POST': | |
1117 | form = DevConfForm(request.POST, instance=conf) |
|
1117 | form = DevConfForm(request.POST, instance=conf) | |
1118 |
|
1118 | |||
1119 | if form.is_valid(): |
|
1119 | if form.is_valid(): | |
1120 | form.save() |
|
1120 | form.save() | |
1121 | return redirect('url_dev_conf', id_conf=id_conf) |
|
1121 | return redirect('url_dev_conf', id_conf=id_conf) | |
1122 |
|
1122 | |||
1123 | kwargs = {} |
|
1123 | kwargs = {} | |
1124 | kwargs['form'] = form |
|
1124 | kwargs['form'] = form | |
1125 | kwargs['title'] = 'Device Configuration' |
|
1125 | kwargs['title'] = 'Device Configuration' | |
1126 | kwargs['suptitle'] = 'Edit' |
|
1126 | kwargs['suptitle'] = 'Edit' | |
1127 | kwargs['button'] = 'Update' |
|
1127 | kwargs['button'] = 'Update' | |
1128 |
|
1128 | |||
1129 | ###### SIDEBAR ###### |
|
1129 | ###### SIDEBAR ###### | |
1130 | kwargs.update(sidebar(conf=conf)) |
|
1130 | kwargs.update(sidebar(conf=conf)) | |
1131 |
|
1131 | |||
1132 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1132 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1133 |
|
1133 | |||
1134 |
|
1134 | |||
1135 | def dev_conf_start(request, id_conf): |
|
1135 | def dev_conf_start(request, id_conf): | |
1136 |
|
1136 | |||
1137 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1137 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1138 |
|
1138 | |||
1139 | if conf.start_device(): |
|
1139 | if conf.start_device(): | |
1140 | messages.success(request, conf.message) |
|
1140 | messages.success(request, conf.message) | |
1141 | else: |
|
1141 | else: | |
1142 | messages.error(request, conf.message) |
|
1142 | messages.error(request, conf.message) | |
1143 |
|
1143 | |||
1144 | conf.status_device() |
|
1144 | conf.status_device() | |
1145 |
|
1145 | |||
1146 | return redirect(conf.get_absolute_url()) |
|
1146 | return redirect(conf.get_absolute_url()) | |
1147 |
|
1147 | |||
1148 |
|
1148 | |||
1149 | def dev_conf_stop(request, id_conf): |
|
1149 | def dev_conf_stop(request, id_conf): | |
1150 |
|
1150 | |||
1151 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1151 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1152 |
|
1152 | |||
1153 | if conf.stop_device(): |
|
1153 | if conf.stop_device(): | |
1154 | messages.success(request, conf.message) |
|
1154 | messages.success(request, conf.message) | |
1155 | else: |
|
1155 | else: | |
1156 | messages.error(request, conf.message) |
|
1156 | messages.error(request, conf.message) | |
1157 |
|
1157 | |||
1158 | conf.status_device() |
|
1158 | conf.status_device() | |
1159 |
|
1159 | |||
1160 | return redirect(conf.get_absolute_url()) |
|
1160 | return redirect(conf.get_absolute_url()) | |
1161 |
|
1161 | |||
1162 |
|
1162 | |||
1163 | def dev_conf_status(request, id_conf): |
|
1163 | def dev_conf_status(request, id_conf): | |
1164 |
|
1164 | |||
1165 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1165 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1166 |
|
1166 | |||
1167 | if conf.status_device(): |
|
1167 | if conf.status_device(): | |
1168 | messages.success(request, conf.message) |
|
1168 | messages.success(request, conf.message) | |
1169 | else: |
|
1169 | else: | |
1170 | messages.error(request, conf.message) |
|
1170 | messages.error(request, conf.message) | |
1171 |
|
1171 | |||
1172 | return redirect(conf.get_absolute_url()) |
|
1172 | return redirect(conf.get_absolute_url()) | |
1173 |
|
1173 | |||
1174 |
|
1174 | |||
1175 | def dev_conf_write(request, id_conf): |
|
1175 | def dev_conf_write(request, id_conf): | |
1176 |
|
1176 | |||
1177 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1177 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1178 |
|
1178 | |||
1179 | answer = conf.write_device() |
|
1179 | answer = conf.write_device() | |
1180 | conf.status_device() |
|
1180 | conf.status_device() | |
1181 |
|
1181 | |||
1182 | if answer: |
|
1182 | if answer: | |
1183 | messages.success(request, conf.message) |
|
1183 | messages.success(request, conf.message) | |
1184 |
|
1184 | |||
1185 | #Creating a historical configuration |
|
1185 | #Creating a historical configuration | |
1186 | conf.clone(type=1, template=False) |
|
1186 | conf.clone(type=1, template=False) | |
1187 |
|
1187 | |||
1188 | #Original configuration |
|
1188 | #Original configuration | |
1189 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1189 | conf = DevConfModel.objects.get(pk=id_conf) | |
1190 | else: |
|
1190 | else: | |
1191 | messages.error(request, conf.message) |
|
1191 | messages.error(request, conf.message) | |
1192 |
|
1192 | |||
1193 | return redirect(conf.get_absolute_url()) |
|
1193 | return redirect(conf.get_absolute_url()) | |
1194 |
|
1194 | |||
1195 |
|
1195 | |||
1196 | def dev_conf_read(request, id_conf): |
|
1196 | def dev_conf_read(request, id_conf): | |
1197 |
|
1197 | |||
1198 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1198 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1199 |
|
1199 | |||
1200 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1200 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1201 |
|
1201 | |||
1202 | if request.method=='GET': |
|
1202 | if request.method=='GET': | |
1203 |
|
1203 | |||
1204 | parms = conf.read_device() |
|
1204 | parms = conf.read_device() | |
1205 | conf.status_device() |
|
1205 | conf.status_device() | |
1206 |
|
1206 | |||
1207 | if not parms: |
|
1207 | if not parms: | |
1208 | messages.error(request, conf.message) |
|
1208 | messages.error(request, conf.message) | |
1209 | return redirect(conf.get_absolute_url()) |
|
1209 | return redirect(conf.get_absolute_url()) | |
1210 |
|
1210 | |||
1211 | form = DevConfForm(initial=parms, instance=conf) |
|
1211 | form = DevConfForm(initial=parms, instance=conf) | |
1212 |
|
1212 | |||
1213 | if request.method=='POST': |
|
1213 | if request.method=='POST': | |
1214 | form = DevConfForm(request.POST, instance=conf) |
|
1214 | form = DevConfForm(request.POST, instance=conf) | |
1215 |
|
1215 | |||
1216 | if form.is_valid(): |
|
1216 | if form.is_valid(): | |
1217 | form.save() |
|
1217 | form.save() | |
1218 | return redirect(conf.get_absolute_url()) |
|
1218 | return redirect(conf.get_absolute_url()) | |
1219 |
|
1219 | |||
1220 | messages.error(request, "Parameters could not be saved") |
|
1220 | messages.error(request, "Parameters could not be saved") | |
1221 |
|
1221 | |||
1222 | kwargs = {} |
|
1222 | kwargs = {} | |
1223 | kwargs['id_dev'] = conf.id |
|
1223 | kwargs['id_dev'] = conf.id | |
1224 | kwargs['form'] = form |
|
1224 | kwargs['form'] = form | |
1225 | kwargs['title'] = 'Device Configuration' |
|
1225 | kwargs['title'] = 'Device Configuration' | |
1226 | kwargs['suptitle'] = 'Parameters read from device' |
|
1226 | kwargs['suptitle'] = 'Parameters read from device' | |
1227 | kwargs['button'] = 'Save' |
|
1227 | kwargs['button'] = 'Save' | |
1228 |
|
1228 | |||
1229 | ###### SIDEBAR ###### |
|
1229 | ###### SIDEBAR ###### | |
1230 | kwargs.update(sidebar(conf=conf)) |
|
1230 | kwargs.update(sidebar(conf=conf)) | |
1231 |
|
1231 | |||
1232 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
1232 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
1233 |
|
1233 | |||
1234 |
|
1234 | |||
1235 | def dev_conf_import(request, id_conf): |
|
1235 | def dev_conf_import(request, id_conf): | |
1236 |
|
1236 | |||
1237 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1237 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1238 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1238 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1239 |
|
1239 | |||
1240 | if request.method == 'GET': |
|
1240 | if request.method == 'GET': | |
1241 | file_form = UploadFileForm() |
|
1241 | file_form = UploadFileForm() | |
1242 |
|
1242 | |||
1243 | if request.method == 'POST': |
|
1243 | if request.method == 'POST': | |
1244 | file_form = UploadFileForm(request.POST, request.FILES) |
|
1244 | file_form = UploadFileForm(request.POST, request.FILES) | |
1245 |
|
1245 | |||
1246 | if file_form.is_valid(): |
|
1246 | if file_form.is_valid(): | |
1247 |
|
1247 | |||
1248 | parms = conf.import_from_file(request.FILES['file']) |
|
1248 | parms = conf.import_from_file(request.FILES['file']) | |
1249 |
|
1249 | |||
1250 | if parms: |
|
1250 | if parms: | |
1251 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
1251 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
1252 | form = DevConfForm(initial=parms, instance=conf) |
|
1252 | form = DevConfForm(initial=parms, instance=conf) | |
1253 |
|
1253 | |||
1254 | kwargs = {} |
|
1254 | kwargs = {} | |
1255 | kwargs['id_dev'] = conf.id |
|
1255 | kwargs['id_dev'] = conf.id | |
1256 | kwargs['form'] = form |
|
1256 | kwargs['form'] = form | |
1257 | kwargs['title'] = 'Device Configuration' |
|
1257 | kwargs['title'] = 'Device Configuration' | |
1258 | kwargs['suptitle'] = 'Parameters imported' |
|
1258 | kwargs['suptitle'] = 'Parameters imported' | |
1259 | kwargs['button'] = 'Save' |
|
1259 | kwargs['button'] = 'Save' | |
1260 | kwargs['action'] = conf.get_absolute_url_edit() |
|
1260 | kwargs['action'] = conf.get_absolute_url_edit() | |
1261 | kwargs['previous'] = conf.get_absolute_url() |
|
1261 | kwargs['previous'] = conf.get_absolute_url() | |
1262 |
|
1262 | |||
1263 | ###### SIDEBAR ###### |
|
1263 | ###### SIDEBAR ###### | |
1264 | kwargs.update(sidebar(conf=conf)) |
|
1264 | kwargs.update(sidebar(conf=conf)) | |
1265 |
|
1265 | |||
1266 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1266 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1267 |
|
1267 | |||
1268 | messages.error(request, "Could not import parameters from file") |
|
1268 | messages.error(request, "Could not import parameters from file") | |
1269 |
|
1269 | |||
1270 | kwargs = {} |
|
1270 | kwargs = {} | |
1271 | kwargs['id_dev'] = conf.id |
|
1271 | kwargs['id_dev'] = conf.id | |
1272 | kwargs['title'] = 'Device Configuration' |
|
1272 | kwargs['title'] = 'Device Configuration' | |
1273 | kwargs['form'] = file_form |
|
1273 | kwargs['form'] = file_form | |
1274 | kwargs['suptitle'] = 'Importing file' |
|
1274 | kwargs['suptitle'] = 'Importing file' | |
1275 | kwargs['button'] = 'Import' |
|
1275 | kwargs['button'] = 'Import' | |
1276 |
|
1276 | |||
1277 | kwargs.update(sidebar(conf=conf)) |
|
1277 | kwargs.update(sidebar(conf=conf)) | |
1278 |
|
1278 | |||
1279 | return render(request, 'dev_conf_import.html', kwargs) |
|
1279 | return render(request, 'dev_conf_import.html', kwargs) | |
1280 |
|
1280 | |||
1281 |
|
1281 | |||
1282 | def dev_conf_export(request, id_conf): |
|
1282 | def dev_conf_export(request, id_conf): | |
1283 |
|
1283 | |||
1284 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1284 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1285 |
|
1285 | |||
1286 | if request.method == 'GET': |
|
1286 | if request.method == 'GET': | |
1287 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1287 | file_form = DownloadFileForm(conf.device.device_type.name) | |
1288 |
|
1288 | |||
1289 | if request.method == 'POST': |
|
1289 | if request.method == 'POST': | |
1290 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
1290 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
1291 |
|
1291 | |||
1292 | if file_form.is_valid(): |
|
1292 | if file_form.is_valid(): | |
1293 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
1293 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
1294 |
|
1294 | |||
1295 | response = HttpResponse(content_type=fields['content_type']) |
|
1295 | response = HttpResponse(content_type=fields['content_type']) | |
1296 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
1296 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
1297 | response.write(fields['content']) |
|
1297 | response.write(fields['content']) | |
1298 |
|
1298 | |||
1299 | return response |
|
1299 | return response | |
1300 |
|
1300 | |||
1301 | messages.error(request, "Could not export parameters") |
|
1301 | messages.error(request, "Could not export parameters") | |
1302 |
|
1302 | |||
1303 | kwargs = {} |
|
1303 | kwargs = {} | |
1304 | kwargs['id_dev'] = conf.id |
|
1304 | kwargs['id_dev'] = conf.id | |
1305 | kwargs['title'] = 'Device Configuration' |
|
1305 | kwargs['title'] = 'Device Configuration' | |
1306 | kwargs['form'] = file_form |
|
1306 | kwargs['form'] = file_form | |
1307 | kwargs['suptitle'] = 'Exporting file' |
|
1307 | kwargs['suptitle'] = 'Exporting file' | |
1308 | kwargs['button'] = 'Export' |
|
1308 | kwargs['button'] = 'Export' | |
1309 |
|
1309 | |||
1310 | return render(request, 'dev_conf_export.html', kwargs) |
|
1310 | return render(request, 'dev_conf_export.html', kwargs) | |
1311 |
|
1311 | |||
1312 |
|
1312 | |||
1313 | def dev_conf_delete(request, id_conf): |
|
1313 | def dev_conf_delete(request, id_conf): | |
1314 |
|
1314 | |||
1315 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1315 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1316 |
|
1316 | |||
1317 | if request.method=='POST': |
|
1317 | if request.method=='POST': | |
1318 | if request.user.is_staff: |
|
1318 | if request.user.is_staff: | |
1319 | conf.delete() |
|
1319 | conf.delete() | |
1320 | return redirect('url_dev_confs') |
|
1320 | return redirect('url_dev_confs') | |
1321 |
|
1321 | |||
1322 | messages.error(request, 'Not enough permission to delete this object') |
|
1322 | messages.error(request, 'Not enough permission to delete this object') | |
1323 | return redirect(conf.get_absolute_url()) |
|
1323 | return redirect(conf.get_absolute_url()) | |
1324 |
|
1324 | |||
1325 | kwargs = { |
|
1325 | kwargs = { | |
1326 | 'title': 'Delete', |
|
1326 | 'title': 'Delete', | |
1327 | 'suptitle': 'Experiment', |
|
1327 | 'suptitle': 'Experiment', | |
1328 | 'object': conf, |
|
1328 | 'object': conf, | |
1329 | 'previous': conf.get_absolute_url(), |
|
1329 | 'previous': conf.get_absolute_url(), | |
1330 | 'delete': True |
|
1330 | 'delete': True | |
1331 | } |
|
1331 | } | |
1332 |
|
1332 | |||
1333 | return render(request, 'confirm.html', kwargs) |
|
1333 | return render(request, 'confirm.html', kwargs) | |
1334 |
|
1334 | |||
1335 |
|
1335 | |||
1336 | def sidebar(**kwargs): |
|
1336 | def sidebar(**kwargs): | |
1337 |
|
1337 | |||
1338 | side_data = {} |
|
1338 | side_data = {} | |
1339 |
|
1339 | |||
1340 | conf = kwargs.get('conf', None) |
|
1340 | conf = kwargs.get('conf', None) | |
1341 | experiment = kwargs.get('experiment', None) |
|
1341 | experiment = kwargs.get('experiment', None) | |
1342 |
|
1342 | |||
1343 | if not experiment: |
|
1343 | if not experiment: | |
1344 | experiment = conf.experiment |
|
1344 | experiment = conf.experiment | |
1345 |
|
1345 | |||
1346 | if experiment: |
|
1346 | if experiment: | |
1347 | side_data['experiment'] = experiment |
|
1347 | side_data['experiment'] = experiment | |
1348 | campaign = experiment.campaign_set.all() |
|
1348 | campaign = experiment.campaign_set.all() | |
1349 | if campaign: |
|
1349 | if campaign: | |
1350 | side_data['campaign'] = campaign[0] |
|
1350 | side_data['campaign'] = campaign[0] | |
1351 | experiments = campaign[0].experiments.all() |
|
1351 | experiments = campaign[0].experiments.all() | |
1352 | else: |
|
1352 | else: | |
1353 | experiments = [experiment] |
|
1353 | experiments = [experiment] | |
1354 | configurations = experiment.configuration_set.filter(type=0) |
|
1354 | configurations = experiment.configuration_set.filter(type=0) | |
1355 | side_data['side_experiments'] = experiments |
|
1355 | side_data['side_experiments'] = experiments | |
1356 | side_data['side_configurations'] = configurations |
|
1356 | side_data['side_configurations'] = configurations | |
1357 |
|
1357 | |||
1358 | return side_data |
|
1358 | return side_data | |
1359 |
|
1359 | |||
1360 | def get_paginator(model, page, order, filters={}, n=10): |
|
1360 | def get_paginator(model, page, order, filters={}, n=10): | |
1361 |
|
1361 | |||
1362 | kwargs = {} |
|
1362 | kwargs = {} | |
1363 | query = Q() |
|
1363 | query = Q() | |
1364 | if isinstance(filters, QueryDict): |
|
1364 | if isinstance(filters, QueryDict): | |
1365 | filters = filters.dict() |
|
1365 | filters = filters.dict() | |
1366 | [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] |
|
1366 | [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] | |
1367 | filters.pop('page', None) |
|
1367 | filters.pop('page', None) | |
1368 |
|
1368 | |||
1369 | if 'start_date' in filters: |
|
1369 | if 'start_date' in filters: | |
1370 | filters['start_date__gte'] = filters.pop('start_date') |
|
1370 | filters['start_date__gte'] = filters.pop('start_date') | |
1371 | if 'end_date' in filters: |
|
1371 | if 'end_date' in filters: | |
1372 | filters['start_date__lte'] = filters.pop('end_date') |
|
1372 | filters['start_date__lte'] = filters.pop('end_date') | |
1373 | if 'tags' in filters: |
|
1373 | if 'tags' in filters: | |
1374 | tags = filters.pop('tags') |
|
1374 | tags = filters.pop('tags') | |
1375 | if 'tags' in model._meta.get_all_field_names(): |
|
1375 | if 'tags' in model._meta.get_all_field_names(): | |
1376 | query = query | Q(tags__icontains=tags) |
|
1376 | query = query | Q(tags__icontains=tags) | |
1377 | if 'name' in model._meta.get_all_field_names(): |
|
1377 | if 'name' in model._meta.get_all_field_names(): | |
1378 | query = query | Q(name__icontains=tags) |
|
1378 | query = query | Q(name__icontains=tags) | |
1379 | if 'location' in model._meta.get_all_field_names(): |
|
1379 | if 'location' in model._meta.get_all_field_names(): | |
1380 | query = query | Q(location__name__icontains=tags) |
|
1380 | query = query | Q(location__name__icontains=tags) | |
1381 | if 'device' in model._meta.get_all_field_names(): |
|
1381 | if 'device' in model._meta.get_all_field_names(): | |
1382 | query = query | Q(device__name__icontains=tags) |
|
1382 | query = query | Q(device__name__icontains=tags) | |
1383 |
|
1383 | |||
1384 | object_list = model.objects.filter(query, **filters).order_by(*order) |
|
1384 | object_list = model.objects.filter(query, **filters).order_by(*order) | |
1385 | paginator = Paginator(object_list, n) |
|
1385 | paginator = Paginator(object_list, n) | |
1386 |
|
1386 | |||
1387 | try: |
|
1387 | try: | |
1388 | objects = paginator.page(page) |
|
1388 | objects = paginator.page(page) | |
1389 | except PageNotAnInteger: |
|
1389 | except PageNotAnInteger: | |
1390 | objects = paginator.page(1) |
|
1390 | objects = paginator.page(1) | |
1391 | except EmptyPage: |
|
1391 | except EmptyPage: | |
1392 | objects = paginator.page(paginator.num_pages) |
|
1392 | objects = paginator.page(paginator.num_pages) | |
1393 |
|
1393 | |||
1394 | kwargs['objects'] = objects |
|
1394 | kwargs['objects'] = objects | |
1395 | kwargs['offset'] = (int(page)-1)*n if page else 0 |
|
1395 | kwargs['offset'] = (int(page)-1)*n if page else 0 | |
1396 |
|
1396 | |||
1397 | return kwargs |
|
1397 | return kwargs | |
1398 |
|
1398 | |||
1399 | def operation(request, id_camp=None): |
|
1399 | def operation(request, id_camp=None): | |
1400 |
|
1400 | |||
1401 | kwargs = {} |
|
1401 | kwargs = {} | |
1402 | campaigns = Campaign.objects.filter(start_date__lte=datetime.now(), |
|
1402 | campaigns = Campaign.objects.filter(start_date__lte=datetime.now(), | |
1403 | end_date__gte=datetime.now()).order_by('-start_date') |
|
1403 | end_date__gte=datetime.now()).order_by('-start_date') | |
1404 |
|
1404 | |||
1405 |
|
1405 | |||
1406 | if id_camp: |
|
1406 | if id_camp: | |
1407 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1407 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1408 | form = OperationForm(initial={'campaign': campaign.id}, campaigns=campaigns) |
|
1408 | form = OperationForm(initial={'campaign': campaign.id}, campaigns=campaigns) | |
1409 | kwargs['campaign'] = campaign |
|
1409 | kwargs['campaign'] = campaign | |
1410 | else: |
|
1410 | else: | |
1411 | form = OperationForm(campaigns=campaigns) |
|
1411 | form = OperationForm(campaigns=campaigns) | |
1412 | kwargs['form'] = form |
|
1412 | kwargs['form'] = form | |
1413 | return render(request, 'operation.html', kwargs) |
|
1413 | return render(request, 'operation.html', kwargs) | |
1414 |
|
1414 | |||
1415 |
|
1415 | |||
1416 |
|
1416 | |||
1417 | #---Experiment |
|
1417 | #---Experiment | |
1418 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1418 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1419 | kwargs['experiment_keys'] = keys[1:] |
|
1419 | kwargs['experiment_keys'] = keys[1:] | |
1420 | kwargs['experiments'] = experiments |
|
1420 | kwargs['experiments'] = experiments | |
1421 | #---Radar |
|
1421 | #---Radar | |
1422 | kwargs['locations'] = campaign.get_experiments_by_location() |
|
1422 | kwargs['locations'] = campaign.get_experiments_by_location() | |
1423 | print kwargs['locations'] |
|
|||
1424 | #---Else |
|
1423 | #---Else | |
1425 | kwargs['title'] = 'Campaign' |
|
1424 | kwargs['title'] = 'Campaign' | |
1426 | kwargs['suptitle'] = campaign.name |
|
1425 | kwargs['suptitle'] = campaign.name | |
1427 |
kwargs['form'] = form |
|
1426 | kwargs['form'] = form | |
1428 |
|
1427 | |||
1429 | return render(request, 'operation.html', kwargs) |
|
1428 | return render(request, 'operation.html', kwargs) | |
1430 |
|
1429 | |||
1431 |
|
1430 | |||
1432 | def operation_search(request, id_camp=None): |
|
1431 | def operation_search(request, id_camp=None): | |
1433 |
|
1432 | |||
1434 |
|
1433 | |||
1435 | if not id_camp: |
|
1434 | if not id_camp: | |
1436 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1435 | campaigns = Campaign.objects.all().order_by('-start_date') | |
1437 |
|
1436 | |||
1438 | if not campaigns: |
|
1437 | if not campaigns: | |
1439 | return render(request, 'operation.html', {}) |
|
1438 | return render(request, 'operation.html', {}) | |
1440 |
|
1439 | |||
1441 | id_camp = campaigns[0].id |
|
1440 | id_camp = campaigns[0].id | |
1442 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1441 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1443 |
|
1442 | |||
1444 | if request.method=='GET': |
|
1443 | if request.method=='GET': | |
1445 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1444 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1446 |
|
1445 | |||
1447 | if request.method=='POST': |
|
1446 | if request.method=='POST': | |
1448 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
1447 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
1449 |
|
1448 | |||
1450 | if form.is_valid(): |
|
1449 | if form.is_valid(): | |
1451 | return redirect('url_operation', id_camp=campaign.id) |
|
1450 | return redirect('url_operation', id_camp=campaign.id) | |
1452 |
|
1451 | |||
1453 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1452 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
1454 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1453 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
1455 | #for exs in experiments: |
|
1454 | #for exs in experiments: | |
1456 | # exs.get_status() |
|
1455 | # exs.get_status() | |
1457 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1456 | locations= Location.objects.filter(experiment=experiments).distinct() | |
1458 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1457 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1459 |
|
1458 | |||
1460 | kwargs = {} |
|
1459 | kwargs = {} | |
1461 | #---Campaign |
|
1460 | #---Campaign | |
1462 | kwargs['campaign'] = campaign |
|
1461 | kwargs['campaign'] = campaign | |
1463 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1462 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
1464 | #---Experiment |
|
1463 | #---Experiment | |
1465 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1464 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1466 | kwargs['experiment_keys'] = keys[1:] |
|
1465 | kwargs['experiment_keys'] = keys[1:] | |
1467 | kwargs['experiments'] = experiments |
|
1466 | kwargs['experiments'] = experiments | |
1468 | #---Radar |
|
1467 | #---Radar | |
1469 | kwargs['locations'] = locations |
|
1468 | kwargs['locations'] = locations | |
1470 | #---Else |
|
1469 | #---Else | |
1471 | kwargs['title'] = 'Campaign' |
|
1470 | kwargs['title'] = 'Campaign' | |
1472 | kwargs['suptitle'] = campaign.name |
|
1471 | kwargs['suptitle'] = campaign.name | |
1473 | kwargs['form'] = form |
|
1472 | kwargs['form'] = form | |
1474 | kwargs['button'] = 'Select' |
|
1473 | kwargs['button'] = 'Select' | |
1475 | kwargs['details'] = True |
|
1474 | kwargs['details'] = True | |
1476 | kwargs['search_button'] = False |
|
1475 | kwargs['search_button'] = False | |
1477 |
|
1476 | |||
1478 | return render(request, 'operation.html', kwargs) |
|
1477 | return render(request, 'operation.html', kwargs) | |
1479 |
|
1478 | |||
1480 |
|
1479 | |||
1481 | def radar_play(request, id_camp, id_radar): |
|
1480 | def radar_play(request, id_camp, id_radar): | |
1482 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1481 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1483 | radar = get_object_or_404(Location, pk = id_radar) |
|
1482 | radar = get_object_or_404(Location, pk = id_radar) | |
1484 | today = datetime.today() |
|
1483 | today = datetime.today() | |
1485 | now = today.time() |
|
1484 | now = today.time() | |
1486 |
|
1485 | |||
1487 | #--Clear Old Experiments From RunningExperiment Object |
|
1486 | #--Clear Old Experiments From RunningExperiment Object | |
1488 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1487 | running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1489 | if running_experiment: |
|
1488 | if running_experiment: | |
1490 | running_experiment = running_experiment[0] |
|
1489 | running_experiment = running_experiment[0] | |
1491 | running_experiment.running_experiment.clear() |
|
1490 | running_experiment.running_experiment.clear() | |
1492 | running_experiment.save() |
|
1491 | running_experiment.save() | |
1493 |
|
1492 | |||
1494 | #--If campaign datetime is ok: |
|
1493 | #--If campaign datetime is ok: | |
1495 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1494 | if today >= campaign.start_date and today <= campaign.end_date: | |
1496 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1495 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1497 | for exp in experiments: |
|
1496 | for exp in experiments: | |
1498 | #--If experiment time is ok: |
|
1497 | #--If experiment time is ok: | |
1499 | if now >= exp.start_time and now <= exp.end_time: |
|
1498 | if now >= exp.start_time and now <= exp.end_time: | |
1500 | configurations = Configuration.objects.filter(experiment = exp) |
|
1499 | configurations = Configuration.objects.filter(experiment = exp) | |
1501 | for conf in configurations: |
|
1500 | for conf in configurations: | |
1502 | if 'cgs' in conf.device.device_type.name: |
|
1501 | if 'cgs' in conf.device.device_type.name: | |
1503 | conf.status_device() |
|
1502 | conf.status_device() | |
1504 | else: |
|
1503 | else: | |
1505 | answer = conf.start_device() |
|
1504 | answer = conf.start_device() | |
1506 | conf.status_device() |
|
1505 | conf.status_device() | |
1507 | #--Running Experiment |
|
1506 | #--Running Experiment | |
1508 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1507 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1509 | #--If RunningExperiment element exists |
|
1508 | #--If RunningExperiment element exists | |
1510 | if old_running_experiment: |
|
1509 | if old_running_experiment: | |
1511 | old_running_experiment = old_running_experiment[0] |
|
1510 | old_running_experiment = old_running_experiment[0] | |
1512 | old_running_experiment.running_experiment.add(exp) |
|
1511 | old_running_experiment.running_experiment.add(exp) | |
1513 | old_running_experiment.status = 3 |
|
1512 | old_running_experiment.status = 3 | |
1514 | old_running_experiment.save() |
|
1513 | old_running_experiment.save() | |
1515 | #--Create a new Running_Experiment Object |
|
1514 | #--Create a new Running_Experiment Object | |
1516 | else: |
|
1515 | else: | |
1517 | new_running_experiment = RunningExperiment( |
|
1516 | new_running_experiment = RunningExperiment( | |
1518 | radar = radar, |
|
1517 | radar = radar, | |
1519 | status = 3, |
|
1518 | status = 3, | |
1520 | ) |
|
1519 | ) | |
1521 | new_running_experiment.save() |
|
1520 | new_running_experiment.save() | |
1522 | new_running_experiment.running_experiment.add(exp) |
|
1521 | new_running_experiment.running_experiment.add(exp) | |
1523 | new_running_experiment.save() |
|
1522 | new_running_experiment.save() | |
1524 |
|
1523 | |||
1525 | if answer: |
|
1524 | if answer: | |
1526 | messages.success(request, conf.message) |
|
1525 | messages.success(request, conf.message) | |
1527 | exp.status=2 |
|
1526 | exp.status=2 | |
1528 | exp.save() |
|
1527 | exp.save() | |
1529 | else: |
|
1528 | else: | |
1530 | messages.error(request, conf.message) |
|
1529 | messages.error(request, conf.message) | |
1531 | else: |
|
1530 | else: | |
1532 | if exp.status == 1 or exp.status == 3: |
|
1531 | if exp.status == 1 or exp.status == 3: | |
1533 | exp.status=3 |
|
1532 | exp.status=3 | |
1534 | exp.save() |
|
1533 | exp.save() | |
1535 |
|
1534 | |||
1536 |
|
1535 | |||
1537 | route = request.META['HTTP_REFERER'] |
|
1536 | route = request.META['HTTP_REFERER'] | |
1538 | route = str(route) |
|
1537 | route = str(route) | |
1539 | if 'search' in route: |
|
1538 | if 'search' in route: | |
1540 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1539 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1541 | else: |
|
1540 | else: | |
1542 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1541 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1543 |
|
1542 | |||
1544 |
|
1543 | |||
1545 | def radar_stop(request, id_camp, id_radar): |
|
1544 | def radar_stop(request, id_camp, id_radar): | |
1546 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1545 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1547 | radar = get_object_or_404(Location, pk = id_radar) |
|
1546 | radar = get_object_or_404(Location, pk = id_radar) | |
1548 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1547 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1549 |
|
1548 | |||
1550 | for exp in experiments: |
|
1549 | for exp in experiments: | |
1551 | configurations = Configuration.objects.filter(experiment = exp) |
|
1550 | configurations = Configuration.objects.filter(experiment = exp) | |
1552 | for conf in configurations: |
|
1551 | for conf in configurations: | |
1553 | if 'cgs' in conf.device.device_type.name: |
|
1552 | if 'cgs' in conf.device.device_type.name: | |
1554 | conf.status_device() |
|
1553 | conf.status_device() | |
1555 | else: |
|
1554 | else: | |
1556 | answer = conf.stop_device() |
|
1555 | answer = conf.stop_device() | |
1557 | conf.status_device() |
|
1556 | conf.status_device() | |
1558 |
|
1557 | |||
1559 | if answer: |
|
1558 | if answer: | |
1560 | messages.success(request, conf.message) |
|
1559 | messages.success(request, conf.message) | |
1561 | exp.status=1 |
|
1560 | exp.status=1 | |
1562 | exp.save() |
|
1561 | exp.save() | |
1563 | else: |
|
1562 | else: | |
1564 | messages.error(request, conf.message) |
|
1563 | messages.error(request, conf.message) | |
1565 |
|
1564 | |||
1566 |
|
1565 | |||
1567 | route = request.META['HTTP_REFERER'] |
|
1566 | route = request.META['HTTP_REFERER'] | |
1568 | route = str(route) |
|
1567 | route = str(route) | |
1569 | if 'search' in route: |
|
1568 | if 'search' in route: | |
1570 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1569 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1571 | else: |
|
1570 | else: | |
1572 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1571 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1573 |
|
1572 | |||
1574 |
|
1573 | |||
1575 | def radar_refresh(request, id_camp, id_radar): |
|
1574 | def radar_refresh(request, id_camp, id_radar): | |
1576 |
|
1575 | |||
1577 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1576 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1578 | radar = get_object_or_404(Location, pk = id_radar) |
|
1577 | radar = get_object_or_404(Location, pk = id_radar) | |
1579 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1578 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1580 | for exs in experiments: |
|
1579 | for exs in experiments: | |
1581 | exs.get_status() |
|
1580 | exs.get_status() | |
1582 |
|
1581 | |||
1583 | route = request.META['HTTP_REFERER'] |
|
1582 | route = request.META['HTTP_REFERER'] | |
1584 | route = str(route) |
|
1583 | route = str(route) | |
1585 | if 'search' in route: |
|
1584 | if 'search' in route: | |
1586 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1585 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1587 | else: |
|
1586 | else: | |
1588 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1587 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1589 |
|
General Comments 0
You need to be logged in to leave comments.
Login now