@@ -1,525 +1,531 | |||
|
1 | 1 | from django.shortcuts import render_to_response, redirect |
|
2 | 2 | from django.http import HttpResponse |
|
3 | 3 | from django.conf import settings |
|
4 | 4 | from django.utils.encoding import smart_str |
|
5 | 5 | from django.core.servers.basehttp import FileWrapper |
|
6 | 6 | import mimetypes |
|
7 | 7 | from django.contrib.auth.decorators import login_required |
|
8 | 8 | from django.template import RequestContext |
|
9 | 9 | |
|
10 | 10 | from datetime import datetime |
|
11 | 11 | import os |
|
12 | 12 | from abscontrol.models import Profile, Pattern, AntennaDown, AntennaUp |
|
13 | 13 | |
|
14 | 14 | from util.readABSFile import readABSFile |
|
15 | 15 | from util.saveABSFile import saveABSFile |
|
16 | 16 | from util.ABSData import ABSData |
|
17 | 17 | from util.OverJRO import OverJRO |
|
18 | 18 | from scripts.sendFile import sendFile |
|
19 | 19 | from scripts.changeBeam import changeBeam |
|
20 | 20 | from overJroShow import overJroShow |
|
21 | 21 | |
|
22 | 22 | arrayTx = [["0","0","0","0","0","0","0","0"],\ |
|
23 | 23 | ["0","0","0","0","0","0","0","0"],\ |
|
24 | 24 | ["0","0","0","0","0","0","0","0"],\ |
|
25 | 25 | ["0","0","0","0","0","0","0","0"],\ |
|
26 | 26 | ["0","0","0","0","0","0","0","0"],\ |
|
27 | 27 | ["0","0","0","0","0","0","0","0"],\ |
|
28 | 28 | ["0","0","0","0","0","0","0","0"],\ |
|
29 | 29 | ["0","0","0","0","0","0","0","0"]] |
|
30 | 30 | |
|
31 | 31 | arrayUes = ["0.533333","0.00000","1.06667","0.00000"] |
|
32 | 32 | |
|
33 | 33 | @login_required(login_url='/accounts/login/') |
|
34 | 34 | def index(request): |
|
35 | 35 | #latest_poll_list = profileAntenna.objects.all().order_by('-pub_date')[:5] |
|
36 | 36 | profile_list = Profile.objects.filter(state=1) |
|
37 | 37 | return render_to_response('abscontrol/index.html', {'profile_list': profile_list}, context_instance=RequestContext(request)) |
|
38 | 38 | |
|
39 | 39 | def new(request): |
|
40 | 40 | profile_list = Profile.objects.filter(state=1) |
|
41 | 41 | txtProfile = datetime.now().strftime("%Y%m%d%H%M%S%f") |
|
42 | 42 | newprofile = Profile(name=txtProfile) |
|
43 | 43 | newprofile.save() |
|
44 | 44 | |
|
45 | 45 | lsPatterns = None |
|
46 | 46 | |
|
47 | 47 | return render_to_response('abscontrol/new.html', {'profile_list': profile_list, |
|
48 | 48 | 'profile_name' : newprofile.name, |
|
49 | 49 | 'profile_id' : newprofile.id, |
|
50 | 50 | 'lsPatterns' : lsPatterns, |
|
51 | 51 | 'range' : range(8), 'arrayUes' : arrayUes, |
|
52 | 52 | }, context_instance=RequestContext(request)) |
|
53 | 53 | |
|
54 | 54 | def save(request): |
|
55 | 55 | |
|
56 | 56 | txtProfile = request.POST["txtProfile"] |
|
57 | 57 | |
|
58 | 58 | txtAntennaUp = request.POST["txtAntennaUp"] |
|
59 | 59 | txtTxUp = request.POST["txtTxUp"] |
|
60 | 60 | txtRxUp = request.POST["txtRxUp"] |
|
61 | 61 | txtUesUp = request.POST["txtUesUp"] |
|
62 | 62 | |
|
63 | 63 | txtAntennaDown = request.POST["txtAntennaDown"] |
|
64 | 64 | txtTxDown = request.POST["txtTxDown"] |
|
65 | 65 | txtRxDown = request.POST["txtRxDown"] |
|
66 | 66 | txtUesDown = request.POST["txtUesDown"] |
|
67 | 67 | |
|
68 | 68 | newprofile = Profile(name=txtProfile) |
|
69 | 69 | newprofile.save() |
|
70 | 70 | |
|
71 | 71 | newpattern = newprofile.pattern_set.create(value=1) |
|
72 | 72 | newpattern.antennaup_set.create(value=txtAntennaUp,tx=txtTxUp,rx=txtRxUp,ues=txtUesUp) |
|
73 | 73 | newpattern.antennadown_set.create(value=txtAntennaDown,tx=txtTxDown,rx=txtRxDown,ues=txtUesDown) |
|
74 | 74 | |
|
75 | 75 | newurl = '/abscontrol/view/%d' % newprofile.id |
|
76 | 76 | |
|
77 | 77 | return redirect(newurl) |
|
78 | 78 | |
|
79 | 79 | # Update temporal experiment |
|
80 | 80 | def upgrade(request, profile_id): |
|
81 | 81 | txtAntennaUp = request.POST["txtAntennaUp"] |
|
82 | 82 | txtTxUp = request.POST["txtTxUp"] |
|
83 | 83 | txtRxUp = request.POST["txtRxUp"] |
|
84 | 84 | txtUesUp = request.POST["txtUesUp"] |
|
85 | 85 | |
|
86 | 86 | txtAntennaDown = request.POST["txtAntennaDown"] |
|
87 | 87 | txtTxDown = request.POST["txtTxDown"] |
|
88 | 88 | txtRxDown = request.POST["txtRxDown"] |
|
89 | 89 | txtUesDown = request.POST["txtUesDown"] |
|
90 | 90 | |
|
91 | 91 | objProfile = Profile.objects.get(pk=profile_id) |
|
92 | 92 | newpattern = objProfile.pattern_set.create(value=1) |
|
93 | 93 | newpattern.antennaup_set.create(value=txtAntennaUp,tx=txtTxUp,rx=txtRxUp,ues=txtUesUp) |
|
94 | 94 | newpattern.antennadown_set.create(value=txtAntennaDown,tx=txtTxDown,rx=txtRxDown,ues=txtUesDown) |
|
95 | 95 | |
|
96 | 96 | newurl = '/abscontrol/%d/edit/%d' % (int(profile_id), newpattern.id) |
|
97 | 97 | return redirect(newurl) |
|
98 | 98 | |
|
99 | 99 | def update(request, profile_id): |
|
100 | 100 | txtProfile = request.POST["txtProfile"] |
|
101 | 101 | |
|
102 | 102 | objProfile = Profile.objects.get(pk=profile_id) |
|
103 | 103 | objProfile.name = txtProfile |
|
104 | 104 | objProfile.state = 1 |
|
105 | 105 | objProfile.save() |
|
106 | 106 | |
|
107 | 107 | newurl = '/abscontrol/view/%d' % objProfile.id |
|
108 | 108 | return redirect(newurl) |
|
109 | 109 | |
|
110 | 110 | def changeName(request, profile_id): |
|
111 | 111 | profile_list = Profile.objects.filter(state=1) |
|
112 | 112 | objProfile = Profile.objects.get(pk=profile_id) |
|
113 | 113 | lsPatterns = objProfile.pattern_set.all() |
|
114 | 114 | |
|
115 | 115 | return render_to_response('abscontrol/changeName.html', {'profile_list': profile_list, |
|
116 | 116 | 'objProfile': objProfile, |
|
117 | 117 | 'lsPatterns' : lsPatterns, |
|
118 | 118 | }, context_instance=RequestContext(request)) |
|
119 | 119 | |
|
120 | 120 | def view(request, profile_id): |
|
121 | 121 | if request.method == 'GET' and 'pattern' in request.GET: |
|
122 | 122 | pattern_value = request.GET["pattern"] |
|
123 | 123 | else: |
|
124 | 124 | pattern_value = 1 |
|
125 | 125 | |
|
126 | 126 | profile_list = Profile.objects.filter(state=1) |
|
127 | 127 | objProfile = Profile.objects.get(pk=profile_id) |
|
128 | 128 | |
|
129 | 129 | lsPatterns = objProfile.pattern_set.all() |
|
130 | 130 | patternChoosen = objProfile.pattern_set.get(value=pattern_value) |
|
131 | 131 | objAntennaUp = patternChoosen.antennaup_set.get() |
|
132 | 132 | objAntennaDown = patternChoosen.antennadown_set.get() |
|
133 | 133 | |
|
134 | 134 | return render_to_response('abscontrol/view.html', {'objProfile': objProfile, 'profile_list': profile_list, |
|
135 | 135 | 'patternChoosen' : patternChoosen, 'lsPatterns' : lsPatterns, |
|
136 | 136 | 'antennaUp' : objAntennaUp, 'antennaDown' : objAntennaDown, |
|
137 | 137 | }, context_instance=RequestContext(request)) |
|
138 | 138 | |
|
139 | 139 | def edit(request, profile_id): |
|
140 | 140 | if request.method == 'GET' and 'pattern' in request.GET: |
|
141 | 141 | pattern_value = request.GET["pattern"] |
|
142 | 142 | else: |
|
143 | 143 | pattern_value = 1 |
|
144 | 144 | |
|
145 | 145 | absData = ABSData() |
|
146 | 146 | profile_list = Profile.objects.filter(state=1) |
|
147 | 147 | objProfile = Profile.objects.get(pk=profile_id) |
|
148 | 148 | |
|
149 | 149 | lsPatterns = objProfile.pattern_set.all() |
|
150 | 150 | patternChoosen = objProfile.pattern_set.get(value=pattern_value) |
|
151 | 151 | objAntennaUp = patternChoosen.antennaup_set.get() |
|
152 | 152 | objAntennaDown = patternChoosen.antennadown_set.get() |
|
153 | 153 | |
|
154 | 154 | arrayAntennaUp = absData.convertStringtoList2(objAntennaUp.value) |
|
155 | 155 | if objAntennaUp.tx != None: |
|
156 | 156 | arrayTxUp = absData.convertStringtoList2(objAntennaUp.tx) |
|
157 | 157 | else: |
|
158 | 158 | arrayTxUp = arrayTx |
|
159 | 159 | if objAntennaUp.rx != None: |
|
160 | 160 | arrayRxUp = absData.convertStringtoList2(objAntennaUp.rx) |
|
161 | 161 | else: |
|
162 | 162 | arrayRxUp = arrayTx |
|
163 | 163 | if objAntennaUp.ues != None: |
|
164 | 164 | arrayUesUp = absData.convertStringtoList1(objAntennaUp.ues) |
|
165 | 165 | else: |
|
166 | 166 | arrayUesUp = arrayUes |
|
167 | 167 | |
|
168 | 168 | arrayAntennaDown = absData.convertStringtoList2(objAntennaDown.value) |
|
169 | 169 | if objAntennaDown.tx != None: |
|
170 | 170 | arrayTxDown = absData.convertStringtoList2(objAntennaDown.tx) |
|
171 | 171 | else: |
|
172 | 172 | arrayTxDown = arrayTx |
|
173 | 173 | if objAntennaDown.rx != None: |
|
174 | 174 | arrayRxDown = absData.convertStringtoList2(objAntennaDown.rx) |
|
175 | 175 | else: |
|
176 | 176 | arrayRxDown = arrayTx |
|
177 | 177 | if objAntennaDown.ues != None: |
|
178 | 178 | arrayUesDown = absData.convertStringtoList1(objAntennaDown.ues) |
|
179 | 179 | else: |
|
180 | 180 | arrayUesDown = arrayUes |
|
181 | 181 | |
|
182 | 182 | return render_to_response('abscontrol/edit.html', {'objProfile': objProfile, 'profile_list': profile_list, |
|
183 | 183 | 'patternChoosen' : patternChoosen, 'lsPatterns' : lsPatterns, |
|
184 | 184 | 'antennaUp' : objAntennaUp, 'antennaDown' : objAntennaDown, |
|
185 | 185 | 'arrayAntennaUp' : arrayAntennaUp, 'arrayTxUp' : arrayTxUp, |
|
186 | 186 | 'arrayRxUp' : arrayRxUp, 'arrayRxDown' : arrayRxDown, |
|
187 | 187 | 'arrayAntennaDown' : arrayAntennaDown, 'arrayTxDown' : arrayTxDown, |
|
188 | 188 | 'arrayUesUp' : arrayUesUp, 'arrayUesDown' : arrayUesDown, |
|
189 | 189 | }, context_instance=RequestContext(request)) |
|
190 | 190 | |
|
191 | 191 | def addPattern(request, profile_id): |
|
192 | 192 | profile_list = Profile.objects.filter(state=1) |
|
193 | 193 | objProfile = Profile.objects.get(pk=profile_id) |
|
194 | 194 | |
|
195 | 195 | return render_to_response('abscontrol/addPattern.html', {'objProfile': objProfile, 'profile_list': profile_list, |
|
196 | 196 | 'range' : range(8), 'arrayUes' : arrayUes, |
|
197 | 197 | }, context_instance=RequestContext(request)) |
|
198 | 198 | |
|
199 | 199 | def editPattern(request, profile_id, pattern_id): |
|
200 | 200 | absData = ABSData() |
|
201 | 201 | profile_list = Profile.objects.filter(state=1) |
|
202 | 202 | objProfile = Profile.objects.get(pk=profile_id) |
|
203 | 203 | lsPatterns = objProfile.pattern_set.all() |
|
204 | 204 | patternChoosen = Pattern.objects.get(pk=pattern_id) |
|
205 | 205 | objAntennaUp = patternChoosen.antennaup_set.get() |
|
206 | 206 | objAntennaDown = patternChoosen.antennadown_set.get() |
|
207 | 207 | |
|
208 | 208 | arrayAntennaUp = absData.convertStringtoList2(objAntennaUp.value) |
|
209 | 209 | if objAntennaUp.tx != None: |
|
210 | 210 | arrayTxUp = absData.convertStringtoList2(objAntennaUp.tx) |
|
211 | 211 | else: |
|
212 | 212 | arrayTxUp = arrayTx |
|
213 | 213 | if objAntennaUp.rx != None: |
|
214 | 214 | arrayRxUp = absData.convertStringtoList2(objAntennaUp.rx) |
|
215 | 215 | else: |
|
216 | 216 | arrayRxUp = arrayTx |
|
217 | 217 | if objAntennaUp.ues != None: |
|
218 | 218 | arrayUesUp = absData.convertStringtoList1(objAntennaUp.ues) |
|
219 | 219 | else: |
|
220 | 220 | arrayUesUp = arrayUes |
|
221 | 221 | |
|
222 | 222 | arrayAntennaDown = absData.convertStringtoList2(objAntennaDown.value) |
|
223 | 223 | if objAntennaDown.tx != None: |
|
224 | 224 | arrayTxDown = absData.convertStringtoList2(objAntennaDown.tx) |
|
225 | 225 | else: |
|
226 | 226 | arrayTxDown = arrayTx |
|
227 | 227 | if objAntennaDown.rx != None: |
|
228 | 228 | arrayRxDown = absData.convertStringtoList2(objAntennaDown.rx) |
|
229 | 229 | else: |
|
230 | 230 | arrayRxDown = arrayTx |
|
231 | 231 | if objAntennaDown.ues != None: |
|
232 | 232 | arrayUesDown = absData.convertStringtoList1(objAntennaDown.ues) |
|
233 | 233 | else: |
|
234 | 234 | arrayUesDown = arrayUes |
|
235 | 235 | |
|
236 | 236 | return render_to_response('abscontrol/editPattern.html', {'objProfile': objProfile, 'profile_list': profile_list, |
|
237 | 237 | 'patternChoosen' : patternChoosen, 'lsPatterns' : lsPatterns, |
|
238 | 238 | 'antennaUp' : objAntennaUp, 'antennaDown' : objAntennaDown, |
|
239 | 239 | 'arrayAntennaUp' : arrayAntennaUp, 'arrayTxUp' : arrayTxUp, |
|
240 | 240 | 'arrayRxUp' : arrayRxUp, 'arrayRxDown' : arrayRxDown, |
|
241 | 241 | 'arrayAntennaDown' : arrayAntennaDown, 'arrayTxDown' : arrayTxDown, |
|
242 | 242 | 'arrayUesUp' : arrayUesUp, 'arrayUesDown' : arrayUesDown, |
|
243 | 243 | }, context_instance=RequestContext(request)) |
|
244 | 244 | |
|
245 | 245 | def savePattern(request, profile_id): |
|
246 | 246 | pattern_id = 0 |
|
247 | 247 | method = "save" |
|
248 | 248 | |
|
249 | 249 | if 'pattern_id' in request.POST: |
|
250 | 250 | pattern_id = request.POST["pattern_id"] |
|
251 | 251 | method = "update" |
|
252 | 252 | |
|
253 | 253 | maxValuePattern = 0 |
|
254 | 254 | txtAntennaUp = request.POST["txtAntennaUp"] |
|
255 | 255 | txtTxUp = request.POST["txtTxUp"] |
|
256 | 256 | txtRxUp = request.POST["txtRxUp"] |
|
257 | 257 | txtUesUp = request.POST["txtUesUp"] |
|
258 | 258 | |
|
259 | 259 | txtAntennaDown = request.POST["txtAntennaDown"] |
|
260 | 260 | txtTxDown = request.POST["txtTxDown"] |
|
261 | 261 | txtRxDown = request.POST["txtRxDown"] |
|
262 | 262 | txtUesDown = request.POST["txtUesDown"] |
|
263 | 263 | |
|
264 | 264 | mode = request.POST["mode"] |
|
265 | 265 | |
|
266 | 266 | if method == "save": |
|
267 | 267 | objProfile = Profile.objects.get(pk=profile_id) |
|
268 | 268 | lsPatterns = objProfile.pattern_set.all() |
|
269 | 269 | if len(lsPatterns) > 0: |
|
270 | 270 | for element in lsPatterns: |
|
271 | 271 | if element.value > maxValuePattern: |
|
272 | 272 | maxPattern = element.value |
|
273 | 273 | else: |
|
274 | 274 | maxPattern = 0 |
|
275 | 275 | |
|
276 | 276 | if maxPattern < 10 : |
|
277 | 277 | newValuePattern = maxPattern + 1 |
|
278 | 278 | newpattern = objProfile.pattern_set.create(value=newValuePattern) |
|
279 | 279 | newpattern.antennaup_set.create(value=txtAntennaUp,tx=txtTxUp,rx=txtRxUp,ues=txtUesUp) |
|
280 | 280 | newpattern.antennadown_set.create(value=txtAntennaDown,tx=txtTxDown,rx=txtRxDown,ues=txtUesDown) |
|
281 | 281 | error = 0 |
|
282 | 282 | else: |
|
283 | 283 | error = 1 # Can not add more patterns |
|
284 | 284 | |
|
285 | 285 | if mode == "e": |
|
286 | 286 | newurl = '/abscontrol/%d/edit/%d' % (int(profile_id), newpattern.id) |
|
287 | 287 | else: |
|
288 | 288 | newurl = '/abscontrol/%d/view/%d' % (int(profile_id), newpattern.id) |
|
289 | 289 | else: |
|
290 | 290 | txtAntennaUpId = request.POST["txtAntennaUpId"] |
|
291 | 291 | objAntennaUp = AntennaUp.objects.get(pk=txtAntennaUpId) |
|
292 | 292 | objAntennaUp.value = txtAntennaUp |
|
293 | 293 | objAntennaUp.tx = txtTxUp |
|
294 | 294 | objAntennaUp.rx = txtRxUp |
|
295 | 295 | objAntennaUp.ues = txtUesUp |
|
296 | 296 | objAntennaUp.save() |
|
297 | 297 | |
|
298 | 298 | txtAntennaDownId = request.POST["txtAntennaDownId"] |
|
299 | 299 | objAntennaDown = AntennaDown.objects.get(pk=txtAntennaDownId) |
|
300 | 300 | objAntennaDown.value = txtAntennaDown |
|
301 | 301 | objAntennaDown.tx = txtTxDown |
|
302 | 302 | objAntennaDown.rx = txtRxDown |
|
303 | 303 | objAntennaDown.ues = txtUesDown |
|
304 | 304 | objAntennaDown.save() |
|
305 | 305 | |
|
306 | 306 | if mode == "e": |
|
307 | 307 | newurl = '/abscontrol/%d/edit/%d' % (int(profile_id), int(pattern_id)) |
|
308 | 308 | else: |
|
309 | 309 | newurl = '/abscontrol/%d/view/%d' % (int(profile_id), int(pattern_id)) |
|
310 | 310 | |
|
311 | 311 | return redirect(newurl) |
|
312 | 312 | |
|
313 | 313 | def viewPattern(request, profile_id, pattern_id): |
|
314 | 314 | |
|
315 | 315 | profile_list = Profile.objects.filter(state=1) |
|
316 | 316 | objProfile = Profile.objects.get(pk=profile_id) |
|
317 | 317 | |
|
318 | 318 | patternChoosen = Pattern.objects.get(pk=pattern_id) |
|
319 | 319 | |
|
320 | 320 | objAntennaUp = patternChoosen.antennaup_set.get() |
|
321 | 321 | objAntennaDown = patternChoosen.antennadown_set.get() |
|
322 | 322 | |
|
323 | 323 | lsPatterns = objProfile.pattern_set.all() |
|
324 | 324 | |
|
325 | 325 | return render_to_response('abscontrol/viewPattern.html', {'objProfile': objProfile, 'profile_list': profile_list, |
|
326 | 326 | 'patternChoosen' : patternChoosen, 'lsPatterns' : lsPatterns, |
|
327 | 327 | 'antennaUp' : objAntennaUp, 'antennaDown' : objAntennaDown, |
|
328 | 328 | }, context_instance=RequestContext(request)) |
|
329 | 329 | |
|
330 | 330 | def deletePattern(request, profile_id, pattern_id): |
|
331 | 331 | newurl = '/abscontrol/edit/%d' % int(profile_id) |
|
332 | 332 | |
|
333 | 333 | return redirect(newurl) |
|
334 | 334 | |
|
335 | 335 | def importProfile(request): |
|
336 | 336 | profile_list = Profile.objects.filter(state=1) |
|
337 | 337 | return render_to_response('abscontrol/import.html', {'profile_list': profile_list,}, context_instance=RequestContext(request)) |
|
338 | 338 | |
|
339 | 339 | def upload(request): |
|
340 | 340 | profile_list = Profile.objects.filter(state=1) |
|
341 | 341 | if request.method == 'POST': |
|
342 | 342 | txtFilename = request.FILES['txtFile'] |
|
343 | 343 | if txtFilename: |
|
344 | 344 | destination = open('/tmp/'+txtFilename.name, 'wb+') |
|
345 | 345 | for chunk in txtFilename.chunks(): |
|
346 | 346 | destination.write(chunk) |
|
347 | 347 | destination.close() |
|
348 | 348 | filename = '/tmp/'+txtFilename.name |
|
349 | 349 | readFile = readABSFile(filename) |
|
350 | 350 | expName, num_patterns, patterns = readFile.getMetadata() |
|
351 | 351 | |
|
352 | 352 | if expName != "" and num_patterns > 0: |
|
353 | 353 | if len(Profile.objects.filter(name__iexact=expName)) > 0: |
|
354 | 354 | txtError = "Experiment's name found." |
|
355 | 355 | return render_to_response('abscontrol/error.html', {'profile_list': profile_list, |
|
356 | 356 | 'txtError' : txtError, }, |
|
357 | 357 | context_instance=RequestContext(request)) |
|
358 | 358 | else: |
|
359 | 359 | newprofile = Profile(name=expName) |
|
360 | 360 | newprofile.save() |
|
361 | 361 | newprofile.state = 1 |
|
362 | 362 | |
|
363 | 363 | for element in patterns: |
|
364 | 364 | newpattern = newprofile.pattern_set.create(value=element["number"]) |
|
365 | 365 | newpattern.antennaup_set.create(value=element["up"]) |
|
366 | 366 | newpattern.antennadown_set.create(value=element["down"]) |
|
367 | 367 | |
|
368 | 368 | newprofile.save() |
|
369 | 369 | |
|
370 | 370 | newurl = '/abscontrol/edit/%d' % int(newprofile.id) |
|
371 | 371 | return redirect(newurl) |
|
372 | 372 | else: |
|
373 | 373 | txtError = "Experiment's name not found or the number of patterns is 0." |
|
374 | 374 | return render_to_response('abscontrol/error.html', {'profile_list': profile_list, |
|
375 | 375 | 'txtError' : txtError, }, |
|
376 | 376 | context_instance=RequestContext(request)) |
|
377 | 377 | else: |
|
378 | 378 | txtError = "No file." |
|
379 | 379 | |
|
380 | 380 | return render_to_response('abscontrol/error.html', {'profile_list': profile_list, 'txtError' : txtError, }, |
|
381 | 381 | context_instance=RequestContext(request)) |
|
382 | 382 | |
|
383 | 383 | def getImgfromOverJRO(profile_id, objAntenna): |
|
384 | 384 | objProfile = Profile.objects.get(pk=profile_id) |
|
385 | 385 | exp_name = objProfile.name |
|
386 | 386 | phase_tx = objAntenna.value |
|
387 | 387 | gain_tx = objAntenna.tx |
|
388 | 388 | gain_rx = objAntenna.rx |
|
389 | 389 | ues_tx = objAntenna.ues |
|
390 | 390 | just_rx = objAntenna.only_rx |
|
391 | 391 | |
|
392 | 392 | overjro = OverJRO() |
|
393 | 393 | overjro.setParameters(settings.MEDIA_ROOT, exp_name, phase_tx, gain_tx, gain_rx, ues_tx, just_rx) |
|
394 | 394 | contentFile = overjro.setTextContent() |
|
395 | 395 | finalpath = overjro.saveFile(contentFile) |
|
396 | 396 | |
|
397 | 397 | currentdate = datetime.today() |
|
398 | 398 | newOverJro = overJroShow() |
|
399 | 399 | newOverJro.setInputParameters(settings.MEDIA_ROOT, currentdate, finalpath) |
|
400 | 400 | newOverJro.setupParameters() |
|
401 | 401 | newOverJro.execute() |
|
402 | 402 | path = newOverJro.getPlot() |
|
403 | 403 | |
|
404 | 404 | return path |
|
405 | 405 | |
|
406 | 406 | def overJROUp(request, profile_id, pattern_id, antenna_id): |
|
407 | 407 | objAntenna = AntennaUp.objects.get(pk=antenna_id) |
|
408 | 408 | img_path = getImgfromOverJRO(profile_id, objAntenna) |
|
409 | 409 | filename = os.path.split(img_path)[1] |
|
410 | 410 | return render_to_response('abscontrol/overjro_up.html', {'img_up': filename,'antennaUp': objAntenna,}, |
|
411 | 411 | context_instance=RequestContext(request)) |
|
412 | 412 | |
|
413 | 413 | def overJRODown(request, profile_id, pattern_id, antenna_id): |
|
414 | 414 | objAntenna = AntennaDown.objects.get(pk=antenna_id) |
|
415 | 415 | img_path = getImgfromOverJRO(profile_id, objAntenna) |
|
416 | 416 | filename = os.path.split(img_path)[1] |
|
417 | 417 | return render_to_response('abscontrol/overjro_down.html', {'img_down': filename, 'antennaDown': objAntenna,}, |
|
418 | 418 | context_instance=RequestContext(request)) |
|
419 | 419 | |
|
420 | 420 | def export(request, profile_id): |
|
421 | 421 | listPatterns = [] |
|
422 | 422 | objProfile = Profile.objects.get(pk=profile_id) |
|
423 | 423 | exp_name = objProfile.name |
|
424 | 424 | lsPatterns = objProfile.pattern_set.all() |
|
425 | 425 | for element in lsPatterns: |
|
426 | 426 | objAntennaUp = element.antennaup_set.get() |
|
427 | 427 | objAntennaDown = element.antennadown_set.get() |
|
428 | 428 | dicPatterns = {"number" : element.value, "up" : objAntennaUp.value, "down" : objAntennaDown.value} |
|
429 | 429 | listPatterns.append(dicPatterns) |
|
430 | 430 | |
|
431 | 431 | absFile = saveABSFile() |
|
432 | 432 | absFile.setParameters(settings.MEDIA_ROOT, exp_name, listPatterns) |
|
433 | 433 | filename, filesize = absFile.save() |
|
434 | 434 | |
|
435 | 435 | wrapper = FileWrapper( open( filename, "r" ) ) |
|
436 | 436 | content_type = mimetypes.guess_type( filename )[0] |
|
437 | 437 | |
|
438 | 438 | response = HttpResponse(wrapper, content_type = content_type) |
|
439 | 439 | response['Content-Description'] = 'File Transfer' |
|
440 | 440 | response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(filename) |
|
441 | 441 | response['Content-Transfer-Encoding'] = 'binary' |
|
442 | 442 | response['Expires'] = '0' |
|
443 | 443 | response['Cache-Control'] = 'must-revalidate' |
|
444 | 444 | response['Pragma'] = 'public' |
|
445 | 445 | response['Content-Length'] = '%s' % str(filesize) |
|
446 | 446 | response['X-Sendfile'] = '%s' % smart_str(filename) |
|
447 | 447 | |
|
448 | 448 | return response |
|
449 | 449 | |
|
450 | 450 | def send(request, profile_id): |
|
451 | 451 | listPatterns = [] |
|
452 | 452 | objProfile = Profile.objects.get(pk=profile_id) |
|
453 | 453 | exp_name = objProfile.name |
|
454 | 454 | |
|
455 | 455 | lsPatterns = objProfile.pattern_set.all() |
|
456 | 456 | for element in lsPatterns: |
|
457 | 457 | objAntennaUp = element.antennaup_set.get() |
|
458 | 458 | objAntennaDown = element.antennadown_set.get() |
|
459 | 459 | dicPatterns = {"number" : element.value, "up" : objAntennaUp.value, "down" : objAntennaDown.value} |
|
460 | 460 | listPatterns.append(dicPatterns) |
|
461 | 461 | |
|
462 | 462 | absFile = saveABSFile() |
|
463 | 463 | absFile.setParameters(settings.MEDIA_ROOT, exp_name, listPatterns) |
|
464 | 464 | filename, filesize = absFile.save() |
|
465 | 465 | |
|
466 | 466 | apiclient = sendFile() |
|
467 | 467 | apiclient.execute(filename) |
|
468 | 468 | output = apiclient.getOutput() |
|
469 | 469 | |
|
470 | 470 | if output == "OK": |
|
471 | 471 | message = "File sent successfully." |
|
472 | 472 | lsProfilesActive = Profile.objects.filter(is_active=1) |
|
473 | 473 | if len(lsProfilesActive) > 0: |
|
474 | 474 | objProfileActive = Profile.objects.get(is_active=1) |
|
475 | 475 | objProfileActive.is_active = 0 |
|
476 | 476 | objProfileActive.save() |
|
477 | 477 | |
|
478 | lsPatternsActive = Pattern.objects.filter(is_active=1) | |
|
479 | if len(lsPatternsActive) > 0: | |
|
480 | objPatternActive = Pattern.objects.get(is_active=1) | |
|
481 | objPatternActive.is_active = 0 | |
|
482 | objPatternActive.save() | |
|
483 | ||
|
478 | 484 | objProfile.hits += 1 |
|
479 | 485 | objProfile.is_active = 1 |
|
480 | 486 | objProfile.save() |
|
481 | 487 | |
|
482 | 488 | pattern_value = 1 |
|
483 | 489 | patternChoosen = objProfile.pattern_set.get(value=pattern_value) |
|
484 | 490 | patternChoosen.is_active = 1 |
|
485 | 491 | patternChoosen.save() |
|
486 | 492 | |
|
487 | 493 | newurl = '/abscontrol/view/%d' % int(profile_id) |
|
488 | 494 | |
|
489 | 495 | return redirect(newurl) |
|
490 | 496 | else: |
|
491 | 497 | message = "Error sending file." |
|
492 | 498 | |
|
493 | 499 | profile_list = Profile.objects.all() |
|
494 | 500 | |
|
495 | 501 | return render_to_response('abscontrol/sendFile.html', {'message': message, "profile_list" : profile_list, |
|
496 | 502 | 'objProfile': objProfile, |
|
497 | 503 | }, context_instance=RequestContext(request)) |
|
498 | 504 | |
|
499 | 505 | def changePattern(request, profile_id, pattern_id): |
|
500 | 506 | patternChoosen = Pattern.objects.get(id=pattern_id) |
|
501 | 507 | beam = int(patternChoosen.value)-1 |
|
502 | 508 | |
|
503 | 509 | apiclient = changeBeam() |
|
504 | 510 | apiclient.execute(str(beam)) |
|
505 | 511 | output = apiclient.getOutput() |
|
506 | 512 | |
|
507 | 513 | if output == "OK": |
|
508 | 514 | lsPatternsActive = Pattern.objects.filter(is_active=1) |
|
509 | 515 | if len(lsPatternsActive) > 0: |
|
510 | 516 | objPatternActive = Pattern.objects.get(is_active=1) |
|
511 | 517 | objPatternActive.is_active = 0 |
|
512 | 518 | objPatternActive.save() |
|
513 | 519 | |
|
514 | 520 | patternChoosen.hits += 1 |
|
515 | 521 | patternChoosen.is_active = 1 |
|
516 | 522 | patternChoosen.save() |
|
517 | 523 | |
|
518 | 524 | newurl = '/abscontrol/%d/view/%d/' % (int(profile_id), int(pattern_id)) |
|
519 | 525 | return redirect(newurl) |
|
520 | 526 | else: |
|
521 | 527 | message = "Error sending file." |
|
522 | 528 | profile_list = Profile.objects.all() |
|
523 | 529 | return render_to_response('abscontrol/sendFile.html', {'message': message, "profile_list" : profile_list, |
|
524 | 530 | }, context_instance=RequestContext(request)) |
|
525 | 531 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now