@@ -2,12 +2,21 from django.shortcuts import render_to_response | |||
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
4 | 4 | from django.contrib import messages |
|
5 | from django.conf import settings | |
|
6 | from django.http import HttpResponse | |
|
7 | ||
|
8 | from datetime import datetime | |
|
9 | from time import sleep | |
|
10 | import os | |
|
5 | 11 | |
|
6 | 12 | from apps.main.models import Device, Configuration |
|
7 | 13 | from apps.main.views import sidebar |
|
8 | 14 | |
|
9 | 15 | from .models import ABSConfiguration, ABSBeam |
|
10 | 16 | from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm |
|
17 | ||
|
18 | from .utils.overJroShow import overJroShow | |
|
19 | from .utils.OverJRO import OverJRO | |
|
11 | 20 | # Create your views here. |
|
12 | 21 | import json, ast |
|
13 | 22 | |
@@ -190,29 +199,7 def abs_conf_edit(request, id_conf): | |||
|
190 | 199 | return render(request, 'abs_conf_edit.html', kwargs) |
|
191 | 200 | |
|
192 | 201 | |
|
193 | def plot_patterns(request, id_conf): | |
|
194 | ||
|
195 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
196 | beams_list = ast.literal_eval(conf.beams) | |
|
197 | i = 1 | |
|
198 | beams = [] | |
|
199 | for b in beams_list: | |
|
200 | beam = ABSBeam.objects.get(pk=beams_list['beam'+str(i)]) | |
|
201 | beams.append(beam) | |
|
202 | i=i+1 | |
|
203 | ||
|
204 | ###### SIDEBAR ###### | |
|
205 | kwargs = {} | |
|
206 | ||
|
207 | kwargs['dev_conf'] = conf.device | |
|
208 | kwargs['id_dev'] = conf.device | |
|
209 | kwargs['id_conf'] = conf.id | |
|
210 | kwargs['abs_beams'] = beams | |
|
211 | kwargs['title'] = 'ABS Patterns' | |
|
212 | kwargs['suptitle'] = conf.name | |
|
213 | kwargs['no_sidebar'] = True | |
|
214 | 202 | |
|
215 | return render(request, 'abs_patterns.html', kwargs) | |
|
216 | 203 | |
|
217 | 204 | def add_beam(request, id_conf): |
|
218 | 205 | |
@@ -325,3 +312,171 def remove_beam(request, id_conf, id_beam): | |||
|
325 | 312 | kwargs['suptitle'] = 'Beam' |
|
326 | 313 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
327 | 314 | return render(request, 'confirm.html', kwargs) |
|
315 | ||
|
316 | ||
|
317 | ||
|
318 | def plot_patterns(request, id_conf): | |
|
319 | ||
|
320 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
321 | beams_list = ast.literal_eval(conf.beams) | |
|
322 | i = 1 | |
|
323 | beams = [] | |
|
324 | for b in beams_list: | |
|
325 | beam = ABSBeam.objects.get(pk=beams_list['beam'+str(i)]) | |
|
326 | beams.append(beam) | |
|
327 | i=i+1 | |
|
328 | ||
|
329 | ###### SIDEBAR ###### | |
|
330 | kwargs = {} | |
|
331 | ||
|
332 | kwargs['dev_conf'] = conf.device | |
|
333 | kwargs['id_dev'] = conf.device | |
|
334 | kwargs['id_conf'] = conf.id | |
|
335 | kwargs['abs_beams'] = beams | |
|
336 | kwargs['title'] = 'ABS Patterns' | |
|
337 | kwargs['suptitle'] = conf.name | |
|
338 | kwargs['no_sidebar'] = True | |
|
339 | ||
|
340 | return render(request, 'abs_patterns.html', kwargs) | |
|
341 | ||
|
342 | ||
|
343 | def plot_pattern(request, id_conf, id_beam): | |
|
344 | ||
|
345 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
346 | beam = get_object_or_404(ABSBeam, pk=id_beam) | |
|
347 | ||
|
348 | #Lista de Beams de la configuracion con su respectivo ID | |
|
349 | beams_list = ast.literal_eval(conf.beams) | |
|
350 | i = 1 | |
|
351 | #Lista de Objetos ABSBeams en el 0rden de su respectiva configuracion | |
|
352 | beams = [] | |
|
353 | for b in beams_list: | |
|
354 | beam = ABSBeam.objects.get(pk=beams_list['beam'+str(i)]) | |
|
355 | beams.append(beam) | |
|
356 | i=i+1 | |
|
357 | ||
|
358 | ###### SIDEBAR ###### | |
|
359 | beam = get_object_or_404(ABSBeam, pk=id_beam) | |
|
360 | kwargs = {} | |
|
361 | ||
|
362 | kwargs['dev_conf'] = conf.device | |
|
363 | kwargs['id_dev'] = conf.device | |
|
364 | kwargs['id_conf'] = conf.id | |
|
365 | kwargs['abs_beams'] = beams | |
|
366 | kwargs['beam'] = beam | |
|
367 | kwargs['title'] = 'ABS Patterns' | |
|
368 | kwargs['suptitle'] = conf.name | |
|
369 | kwargs['no_sidebar'] = True | |
|
370 | ||
|
371 | return render(request, 'abs_patterns.html', kwargs) | |
|
372 | ||
|
373 | ||
|
374 | ||
|
375 | def plot_uppattern(request, id_conf, id_beam): | |
|
376 | ||
|
377 | from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas | |
|
378 | ||
|
379 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
380 | beam = get_object_or_404(ABSBeam, pk=id_beam) | |
|
381 | ||
|
382 | exp_name = conf.experiment.name | |
|
383 | ||
|
384 | just_rx = 0 | |
|
385 | ||
|
386 | only_rx = json.loads(beam.only_rx) | |
|
387 | if only_rx['up'] == True: | |
|
388 | just_rx = 1 | |
|
389 | ||
|
390 | antenna = ast.literal_eval(beam.antenna) | |
|
391 | objAntenna = json.dumps(antenna['antenna_up']) | |
|
392 | antenna_up = ''.join(str(i) for i in objAntenna) | |
|
393 | phase_tx = antenna_up.replace(' ','') | |
|
394 | ||
|
395 | tx = ast.literal_eval(beam.tx) | |
|
396 | tx = json.dumps(tx['up']) | |
|
397 | tx = ''.join(str(i) for i in tx) | |
|
398 | gain_tx = tx.replace(' ','') | |
|
399 | ||
|
400 | rx = ast.literal_eval(beam.rx) | |
|
401 | rx = json.dumps(rx['up']) | |
|
402 | rx = ''.join(str(i) for i in rx) | |
|
403 | gain_rx = rx.replace(' ','') | |
|
404 | ||
|
405 | ues = json.dumps(beam.get_up_ues) | |
|
406 | ues = ''.join(str(i) for i in ues) | |
|
407 | ues_tx = ues.replace(' ','') | |
|
408 | ||
|
409 | #sleep(1) | |
|
410 | ||
|
411 | overjro = OverJRO() | |
|
412 | overjro.setParameters(settings.MEDIA_ROOT, exp_name, phase_tx, gain_tx, gain_rx, ues_tx, just_rx) | |
|
413 | contentFile = overjro.setTextContent() | |
|
414 | finalpath = overjro.saveFile(contentFile) | |
|
415 | ||
|
416 | currentdate = datetime.today() | |
|
417 | newOverJro = overJroShow() | |
|
418 | newOverJro.setInputParameters(settings.MEDIA_ROOT, currentdate, finalpath) | |
|
419 | newOverJro.setupParameters() | |
|
420 | newOverJro.execute() | |
|
421 | path = newOverJro.getPlot() | |
|
422 | path= "apps/abs/media/"+path | |
|
423 | ||
|
424 | ||
|
425 | canvas=FigureCanvas(newOverJro.figure) | |
|
426 | response=HttpResponse(content_type='image/png') | |
|
427 | canvas.print_png(response) | |
|
428 | return response | |
|
429 | ||
|
430 | def plot_downpattern(request, id_conf, id_beam): | |
|
431 | ||
|
432 | sleep(4) | |
|
433 | from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas | |
|
434 | ||
|
435 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
436 | beam = get_object_or_404(ABSBeam, pk=id_beam) | |
|
437 | ||
|
438 | exp_name = conf.experiment.name | |
|
439 | ||
|
440 | just_rx = 0 | |
|
441 | ||
|
442 | only_rx = json.loads(beam.only_rx) | |
|
443 | if only_rx['down'] == True: | |
|
444 | just_rx = 1 | |
|
445 | ||
|
446 | antenna = ast.literal_eval(beam.antenna) | |
|
447 | objAntenna = json.dumps(antenna['antenna_down']) | |
|
448 | antenna_down = ''.join(str(i) for i in objAntenna) | |
|
449 | phase_tx = antenna_down.replace(' ','') | |
|
450 | ||
|
451 | tx = ast.literal_eval(beam.tx) | |
|
452 | tx = json.dumps(tx['down']) | |
|
453 | tx = ''.join(str(i) for i in tx) | |
|
454 | gain_tx = tx.replace(' ','') | |
|
455 | ||
|
456 | rx = ast.literal_eval(beam.rx) | |
|
457 | rx = json.dumps(rx['down']) | |
|
458 | rx = ''.join(str(i) for i in rx) | |
|
459 | gain_rx = rx.replace(' ','') | |
|
460 | ||
|
461 | ues = json.dumps(beam.get_down_ues) | |
|
462 | ues = ''.join(str(i) for i in ues) | |
|
463 | ues_tx = ues.replace(' ','') | |
|
464 | ||
|
465 | overjro = OverJRO() | |
|
466 | overjro.setParameters(settings.MEDIA_ROOT, exp_name, phase_tx, gain_tx, gain_rx, ues_tx, just_rx) | |
|
467 | contentFile = overjro.setTextContent() | |
|
468 | finalpath = overjro.saveFile(contentFile) | |
|
469 | ||
|
470 | currentdate = datetime.today() | |
|
471 | newOverJro = overJroShow() | |
|
472 | newOverJro.setInputParameters(settings.MEDIA_ROOT, currentdate, finalpath) | |
|
473 | newOverJro.setupParameters() | |
|
474 | newOverJro.execute() | |
|
475 | path = newOverJro.getPlot() | |
|
476 | path= "apps/abs/media/"+path | |
|
477 | ||
|
478 | ||
|
479 | canvas=FigureCanvas(newOverJro.figure) | |
|
480 | response=HttpResponse(content_type='image/png') | |
|
481 | canvas.print_png(response) | |
|
482 | return response |
General Comments 0
You need to be logged in to leave comments.
Login now