The requested changes are too big and content was truncated. Show full diff
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,13 +1,15 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
|
3 | import views | |||
|
4 | ||||
3 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
4 |
url(r'^(?P<id_conf>-?\d+)/$', |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', views.abs_conf, name='url_abs_conf'), | |
5 |
url(r'^(?P<id_conf>-?\d+)/edit/$', |
|
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.abs_conf_edit, name='url_edit_abs_conf'), | |
6 |
url(r'^(?P<id_conf>-?\d+)/read/$', |
|
8 | url(r'^(?P<id_conf>-?\d+)/read/$', views.dev_conf_read, name='url_read_abs_conf'), | |
7 |
url(r'^(?P<id_conf>-?\d+)/import/$', |
|
9 | url(r'^(?P<id_conf>-?\d+)/import/$', views.dev_conf_import, name='url_import_abs_conf'), | |
8 |
url(r'^(?P<id_conf>-?\d+)/export/$', |
|
10 | url(r'^(?P<id_conf>-?\d+)/export/$', views.dev_conf_export, name='url_export_abs_conf'), | |
9 |
url(r'^(?P<id_conf>-?\d+)/plot/$', |
|
11 | url(r'^(?P<id_conf>-?\d+)/plot/$', views.plot_patterns, name='url_plot_abs_patterns'), | |
10 |
url(r'^(?P<id_conf>-?\d+)/add_beam/$', |
|
12 | url(r'^(?P<id_conf>-?\d+)/add_beam/$', views.add_beam, name='url_add_abs_beam'), | |
11 |
url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/delete/$', |
|
13 | url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/delete/$', views.remove_beam, name='url_remove_abs_beam'), | |
12 |
url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/edit/$', |
|
14 | url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/edit/$', views.edit_beam, name='url_edit_abs_beam'), | |
13 | ) |
|
15 | ) |
@@ -7,7 +7,7 | |||||
7 |
|
7 | |||
8 | {% block content %} |
|
8 | {% block content %} | |
9 | <div class='col-md-8'> |
|
9 | <div class='col-md-8'> | |
10 |
<form class="form" method="post" action="{% url ' |
|
10 | <form class="form" method="post" action="{% url 'url_login' %}"> | |
11 | {% csrf_token %} |
|
11 | {% csrf_token %} | |
12 | {% bootstrap_form form %} |
|
12 | {% bootstrap_form form %} | |
13 | <input type="hidden" name="next" value="{{ next }}" /> |
|
13 | <input type="hidden" name="next" value="{{ next }}" /> |
@@ -1,7 +1,7 | |||||
1 |
from django.conf.urls import |
|
1 | from django.conf.urls import url | |
2 | from django.contrib.auth import views as auth_views |
|
2 | from django.contrib.auth import views as auth_views | |
3 |
|
3 | |||
4 |
urlpatterns = |
|
4 | urlpatterns = ( | |
5 |
url(r'^logout/$', |
|
5 | url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='url_logout'), | |
6 | url(r'^login/$', auth_views.login, {'template_name': 'login.html'}), |
|
6 | url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name='url_login'), | |
7 | ) |
|
7 | ) |
@@ -2,82 +2,79 from django.db import models | |||||
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
3 | from django.core.validators import MinValueValidator, MaxValueValidator | |
4 |
|
4 | |||
5 |
|
5 | from .files import read_json_file | ||
6 | from apps.main.models import Device, Experiment |
|
|||
7 |
|
||||
8 | from files import read_json_file |
|
|||
9 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
6 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |
10 |
|
7 | |||
11 | class CGSConfiguration(Configuration): |
|
8 | class CGSConfiguration(Configuration): | |
12 |
|
9 | |||
13 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) |
|
10 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) | |
14 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) |
|
11 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) | |
15 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) |
|
12 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) | |
16 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) |
|
13 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) | |
17 |
|
14 | |||
18 | def verify_frequencies(self): |
|
15 | def verify_frequencies(self): | |
19 |
|
16 | |||
20 | return True |
|
17 | return True | |
21 |
|
18 | |||
22 |
|
19 | |||
23 | def update_from_file(self, fp): |
|
20 | def update_from_file(self, fp): | |
24 |
|
21 | |||
25 | kwargs = read_json_file(fp) |
|
22 | kwargs = read_json_file(fp) | |
26 |
|
23 | |||
27 | if not kwargs: |
|
24 | if not kwargs: | |
28 | return False |
|
25 | return False | |
29 |
|
26 | |||
30 | self.freq0 = kwargs['freq0'] |
|
27 | self.freq0 = kwargs['freq0'] | |
31 | self.freq1 = kwargs['freq1'] |
|
28 | self.freq1 = kwargs['freq1'] | |
32 | self.freq2 = kwargs['freq2'] |
|
29 | self.freq2 = kwargs['freq2'] | |
33 | self.freq3 = kwargs['freq3'] |
|
30 | self.freq3 = kwargs['freq3'] | |
34 |
|
31 | |||
35 | return True |
|
32 | return True | |
36 |
|
33 | |||
37 | def parms_to_dict(self): |
|
34 | def parms_to_dict(self): | |
38 |
|
35 | |||
39 | parameters = {} |
|
36 | parameters = {} | |
40 |
|
37 | |||
41 | parameters['device_id'] = self.device.id |
|
38 | parameters['device_id'] = self.device.id | |
42 |
|
39 | |||
43 | if self.freq0 == None or self.freq0 == '': |
|
40 | if self.freq0 == None or self.freq0 == '': | |
44 | parameters['freq0'] = 0 |
|
41 | parameters['freq0'] = 0 | |
45 | else: |
|
42 | else: | |
46 | parameters['freq0'] = self.freq0 |
|
43 | parameters['freq0'] = self.freq0 | |
47 |
|
44 | |||
48 | if self.freq1 == None or self.freq1 == '': |
|
45 | if self.freq1 == None or self.freq1 == '': | |
49 | parameters['freq1'] = 0 |
|
46 | parameters['freq1'] = 0 | |
50 | else: |
|
47 | else: | |
51 | parameters['freq1'] = self.freq1 |
|
48 | parameters['freq1'] = self.freq1 | |
52 |
|
49 | |||
53 | if self.freq2 == None or self.freq2 == '': |
|
50 | if self.freq2 == None or self.freq2 == '': | |
54 | parameters['freq2'] = 0 |
|
51 | parameters['freq2'] = 0 | |
55 | else: |
|
52 | else: | |
56 |
parameters['freq2'] = self.freq2 |
|
53 | parameters['freq2'] = self.freq2 | |
57 |
|
54 | |||
58 | if self.freq3 == None or self.freq3 == '': |
|
55 | if self.freq3 == None or self.freq3 == '': | |
59 | parameters['freq3'] = 0 |
|
56 | parameters['freq3'] = 0 | |
60 | else: |
|
57 | else: | |
61 | parameters['freq3'] = self.freq3 |
|
58 | parameters['freq3'] = self.freq3 | |
62 |
|
59 | |||
63 | return parameters |
|
60 | return parameters | |
64 |
|
61 | |||
65 |
|
62 | |||
66 | def dict_to_parms(self, parameters): |
|
63 | def dict_to_parms(self, parameters): | |
67 |
|
64 | |||
68 | self.freq0 = parameters['freq0'] |
|
65 | self.freq0 = parameters['freq0'] | |
69 | self.freq1 = parameters['freq1'] |
|
66 | self.freq1 = parameters['freq1'] | |
70 | self.freq2 = parameters['freq2'] |
|
67 | self.freq2 = parameters['freq2'] | |
71 | self.freq3 = parameters['freq3'] |
|
68 | self.freq3 = parameters['freq3'] | |
72 |
|
69 | |||
73 |
|
70 | |||
74 | def status_device(self): |
|
71 | def status_device(self): | |
75 |
|
72 | |||
76 | import requests |
|
73 | import requests | |
77 |
|
74 | |||
78 | ip=self.device.ip_address |
|
75 | ip=self.device.ip_address | |
79 | port=self.device.port_address |
|
76 | port=self.device.port_address | |
80 |
|
77 | |||
81 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
78 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
82 | try: |
|
79 | try: | |
83 | r = requests.get(route,timeout=0.5) |
|
80 | r = requests.get(route,timeout=0.5) | |
@@ -85,13 +82,13 class CGSConfiguration(Configuration): | |||||
85 | self.device.status = 0 |
|
82 | self.device.status = 0 | |
86 | self.device.save() |
|
83 | self.device.save() | |
87 | return self.device.status |
|
84 | return self.device.status | |
88 |
|
85 | |||
89 | response = str(r.text) |
|
86 | response = str(r.text) | |
90 | response = response.split(";") |
|
87 | response = response.split(";") | |
91 | icon = response[0] |
|
88 | icon = response[0] | |
92 |
status = response[-1] |
|
89 | status = response[-1] | |
93 |
|
90 | |||
94 |
|
|
91 | #print(icon, status) | |
95 | #"icon" could be: "alert" or "okay" |
|
92 | #"icon" could be: "alert" or "okay" | |
96 | if "alert" in icon: |
|
93 | if "alert" in icon: | |
97 | if "Starting Up" in status: #No Esta conectado |
|
94 | if "Starting Up" in status: #No Esta conectado | |
@@ -102,52 +99,52 class CGSConfiguration(Configuration): | |||||
102 | self.device.status = 3 |
|
99 | self.device.status = 3 | |
103 | else: |
|
100 | else: | |
104 | self.device.status = 1 |
|
101 | self.device.status = 1 | |
105 |
|
102 | |||
106 | self.message = status |
|
103 | self.message = status | |
107 | self.device.save() |
|
104 | self.device.save() | |
108 |
|
105 | |||
109 |
|
106 | |||
110 | return self.device.status |
|
107 | return self.device.status | |
111 |
|
108 | |||
112 |
|
109 | |||
113 | def read_device(self): |
|
110 | def read_device(self): | |
114 |
|
111 | |||
115 | import requests |
|
112 | import requests | |
116 |
|
113 | |||
117 | ip=self.device.ip_address |
|
114 | ip=self.device.ip_address | |
118 | port=self.device.port_address |
|
115 | port=self.device.port_address | |
119 |
|
116 | |||
120 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
117 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
121 | try: |
|
118 | try: | |
122 | frequencies = requests.get(route,timeout=0.5) |
|
119 | frequencies = requests.get(route,timeout=0.5) | |
123 |
|
120 | |||
124 | except: |
|
121 | except: | |
125 | self.message = "Could not read CGS parameters from this device" |
|
122 | self.message = "Could not read CGS parameters from this device" | |
126 | return None |
|
123 | return None | |
127 |
|
124 | |||
128 | frequencies = frequencies.json() |
|
125 | frequencies = frequencies.json() | |
129 | frequencies = frequencies.get("Frecuencias") |
|
126 | frequencies = frequencies.get("Frecuencias") | |
130 | f0 = frequencies.get("f0") |
|
127 | f0 = frequencies.get("f0") | |
131 | f1 = frequencies.get("f1") |
|
128 | f1 = frequencies.get("f1") | |
132 | f2 = frequencies.get("f2") |
|
129 | f2 = frequencies.get("f2") | |
133 | f3 = frequencies.get("f3") |
|
130 | f3 = frequencies.get("f3") | |
134 |
|
131 | |||
135 | parms = {'freq0': f0, |
|
132 | parms = {'freq0': f0, | |
136 | 'freq1': f1, |
|
133 | 'freq1': f1, | |
137 | 'freq2': f2, |
|
134 | 'freq2': f2, | |
138 | 'freq3': f3} |
|
135 | 'freq3': f3} | |
139 |
|
136 | |||
140 | self.message = "" |
|
137 | self.message = "" | |
141 | return parms |
|
138 | return parms | |
142 |
|
139 | |||
143 |
|
140 | |||
144 | def write_device(self): |
|
141 | def write_device(self): | |
145 |
|
142 | |||
146 | import requests |
|
143 | import requests | |
147 |
|
144 | |||
148 | ip=self.device.ip_address |
|
145 | ip=self.device.ip_address | |
149 | port=self.device.port_address |
|
146 | port=self.device.port_address | |
150 |
|
147 | |||
151 | #---Frequencies from form |
|
148 | #---Frequencies from form | |
152 | f0 = self.freq0 |
|
149 | f0 = self.freq0 | |
153 | f1 = self.freq1 |
|
150 | f1 = self.freq1 | |
@@ -155,16 +152,16 class CGSConfiguration(Configuration): | |||||
155 | f3 = self.freq3 |
|
152 | f3 = self.freq3 | |
156 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
153 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
157 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
154 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
158 |
|
155 | |||
159 |
try: |
|
156 | try: | |
160 | r = requests.post(route, post_data, timeout=0.5) |
|
157 | r = requests.post(route, post_data, timeout=0.5) | |
161 | except: |
|
158 | except: | |
162 | self.message = "Could not write CGS parameters" |
|
159 | self.message = "Could not write CGS parameters" | |
163 | return None |
|
160 | return None | |
164 |
|
161 | |||
165 | text = r.text |
|
162 | text = r.text | |
166 | text = text.split(',') |
|
163 | text = text.split(',') | |
167 |
|
164 | |||
168 | if len(text)>1: |
|
165 | if len(text)>1: | |
169 | title = text[0] |
|
166 | title = text[0] | |
170 | status = text[1] |
|
167 | status = text[1] | |
@@ -174,9 +171,9 class CGSConfiguration(Configuration): | |||||
174 | else: |
|
171 | else: | |
175 | self.message = title + ", " + status |
|
172 | self.message = title + ", " + status | |
176 | return 1 |
|
173 | return 1 | |
177 |
|
174 | |||
178 | return 1 |
|
175 | return 1 | |
179 |
|
176 | |||
180 |
|
177 | |||
181 | class Meta: |
|
178 | class Meta: | |
182 | db_table = 'cgs_configurations' |
|
179 | db_table = 'cgs_configurations' |
@@ -1,14 +1,8 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
|
3 | from apps.cgs import views | |||
|
4 | ||||
3 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
4 |
url(r'^(?P<id_conf>-?\d+)/$', |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', views.cgs_conf, name='url_cgs_conf'), | |
5 |
url(r'^(?P<id_conf>-?\d+)/edit/$', |
|
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.cgs_conf_edit, name='url_edit_cgs_conf'), | |
6 | #url(r'^(?P<id_conf>-?\d+)/(?P<message>-?\d+)/$', 'apps.cgs.views.cgs_conf', name='url_cgs_conf'), |
|
|||
7 | # url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.cgs.views.cgs_conf_edit', name='url_edit_cgs_conf'), |
|
|||
8 | # url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.cgs.views.cgs_conf_write', name='url_write_cgs_conf'), |
|
|||
9 | # url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.cgs.views.cgs_conf_read', name='url_read_cgs_conf'), |
|
|||
10 | # url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.cgs.views.cgs_conf_import', name='url_import_cgs_conf'), |
|
|||
11 | # url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.cgs.views.cgs_conf_export', name='url_export_cgs_conf'), |
|
|||
12 | #url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_cgs_conf'), |
|
|||
13 | ) |
|
8 | ) | |
14 |
|
@@ -2,7 +2,7 from django.shortcuts import redirect, render, get_object_or_404 | |||||
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 | from django.http import HttpResponse |
|
3 | from django.http import HttpResponse | |
4 |
|
4 | |||
5 |
from apps.main.models import Experiment |
|
5 | from apps.main.models import Experiment | |
6 | from .models import CGSConfiguration |
|
6 | from .models import CGSConfiguration | |
7 |
|
7 | |||
8 | from .forms import CGSConfigurationForm, UploadFileForm |
|
8 | from .forms import CGSConfigurationForm, UploadFileForm | |
@@ -14,16 +14,16 import json | |||||
14 | # Create your views here. |
|
14 | # Create your views here. | |
15 |
|
15 | |||
16 | def cgs_conf(request, id_conf): |
|
16 | def cgs_conf(request, id_conf): | |
17 |
|
17 | |||
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
19 |
|
19 | |||
20 | ip=conf.device.ip_address |
|
20 | ip=conf.device.ip_address | |
21 | port=conf.device.port_address |
|
21 | port=conf.device.port_address | |
22 |
|
22 | |||
23 | kwargs = {} |
|
23 | kwargs = {} | |
24 |
|
24 | |||
25 | kwargs['status'] = conf.device.get_status_display() |
|
25 | kwargs['status'] = conf.device.get_status_display() | |
26 |
|
26 | |||
27 | #if request.method=='GET': |
|
27 | #if request.method=='GET': | |
28 | #r: response = icon, status |
|
28 | #r: response = icon, status | |
29 | # try: |
|
29 | # try: | |
@@ -32,7 +32,7 def cgs_conf(request, id_conf): | |||||
32 | # response = str(r.text) |
|
32 | # response = str(r.text) | |
33 | # response = response.split(";") |
|
33 | # response = response.split(";") | |
34 | # icon = response[0] |
|
34 | # icon = response[0] | |
35 |
# status = response[-1] |
|
35 | # status = response[-1] | |
36 | #print r.text |
|
36 | #print r.text | |
37 | #"icon" could be: "alert" or "okay" |
|
37 | #"icon" could be: "alert" or "okay" | |
38 | # Si hay alerta pero esta conectado |
|
38 | # Si hay alerta pero esta conectado | |
@@ -45,131 +45,131 def cgs_conf(request, id_conf): | |||||
45 | # kwargs['connected'] = True |
|
45 | # kwargs['connected'] = True | |
46 | # else: |
|
46 | # else: | |
47 | # kwargs['connected'] = False |
|
47 | # kwargs['connected'] = False | |
48 |
|
48 | |||
49 |
# except: |
|
49 | # except: | |
50 | # kwargs['connected'] = False |
|
50 | # kwargs['connected'] = False | |
51 | # status = "The Device is not connected." |
|
51 | # status = "The Device is not connected." | |
52 |
|
52 | |||
53 | #if not kwargs['connected']: |
|
53 | #if not kwargs['connected']: | |
54 | # messages.error(request, message=status) |
|
54 | # messages.error(request, message=status) | |
55 |
|
55 | |||
56 | kwargs['dev_conf'] = conf |
|
56 | kwargs['dev_conf'] = conf | |
57 | kwargs['dev_conf_keys'] = ['name', |
|
57 | kwargs['dev_conf_keys'] = ['name', | |
58 | 'freq0', 'freq1', |
|
58 | 'freq0', 'freq1', | |
59 | 'freq2', 'freq3'] |
|
59 | 'freq2', 'freq3'] | |
60 |
|
60 | |||
61 | kwargs['title'] = 'CGS Configuration' |
|
61 | kwargs['title'] = 'CGS Configuration' | |
62 | kwargs['suptitle'] = 'Details' |
|
62 | kwargs['suptitle'] = 'Details' | |
63 |
|
63 | |||
64 | kwargs['button'] = 'Edit Configuration' |
|
64 | kwargs['button'] = 'Edit Configuration' | |
65 |
|
65 | |||
66 | kwargs['no_play'] = True |
|
66 | kwargs['no_play'] = True | |
67 |
|
67 | |||
68 | ###### SIDEBAR ###### |
|
68 | ###### SIDEBAR ###### | |
69 | kwargs.update(sidebar(conf=conf)) |
|
69 | kwargs.update(sidebar(conf=conf)) | |
70 |
|
70 | |||
71 | return render(request, 'cgs_conf.html', kwargs) |
|
71 | return render(request, 'cgs_conf.html', kwargs) | |
72 |
|
72 | |||
73 | def cgs_conf_edit(request, id_conf): |
|
73 | def cgs_conf_edit(request, id_conf): | |
74 |
|
74 | |||
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
76 |
|
76 | |||
77 | if request.method=='GET': |
|
77 | if request.method=='GET': | |
78 | form = CGSConfigurationForm(instance=conf) |
|
78 | form = CGSConfigurationForm(instance=conf) | |
79 |
|
79 | |||
80 | if request.method=='POST': |
|
80 | if request.method=='POST': | |
81 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
81 | form = CGSConfigurationForm(request.POST, instance=conf) | |
82 |
|
82 | |||
83 | if form.is_valid(): |
|
83 | if form.is_valid(): | |
84 | if conf.freq0 == None: conf.freq0 = 0 |
|
84 | if conf.freq0 == None: conf.freq0 = 0 | |
85 | if conf.freq1 == None: conf.freq1 = 0 |
|
85 | if conf.freq1 == None: conf.freq1 = 0 | |
86 | if conf.freq2 == None: conf.freq2 = 0 |
|
86 | if conf.freq2 == None: conf.freq2 = 0 | |
87 | if conf.freq3 == None: conf.freq3 = 0 |
|
87 | if conf.freq3 == None: conf.freq3 = 0 | |
88 |
|
88 | |||
89 | conf = form.save(commit=False) |
|
89 | conf = form.save(commit=False) | |
90 |
|
90 | |||
91 | if conf.verify_frequencies(): |
|
91 | if conf.verify_frequencies(): | |
92 | conf.save() |
|
92 | conf.save() | |
93 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
93 | return redirect('url_cgs_conf', id_conf=conf.id) | |
94 |
|
94 | |||
95 | ##ERRORS |
|
95 | ##ERRORS | |
96 |
|
96 | |||
97 | kwargs = {} |
|
97 | kwargs = {} | |
98 | kwargs['id_dev'] = conf.id |
|
98 | kwargs['id_dev'] = conf.id | |
99 | kwargs['form'] = form |
|
99 | kwargs['form'] = form | |
100 | kwargs['title'] = 'Device Configuration' |
|
100 | kwargs['title'] = 'Device Configuration' | |
101 | kwargs['suptitle'] = 'Edit' |
|
101 | kwargs['suptitle'] = 'Edit' | |
102 | kwargs['button'] = 'Save' |
|
102 | kwargs['button'] = 'Save' | |
103 |
|
103 | |||
104 | return render(request, 'cgs_conf_edit.html', kwargs) |
|
104 | return render(request, 'cgs_conf_edit.html', kwargs) | |
105 |
# |
|
105 | # | |
106 | # def cgs_conf_write(request, id_conf): |
|
106 | # def cgs_conf_write(request, id_conf): | |
107 | # |
|
107 | # | |
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
109 | # ip=conf.device.ip_address |
|
109 | # ip=conf.device.ip_address | |
110 | # port=conf.device.port_address |
|
110 | # port=conf.device.port_address | |
111 | # |
|
111 | # | |
112 | # #Frequencies from form |
|
112 | # #Frequencies from form | |
113 | # f0 = conf.freq0 |
|
113 | # f0 = conf.freq0 | |
114 | # f1 = conf.freq1 |
|
114 | # f1 = conf.freq1 | |
115 | # f2 = conf.freq2 |
|
115 | # f2 = conf.freq2 | |
116 | # f3 = conf.freq3 |
|
116 | # f3 = conf.freq3 | |
117 | # |
|
117 | # | |
118 |
# try: |
|
118 | # try: | |
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
121 | # r = requests.post(route, post_data) |
|
121 | # r = requests.post(route, post_data) | |
122 | # text = r.text |
|
122 | # text = r.text | |
123 | # text = text.split(',') |
|
123 | # text = text.split(',') | |
124 | # |
|
124 | # | |
125 |
# try: |
|
125 | # try: | |
126 | # if len(text)>1: |
|
126 | # if len(text)>1: | |
127 | # title = text[0] |
|
127 | # title = text[0] | |
128 | # status = text[1] |
|
128 | # status = text[1] | |
129 |
# status_ok = r.status_code |
|
129 | # status_ok = r.status_code | |
130 | # if title == "okay": |
|
130 | # if title == "okay": | |
131 | # messages.success(request, status) |
|
131 | # messages.success(request, status) | |
132 | # else: |
|
132 | # else: | |
133 | # messages.error(request, status) |
|
133 | # messages.error(request, status) | |
134 | # |
|
134 | # | |
135 | # else: |
|
135 | # else: | |
136 | # title = text[0] |
|
136 | # title = text[0] | |
137 | # messages.error(request, title) |
|
137 | # messages.error(request, title) | |
138 | # |
|
138 | # | |
139 | # except: |
|
139 | # except: | |
140 | # messages.error(request, "An hardware error was found.") |
|
140 | # messages.error(request, "An hardware error was found.") | |
141 | # |
|
141 | # | |
142 | # except: |
|
142 | # except: | |
143 | # messages.error(request, "Could not write parameters.") |
|
143 | # messages.error(request, "Could not write parameters.") | |
144 | # |
|
144 | # | |
145 | # |
|
145 | # | |
146 | # |
|
146 | # | |
147 | # |
|
147 | # | |
148 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
148 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
149 |
# |
|
149 | # | |
150 | # def cgs_conf_read(request, id_conf): |
|
150 | # def cgs_conf_read(request, id_conf): | |
151 | # |
|
151 | # | |
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
153 | # |
|
153 | # | |
154 | # ip=conf.device.ip_address |
|
154 | # ip=conf.device.ip_address | |
155 | # port=conf.device.port_address |
|
155 | # port=conf.device.port_address | |
156 | # |
|
156 | # | |
157 | # if request.method=='POST': |
|
157 | # if request.method=='POST': | |
158 | # form = CGSConfigurationForm(request.POST, instance=conf) |
|
158 | # form = CGSConfigurationForm(request.POST, instance=conf) | |
159 | # |
|
159 | # | |
160 | # if form.is_valid(): |
|
160 | # if form.is_valid(): | |
161 | # cgs_model = form.save(commit=False) |
|
161 | # cgs_model = form.save(commit=False) | |
162 | # |
|
162 | # | |
163 | # if cgs_model.verify_frequencies(): |
|
163 | # if cgs_model.verify_frequencies(): | |
164 | # |
|
164 | # | |
165 | # cgs_model.save() |
|
165 | # cgs_model.save() | |
166 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
166 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
167 | # |
|
167 | # | |
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") |
|
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") | |
169 | # |
|
169 | # | |
170 | # data = {} |
|
170 | # data = {} | |
171 | # |
|
171 | # | |
172 | # |
|
172 | # | |
173 | # if request.method=='GET': |
|
173 | # if request.method=='GET': | |
174 | # #r: response = icon, status |
|
174 | # #r: response = icon, status | |
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
@@ -178,7 +178,7 def cgs_conf_edit(request, id_conf): | |||||
178 | # response = str(r.text) |
|
178 | # response = str(r.text) | |
179 | # response = response.split(";") |
|
179 | # response = response.split(";") | |
180 | # icon = response[0] |
|
180 | # icon = response[0] | |
181 |
# status = response[-1] |
|
181 | # status = response[-1] | |
182 | # print r.text |
|
182 | # print r.text | |
183 | # #"icon" could be: "alert" or "okay" |
|
183 | # #"icon" could be: "alert" or "okay" | |
184 | # if "okay" in icon: |
|
184 | # if "okay" in icon: | |
@@ -196,12 +196,12 def cgs_conf_edit(request, id_conf): | |||||
196 | # f2 = frequencies.get("f2") |
|
196 | # f2 = frequencies.get("f2") | |
197 | # f3 = frequencies.get("f3") |
|
197 | # f3 = frequencies.get("f3") | |
198 | # print f0,f1,f2,f3 |
|
198 | # print f0,f1,f2,f3 | |
199 | # |
|
199 | # | |
200 | # |
|
200 | # | |
201 | # if not response: |
|
201 | # if not response: | |
202 | # messages.error(request, "Could not read parameters from Device") |
|
202 | # messages.error(request, "Could not read parameters from Device") | |
203 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
203 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
204 | # |
|
204 | # | |
205 | # data = {'experiment' : conf.experiment.id, |
|
205 | # data = {'experiment' : conf.experiment.id, | |
206 | # 'device' : conf.device.id, |
|
206 | # 'device' : conf.device.id, | |
207 | # 'freq0' : f0, |
|
207 | # 'freq0' : f0, | |
@@ -210,7 +210,7 def cgs_conf_edit(request, id_conf): | |||||
210 | # 'freq3' : f3, |
|
210 | # 'freq3' : f3, | |
211 | # } |
|
211 | # } | |
212 | # except: |
|
212 | # except: | |
213 |
# messages.error(request, "Could not read parameters from Device") |
|
213 | # messages.error(request, "Could not read parameters from Device") | |
214 | # data = {'experiment' : conf.experiment.id, |
|
214 | # data = {'experiment' : conf.experiment.id, | |
215 | # 'device' : conf.device.id, |
|
215 | # 'device' : conf.device.id, | |
216 | # 'freq0' : None, |
|
216 | # 'freq0' : None, | |
@@ -219,79 +219,79 def cgs_conf_edit(request, id_conf): | |||||
219 | # 'freq3' : None, |
|
219 | # 'freq3' : None, | |
220 | # } |
|
220 | # } | |
221 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
221 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
222 | # |
|
222 | # | |
223 | # form = CGSConfigurationForm(initial = data) |
|
223 | # form = CGSConfigurationForm(initial = data) | |
224 | # |
|
224 | # | |
225 | # kwargs = {} |
|
225 | # kwargs = {} | |
226 | # kwargs['id_dev'] = conf.id |
|
226 | # kwargs['id_dev'] = conf.id | |
227 | # kwargs['form'] = form |
|
227 | # kwargs['form'] = form | |
228 | # kwargs['title'] = 'Device Configuration' |
|
228 | # kwargs['title'] = 'Device Configuration' | |
229 | # kwargs['suptitle'] = 'Parameters read from device' |
|
229 | # kwargs['suptitle'] = 'Parameters read from device' | |
230 | # kwargs['button'] = 'Save' |
|
230 | # kwargs['button'] = 'Save' | |
231 | # |
|
231 | # | |
232 | # ###### SIDEBAR ###### |
|
232 | # ###### SIDEBAR ###### | |
233 | # kwargs.update(sidebar(conf)) |
|
233 | # kwargs.update(sidebar(conf)) | |
234 | # |
|
234 | # | |
235 | # return render(request, 'cgs_conf_edit.html', kwargs) |
|
235 | # return render(request, 'cgs_conf_edit.html', kwargs) | |
236 |
# |
|
236 | # | |
237 | # def cgs_conf_import(request, id_conf): |
|
237 | # def cgs_conf_import(request, id_conf): | |
238 | # |
|
238 | # | |
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
240 | # |
|
240 | # | |
241 | # if request.method == 'POST': |
|
241 | # if request.method == 'POST': | |
242 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
242 | # file_form = UploadFileForm(request.POST, request.FILES) | |
243 | # |
|
243 | # | |
244 | # if file_form.is_valid(): |
|
244 | # if file_form.is_valid(): | |
245 | # |
|
245 | # | |
246 | # try: |
|
246 | # try: | |
247 | # if conf.update_from_file(request.FILES['file']): |
|
247 | # if conf.update_from_file(request.FILES['file']): | |
248 | # |
|
248 | # | |
249 | # try: |
|
249 | # try: | |
250 | # conf.full_clean() |
|
250 | # conf.full_clean() | |
251 | # except ValidationError as e: |
|
251 | # except ValidationError as e: | |
252 | # messages.error(request, e) |
|
252 | # messages.error(request, e) | |
253 | # else: |
|
253 | # else: | |
254 | # conf.save() |
|
254 | # conf.save() | |
255 | # |
|
255 | # | |
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) |
|
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) | |
257 | # #messages.warning(request,"") |
|
257 | # #messages.warning(request,"") | |
258 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
258 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
259 | # except: |
|
259 | # except: | |
260 | # messages.error(request, "No JSON object could be decoded.") |
|
260 | # messages.error(request, "No JSON object could be decoded.") | |
261 | # |
|
261 | # | |
262 | # messages.error(request, "Could not import parameters from file") |
|
262 | # messages.error(request, "Could not import parameters from file") | |
263 | # |
|
263 | # | |
264 | # else: |
|
264 | # else: | |
265 | # file_form = UploadFileForm(initial={'title': '.json'}) |
|
265 | # file_form = UploadFileForm(initial={'title': '.json'}) | |
266 | # |
|
266 | # | |
267 | # |
|
267 | # | |
268 | # kwargs = {} |
|
268 | # kwargs = {} | |
269 | # kwargs['id_dev'] = conf.id |
|
269 | # kwargs['id_dev'] = conf.id | |
270 | # kwargs['title'] = 'Device Configuration' |
|
270 | # kwargs['title'] = 'Device Configuration' | |
271 | # kwargs['form'] = file_form |
|
271 | # kwargs['form'] = file_form | |
272 | # kwargs['suptitle'] = 'Importing file' |
|
272 | # kwargs['suptitle'] = 'Importing file' | |
273 | # kwargs['button'] = 'Import' |
|
273 | # kwargs['button'] = 'Import' | |
274 | # |
|
274 | # | |
275 | # kwargs.update(sidebar(conf)) |
|
275 | # kwargs.update(sidebar(conf)) | |
276 | # |
|
276 | # | |
277 | # return render(request, 'cgs_conf_import.html', kwargs) |
|
277 | # return render(request, 'cgs_conf_import.html', kwargs) | |
278 |
# |
|
278 | # | |
279 | # def handle_uploaded_file(f): |
|
279 | # def handle_uploaded_file(f): | |
280 | # |
|
280 | # | |
281 | # data = {'freq0' : 62500000, |
|
281 | # data = {'freq0' : 62500000, | |
282 | # 'freq1' : 62500000, |
|
282 | # 'freq1' : 62500000, | |
283 | # 'freq2' : 62500000, |
|
283 | # 'freq2' : 62500000, | |
284 | # 'freq3' : 62500000, |
|
284 | # 'freq3' : 62500000, | |
285 | # } |
|
285 | # } | |
286 | # |
|
286 | # | |
287 | # return data |
|
287 | # return data | |
288 |
# |
|
288 | # | |
289 | # def cgs_conf_export(request, id_conf): |
|
289 | # def cgs_conf_export(request, id_conf): | |
290 | # |
|
290 | # | |
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
292 | # ip=conf.device.ip_address |
|
292 | # ip=conf.device.ip_address | |
293 | # port=conf.device.port_address |
|
293 | # port=conf.device.port_address | |
294 | # |
|
294 | # | |
295 | # #if request.method=='GET': |
|
295 | # #if request.method=='GET': | |
296 | # # data = {"Frequencies": [ |
|
296 | # # data = {"Frequencies": [ | |
297 | # # ["freq0", conf.freq0], |
|
297 | # # ["freq0", conf.freq0], | |
@@ -303,20 +303,20 def cgs_conf_edit(request, id_conf): | |||||
303 | # # conf.parameters = json_data |
|
303 | # # conf.parameters = json_data | |
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") |
|
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") | |
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' |
|
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' | |
306 | # |
|
306 | # | |
307 | # # return response |
|
307 | # # return response | |
308 | # |
|
308 | # | |
309 | # kwargs = {} |
|
309 | # kwargs = {} | |
310 | # kwargs['dev_conf'] = conf |
|
310 | # kwargs['dev_conf'] = conf | |
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', | |
312 | # 'freq0', 'freq1', |
|
312 | # 'freq0', 'freq1', | |
313 | # 'freq2', 'freq3'] |
|
313 | # 'freq2', 'freq3'] | |
314 | # |
|
314 | # | |
315 | # kwargs['title'] = 'CGS Configuration' |
|
315 | # kwargs['title'] = 'CGS Configuration' | |
316 | # kwargs['suptitle'] = 'Details' |
|
316 | # kwargs['suptitle'] = 'Details' | |
317 | # |
|
317 | # | |
318 | # kwargs['button'] = 'Edit Configuration' |
|
318 | # kwargs['button'] = 'Edit Configuration' | |
319 | # |
|
319 | # | |
320 | # ###### SIDEBAR ###### |
|
320 | # ###### SIDEBAR ###### | |
321 | # kwargs.update(sidebar(conf)) |
|
321 | # kwargs.update(sidebar(conf)) | |
322 | # return render(request, 'cgs_conf.html', kwargs) No newline at end of file |
|
322 | # return render(request, 'cgs_conf.html', kwargs) |
@@ -18,11 +18,11 MOD_TYPES = ( | |||||
18 | (3, 'Chirp'), |
|
18 | (3, 'Chirp'), | |
19 | (4, 'BPSK'), |
|
19 | (4, 'BPSK'), | |
20 | ) |
|
20 | ) | |
21 |
|
21 | |||
22 | class DDSConfiguration(Configuration): |
|
22 | class DDSConfiguration(Configuration): | |
23 |
|
23 | |||
24 | DDS_NBITS = 48 |
|
24 | DDS_NBITS = 48 | |
25 |
|
25 | |||
26 | clock = models.FloatField(verbose_name='Clock In (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) |
|
26 | clock = models.FloatField(verbose_name='Clock In (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) | |
27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) | |
28 |
|
28 | |||
@@ -31,98 +31,98 class DDSConfiguration(Configuration): | |||||
31 |
|
31 | |||
32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) |
|
32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) | |
33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) |
|
33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |
34 |
|
34 | |||
35 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) |
|
35 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) | |
36 |
|
36 | |||
37 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) |
|
37 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) | |
38 |
|
38 | |||
39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) |
|
39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) | |
40 |
|
40 | |||
41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) |
|
41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) | |
42 |
|
42 | |||
43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) | |
44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | def get_nbits(self): |
|
47 | def get_nbits(self): | |
48 |
|
48 | |||
49 | return self.DDS_NBITS |
|
49 | return self.DDS_NBITS | |
50 |
|
50 | |||
51 | def clean(self): |
|
51 | def clean(self): | |
52 |
|
52 | |||
53 | if self.modulation in [1,2,3]: |
|
53 | if self.modulation in [1,2,3]: | |
54 | if self.frequencyB is None or self.frequencyB_Mhz is None: |
|
54 | if self.frequencyB is None or self.frequencyB_Mhz is None: | |
55 | raise ValidationError({ |
|
55 | raise ValidationError({ | |
56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' |
|
56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' | |
57 | }) |
|
57 | }) | |
58 |
|
58 | |||
59 | if self.modulation in [4,]: |
|
59 | if self.modulation in [4,]: | |
60 | if self.phaseB_degrees is None: |
|
60 | if self.phaseB_degrees is None: | |
61 | raise ValidationError({ |
|
61 | raise ValidationError({ | |
62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' |
|
62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' | |
63 | }) |
|
63 | }) | |
64 |
|
64 | |||
65 | self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier) |
|
65 | self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier) | |
66 | self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier) |
|
66 | self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier) | |
67 |
|
67 | |||
68 | def verify_frequencies(self): |
|
68 | def verify_frequencies(self): | |
69 |
|
69 | |||
70 | return True |
|
70 | return True | |
71 |
|
71 | |||
72 | def parms_to_dict(self): |
|
72 | def parms_to_dict(self): | |
73 |
|
73 | |||
74 | parameters = {} |
|
74 | parameters = {} | |
75 |
|
75 | |||
76 | parameters['device_id'] = self.device.id |
|
76 | parameters['device_id'] = self.device.id | |
77 |
|
77 | |||
78 | parameters['clock'] = float(self.clock) |
|
78 | parameters['clock'] = float(self.clock) | |
79 | parameters['multiplier'] = int(self.multiplier) |
|
79 | parameters['multiplier'] = int(self.multiplier) | |
80 |
|
80 | |||
81 | parameters['frequencyA'] = int(self.frequencyA) |
|
81 | parameters['frequencyA'] = int(self.frequencyA) | |
82 | parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz) |
|
82 | parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz) | |
83 |
|
83 | |||
84 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) |
|
84 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) | |
85 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) |
|
85 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) | |
86 |
|
86 | |||
87 | parameters['modulation'] = int(self.modulation) |
|
87 | parameters['modulation'] = int(self.modulation) | |
88 | parameters['amplitude_enabled'] = bool(self.amplitude_enabled) |
|
88 | parameters['amplitude_enabled'] = bool(self.amplitude_enabled) | |
89 |
|
89 | |||
90 | if self.frequencyB: |
|
90 | if self.frequencyB: | |
91 | parameters['frequencyB'] = int(self.frequencyB) |
|
91 | parameters['frequencyB'] = int(self.frequencyB) | |
92 | parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz) |
|
92 | parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz) | |
93 | else: |
|
93 | else: | |
94 | parameters['frequencyB'] = 0 |
|
94 | parameters['frequencyB'] = 0 | |
95 | parameters['frequencyB_Mhz'] = 0 |
|
95 | parameters['frequencyB_Mhz'] = 0 | |
96 |
|
96 | |||
97 | if self.phaseB_degrees: |
|
97 | if self.phaseB_degrees: | |
98 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) |
|
98 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) | |
99 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) |
|
99 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) | |
100 | else: |
|
100 | else: | |
101 | parameters['phaseB_degrees'] = 0 |
|
101 | parameters['phaseB_degrees'] = 0 | |
102 | parameters['phaseB'] = 0 |
|
102 | parameters['phaseB'] = 0 | |
103 |
|
103 | |||
104 | if self.amplitudeI: |
|
104 | if self.amplitudeI: | |
105 | parameters['amplitudeI'] = int(self.amplitudeI) |
|
105 | parameters['amplitudeI'] = int(self.amplitudeI) | |
106 | else: |
|
106 | else: | |
107 | parameters['amplitudeI'] = 0 |
|
107 | parameters['amplitudeI'] = 0 | |
108 |
|
108 | |||
109 | if self.amplitudeQ: |
|
109 | if self.amplitudeQ: | |
110 | parameters['amplitudeQ'] = int(self.amplitudeQ) |
|
110 | parameters['amplitudeQ'] = int(self.amplitudeQ) | |
111 | else: |
|
111 | else: | |
112 | parameters['amplitudeQ'] = 0 |
|
112 | parameters['amplitudeQ'] = 0 | |
113 |
|
113 | |||
114 | return parameters |
|
114 | return parameters | |
115 |
|
115 | |||
116 | def parms_to_text(self): |
|
116 | def parms_to_text(self): | |
117 |
|
117 | |||
118 | my_dict = self.parms_to_dict() |
|
118 | my_dict = self.parms_to_dict() | |
119 |
|
119 | |||
120 | text = data.dict_to_text(my_dict) |
|
120 | text = data.dict_to_text(my_dict) | |
121 |
|
121 | |||
122 | return text |
|
122 | return text | |
123 |
|
123 | |||
124 | def dict_to_parms(self, parameters): |
|
124 | def dict_to_parms(self, parameters): | |
125 |
|
125 | |||
126 | self.clock = parameters['clock'] |
|
126 | self.clock = parameters['clock'] | |
127 | self.multiplier = parameters['multiplier'] |
|
127 | self.multiplier = parameters['multiplier'] | |
128 | self.frequencyA = parameters['frequencyA'] |
|
128 | self.frequencyA = parameters['frequencyA'] | |
@@ -133,98 +133,97 class DDSConfiguration(Configuration): | |||||
133 | self.phaseB_degrees = parameters['phaseB_degrees'] |
|
133 | self.phaseB_degrees = parameters['phaseB_degrees'] | |
134 | self.modulation = parameters['modulation'] |
|
134 | self.modulation = parameters['modulation'] | |
135 | self.amplitude_enabled = parameters['amplitude_enabled'] |
|
135 | self.amplitude_enabled = parameters['amplitude_enabled'] | |
136 |
|
136 | |||
137 | def import_from_file(self, fp): |
|
137 | def import_from_file(self, fp): | |
138 |
|
138 | |||
139 | import os, json |
|
139 | import os, json | |
140 |
|
140 | |||
141 | parms = {} |
|
141 | parms = {} | |
142 |
|
142 | |||
143 | path, ext = os.path.splitext(fp.name) |
|
143 | path, ext = os.path.splitext(fp.name) | |
144 |
|
144 | |||
145 | if ext == '.json': |
|
145 | if ext == '.json': | |
146 | parms = json.load(fp) |
|
146 | parms = json.load(fp) | |
147 |
|
147 | |||
148 | if ext == '.dds': |
|
148 | if ext == '.dds': | |
149 | lines = fp.readlines() |
|
149 | lines = fp.readlines() | |
150 | parms = data.text_to_dict(lines) |
|
150 | parms = data.text_to_dict(lines) | |
151 |
|
151 | |||
152 | return parms |
|
152 | return parms | |
153 |
|
153 | |||
154 | def status_device(self): |
|
154 | def status_device(self): | |
155 |
|
155 | |||
156 | answer = api.status(ip = self.device.ip_address, |
|
156 | answer = api.status(ip = self.device.ip_address, | |
157 | port = self.device.port_address) |
|
157 | port = self.device.port_address) | |
158 |
|
158 | |||
159 | self.device.status = int(answer[0]) |
|
159 | self.device.status = int(answer[0]) | |
160 | self.message = answer[2:] |
|
160 | self.message = answer[2:] | |
161 |
|
161 | |||
162 | self.device.save() |
|
162 | self.device.save() | |
163 |
|
163 | |||
164 | return self.device.status |
|
164 | return self.device.status | |
165 |
|
165 | |||
166 | def reset_device(self): |
|
166 | def reset_device(self): | |
167 |
|
167 | |||
168 | answer = api.reset(ip = self.device.ip_address, |
|
168 | answer = api.reset(ip = self.device.ip_address, | |
169 | port = self.device.port_address) |
|
169 | port = self.device.port_address) | |
170 |
|
170 | |||
171 | if answer[0] != "1": |
|
171 | if answer[0] != "1": | |
172 | self.message = answer[0:] |
|
172 | self.message = answer[0:] | |
173 | return 0 |
|
173 | return 0 | |
174 |
|
174 | |||
175 | self.message = answer[2:] |
|
175 | self.message = answer[2:] | |
176 | return 1 |
|
176 | return 1 | |
177 |
|
177 | |||
178 | def stop_device(self): |
|
178 | def stop_device(self): | |
179 |
|
179 | |||
180 | answer = api.disable_rf(ip = self.device.ip_address, |
|
180 | answer = api.disable_rf(ip = self.device.ip_address, | |
181 | port = self.device.port_address) |
|
181 | port = self.device.port_address) | |
182 |
|
182 | |||
183 | if answer[0] != "1": |
|
183 | if answer[0] != "1": | |
184 | self.message = answer[0:] |
|
184 | self.message = answer[0:] | |
185 | return 0 |
|
185 | return 0 | |
186 |
|
186 | |||
187 | self.message = answer[2:] |
|
187 | self.message = answer[2:] | |
188 | return 1 |
|
188 | return 1 | |
189 |
|
189 | |||
190 | def start_device(self): |
|
190 | def start_device(self): | |
191 |
|
191 | |||
192 | answer = api.enable_rf(ip = self.device.ip_address, |
|
192 | answer = api.enable_rf(ip = self.device.ip_address, | |
193 | port = self.device.port_address) |
|
193 | port = self.device.port_address) | |
194 |
|
194 | |||
195 | if answer[0] != "1": |
|
195 | if answer[0] != "1": | |
196 | self.message = answer[0:] |
|
196 | self.message = answer[0:] | |
197 | return 0 |
|
197 | return 0 | |
198 |
|
198 | |||
199 | self.message = answer[2:] |
|
199 | self.message = answer[2:] | |
200 | return 1 |
|
200 | return 1 | |
201 |
|
201 | |||
202 | def read_device(self): |
|
202 | def read_device(self): | |
203 |
|
203 | |||
204 | parms = api.read_config(ip = self.device.ip_address, |
|
204 | parms = api.read_config(ip = self.device.ip_address, | |
205 | port = self.device.port_address) |
|
205 | port = self.device.port_address) | |
206 |
|
206 | |||
207 | if not parms: |
|
207 | if not parms: | |
208 | self.message = "Could not read DDS parameters from this device" |
|
208 | self.message = "Could not read DDS parameters from this device" | |
209 | return parms |
|
209 | return parms | |
210 |
|
210 | |||
211 | self.message = "" |
|
211 | self.message = "" | |
212 | return parms |
|
212 | return parms | |
213 |
|
213 | |||
214 |
|
214 | |||
215 | def write_device(self): |
|
215 | def write_device(self): | |
216 |
|
216 | |||
217 | answer = api.write_config(ip = self.device.ip_address, |
|
217 | answer = api.write_config(ip = self.device.ip_address, | |
218 | port = self.device.port_address, |
|
218 | port = self.device.port_address, | |
219 | parms = self.parms_to_dict()) |
|
219 | parms = self.parms_to_dict()) | |
220 |
|
220 | |||
221 | if answer[0] != "1": |
|
221 | if answer[0] != "1": | |
222 | self.message = answer[0:] |
|
222 | self.message = answer[0:] | |
223 | return 0 |
|
223 | return 0 | |
224 |
|
224 | |||
225 | self.message = answer[2:] |
|
225 | self.message = answer[2:] | |
226 | return 1 |
|
226 | return 1 | |
227 |
|
227 | |||
228 | class Meta: |
|
228 | class Meta: | |
229 | db_table = 'dds_configurations' |
|
229 | db_table = 'dds_configurations' | |
230 | No newline at end of file |
|
@@ -1,14 +1,9 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
|
3 | from apps.dds import views | |||
|
4 | ||||
3 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
4 |
url(r'^(?P<id_conf>-?\d+)/$', |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', views.dds_conf, name='url_dds_conf'), | |
5 |
url(r'^(?P<id_conf>-?\d+)/(?P<message>-?\d+)/$', |
|
7 | url(r'^(?P<id_conf>-?\d+)/(?P<message>-?\d+)/$', views.dds_conf, name='url_dds_conf'), | |
6 |
url(r'^(?P<id_conf>-?\d+)/edit/$', |
|
8 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.dds_conf_edit, name='url_edit_dds_conf'), | |
7 | # url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.dds.views.dds_conf_write', name='url_write_dds_conf'), |
|
|||
8 | # url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.dds.views.dds_conf_read', name='url_read_dds_conf'), |
|
|||
9 | # url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.dds.views.dds_conf_import', name='url_import_dds_conf'), |
|
|||
10 | # url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.dds.views.dds_conf_export', name='url_export_dds_conf'), |
|
|||
11 | # url(r'^(?P<id_conf>-?\d+)/start/$', 'apps.dds.views.dds_conf_start', name='url_start_dds_conf'), |
|
|||
12 | # url(r'^(?P<id_conf>-?\d+)/stop/$', 'apps.dds.views.dds_conf_stop', name='url_stop_dds_conf'), |
|
|||
13 | # url(r'^(?P<id_conf>-?\d+)/status/$', 'apps.dds.views.dds_conf_status', name='url_status_dds_conf'), |
|
|||
14 | ) |
|
9 | ) |
@@ -1,2 +1,2 | |||||
1 |
[{"fields": {"name": "49_920MHz_clock60MHz_F0MHz_12_25_2", "clock": "60", "mult": 5, "fch": 49.92, "fch_decimal": 721554505, "filter_fir": 6, "filter_2": 10, "filter_5": 1, "speed": 0}, "model": "jars.jarsfilter", "pk": 1} |
|
1 | [{"fields": {"name": "49_920MHz_clock60MHz_F0MHz_12_25_2", "clock": "60", "mult": 5, "fch": 49.92, "fch_decimal": 721554505, "filter_fir": 6, "filter_2": 10, "filter_5": 1, "speed": 0}, "model": "jars.jarsfilter", "pk": 1} | |
2 | ] No newline at end of file |
|
2 | ] |
@@ -20,9 +20,9 DATA_TYPE = ( | |||||
20 | ) |
|
20 | ) | |
21 |
|
21 | |||
22 | class JARSfilter(models.Model): |
|
22 | class JARSfilter(models.Model): | |
23 |
|
23 | |||
24 | JARS_NBITS = 32 |
|
24 | JARS_NBITS = 32 | |
25 |
|
25 | |||
26 | name = models.CharField(max_length=60, unique=True, default='') |
|
26 | name = models.CharField(max_length=60, unique=True, default='') | |
27 | clock = models.FloatField(verbose_name='Clock In (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) |
|
27 | clock = models.FloatField(verbose_name='Clock In (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) | |
28 | mult = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=5) |
|
28 | mult = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=5) | |
@@ -32,17 +32,17 class JARSfilter(models.Model): | |||||
32 | filter_2 = models.PositiveIntegerField(verbose_name='Filter 2',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 10) |
|
32 | filter_2 = models.PositiveIntegerField(verbose_name='Filter 2',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 10) | |
33 | filter_5 = models.PositiveIntegerField(verbose_name='Filter 5',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) |
|
33 | filter_5 = models.PositiveIntegerField(verbose_name='Filter 5',validators=[MinValueValidator(1), MaxValueValidator(20)], default = 1) | |
34 | speed = models.PositiveIntegerField(verbose_name='Speed',validators=[MinValueValidator(0), MaxValueValidator(100000)], default = 0) |
|
34 | speed = models.PositiveIntegerField(verbose_name='Speed',validators=[MinValueValidator(0), MaxValueValidator(100000)], default = 0) | |
35 |
|
35 | |||
36 | class Meta: |
|
36 | class Meta: | |
37 | db_table = 'jars_filters' |
|
37 | db_table = 'jars_filters' | |
38 |
|
38 | |||
39 | def __unicode__(self): |
|
39 | def __unicode__(self): | |
40 | return u'%s' % (self.name) |
|
40 | return u'%s' % (self.name) | |
41 |
|
41 | |||
42 | def parms_to_dict(self): |
|
42 | def parms_to_dict(self): | |
43 |
|
43 | |||
44 | parameters = {} |
|
44 | parameters = {} | |
45 |
|
45 | |||
46 | parameters['name'] = self.name |
|
46 | parameters['name'] = self.name | |
47 | parameters['clock'] = float(self.clock) |
|
47 | parameters['clock'] = float(self.clock) | |
48 | parameters['mult'] = int(self.mult) |
|
48 | parameters['mult'] = int(self.mult) | |
@@ -52,11 +52,11 class JARSfilter(models.Model): | |||||
52 | parameters['filter_2'] = int(self.filter_2) |
|
52 | parameters['filter_2'] = int(self.filter_2) | |
53 | parameters['filter_5'] = int(self.filter_5) |
|
53 | parameters['filter_5'] = int(self.filter_5) | |
54 | parameters['speed'] = int(self.speed) |
|
54 | parameters['speed'] = int(self.speed) | |
55 |
|
55 | |||
56 | return parameters |
|
56 | return parameters | |
57 |
|
57 | |||
58 | def dict_to_parms(self, parameters): |
|
58 | def dict_to_parms(self, parameters): | |
59 |
|
59 | |||
60 | self.name = parameters['name'] |
|
60 | self.name = parameters['name'] | |
61 | self.clock = parameters['clock'] |
|
61 | self.clock = parameters['clock'] | |
62 | self.mult = parameters['mult'] |
|
62 | self.mult = parameters['mult'] | |
@@ -66,16 +66,16 class JARSfilter(models.Model): | |||||
66 | self.filter_2 = parameters['filter_2'] |
|
66 | self.filter_2 = parameters['filter_2'] | |
67 | self.filter_5 = parameters['filter_5'] |
|
67 | self.filter_5 = parameters['filter_5'] | |
68 | self.speed = parameters['speed'] |
|
68 | self.speed = parameters['speed'] | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | class JARSConfiguration(Configuration): |
|
71 | class JARSConfiguration(Configuration): | |
72 |
|
72 | |||
73 | ADC_RESOLUTION = 8 |
|
73 | ADC_RESOLUTION = 8 | |
74 | PCI_DIO_BUSWIDTH = 32 |
|
74 | PCI_DIO_BUSWIDTH = 32 | |
75 | HEADER_VERSION = 1103 |
|
75 | HEADER_VERSION = 1103 | |
76 | BEGIN_ON_START = True |
|
76 | BEGIN_ON_START = True | |
77 | REFRESH_RATE = 1 |
|
77 | REFRESH_RATE = 1 | |
78 |
|
78 | |||
79 | #rc = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE, null=True) |
|
79 | #rc = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE, null=True) | |
80 | exp_type = models.PositiveIntegerField(verbose_name='Experiment Type', choices=EXPERIMENT_TYPE, default=0) |
|
80 | exp_type = models.PositiveIntegerField(verbose_name='Experiment Type', choices=EXPERIMENT_TYPE, default=0) | |
81 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) |
|
81 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) | |
@@ -105,11 +105,11 class JARSConfiguration(Configuration): | |||||
105 |
|
105 | |||
106 | class Meta: |
|
106 | class Meta: | |
107 | db_table = 'jars_configurations' |
|
107 | db_table = 'jars_configurations' | |
108 |
|
108 | |||
109 | def parms_to_dict(self): |
|
109 | def parms_to_dict(self): | |
110 |
|
110 | |||
111 | parameters = {} |
|
111 | parameters = {} | |
112 |
|
112 | |||
113 | parameters['device_id'] = self.device.id |
|
113 | parameters['device_id'] = self.device.id | |
114 | parameters['name'] = self.name |
|
114 | parameters['name'] = self.name | |
115 | #parameters['rc'] = self.rc.name |
|
115 | #parameters['rc'] = self.rc.name | |
@@ -138,31 +138,31 class JARSConfiguration(Configuration): | |||||
138 | #parameters['view_raw_data'] = bool(self.view_raw_data) |
|
138 | #parameters['view_raw_data'] = bool(self.view_raw_data) | |
139 | parameters['save_ch_dc'] = bool(self.save_ch_dc) |
|
139 | parameters['save_ch_dc'] = bool(self.save_ch_dc) | |
140 | parameters['save_data'] = bool(self.save_data) |
|
140 | parameters['save_data'] = bool(self.save_data) | |
141 |
|
141 | |||
142 | if parameters['exptype'] == 'PDATA': |
|
142 | if parameters['exptype'] == 'PDATA': | |
143 | parameters['incohe_integr'] = self.incohe_integr |
|
143 | parameters['incohe_integr'] = self.incohe_integr | |
144 | parameters['spectral_number'] = self.spectral_number |
|
144 | parameters['spectral_number'] = self.spectral_number | |
145 | parameters['spectral'] = self.spectral |
|
145 | parameters['spectral'] = self.spectral | |
146 | parameters['pd_directory'] = self.pd_directory |
|
146 | parameters['pd_directory'] = self.pd_directory | |
147 |
|
147 | |||
148 | return parameters |
|
148 | return parameters | |
149 |
|
149 | |||
150 | def add_parms_to_filter(self): |
|
150 | def add_parms_to_filter(self): | |
151 | self.filter_parms = self.filter.parms_to_dict() |
|
151 | self.filter_parms = self.filter.parms_to_dict() | |
152 | self.save() |
|
152 | self.save() | |
153 |
|
153 | |||
154 | def dict_to_parms(self, parameters): |
|
154 | def dict_to_parms(self, parameters): | |
155 |
|
155 | |||
156 | self.name = parameters['name'] |
|
156 | self.name = parameters['name'] | |
157 | self.device.id = int(parameters['device_id']) |
|
157 | self.device.id = int(parameters['device_id']) | |
158 |
|
158 | |||
159 | self.exp_type = int(parameters['exp_type']) |
|
159 | self.exp_type = int(parameters['exp_type']) | |
160 |
if parameters['exptype'] == 'PDATA': |
|
160 | if parameters['exptype'] == 'PDATA': | |
161 | self.incohe_integr = parameters['incohe_integr'] |
|
161 | self.incohe_integr = parameters['incohe_integr'] | |
162 | self.spectral_number = parameters['spectral_number'] |
|
162 | self.spectral_number = parameters['spectral_number'] | |
163 | self.spectral = parameters['spectral'] |
|
163 | self.spectral = parameters['spectral'] | |
164 | self.pd_directory = parameters['pd_directory'] |
|
164 | self.pd_directory = parameters['pd_directory'] | |
165 |
|
165 | |||
166 | self.cards_number = int(parameters['cards_number']) |
|
166 | self.cards_number = int(parameters['cards_number']) | |
167 | self.channels_number = int(parameters['channels_number']) |
|
167 | self.channels_number = int(parameters['channels_number']) | |
168 | self.channels = parameters['channels'] |
|
168 | self.channels = parameters['channels'] | |
@@ -175,39 +175,39 class JARSConfiguration(Configuration): | |||||
175 | self.ftp_interval = parameters['ftp_interval'] |
|
175 | self.ftp_interval = parameters['ftp_interval'] | |
176 | self.fftpoints = parameters['fftpoints'] |
|
176 | self.fftpoints = parameters['fftpoints'] | |
177 | self.cohe_integr = parameters['cohe_integr'] |
|
177 | self.cohe_integr = parameters['cohe_integr'] | |
178 |
|
178 | |||
179 | filter_name = parameters['filter'] |
|
179 | filter_name = parameters['filter'] | |
180 | self.filter = JARSfilter.objects.get(name=filter_name) |
|
180 | self.filter = JARSfilter.objects.get(name=filter_name) | |
181 | self.add_parms_to_filter() |
|
181 | self.add_parms_to_filter() | |
182 | self.filter_parms = parameters['filter_parms'] |
|
182 | self.filter_parms = parameters['filter_parms'] | |
183 |
|
183 | |||
184 | self.create_directory = bool(parameters['create_directory']) |
|
184 | self.create_directory = bool(parameters['create_directory']) | |
185 | self.include_expname = bool(parameters['include_expname']) |
|
185 | self.include_expname = bool(parameters['include_expname']) | |
186 | #self.acq_link = bool(parameters['acq_link']) |
|
186 | #self.acq_link = bool(parameters['acq_link']) | |
187 | #self.view_raw_data = bool(parameters['view_raw_data']) |
|
187 | #self.view_raw_data = bool(parameters['view_raw_data']) | |
188 | self.save_ch_dc = bool(parameters['save_ch_dc']) |
|
188 | self.save_ch_dc = bool(parameters['save_ch_dc']) | |
189 | self.save_data = bool(parameters['save_data']) |
|
189 | self.save_data = bool(parameters['save_data']) | |
190 |
|
190 | |||
191 | def status_device(self): |
|
191 | def status_device(self): | |
192 |
|
192 | |||
193 | answer = api.status(self.device.ip_address,self.device.port_address) |
|
193 | answer = api.status(self.device.ip_address,self.device.port_address) | |
194 | self.device.status = int(answer[0]) |
|
194 | self.device.status = int(answer[0]) | |
195 | self.message = answer[2:] |
|
195 | self.message = answer[2:] | |
196 | self.device.save() |
|
196 | self.device.save() | |
197 |
|
197 | |||
198 | return self.device.status |
|
198 | return self.device.status | |
199 |
|
199 | |||
200 | def stop_device(self): |
|
200 | def stop_device(self): | |
201 |
|
201 | |||
202 | answer = api.stop(self.device.ip_address,self.device.port_address) |
|
202 | answer = api.stop(self.device.ip_address,self.device.port_address) | |
203 | self.device.status = int(answer[0]) |
|
203 | self.device.status = int(answer[0]) | |
204 | self.message = answer[2:] |
|
204 | self.message = answer[2:] | |
205 | self.device.save() |
|
205 | self.device.save() | |
206 |
|
206 | |||
207 | return self.device.status |
|
207 | return self.device.status | |
208 |
|
208 | |||
209 | def read_device(self): |
|
209 | def read_device(self): | |
210 |
|
210 | |||
211 | answer = api.read(self.device.ip_address,self.device.port_address) |
|
211 | answer = api.read(self.device.ip_address,self.device.port_address) | |
212 | self.device.status = int(answer[0]) |
|
212 | self.device.status = int(answer[0]) | |
213 | try: |
|
213 | try: | |
@@ -218,15 +218,15 class JARSConfiguration(Configuration): | |||||
218 | self.device.save() |
|
218 | self.device.save() | |
219 | self.message = 'Could not read JARS configuration.' |
|
219 | self.message = 'Could not read JARS configuration.' | |
220 | return '' |
|
220 | return '' | |
221 |
|
221 | |||
222 | #self.dict_to_parms(parms) |
|
222 | #self.dict_to_parms(parms) | |
223 | self.message = 'Current JARS configuration was read successfully.' |
|
223 | self.message = 'Current JARS configuration was read successfully.' | |
224 | self.device.save() |
|
224 | self.device.save() | |
225 | return parms |
|
225 | return parms | |
226 |
|
226 | |||
227 |
|
227 | |||
228 | def write_device(self): |
|
228 | def write_device(self): | |
229 |
|
229 | |||
230 | data = self.experiment.parms_to_dict() |
|
230 | data = self.experiment.parms_to_dict() | |
231 | data = json.loads(data) |
|
231 | data = json.loads(data) | |
232 | data['configurations']['dds'] ='' |
|
232 | data['configurations']['dds'] ='' | |
@@ -234,40 +234,40 class JARSConfiguration(Configuration): | |||||
234 | data['configurations']['rc']['pulses']='' |
|
234 | data['configurations']['rc']['pulses']='' | |
235 | data['configurations']['rc']['delays']='' |
|
235 | data['configurations']['rc']['delays']='' | |
236 | json_data = json.dumps(data) |
|
236 | json_data = json.dumps(data) | |
237 |
|
237 | |||
238 | answer = api.configure(self.device.ip_address,self.device.port_address,json_data) |
|
238 | answer = api.configure(self.device.ip_address,self.device.port_address,json_data) | |
239 | #print answer |
|
239 | #print answer | |
240 | self.device.status = int(answer[0]) |
|
240 | self.device.status = int(answer[0]) | |
241 | self.message = answer[2:] |
|
241 | self.message = answer[2:] | |
242 |
|
242 | |||
243 | self.device.save() |
|
243 | self.device.save() | |
244 |
|
244 | |||
245 | return self.device.status |
|
245 | return self.device.status | |
246 |
|
246 | |||
247 |
|
247 | |||
248 | def start_device(self): |
|
248 | def start_device(self): | |
249 |
|
249 | |||
250 | self.write_device() |
|
250 | self.write_device() | |
251 |
|
251 | |||
252 |
|
252 | |||
253 | def echo(self): |
|
253 | def echo(self): | |
254 |
|
254 | |||
255 | answer = api.echo(self.device.ip_address,self.device.port_address,'(=') |
|
255 | answer = api.echo(self.device.ip_address,self.device.port_address,'(=') | |
256 | #print answer |
|
256 | #print answer | |
257 | self.device.status = int(answer[0]) |
|
257 | self.device.status = int(answer[0]) | |
258 | self.message = answer[2:] |
|
258 | self.message = answer[2:] | |
259 |
|
259 | |||
260 | self.device.save() |
|
260 | self.device.save() | |
261 |
|
261 | |||
262 | return #self.device.status |
|
262 | return #self.device.status | |
263 |
|
263 | |||
264 | def update_from_file(self, parameters): |
|
264 | def update_from_file(self, parameters): | |
265 |
|
265 | |||
266 | self.dict_to_parms(parameters) |
|
266 | self.dict_to_parms(parameters) | |
267 | self.save() |
|
267 | self.save() | |
268 |
|
268 | |||
269 | def get_absolute_url_import(self): |
|
269 | def get_absolute_url_import(self): | |
270 | return reverse('url_import_jars_conf', args=[str(self.id)]) |
|
270 | return reverse('url_import_jars_conf', args=[str(self.id)]) | |
271 |
|
271 | |||
272 | def get_absolute_url_read(self): |
|
272 | def get_absolute_url_read(self): | |
273 | return reverse('url_read_jars_conf', args=[str(self.id)]) No newline at end of file |
|
273 | return reverse('url_read_jars_conf', args=[str(self.id)]) |
@@ -1,11 +1,13 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
|
3 | from apps.jars import views | |||
|
4 | ||||
3 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
4 |
url(r'^(?P<id_conf>-?\d+)/$', |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', views.jars_conf, name='url_jars_conf'), | |
5 |
url(r'^(?P<id_conf>-?\d+)/edit/$', |
|
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.jars_conf_edit, name='url_edit_jars_conf'), | |
6 |
url(r'^(?P<conf_id>-?\d+)/new_filter/$', |
|
8 | url(r'^(?P<conf_id>-?\d+)/new_filter/$', views.new_filter, name='url_new_jars_filter'), | |
7 |
url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/$', |
|
9 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/$', views.view_filter, name='url_jars_filter'), | |
8 |
url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/edit$', |
|
10 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/edit$', views.edit_filter, name='url_edit_jars_filter'), | |
9 |
url(r'^(?P<conf_id>-?\d+)/import/$', |
|
11 | url(r'^(?P<conf_id>-?\d+)/import/$', views.import_file, name='url_import_jars_conf'), | |
10 |
url(r'^(?P<conf_id>-?\d+)/read/$', |
|
12 | url(r'^(?P<conf_id>-?\d+)/read/$', views.read_conf, name='url_read_jars_conf'), | |
11 | ) |
|
13 | ) |
@@ -5,14 +5,13 from itertools import chain | |||||
5 |
|
5 | |||
6 | from django import forms |
|
6 | from django import forms | |
7 | from django.utils.safestring import mark_safe |
|
7 | from django.utils.safestring import mark_safe | |
8 | from django.utils.encoding import force_unicode |
|
|||
9 | from django.utils.html import conditional_escape |
|
8 | from django.utils.html import conditional_escape | |
10 |
|
9 | |||
11 |
|
10 | |||
12 | class SpectralWidget(forms.widgets.TextInput): |
|
11 | class SpectralWidget(forms.widgets.TextInput): | |
13 |
|
12 | |||
14 | def render(self, label, value, attrs=None): |
|
13 | def render(self, label, value, attrs=None): | |
15 |
|
14 | |||
16 | disabled = 'disabled' if attrs.get('disabled', False) else '' |
|
15 | disabled = 'disabled' if attrs.get('disabled', False) else '' | |
17 | name = attrs.get('name', label) |
|
16 | name = attrs.get('name', label) | |
18 | if '[' in value: |
|
17 | if '[' in value: | |
@@ -21,7 +20,7 class SpectralWidget(forms.widgets.TextInput): | |||||
21 | else: |
|
20 | else: | |
22 | value = value + "," |
|
21 | value = value + "," | |
23 | value = ast.literal_eval(value) |
|
22 | value = ast.literal_eval(value) | |
24 |
|
23 | |||
25 | codes = value |
|
24 | codes = value | |
26 | if not isinstance(value, list): |
|
25 | if not isinstance(value, list): | |
27 | text='' |
|
26 | text='' | |
@@ -33,7 +32,7 class SpectralWidget(forms.widgets.TextInput): | |||||
33 | codes=text |
|
32 | codes=text | |
34 | else: |
|
33 | else: | |
35 | codes='' |
|
34 | codes='' | |
36 |
|
35 | |||
37 | html = '''<textarea rows="5" {0} class="form-control" id="id_{1}" name="{2}" style="white-space:nowrap; overflow:scroll;">{3}</textarea> |
|
36 | html = '''<textarea rows="5" {0} class="form-control" id="id_{1}" name="{2}" style="white-space:nowrap; overflow:scroll;">{3}</textarea> | |
38 | <input type="text" class="col-md-1 col-no-padding" id="num1" value=0> |
|
37 | <input type="text" class="col-md-1 col-no-padding" id="num1" value=0> | |
39 | <input type="text" class="col-md-1 col-no-padding" id="num2" value=0> |
|
38 | <input type="text" class="col-md-1 col-no-padding" id="num2" value=0> | |
@@ -43,23 +42,23 class SpectralWidget(forms.widgets.TextInput): | |||||
43 | <button type="button" class="button pull-right" id="self_spectral_button"> Self </button> |
|
42 | <button type="button" class="button pull-right" id="self_spectral_button"> Self </button> | |
44 | <button type="button" class="button pull-right" id="all_spectral_button"> All </button> |
|
43 | <button type="button" class="button pull-right" id="all_spectral_button"> All </button> | |
45 | '''.format(disabled, label, name, codes) |
|
44 | '''.format(disabled, label, name, codes) | |
46 |
|
45 | |||
47 | script = ''' |
|
46 | script = ''' | |
48 |
<script type="text/javascript"> |
|
47 | <script type="text/javascript"> | |
49 | $(document).ready(function () {{ |
|
48 | $(document).ready(function () {{ | |
50 |
|
49 | |||
51 | var spectral_number1 = $("#num1").val(); |
|
50 | var spectral_number1 = $("#num1").val(); | |
52 | var spectral_number2 = $("#num2").val(); |
|
51 | var spectral_number2 = $("#num2").val(); | |
53 |
|
52 | |||
54 |
|
53 | |||
55 | $("#all_spectral_button").click(function(){{ |
|
54 | $("#all_spectral_button").click(function(){{ | |
56 | var sequence1 = selfSpectral() |
|
55 | var sequence1 = selfSpectral() | |
57 | var sequence2 = crossSpectral() |
|
56 | var sequence2 = crossSpectral() | |
58 | $("#id_spectral").val(sequence1+sequence2) |
|
57 | $("#id_spectral").val(sequence1+sequence2) | |
59 | updateSpectralNumber() |
|
58 | updateSpectralNumber() | |
60 | }}); |
|
59 | }}); | |
61 |
|
60 | |||
62 |
|
61 | |||
63 | $("#add_spectral_button").click(function(){{ |
|
62 | $("#add_spectral_button").click(function(){{ | |
64 | var spectral_comb = $("#id_spectral").val(); |
|
63 | var spectral_comb = $("#id_spectral").val(); | |
65 | var spectral_number1 = $("#num1").val(); |
|
64 | var spectral_number1 = $("#num1").val(); | |
@@ -68,27 +67,27 class SpectralWidget(forms.widgets.TextInput): | |||||
68 | //not to duplicate |
|
67 | //not to duplicate | |
69 | var n = spectral_comb.search(str); |
|
68 | var n = spectral_comb.search(str); | |
70 | if (n==-1){ |
|
69 | if (n==-1){ | |
71 |
$("#id_spectral").val(spectral_comb+"["+$("#num1").val()+", "+$("#num2").val()+"],") |
|
70 | $("#id_spectral").val(spectral_comb+"["+$("#num1").val()+", "+$("#num2").val()+"],") | |
72 | } |
|
71 | } | |
73 |
updateSpectralNumber() |
|
72 | updateSpectralNumber() | |
74 | }}); |
|
73 | }}); | |
75 |
|
74 | |||
76 |
|
75 | |||
77 | $("#self_spectral_button").click(function(){{ |
|
76 | $("#self_spectral_button").click(function(){{ | |
78 | var sequence = selfSpectral() |
|
77 | var sequence = selfSpectral() | |
79 | $("#id_spectral").val(sequence) |
|
78 | $("#id_spectral").val(sequence) | |
80 |
|
79 | |||
81 | updateSpectralNumber() |
|
80 | updateSpectralNumber() | |
82 | }}); |
|
81 | }}); | |
83 |
|
82 | |||
84 | $("#cross_spectral_button").click(function(){{ |
|
83 | $("#cross_spectral_button").click(function(){{ | |
85 | var sequence = crossSpectral() |
|
84 | var sequence = crossSpectral() | |
86 | $("#id_spectral").val(sequence) |
|
85 | $("#id_spectral").val(sequence) | |
87 |
|
86 | |||
88 | updateSpectralNumber() |
|
87 | updateSpectralNumber() | |
89 | }}); |
|
88 | }}); | |
90 |
|
89 | |||
91 |
|
90 | |||
92 | function selfSpectral() { |
|
91 | function selfSpectral() { | |
93 | var channels = $("#id_channels").val(); |
|
92 | var channels = $("#id_channels").val(); | |
94 | var n = (channels.length)-1; |
|
93 | var n = (channels.length)-1; | |
@@ -99,8 +98,8 class SpectralWidget(forms.widgets.TextInput): | |||||
99 | } |
|
98 | } | |
100 | return sequence |
|
99 | return sequence | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 |
|
102 | |||
104 | function crossSpectral() { |
|
103 | function crossSpectral() { | |
105 | var channels = $("#id_channels").val(); |
|
104 | var channels = $("#id_channels").val(); | |
106 | var n = (channels.length)-1; |
|
105 | var n = (channels.length)-1; | |
@@ -113,8 +112,8 class SpectralWidget(forms.widgets.TextInput): | |||||
113 | } |
|
112 | } | |
114 | return sequence |
|
113 | return sequence | |
115 | } |
|
114 | } | |
116 |
|
115 | |||
117 |
|
116 | |||
118 | function updateSpectralNumber(){ |
|
117 | function updateSpectralNumber(){ | |
119 | var spectral_comb = $("#id_spectral").val(); |
|
118 | var spectral_comb = $("#id_spectral").val(); | |
120 | var num = spectral_comb.length; |
|
119 | var num = spectral_comb.length; | |
@@ -126,8 +125,8 class SpectralWidget(forms.widgets.TextInput): | |||||
126 | } |
|
125 | } | |
127 | $("#id_spectral_number").val(cont) |
|
126 | $("#id_spectral_number").val(cont) | |
128 | } |
|
127 | } | |
129 |
|
128 | |||
130 |
|
129 | |||
131 | $("#delete_spectral_button").click(function(){{ |
|
130 | $("#delete_spectral_button").click(function(){{ | |
132 | var spectral_comb = $("#id_spectral").val(); |
|
131 | var spectral_comb = $("#id_spectral").val(); | |
133 | var spectral_number1 = $("#num1").val(); |
|
132 | var spectral_number1 = $("#num1").val(); | |
@@ -135,7 +134,7 class SpectralWidget(forms.widgets.TextInput): | |||||
135 | var str = spectral_number1+", "+spectral_number2; |
|
134 | var str = spectral_number1+", "+spectral_number2; | |
136 | var n = spectral_comb.search(str); |
|
135 | var n = spectral_comb.search(str); | |
137 | if (n==-1){ |
|
136 | if (n==-1){ | |
138 |
|
137 | |||
139 | } |
|
138 | } | |
140 | else { |
|
139 | else { | |
141 | n= spectral_comb.length; |
|
140 | n= spectral_comb.length; | |
@@ -148,17 +147,17 class SpectralWidget(forms.widgets.TextInput): | |||||
148 | var txt = spectral_comb.replace(tuple,''); |
|
147 | var txt = spectral_comb.replace(tuple,''); | |
149 | } |
|
148 | } | |
150 | $("#id_spectral").val(txt) |
|
149 | $("#id_spectral").val(txt) | |
151 |
|
150 | |||
152 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," |
|
151 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |
153 | var txt = spectral_comb.replace(tuple,''); |
|
152 | var txt = spectral_comb.replace(tuple,''); | |
154 | $("#id_spectral").val(txt) |
|
153 | $("#id_spectral").val(txt) | |
155 | } |
|
154 | } | |
156 |
updateSpectralNumber() |
|
155 | updateSpectralNumber() | |
157 | }}); |
|
156 | }}); | |
158 |
|
157 | |||
159 |
|
158 | |||
160 | }}); |
|
159 | }}); | |
161 | </script> |
|
160 | </script> | |
162 | ''' |
|
161 | ''' | |
163 |
|
162 | |||
164 | return mark_safe(html+script) No newline at end of file |
|
163 | return mark_safe(html+script) |
@@ -1,10 +1,11 | |||||
1 | [ |
|
1 | [ | |
2 |
{"fields": {"name": "JRO |
|
2 | {"fields": {"name": "JRO", "description": ""}, "model": "main.location", "pk": 1}, | |
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, |
|
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, | |
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, |
|
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, | |
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, |
|
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, | |
6 |
{"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, |
|
6 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, | |
7 |
{"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, |
|
7 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, | |
8 |
{"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, |
|
8 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, | |
9 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4} |
|
9 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4}, | |
|
10 | {"fields": {"name": "abs", "description": ""}, "model": "main.devicetype", "pk": 5} | |||
10 | ] |
|
11 | ] |
@@ -1,7 +1,7 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | from .models import Device, Experiment, Campaign, Location | ||
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
4 | from apps.main.models import Configuration | |
5 |
|
5 | |||
6 | FILE_FORMAT = ( |
|
6 | FILE_FORMAT = ( | |
7 | ('json', 'json'), |
|
7 | ('json', 'json'), | |
@@ -35,7 +35,7 class DatepickerWidget(forms.widgets.TextInput): | |||||
35 | class DateRangepickerWidget(forms.widgets.TextInput): |
|
35 | class DateRangepickerWidget(forms.widgets.TextInput): | |
36 | def render(self, name, value, attrs=None): |
|
36 | def render(self, name, value, attrs=None): | |
37 | start = attrs['start_date'] |
|
37 | start = attrs['start_date'] | |
38 |
end = attrs['end_date'] |
|
38 | end = attrs['end_date'] | |
39 | html = '''<div class="col-md-5 input-group date" style="float:inherit"> |
|
39 | html = '''<div class="col-md-5 input-group date" style="float:inherit"> | |
40 | <input class="form-control" id="id_start_date" name="start_date" placeholder="Start" title="" type="text" value="{}"> |
|
40 | <input class="form-control" id="id_start_date" name="start_date" placeholder="Start" title="" type="text" value="{}"> | |
41 | <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> |
|
41 | <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> | |
@@ -53,32 +53,32 class TimepickerWidget(forms.widgets.TextInput): | |||||
53 | return mark_safe(html) |
|
53 | return mark_safe(html) | |
54 |
|
54 | |||
55 | class CampaignForm(forms.ModelForm): |
|
55 | class CampaignForm(forms.ModelForm): | |
56 |
|
56 | |||
57 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), |
|
57 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), | |
58 | queryset=Experiment.objects.filter(template=True), |
|
58 | queryset=Experiment.objects.filter(template=True), | |
59 | required=False) |
|
59 | required=False) | |
60 |
|
60 | |||
61 | def __init__(self, *args, **kwargs): |
|
61 | def __init__(self, *args, **kwargs): | |
62 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
62 | super(CampaignForm, self).__init__(*args, **kwargs) | |
63 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
63 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) | |
64 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
64 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
65 | self.fields['description'].widget.attrs = {'rows': 2} |
|
65 | self.fields['description'].widget.attrs = {'rows': 2} | |
66 |
|
66 | |||
67 | if self.instance.pk: |
|
67 | if self.instance.pk: | |
68 | self.fields['experiments'].queryset |= self.instance.experiments.all() |
|
68 | self.fields['experiments'].queryset |= self.instance.experiments.all() | |
69 |
|
69 | |||
70 | class Meta: |
|
70 | class Meta: | |
71 | model = Campaign |
|
71 | model = Campaign | |
72 | exclude = [''] |
|
72 | exclude = [''] | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | class ExperimentForm(forms.ModelForm): |
|
75 | class ExperimentForm(forms.ModelForm): | |
76 |
|
76 | |||
77 | def __init__(self, *args, **kwargs): |
|
77 | def __init__(self, *args, **kwargs): | |
78 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
78 | super(ExperimentForm, self).__init__(*args, **kwargs) | |
79 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
79 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
80 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
80 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
81 |
|
81 | |||
82 | class Meta: |
|
82 | class Meta: | |
83 | model = Experiment |
|
83 | model = Experiment | |
84 | exclude = ['status'] |
|
84 | exclude = ['status'] | |
@@ -87,104 +87,96 class LocationForm(forms.ModelForm): | |||||
87 | class Meta: |
|
87 | class Meta: | |
88 | model = Location |
|
88 | model = Location | |
89 | exclude = [''] |
|
89 | exclude = [''] | |
90 |
|
90 | |||
91 | class DeviceForm(forms.ModelForm): |
|
91 | class DeviceForm(forms.ModelForm): | |
92 | class Meta: |
|
92 | class Meta: | |
93 | model = Device |
|
93 | model = Device | |
94 | exclude = ['status'] |
|
94 | exclude = ['status'] | |
95 |
|
95 | |||
96 | class ConfigurationForm(forms.ModelForm): |
|
96 | class ConfigurationForm(forms.ModelForm): | |
97 |
|
97 | |||
98 | def __init__(self, *args, **kwargs): |
|
98 | def __init__(self, *args, **kwargs): | |
99 | super(ConfigurationForm, self).__init__(*args, **kwargs) |
|
99 | super(ConfigurationForm, self).__init__(*args, **kwargs) | |
100 |
|
100 | |||
101 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): |
|
101 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): | |
102 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' |
|
102 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |
103 |
|
103 | |||
104 | class Meta: |
|
104 | class Meta: | |
105 | model = Configuration |
|
105 | model = Configuration | |
106 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
106 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
107 |
|
107 | |||
108 | class DeviceTypeForm(forms.Form): |
|
108 | #class DeviceTypeForm(forms.Form): | |
109 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
109 | # device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) | |
110 |
|
110 | |||
111 |
|
111 | |||
112 | class UploadFileForm(forms.Form): |
|
112 | class UploadFileForm(forms.Form): | |
113 |
|
113 | |||
114 | file = forms.FileField() |
|
114 | file = forms.FileField() | |
115 |
|
115 | |||
116 | class DownloadFileForm(forms.Form): |
|
116 | class DownloadFileForm(forms.Form): | |
117 |
|
117 | |||
118 | format = forms.ChoiceField(choices= ((0, 'json'),) ) |
|
118 | format = forms.ChoiceField(choices= ((0, 'json'),) ) | |
119 |
|
119 | |||
120 | def __init__(self, device_type, *args, **kwargs): |
|
120 | def __init__(self, device_type, *args, **kwargs): | |
121 |
|
121 | |||
122 | super(DownloadFileForm, self).__init__(*args, **kwargs) |
|
122 | super(DownloadFileForm, self).__init__(*args, **kwargs) | |
123 |
|
123 | |||
124 | self.fields['format'].choices = FILE_FORMAT |
|
124 | self.fields['format'].choices = FILE_FORMAT | |
125 |
|
125 | |||
126 | if device_type == 'dds': |
|
126 | if device_type == 'dds': | |
127 | self.fields['format'].choices = DDS_FILE_FORMAT |
|
127 | self.fields['format'].choices = DDS_FILE_FORMAT | |
128 |
|
128 | |||
129 | if device_type == 'rc': |
|
129 | if device_type == 'rc': | |
130 | self.fields['format'].choices = RC_FILE_FORMAT |
|
130 | self.fields['format'].choices = RC_FILE_FORMAT | |
131 |
|
131 | |||
132 | class OperationForm(forms.Form): |
|
132 | class OperationForm(forms.Form): | |
133 | # today = datetime.today() |
|
133 | ||
134 | # -----Campaigns from this month------[:5] |
|
|||
135 | campaign = forms.ChoiceField(label="Campaign") |
|
134 | campaign = forms.ChoiceField(label="Campaign") | |
136 |
|
135 | |||
137 | def __init__(self, *args, **kwargs): |
|
136 | def __init__(self, *args, **kwargs): | |
138 |
|
137 | |||
139 | if 'length' not in kwargs.keys(): |
|
138 | campaigns = kwargs.pop('campaigns') | |
140 | length = None |
|
|||
141 | else: |
|
|||
142 | length = kwargs['length'] |
|
|||
143 |
|
||||
144 | kwargs.pop('length') |
|
|||
145 |
|
||||
146 | super(OperationForm, self).__init__(*args, **kwargs) |
|
139 | super(OperationForm, self).__init__(*args, **kwargs) | |
147 |
self.fields['campaign'].choices= |
|
140 | self.fields['campaign'].choices=add_empty_choice(campaigns.values_list('id', 'name')) | |
148 |
|
141 | |||
149 |
|
142 | |||
150 | class OperationSearchForm(forms.Form): |
|
143 | class OperationSearchForm(forms.Form): | |
151 | # -----ALL Campaigns------ |
|
144 | # -----ALL Campaigns------ | |
152 | campaign = forms.ChoiceField(label="Campaign") |
|
145 | campaign = forms.ChoiceField(label="Campaign") | |
153 |
|
146 | |||
154 | def __init__(self, *args, **kwargs): |
|
147 | def __init__(self, *args, **kwargs): | |
155 | super(OperationSearchForm, self).__init__(*args, **kwargs) |
|
148 | super(OperationSearchForm, self).__init__(*args, **kwargs) | |
156 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') |
|
149 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') | |
157 |
|
150 | |||
158 |
|
151 | |||
159 | class NewForm(forms.Form): |
|
152 | class NewForm(forms.Form): | |
160 |
|
153 | |||
161 | create_from = forms.ChoiceField(choices=((0, '-----'), |
|
154 | create_from = forms.ChoiceField(choices=((0, '-----'), | |
162 | (1, 'Empty (blank)'), |
|
155 | (1, 'Empty (blank)'), | |
163 | (2, 'Template'))) |
|
156 | (2, 'Template'))) | |
164 | choose_template = forms.ChoiceField() |
|
157 | choose_template = forms.ChoiceField() | |
165 |
|
158 | |||
166 | def __init__(self, *args, **kwargs): |
|
159 | def __init__(self, *args, **kwargs): | |
167 |
|
160 | |||
168 | template_choices = kwargs.pop('template_choices', []) |
|
161 | template_choices = kwargs.pop('template_choices', []) | |
169 | super(NewForm, self).__init__(*args, **kwargs) |
|
162 | super(NewForm, self).__init__(*args, **kwargs) | |
170 | self.fields['choose_template'].choices = add_empty_choice(template_choices) |
|
163 | self.fields['choose_template'].choices = add_empty_choice(template_choices) | |
171 |
|
164 | |||
172 |
|
165 | |||
173 | class FilterForm(forms.Form): |
|
166 | class FilterForm(forms.Form): | |
174 |
|
167 | |||
175 | def __init__(self, *args, **kwargs): |
|
168 | def __init__(self, *args, **kwargs): | |
176 | extra_fields = kwargs.pop('extra_fields', []) |
|
169 | extra_fields = kwargs.pop('extra_fields', []) | |
177 | super(FilterForm, self).__init__(*args, **kwargs) |
|
170 | super(FilterForm, self).__init__(*args, **kwargs) | |
178 |
|
171 | |||
179 |
for field in extra_fields: |
|
172 | for field in extra_fields: | |
180 | if 'range_date' in field: |
|
173 | if 'range_date' in field: | |
181 | self.fields[field] = forms.CharField(required=False) |
|
174 | self.fields[field] = forms.CharField(required=False) | |
182 | self.fields[field].widget = DateRangepickerWidget() |
|
175 | self.fields[field].widget = DateRangepickerWidget() | |
183 | if 'initial' in kwargs: |
|
176 | if 'initial' in kwargs: | |
184 | self.fields[field].widget.attrs = {'start_date':kwargs['initial'].get('start_date', ''), |
|
177 | self.fields[field].widget.attrs = {'start_date':kwargs['initial'].get('start_date', ''), | |
185 |
'end_date':kwargs['initial'].get('end_date', '')} |
|
178 | 'end_date':kwargs['initial'].get('end_date', '')} | |
186 | elif 'template' in field: |
|
179 | elif 'template' in field: | |
187 | self.fields['template'] = forms.BooleanField(required=False) |
|
180 | self.fields['template'] = forms.BooleanField(required=False) | |
188 | else: |
|
181 | else: | |
189 | self.fields[field] = forms.CharField(required=False) |
|
182 | self.fields[field] = forms.CharField(required=False) | |
190 | No newline at end of file |
|
@@ -2,7 +2,7 from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |||||
2 | from datetime import datetime |
|
2 | from datetime import datetime | |
3 |
|
3 | |||
4 | from django.db import models |
|
4 | from django.db import models | |
5 | from polymorphic import PolymorphicModel |
|
5 | from polymorphic.models import PolymorphicModel | |
6 |
|
6 | |||
7 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
8 |
|
8 | |||
@@ -71,7 +71,7 class Location(models.Model): | |||||
71 | class Meta: |
|
71 | class Meta: | |
72 | db_table = 'db_location' |
|
72 | db_table = 'db_location' | |
73 |
|
73 | |||
74 |
def __ |
|
74 | def __str__(self): | |
75 | return u'%s' % self.name |
|
75 | return u'%s' % self.name | |
76 |
|
76 | |||
77 | def get_absolute_url(self): |
|
77 | def get_absolute_url(self): | |
@@ -86,7 +86,7 class DeviceType(models.Model): | |||||
86 | class Meta: |
|
86 | class Meta: | |
87 | db_table = 'db_device_types' |
|
87 | db_table = 'db_device_types' | |
88 |
|
88 | |||
89 |
def __ |
|
89 | def __str__(self): | |
90 | return u'%s' % self.get_name_display() |
|
90 | return u'%s' % self.get_name_display() | |
91 |
|
91 | |||
92 | class Device(models.Model): |
|
92 | class Device(models.Model): | |
@@ -103,7 +103,7 class Device(models.Model): | |||||
103 | class Meta: |
|
103 | class Meta: | |
104 | db_table = 'db_devices' |
|
104 | db_table = 'db_devices' | |
105 |
|
105 | |||
106 |
def __ |
|
106 | def __str__(self): | |
107 | return u'[{}]: {}'.format(self.device_type.name.upper(), |
|
107 | return u'[{}]: {}'.format(self.device_type.name.upper(), | |
108 | self.name) |
|
108 | self.name) | |
109 |
|
109 | |||
@@ -142,13 +142,12 class Campaign(models.Model): | |||||
142 | db_table = 'db_campaigns' |
|
142 | db_table = 'db_campaigns' | |
143 | ordering = ('name',) |
|
143 | ordering = ('name',) | |
144 |
|
144 | |||
145 |
def __ |
|
145 | def __str__(self): | |
146 | if self.template: |
|
146 | if self.template: | |
147 | return u'{} (template)'.format(self.name) |
|
147 | return u'{} (template)'.format(self.name) | |
148 | else: |
|
148 | else: | |
149 | return u'{}'.format(self.name) |
|
149 | return u'{}'.format(self.name) | |
150 |
|
150 | |||
151 |
|
||||
152 | def parms_to_dict(self): |
|
151 | def parms_to_dict(self): | |
153 |
|
152 | |||
154 | import json |
|
153 | import json | |
@@ -166,7 +165,7 class Campaign(models.Model): | |||||
166 | parameters['experiments'] = exp_parameters |
|
165 | parameters['experiments'] = exp_parameters | |
167 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") |
|
166 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
168 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") |
|
167 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
169 |
parameters['campaign'] = self.__ |
|
168 | parameters['campaign'] = self.__str__() | |
170 | parameters['tags'] =self.tags |
|
169 | parameters['tags'] =self.tags | |
171 |
|
170 | |||
172 | parameters = json.dumps(parameters, indent=2, sort_keys=False) |
|
171 | parameters = json.dumps(parameters, indent=2, sort_keys=False) | |
@@ -182,7 +181,7 class Campaign(models.Model): | |||||
182 | path, ext = os.path.splitext(fp.name) |
|
181 | path, ext = os.path.splitext(fp.name) | |
183 |
|
182 | |||
184 | if ext == '.json': |
|
183 | if ext == '.json': | |
185 | parms = json.load(fp) |
|
184 | parms = json.loads(fp.read()) | |
186 |
|
185 | |||
187 | return parms |
|
186 | return parms | |
188 |
|
187 | |||
@@ -220,6 +219,19 class Campaign(models.Model): | |||||
220 |
|
219 | |||
221 | return self |
|
220 | return self | |
222 |
|
221 | |||
|
222 | def get_experiments_by_location(self): | |||
|
223 | ||||
|
224 | ret = [] | |||
|
225 | locations = set([e.location for e in self.experiments.all()]) | |||
|
226 | for loc in locations: | |||
|
227 | dum = {} | |||
|
228 | dum['name'] = loc.name | |||
|
229 | dum['id'] = loc.pk | |||
|
230 | dum['experiments'] = [e for e in self.experiments.all() if e.location==loc] | |||
|
231 | ret.append(dum) | |||
|
232 | ||||
|
233 | return ret | |||
|
234 | ||||
223 | def get_absolute_url(self): |
|
235 | def get_absolute_url(self): | |
224 | return reverse('url_campaign', args=[str(self.id)]) |
|
236 | return reverse('url_campaign', args=[str(self.id)]) | |
225 |
|
237 | |||
@@ -253,7 +265,7 class Experiment(models.Model): | |||||
253 | db_table = 'db_experiments' |
|
265 | db_table = 'db_experiments' | |
254 | ordering = ('template', 'name') |
|
266 | ordering = ('template', 'name') | |
255 |
|
267 | |||
256 |
def __ |
|
268 | def __str__(self): | |
257 | if self.template: |
|
269 | if self.template: | |
258 | return u'%s (template)' % (self.name) |
|
270 | return u'%s (template)' % (self.name) | |
259 | else: |
|
271 | else: | |
@@ -282,7 +294,6 class Experiment(models.Model): | |||||
282 | configurations = Configuration.objects.filter(experiment=self) |
|
294 | configurations = Configuration.objects.filter(experiment=self) | |
283 | exp_status=[] |
|
295 | exp_status=[] | |
284 | for conf in configurations: |
|
296 | for conf in configurations: | |
285 | print conf.status_device() |
|
|||
286 | exp_status.append(conf.status_device()) |
|
297 | exp_status.append(conf.status_device()) | |
287 |
|
298 | |||
288 | if not exp_status: #No Configuration |
|
299 | if not exp_status: #No Configuration | |
@@ -360,7 +371,7 class Experiment(models.Model): | |||||
360 | path, ext = os.path.splitext(fp.name) |
|
371 | path, ext = os.path.splitext(fp.name) | |
361 |
|
372 | |||
362 | if ext == '.json': |
|
373 | if ext == '.json': | |
363 | parms = json.load(fp) |
|
374 | parms = json.loads(fp.read().decode('utf-8')) | |
364 |
|
375 | |||
365 | return parms |
|
376 | return parms | |
366 |
|
377 | |||
@@ -460,11 +471,11 class Configuration(PolymorphicModel): | |||||
460 | class Meta: |
|
471 | class Meta: | |
461 | db_table = 'db_configurations' |
|
472 | db_table = 'db_configurations' | |
462 |
|
473 | |||
463 |
def __ |
|
474 | def __str__(self): | |
464 |
|
475 | |||
465 | device = '{}:'.format(self.device.device_type.name.upper()) |
|
476 | device = '{}:'.format(self.device.device_type.name.upper()) | |
466 |
|
477 | |||
467 |
if 'mix' in self._meta.get_ |
|
478 | if 'mix' in [f.name for f in self._meta.get_fields()]: | |
468 | if self.mix: |
|
479 | if self.mix: | |
469 | device = '{} MIXED:'.format(self.device.device_type.name.upper()) |
|
480 | device = '{} MIXED:'.format(self.device.device_type.name.upper()) | |
470 |
|
481 | |||
@@ -495,15 +506,13 class Configuration(PolymorphicModel): | |||||
495 |
|
506 | |||
496 | def parms_to_text(self): |
|
507 | def parms_to_text(self): | |
497 |
|
508 | |||
498 |
raise NotImplementedError |
|
509 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
499 |
|
510 | |||
500 | return '' |
|
|||
501 |
|
511 | |||
502 | def parms_to_binary(self): |
|
512 | def parms_to_binary(self): | |
503 |
|
513 | |||
504 |
raise NotImplementedError |
|
514 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
505 |
|
515 | |||
506 | return '' |
|
|||
507 |
|
516 | |||
508 | def dict_to_parms(self, parameters): |
|
517 | def dict_to_parms(self, parameters): | |
509 |
|
518 | |||
@@ -556,33 +565,28 class Configuration(PolymorphicModel): | |||||
556 |
|
565 | |||
557 | def status_device(self): |
|
566 | def status_device(self): | |
558 |
|
567 | |||
559 |
raise NotImplementedError |
|
568 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
560 |
|
569 | |||
561 | return None |
|
|||
562 |
|
570 | |||
563 | def stop_device(self): |
|
571 | def stop_device(self): | |
564 |
|
572 | |||
565 |
raise NotImplementedError |
|
573 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
566 |
|
574 | |||
567 | return None |
|
|||
568 |
|
575 | |||
569 | def start_device(self): |
|
576 | def start_device(self): | |
570 |
|
577 | |||
571 |
raise NotImplementedError |
|
578 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
572 |
|
579 | |||
573 | return None |
|
|||
574 |
|
580 | |||
575 | def write_device(self, parms): |
|
581 | def write_device(self, parms): | |
576 |
|
582 | |||
577 |
raise NotImplementedError |
|
583 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
578 |
|
584 | |||
579 | return None |
|
|||
580 |
|
585 | |||
581 | def read_device(self): |
|
586 | def read_device(self): | |
582 |
|
587 | |||
583 |
raise NotImplementedError |
|
588 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
584 |
|
589 | |||
585 | return None |
|
|||
586 |
|
590 | |||
587 | def get_absolute_url(self): |
|
591 | def get_absolute_url(self): | |
588 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
592 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
@@ -73,11 +73,11 | |||||
73 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> |
|
73 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> | |
74 | <ul class="dropdown-menu" role="menu"> |
|
74 | <ul class="dropdown-menu" role="menu"> | |
75 | <li><a href="#">Control Panel</a></li> |
|
75 | <li><a href="#">Control Panel</a></li> | |
76 |
<li><a href="{% url ' |
|
76 | <li><a href="{% url 'url_logout' %}">Logout</a></li> | |
77 | </ul> |
|
77 | </ul> | |
78 | </li> |
|
78 | </li> | |
79 | {% else %} |
|
79 | {% else %} | |
80 |
<li><a href="{% url ' |
|
80 | <li><a href="{% url 'url_login' %}?next={{request.get_full_path}}">Login</a></li> | |
81 | {% endif %} |
|
81 | {% endif %} | |
82 | </ul> |
|
82 | </ul> | |
83 | </div> |
|
83 | </div> |
@@ -6,50 +6,33 | |||||
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 |
{% block |
|
9 | {% block operation-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
|||
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
|||
13 |
|
11 | |||
14 | {% block content %} |
|
12 | {% block content %} | |
15 |
|
13 | |||
16 | <!-- Not Empty--> |
|
14 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
17 | {% if details %} |
|
15 | <div style="clear: both;"></div> | |
18 |
|
16 | |||
19 | <form class="form" method="post" action=""> |
|
17 | {% if campaign %} | |
20 | {% csrf_token %} |
|
|||
21 |
|
18 | |||
22 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
|||
23 | <div style="clear: both;"></div> |
|
|||
24 | <br> |
|
|||
25 | <!-- For deep search --> |
|
|||
26 | {% if search_button == True %} |
|
|||
27 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> |
|
|||
28 | {% endif %} |
|
|||
29 | <br> |
|
|||
30 | <br> |
|
|||
31 | </form> |
|
|||
32 | <br> |
|
|||
33 | <br> |
|
|||
34 |
|
||||
35 | {% endif %} |
|
|||
36 | <div class="clearfix"></div> |
|
19 | <div class="clearfix"></div> | |
37 | <h2>Radar Systems</h2> |
|
20 | <h2>Radar Systems</h2> | |
38 | <br> |
|
21 | <br> | |
39 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
22 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > | |
40 |
|
23 | |||
41 | {% for location in locations %} |
|
24 | {% for location in locations %} | |
42 |
|
25 | |||
43 | <div class="panel panel-default"> |
|
26 | <div class="panel panel-default"> | |
44 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
27 | <div class="panel-heading" role="tab" id="headingTwo"> | |
45 | <h4 class="panel-title"> |
|
28 | <h4 class="panel-title"> | |
46 |
|
29 | |||
47 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> |
|
30 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> | |
48 |
{{location.name}} |
|
31 | {{location.name}} | |
49 | <span> |
|
32 | <span> | |
50 | </span> |
|
33 | </span> | |
51 | </a> |
|
34 | </a> | |
52 |
|
35 | |||
53 | <button type="button" name="bt_play" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_play' campaign.id location.id %}" style="margin-left: 10px"> |
|
36 | <button type="button" name="bt_play" class="btn btn-primary pull-right btn-xs" data-url="{% url 'url_radar_play' campaign.id location.id %}" style="margin-left: 10px"> | |
54 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> |
|
37 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> | |
55 | </button> |
|
38 | </button> | |
@@ -61,7 +44,7 | |||||
61 | </button> |
|
44 | </button> | |
62 | </h4> |
|
45 | </h4> | |
63 | </div> |
|
46 | </div> | |
64 |
|
47 | |||
65 | <div id="collapseTwo-{{ location.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
48 | <div id="collapseTwo-{{ location.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
66 | <div class="panel-body"> |
|
49 | <div class="panel-body"> | |
67 | <table class="table table-hover"> |
|
50 | <table class="table table-hover"> | |
@@ -71,10 +54,10 | |||||
71 | <th>{{ header|title }}</th> |
|
54 | <th>{{ header|title }}</th> | |
72 | {% endfor%} |
|
55 | {% endfor%} | |
73 | </tr> |
|
56 | </tr> | |
74 |
|
57 | |||
75 | {% for item in experiments %} |
|
58 | {% for item in location.experiments %} | |
76 | {% if location.name in item.location.name %} |
|
59 | {% if location.name in item.location.name %} | |
77 |
|
60 | |||
78 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > |
|
61 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > | |
79 | <td>{{ forloop.counter }}</td> |
|
62 | <td>{{ forloop.counter }}</td> | |
80 | {% for key in experiment_keys %} |
|
63 | {% for key in experiment_keys %} | |
@@ -87,14 +70,14 | |||||
87 | </tr> |
|
70 | </tr> | |
88 | {% endif %} |
|
71 | {% endif %} | |
89 | {% endfor %} |
|
72 | {% endfor %} | |
90 |
</table> |
|
73 | </table> | |
91 | </div> |
|
74 | </div> | |
92 | </div> |
|
75 | </div> | |
93 | </div> |
|
76 | </div> | |
94 | {% endfor %} |
|
77 | {% endfor %} | |
95 | </div> |
|
78 | </div> | |
96 |
|
79 | |||
97 |
|
80 | {% endif %} | ||
98 |
|
81 | |||
99 | {% endblock %} |
|
82 | {% endblock %} | |
100 |
|
83 | |||
@@ -102,28 +85,28 | |||||
102 |
|
85 | |||
103 | {% block extra-js%} |
|
86 | {% block extra-js%} | |
104 | <script type="text/javascript"> |
|
87 | <script type="text/javascript"> | |
105 |
|
88 | |||
106 |
//--------For PLAY Button------- |
|
89 | //--------For PLAY Button------- | |
107 | $("#accordion").on("click", "button[name=bt_play]", function(){ |
|
90 | $("#accordion").on("click", "button[name=bt_play]", function(){ | |
108 | //alert($(this).data('url')); |
|
91 | //alert($(this).data('url')); | |
109 | document.location = $(this).data('url'); |
|
92 | document.location = $(this).data('url'); | |
110 | }); |
|
93 | }); | |
111 |
|
94 | |||
112 |
//--------For STOP Button------- |
|
95 | //--------For STOP Button------- | |
113 | $("#accordion").on("click", "button[name=bt_stop]", function(){ |
|
96 | $("#accordion").on("click", "button[name=bt_stop]", function(){ | |
114 | //alert($(this).data('url')); |
|
97 | //alert($(this).data('url')); | |
115 | document.location = $(this).data('url'); |
|
98 | document.location = $(this).data('url'); | |
116 | }); |
|
99 | }); | |
117 |
|
100 | |||
118 |
//--------For REFRESH Button------- |
|
101 | //--------For REFRESH Button------- | |
119 | $("#accordion").on("click", "button[name=bt_refresh]", function(){ |
|
102 | $("#accordion").on("click", "button[name=bt_refresh]", function(){ | |
120 | document.location = $(this).data('url'); |
|
103 | document.location = $(this).data('url'); | |
121 | }); |
|
104 | }); | |
122 |
|
105 | |||
123 | $(".clickable-row").click(function() { |
|
106 | $(".clickable-row").click(function() { | |
124 | document.location = $(this).data("href"); |
|
107 | document.location = $(this).data("href"); | |
125 | }); |
|
108 | }); | |
126 |
|
109 | |||
127 | {% if search_button == True %} |
|
110 | {% if search_button == True %} | |
128 | $(document).ready(function() { |
|
111 | $(document).ready(function() { | |
129 | $("#id_campaign").change(function() { |
|
112 | $("#id_campaign").change(function() { | |
@@ -134,18 +117,12 | |||||
134 | }); |
|
117 | }); | |
135 | {% else %} |
|
118 | {% else %} | |
136 | $(document).ready(function() { |
|
119 | $(document).ready(function() { | |
137 | $("#id_campaign").change(function() { |
|
120 | $("#id_campaign").change(function() { | |
138 | var id_camp = document.getElementById("id_campaign").value; |
|
121 | document.location = "{% url 'url_operation'%}"+$(this).val(); | |
139 | //alert(id_camp); |
|
|||
140 | document.location = "{% url 'url_operation_search'%}"+String(id_camp); |
|
|||
141 | }); |
|
122 | }); | |
142 | }); |
|
123 | }); | |
143 | {% endif %} |
|
124 | {% endif %} | |
144 |
|
125 | |||
145 | $("#button-1").click(function() { |
|
126 | ||
146 | document.location = "{% url 'url_operation_search' %}"; |
|
|||
147 | }); |
|
|||
148 |
|
||||
149 |
|
||||
150 | </script> |
|
127 | </script> | |
151 | {% endblock %} No newline at end of file |
|
128 | {% endblock %} |
@@ -1,34 +1,34 | |||||
1 |
|
1 | |||
2 | {% if campaign %} |
|
2 | {% if campaign %} | |
3 | <div class="panel panel-default"> |
|
3 | <div class="panel panel-default"> | |
4 | <div class="panel-heading"> |
|
4 | <div class="panel-heading"> | |
5 | <h4>Campaign</h4> |
|
5 | <h4>Campaign</h4> | |
6 | </div> |
|
6 | </div> | |
7 |
<div class="list-group"> |
|
7 | <div class="list-group"> | |
8 | <a href="{% url 'url_campaign' campaign.id %}" class="list-group-item active" >{{ campaign.name }}</a> |
|
8 | <a href="{% url 'url_campaign' campaign.id %}" class="list-group-item active" >{{ campaign.name }}</a> | |
9 | </div> |
|
9 | </div> | |
10 | </div> |
|
10 | </div> | |
11 | {% endif %} |
|
11 | {% endif %} | |
12 |
|
12 | |||
13 | {% if experiment %} |
|
13 | {% if experiment %} | |
14 | <div class="panel panel-default"> |
|
14 | <div class="panel panel-default"> | |
15 | <div class="panel-heading"> |
|
15 | <div class="panel-heading"> | |
16 | <h4>Experiments</h4> |
|
16 | <h4>Experiments</h4> | |
17 | </div> |
|
17 | </div> | |
18 |
<div class="list-group"> |
|
18 | <div class="list-group"> | |
19 | {% for item in side_experiments %} |
|
19 | {% for item in side_experiments %} | |
20 |
<a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == experiment.id%}active{%endif%}">{{item.name}}</a> |
|
20 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == experiment.id%}active{%endif%}">{{item.name}}</a> | |
21 | {% endfor %} |
|
21 | {% endfor %} | |
22 | </div> |
|
22 | </div> | |
23 | </div> |
|
23 | </div> | |
24 | {% endif %} |
|
24 | {% endif %} | |
25 |
|
25 | |||
26 | {% if dev_conf %} |
|
26 | {% if dev_conf %} | |
27 | <div class="panel panel-default"> |
|
27 | <div class="panel panel-default"> | |
28 | <div class="panel-heading"> |
|
28 | <div class="panel-heading"> | |
29 | <h4>Device Configurations</h4> |
|
29 | <h4>Device Configurations</h4> | |
30 | </div> |
|
30 | </div> | |
31 |
<div class="list-group"> |
|
31 | <div class="list-group"> | |
32 | {% for item in side_configurations %} |
|
32 | {% for item in side_configurations %} | |
33 | <a href="{{item.get_absolute_url}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item}}</a> |
|
33 | <a href="{{item.get_absolute_url}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item}}</a> | |
34 | {% endfor %} |
|
34 | {% endfor %} |
@@ -1,59 +1,61 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
|
3 | from apps.main import views | |||
|
4 | ||||
3 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
6 | url(r'^$', views.index, name='index'), | |
5 |
url(r'^location/$', |
|
7 | url(r'^location/new/$', views.location_new, name='url_add_location'), | |
6 |
url(r'^location/ |
|
8 | url(r'^location/$', views.locations, name='url_locations'), | |
7 |
url(r'^location/(?P<id_loc>-?\d+)/ |
|
9 | url(r'^location/(?P<id_loc>-?\d+)/$', views.location, name='url_location'), | |
8 |
url(r'^location/(?P<id_loc>-?\d+)/ |
|
10 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', views.location_edit, name='url_edit_location'), | |
9 |
|
11 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', views.location_delete, name='url_delete_location'), | ||
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
12 | ||
11 |
url(r'^device/$', |
|
13 | url(r'^device/new/$', views.device_new, name='url_add_device'), | |
12 |
url(r'^device/ |
|
14 | url(r'^device/$', views.devices, name='url_devices'), | |
13 |
url(r'^device/(?P<id_dev>-?\d+)/ |
|
15 | url(r'^device/(?P<id_dev>-?\d+)/$', views.device, name='url_device'), | |
14 |
url(r'^device/(?P<id_dev>-?\d+)/ |
|
16 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', views.device_edit, name='url_edit_device'), | |
15 |
|
17 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', views.device_delete, name='url_delete_device'), | ||
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
18 | ||
17 |
url(r'^campaign/$', |
|
19 | url(r'^campaign/new/$', views.campaign_new, name='url_add_campaign'), | |
18 |
url(r'^campaign/ |
|
20 | url(r'^campaign/$', views.campaigns, name='url_campaigns'), | |
19 |
url(r'^campaign/(?P<id_camp>-?\d+)/ |
|
21 | url(r'^campaign/(?P<id_camp>-?\d+)/$', views.campaign, name='url_campaign'), | |
20 |
url(r'^campaign/(?P<id_camp>-?\d+)/ |
|
22 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', views.campaign_edit, name='url_edit_campaign'), | |
21 |
url(r'^campaign/(?P<id_camp>-?\d+)/ |
|
23 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', views.campaign_delete, name='url_delete_campaign'), | |
22 |
url(r'^campaign/(?P<id_camp>-?\d+)/ |
|
24 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', views.campaign_export, name='url_export_campaign'), | |
23 |
|
25 | url(r'^campaign/(?P<id_camp>-?\d+)/import/$', views.campaign_import, name='url_import_campaign'), | ||
24 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
26 | ||
25 |
url(r'^experiment/$', |
|
27 | url(r'^experiment/new/$', views.experiment_new, name='url_add_experiment'), | |
26 |
url(r'^experiment/ |
|
28 | url(r'^experiment/$', views.experiments, name='url_experiments'), | |
27 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
29 | url(r'^experiment/(?P<id_exp>-?\d+)/$', views.experiment, name='url_experiment'), | |
28 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
30 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', views.experiment_edit, name='url_edit_experiment'), | |
29 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
31 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', views.experiment_delete, name='url_delete_experiment'), | |
30 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
32 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', views.experiment_export, name='url_export_experiment'), | |
31 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
33 | url(r'^experiment/(?P<id_exp>-?\d+)/import/$', views.experiment_import, name='url_import_experiment'), | |
32 |
url(r'^experiment/(?P<id_exp>-?\d+)/mix/ |
|
34 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', views.experiment_mix, name='url_mix_experiment'), | |
33 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
35 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', views.experiment_mix_delete, name='url_delete_mix_experiment'), | |
34 |
url(r'^experiment/(?P<id_exp>-?\d+)/ |
|
36 | url(r'^experiment/(?P<id_exp>-?\d+)/summary/$', views.experiment_summary, name='url_sum_experiment'), | |
35 |
|
37 | url(r'^experiment/(?P<id_exp>-?\d+)/verify/$', views.experiment_verify, name='url_verify_experiment'), | ||
36 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
38 | ||
37 |
url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/ |
|
39 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', views.dev_conf_new, name='url_add_dev_conf'), | |
38 |
url(r'^dev_conf/$', |
|
40 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', views.dev_conf_new, name='url_add_dev_conf'), | |
39 |
url(r'^dev_conf/ |
|
41 | url(r'^dev_conf/$', views.dev_confs, name='url_dev_confs'), | |
40 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/ |
|
42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', views.dev_conf, name='url_dev_conf'), | |
41 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/ |
|
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', views.dev_conf_edit, name='url_edit_dev_conf'), | |
42 |
|
44 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', views.dev_conf_delete, name='url_delete_dev_conf'), | ||
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
45 | ||
44 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/re |
|
46 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', views.dev_conf_write, name='url_write_dev_conf'), | |
45 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/ |
|
47 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', views.dev_conf_read, name='url_read_dev_conf'), | |
46 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/ |
|
48 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', views.dev_conf_import, name='url_import_dev_conf'), | |
47 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/ |
|
49 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', views.dev_conf_export, name='url_export_dev_conf'), | |
48 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/st |
|
50 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', views.dev_conf_start, name='url_start_dev_conf'), | |
49 |
url(r'^dev_conf/(?P<id_conf>-?\d+)/st |
|
51 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', views.dev_conf_stop, name='url_stop_dev_conf'), | |
50 |
|
52 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', views.dev_conf_status, name='url_status_dev_conf'), | ||
51 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
53 | ||
52 |
url(r'^operation/ |
|
54 | url(r'^operation/$', views.operation, name='url_operation'), | |
53 |
url(r'^operation/ |
|
55 | url(r'^operation/(?P<id_camp>-?\d+)/$', views.operation, name='url_operation'), | |
54 |
url(r'^operation/search/ |
|
56 | url(r'^operation/search/$', views.operation_search, name='url_operation_search'), | |
55 |
url(r'^operation/(?P<id_camp>-?\d+)/ |
|
57 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', views.operation_search, name='url_operation_search'), | |
56 |
url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/ |
|
58 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', views.radar_play, name='url_radar_play'), | |
57 |
url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/ |
|
59 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', views.radar_stop, name='url_radar_stop'), | |
58 |
|
60 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', views.radar_refresh, name='url_radar_refresh'), | ||
59 | ) |
|
61 | ) |
This diff has been collapsed as it changes many lines, (868 lines changed) Show them Hide them | |||||
@@ -5,17 +5,23 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 datetime import datetime |
|
9 | from datetime import datetime | |
9 | import urllib |
|
10 | ||
|
11 | try: | |||
|
12 | from urllib.parse import urlencode | |||
|
13 | except ImportError: | |||
|
14 | from urllib import urlencode | |||
10 |
|
15 | |||
11 | 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 | |
12 | from .forms import OperationSearchForm, FilterForm |
|
17 | from .forms import OperationSearchForm, FilterForm | |
13 | from apps.cgs.forms import CGSConfigurationForm |
|
18 | ||
|
19 | from apps.rc.forms import RCConfigurationForm | |||
|
20 | from apps.dds.forms import DDSConfigurationForm | |||
14 | from apps.jars.forms import JARSConfigurationForm |
|
21 | from apps.jars.forms import JARSConfigurationForm | |
15 |
from apps. |
|
22 | from apps.cgs.forms import CGSConfigurationForm | |
16 | from apps.abs.forms import ABSConfigurationForm |
|
23 | from apps.abs.forms import ABSConfigurationForm | |
17 |
from apps. |
|
24 | from apps.usrp.forms import USRPConfigurationForm | |
18 | from apps.dds.forms import DDSConfigurationForm |
|
|||
19 |
|
25 | |||
20 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
26 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
21 | from apps.cgs.models import CGSConfiguration |
|
27 | from apps.cgs.models import CGSConfiguration | |
@@ -62,309 +68,309 MIX_OPERATIONS = { | |||||
62 |
|
68 | |||
63 | def index(request): |
|
69 | def index(request): | |
64 | kwargs = {} |
|
70 | kwargs = {} | |
65 |
|
71 | |||
66 | return render(request, 'index.html', kwargs) |
|
72 | return render(request, 'index.html', kwargs) | |
67 |
|
73 | |||
68 |
|
74 | |||
69 | def locations(request): |
|
75 | def locations(request): | |
70 |
|
76 | |||
71 | page = request.GET.get('page') |
|
77 | page = request.GET.get('page') | |
72 | order = ('name',) |
|
78 | order = ('name',) | |
73 |
|
79 | |||
74 |
kwargs = get_paginator(Location, page, order) |
|
80 | kwargs = get_paginator(Location, page, order) | |
75 |
|
81 | |||
76 | kwargs['keys'] = ['name', 'description'] |
|
82 | kwargs['keys'] = ['name', 'description'] | |
77 | kwargs['title'] = 'Radar System' |
|
83 | kwargs['title'] = 'Radar System' | |
78 | kwargs['suptitle'] = 'List' |
|
84 | kwargs['suptitle'] = 'List' | |
79 |
|
85 | |||
80 | return render(request, 'base_list.html', kwargs) |
|
86 | return render(request, 'base_list.html', kwargs) | |
81 |
|
87 | |||
82 |
|
88 | |||
83 | def location(request, id_loc): |
|
89 | def location(request, id_loc): | |
84 |
|
90 | |||
85 | location = get_object_or_404(Location, pk=id_loc) |
|
91 | location = get_object_or_404(Location, pk=id_loc) | |
86 |
|
92 | |||
87 | kwargs = {} |
|
93 | kwargs = {} | |
88 | kwargs['location'] = location |
|
94 | kwargs['location'] = location | |
89 | kwargs['location_keys'] = ['name', 'description'] |
|
95 | kwargs['location_keys'] = ['name', 'description'] | |
90 |
|
96 | |||
91 | kwargs['title'] = 'Location' |
|
97 | kwargs['title'] = 'Location' | |
92 | kwargs['suptitle'] = 'Details' |
|
98 | kwargs['suptitle'] = 'Details' | |
93 |
|
99 | |||
94 | return render(request, 'location.html', kwargs) |
|
100 | return render(request, 'location.html', kwargs) | |
95 |
|
101 | |||
96 |
|
102 | |||
97 | def location_new(request): |
|
103 | def location_new(request): | |
98 |
|
104 | |||
99 | if request.method == 'GET': |
|
105 | if request.method == 'GET': | |
100 | form = LocationForm() |
|
106 | form = LocationForm() | |
101 |
|
107 | |||
102 | if request.method == 'POST': |
|
108 | if request.method == 'POST': | |
103 | form = LocationForm(request.POST) |
|
109 | form = LocationForm(request.POST) | |
104 |
|
110 | |||
105 | if form.is_valid(): |
|
111 | if form.is_valid(): | |
106 | form.save() |
|
112 | form.save() | |
107 | return redirect('url_locations') |
|
113 | return redirect('url_locations') | |
108 |
|
114 | |||
109 | kwargs = {} |
|
115 | kwargs = {} | |
110 | kwargs['form'] = form |
|
116 | kwargs['form'] = form | |
111 | kwargs['title'] = 'Radar System' |
|
117 | kwargs['title'] = 'Radar System' | |
112 | kwargs['suptitle'] = 'New' |
|
118 | kwargs['suptitle'] = 'New' | |
113 | kwargs['button'] = 'Create' |
|
119 | kwargs['button'] = 'Create' | |
114 |
|
120 | |||
115 | return render(request, 'base_edit.html', kwargs) |
|
121 | return render(request, 'base_edit.html', kwargs) | |
116 |
|
122 | |||
117 |
|
123 | |||
118 | def location_edit(request, id_loc): |
|
124 | def location_edit(request, id_loc): | |
119 |
|
125 | |||
120 | location = get_object_or_404(Location, pk=id_loc) |
|
126 | location = get_object_or_404(Location, pk=id_loc) | |
121 |
|
127 | |||
122 | if request.method=='GET': |
|
128 | if request.method=='GET': | |
123 | form = LocationForm(instance=location) |
|
129 | form = LocationForm(instance=location) | |
124 |
|
130 | |||
125 | if request.method=='POST': |
|
131 | if request.method=='POST': | |
126 | form = LocationForm(request.POST, instance=location) |
|
132 | form = LocationForm(request.POST, instance=location) | |
127 |
|
133 | |||
128 | if form.is_valid(): |
|
134 | if form.is_valid(): | |
129 | form.save() |
|
135 | form.save() | |
130 | return redirect('url_locations') |
|
136 | return redirect('url_locations') | |
131 |
|
137 | |||
132 | kwargs = {} |
|
138 | kwargs = {} | |
133 | kwargs['form'] = form |
|
139 | kwargs['form'] = form | |
134 | kwargs['title'] = 'Location' |
|
140 | kwargs['title'] = 'Location' | |
135 | kwargs['suptitle'] = 'Edit' |
|
141 | kwargs['suptitle'] = 'Edit' | |
136 | kwargs['button'] = 'Update' |
|
142 | kwargs['button'] = 'Update' | |
137 |
|
143 | |||
138 | return render(request, 'base_edit.html', kwargs) |
|
144 | return render(request, 'base_edit.html', kwargs) | |
139 |
|
145 | |||
140 |
|
146 | |||
141 | def location_delete(request, id_loc): |
|
147 | def location_delete(request, id_loc): | |
142 |
|
148 | |||
143 | location = get_object_or_404(Location, pk=id_loc) |
|
149 | location = get_object_or_404(Location, pk=id_loc) | |
144 |
|
150 | |||
145 | if request.method=='POST': |
|
151 | if request.method=='POST': | |
146 |
|
152 | |||
147 | if request.user.is_staff: |
|
153 | if request.user.is_staff: | |
148 | location.delete() |
|
154 | location.delete() | |
149 | return redirect('url_locations') |
|
155 | return redirect('url_locations') | |
150 |
|
156 | |||
151 | messages.error(request, 'Not enough permission to delete this object') |
|
157 | messages.error(request, 'Not enough permission to delete this object') | |
152 | return redirect(location.get_absolute_url()) |
|
158 | return redirect(location.get_absolute_url()) | |
153 |
|
159 | |||
154 | kwargs = { |
|
160 | kwargs = { | |
155 | 'title': 'Delete', |
|
161 | 'title': 'Delete', | |
156 | 'suptitle': 'Location', |
|
162 | 'suptitle': 'Location', | |
157 |
'object': location, |
|
163 | 'object': location, | |
158 | 'previous': location.get_absolute_url(), |
|
164 | 'previous': location.get_absolute_url(), | |
159 | 'delete': True |
|
165 | 'delete': True | |
160 | } |
|
166 | } | |
161 |
|
167 | |||
162 | return render(request, 'confirm.html', kwargs) |
|
168 | return render(request, 'confirm.html', kwargs) | |
163 |
|
169 | |||
164 |
|
170 | |||
165 | def devices(request): |
|
171 | def devices(request): | |
166 |
|
172 | |||
167 | page = request.GET.get('page') |
|
173 | page = request.GET.get('page') | |
168 | order = ('device_type', 'name') |
|
174 | order = ('device_type', 'name') | |
169 |
|
175 | |||
170 |
kwargs = get_paginator(Device, page, order) |
|
176 | kwargs = get_paginator(Device, page, order) | |
171 |
kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type'] |
|
177 | kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type'] | |
172 | kwargs['title'] = 'Device' |
|
178 | kwargs['title'] = 'Device' | |
173 | kwargs['suptitle'] = 'List' |
|
179 | kwargs['suptitle'] = 'List' | |
174 |
|
180 | |||
175 | return render(request, 'base_list.html', kwargs) |
|
181 | return render(request, 'base_list.html', kwargs) | |
176 |
|
182 | |||
177 |
|
183 | |||
178 | def device(request, id_dev): |
|
184 | def device(request, id_dev): | |
179 |
|
185 | |||
180 | device = get_object_or_404(Device, pk=id_dev) |
|
186 | device = get_object_or_404(Device, pk=id_dev) | |
181 |
|
187 | |||
182 | kwargs = {} |
|
188 | kwargs = {} | |
183 | kwargs['device'] = device |
|
189 | kwargs['device'] = device | |
184 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
190 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
185 |
|
191 | |||
186 | kwargs['title'] = 'Device' |
|
192 | kwargs['title'] = 'Device' | |
187 | kwargs['suptitle'] = 'Details' |
|
193 | kwargs['suptitle'] = 'Details' | |
188 |
|
194 | |||
189 | return render(request, 'device.html', kwargs) |
|
195 | return render(request, 'device.html', kwargs) | |
190 |
|
196 | |||
191 |
|
197 | |||
192 | def device_new(request): |
|
198 | def device_new(request): | |
193 |
|
199 | |||
194 | if request.method == 'GET': |
|
200 | if request.method == 'GET': | |
195 | form = DeviceForm() |
|
201 | form = DeviceForm() | |
196 |
|
202 | |||
197 | if request.method == 'POST': |
|
203 | if request.method == 'POST': | |
198 | form = DeviceForm(request.POST) |
|
204 | form = DeviceForm(request.POST) | |
199 |
|
205 | |||
200 | if form.is_valid(): |
|
206 | if form.is_valid(): | |
201 | form.save() |
|
207 | form.save() | |
202 | return redirect('url_devices') |
|
208 | return redirect('url_devices') | |
203 |
|
209 | |||
204 | kwargs = {} |
|
210 | kwargs = {} | |
205 | kwargs['form'] = form |
|
211 | kwargs['form'] = form | |
206 | kwargs['title'] = 'Device' |
|
212 | kwargs['title'] = 'Device' | |
207 | kwargs['suptitle'] = 'New' |
|
213 | kwargs['suptitle'] = 'New' | |
208 | kwargs['button'] = 'Create' |
|
214 | kwargs['button'] = 'Create' | |
209 |
|
215 | |||
210 | return render(request, 'base_edit.html', kwargs) |
|
216 | return render(request, 'base_edit.html', kwargs) | |
211 |
|
217 | |||
212 |
|
218 | |||
213 | def device_edit(request, id_dev): |
|
219 | def device_edit(request, id_dev): | |
214 |
|
220 | |||
215 | device = get_object_or_404(Device, pk=id_dev) |
|
221 | device = get_object_or_404(Device, pk=id_dev) | |
216 |
|
222 | |||
217 | if request.method=='GET': |
|
223 | if request.method=='GET': | |
218 | form = DeviceForm(instance=device) |
|
224 | form = DeviceForm(instance=device) | |
219 |
|
225 | |||
220 | if request.method=='POST': |
|
226 | if request.method=='POST': | |
221 | form = DeviceForm(request.POST, instance=device) |
|
227 | form = DeviceForm(request.POST, instance=device) | |
222 |
|
228 | |||
223 | if form.is_valid(): |
|
229 | if form.is_valid(): | |
224 | form.save() |
|
230 | form.save() | |
225 | return redirect(device.get_absolute_url()) |
|
231 | return redirect(device.get_absolute_url()) | |
226 |
|
232 | |||
227 | kwargs = {} |
|
233 | kwargs = {} | |
228 | kwargs['form'] = form |
|
234 | kwargs['form'] = form | |
229 | kwargs['title'] = 'Device' |
|
235 | kwargs['title'] = 'Device' | |
230 | kwargs['suptitle'] = 'Edit' |
|
236 | kwargs['suptitle'] = 'Edit' | |
231 | kwargs['button'] = 'Update' |
|
237 | kwargs['button'] = 'Update' | |
232 |
|
238 | |||
233 | return render(request, 'base_edit.html', kwargs) |
|
239 | return render(request, 'base_edit.html', kwargs) | |
234 |
|
240 | |||
235 |
|
241 | |||
236 | def device_delete(request, id_dev): |
|
242 | def device_delete(request, id_dev): | |
237 |
|
243 | |||
238 | device = get_object_or_404(Device, pk=id_dev) |
|
244 | device = get_object_or_404(Device, pk=id_dev) | |
239 |
|
245 | |||
240 | if request.method=='POST': |
|
246 | if request.method=='POST': | |
241 |
|
247 | |||
242 | if request.user.is_staff: |
|
248 | if request.user.is_staff: | |
243 | device.delete() |
|
249 | device.delete() | |
244 | return redirect('url_devices') |
|
250 | return redirect('url_devices') | |
245 |
|
251 | |||
246 | messages.error(request, 'Not enough permission to delete this object') |
|
252 | messages.error(request, 'Not enough permission to delete this object') | |
247 | return redirect(device.get_absolute_url()) |
|
253 | return redirect(device.get_absolute_url()) | |
248 |
|
254 | |||
249 | kwargs = { |
|
255 | kwargs = { | |
250 | 'title': 'Delete', |
|
256 | 'title': 'Delete', | |
251 | 'suptitle': 'Device', |
|
257 | 'suptitle': 'Device', | |
252 |
'object': device, |
|
258 | 'object': device, | |
253 | 'previous': device.get_absolute_url(), |
|
259 | 'previous': device.get_absolute_url(), | |
254 | 'delete': True |
|
260 | 'delete': True | |
255 | } |
|
261 | } | |
256 |
|
262 | |||
257 | return render(request, 'confirm.html', kwargs) |
|
263 | return render(request, 'confirm.html', kwargs) | |
258 |
|
264 | |||
259 |
|
265 | |||
260 | def campaigns(request): |
|
266 | def campaigns(request): | |
261 |
|
267 | |||
262 | page = request.GET.get('page') |
|
268 | page = request.GET.get('page') | |
263 | order = ('start_date',) |
|
269 | order = ('start_date',) | |
264 | filters = request.GET.copy() |
|
270 | filters = request.GET.copy() | |
265 |
|
271 | |||
266 | kwargs = get_paginator(Campaign, page, order, filters) |
|
272 | kwargs = get_paginator(Campaign, page, order, filters) | |
267 |
|
273 | |||
268 | form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template']) |
|
274 | form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template']) | |
269 |
kwargs['keys'] = ['name', 'start_date', 'end_date'] |
|
275 | kwargs['keys'] = ['name', 'start_date', 'end_date'] | |
270 | kwargs['title'] = 'Campaign' |
|
276 | kwargs['title'] = 'Campaign' | |
271 | kwargs['suptitle'] = 'List' |
|
277 | kwargs['suptitle'] = 'List' | |
272 |
kwargs['form'] = form |
|
278 | kwargs['form'] = form | |
273 | filters.pop('page', None) |
|
279 | filters.pop('page', None) | |
274 |
kwargs['q'] = |
|
280 | kwargs['q'] = urlencode(filters) | |
275 |
|
281 | |||
276 | return render(request, 'base_list.html', kwargs) |
|
282 | return render(request, 'base_list.html', kwargs) | |
277 |
|
283 | |||
278 |
|
284 | |||
279 | def campaign(request, id_camp): |
|
285 | def campaign(request, id_camp): | |
280 |
|
286 | |||
281 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
287 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
282 | experiments = Experiment.objects.filter(campaign=campaign) |
|
288 | experiments = Experiment.objects.filter(campaign=campaign) | |
283 |
|
289 | |||
284 | form = CampaignForm(instance=campaign) |
|
290 | form = CampaignForm(instance=campaign) | |
285 |
|
291 | |||
286 | kwargs = {} |
|
292 | kwargs = {} | |
287 | kwargs['campaign'] = campaign |
|
293 | kwargs['campaign'] = campaign | |
288 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
294 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] | |
289 |
|
295 | |||
290 | kwargs['experiments'] = experiments |
|
296 | kwargs['experiments'] = experiments | |
291 | kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time'] |
|
297 | kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time'] | |
292 |
|
298 | |||
293 | kwargs['title'] = 'Campaign' |
|
299 | kwargs['title'] = 'Campaign' | |
294 | kwargs['suptitle'] = 'Details' |
|
300 | kwargs['suptitle'] = 'Details' | |
295 |
|
301 | |||
296 | kwargs['form'] = form |
|
302 | kwargs['form'] = form | |
297 | kwargs['button'] = 'Add Experiment' |
|
303 | kwargs['button'] = 'Add Experiment' | |
298 |
|
304 | |||
299 | return render(request, 'campaign.html', kwargs) |
|
305 | return render(request, 'campaign.html', kwargs) | |
300 |
|
306 | |||
301 |
|
307 | |||
302 | def campaign_new(request): |
|
308 | def campaign_new(request): | |
303 |
|
309 | |||
304 | kwargs = {} |
|
310 | kwargs = {} | |
305 |
|
311 | |||
306 | if request.method == 'GET': |
|
312 | if request.method == 'GET': | |
307 |
|
313 | |||
308 | if 'template' in request.GET: |
|
314 | if 'template' in request.GET: | |
309 | if request.GET['template']=='0': |
|
315 | if request.GET['template']=='0': | |
310 | form = NewForm(initial={'create_from':2}, |
|
316 | form = NewForm(initial={'create_from':2}, | |
311 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
317 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
312 | else: |
|
318 | else: | |
313 | kwargs['button'] = 'Create' |
|
319 | kwargs['button'] = 'Create' | |
314 |
kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
320 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |
315 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
321 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
316 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
322 | camp = Campaign.objects.get(pk=request.GET['template']) | |
317 | form = CampaignForm(instance=camp, |
|
323 | form = CampaignForm(instance=camp, | |
318 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
324 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
319 |
'template':False}) |
|
325 | 'template':False}) | |
320 | elif 'blank' in request.GET: |
|
326 | elif 'blank' in request.GET: | |
321 | kwargs['button'] = 'Create' |
|
327 | kwargs['button'] = 'Create' | |
322 | form = CampaignForm() |
|
328 | form = CampaignForm() | |
323 | else: |
|
329 | else: | |
324 | form = NewForm() |
|
330 | form = NewForm() | |
325 |
|
331 | |||
326 | if request.method == 'POST': |
|
332 | if request.method == 'POST': | |
327 | kwargs['button'] = 'Create' |
|
333 | kwargs['button'] = 'Create' | |
328 | post = request.POST.copy() |
|
334 | post = request.POST.copy() | |
329 | experiments = [] |
|
335 | experiments = [] | |
330 |
|
336 | |||
331 | for id_exp in post.getlist('experiments'): |
|
337 | for id_exp in post.getlist('experiments'): | |
332 | exp = Experiment.objects.get(pk=id_exp) |
|
338 | exp = Experiment.objects.get(pk=id_exp) | |
333 | new_exp = exp.clone(template=False) |
|
339 | new_exp = exp.clone(template=False) | |
334 | experiments.append(new_exp) |
|
340 | experiments.append(new_exp) | |
335 |
|
341 | |||
336 | post.setlist('experiments', []) |
|
342 | post.setlist('experiments', []) | |
337 |
|
343 | |||
338 | form = CampaignForm(post) |
|
344 | form = CampaignForm(post) | |
339 |
|
345 | |||
340 | if form.is_valid(): |
|
346 | if form.is_valid(): | |
341 | campaign = form.save() |
|
347 | campaign = form.save() | |
342 | for exp in experiments: |
|
348 | for exp in experiments: | |
343 | campaign.experiments.add(exp) |
|
349 | campaign.experiments.add(exp) | |
344 | campaign.save() |
|
350 | campaign.save() | |
345 | return redirect('url_campaign', id_camp=campaign.id) |
|
351 | return redirect('url_campaign', id_camp=campaign.id) | |
346 |
|
352 | |||
347 | kwargs['form'] = form |
|
353 | kwargs['form'] = form | |
348 | kwargs['title'] = 'Campaign' |
|
354 | kwargs['title'] = 'Campaign' | |
349 | kwargs['suptitle'] = 'New' |
|
355 | kwargs['suptitle'] = 'New' | |
350 |
|
356 | |||
351 | return render(request, 'campaign_edit.html', kwargs) |
|
357 | return render(request, 'campaign_edit.html', kwargs) | |
352 |
|
358 | |||
353 |
|
359 | |||
354 | def campaign_edit(request, id_camp): |
|
360 | def campaign_edit(request, id_camp): | |
355 |
|
361 | |||
356 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
362 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
357 |
|
363 | |||
358 | if request.method=='GET': |
|
364 | if request.method=='GET': | |
359 | form = CampaignForm(instance=campaign) |
|
365 | form = CampaignForm(instance=campaign) | |
360 |
|
366 | |||
361 | if request.method=='POST': |
|
367 | if request.method=='POST': | |
362 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
368 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
363 | post = request.POST.copy() |
|
369 | post = request.POST.copy() | |
364 | new_exps = post.getlist('experiments') |
|
370 | new_exps = post.getlist('experiments') | |
365 | post.setlist('experiments', []) |
|
371 | post.setlist('experiments', []) | |
366 | form = CampaignForm(post, instance=campaign) |
|
372 | form = CampaignForm(post, instance=campaign) | |
367 |
|
373 | |||
368 | if form.is_valid(): |
|
374 | if form.is_valid(): | |
369 | camp = form.save() |
|
375 | camp = form.save() | |
370 | for id_exp in new_exps: |
|
376 | for id_exp in new_exps: | |
@@ -376,146 +382,146 def campaign_edit(request, id_camp): | |||||
376 | camp.experiments.add(exp.clone(template=False)) |
|
382 | camp.experiments.add(exp.clone(template=False)) | |
377 | else: |
|
383 | else: | |
378 | camp.experiments.add(exp) |
|
384 | camp.experiments.add(exp) | |
379 |
|
385 | |||
380 | for id_exp in exps: |
|
386 | for id_exp in exps: | |
381 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
387 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
382 |
|
388 | |||
383 | return redirect('url_campaign', id_camp=id_camp) |
|
389 | return redirect('url_campaign', id_camp=id_camp) | |
384 |
|
390 | |||
385 | kwargs = {} |
|
391 | kwargs = {} | |
386 | kwargs['form'] = form |
|
392 | kwargs['form'] = form | |
387 | kwargs['title'] = 'Campaign' |
|
393 | kwargs['title'] = 'Campaign' | |
388 | kwargs['suptitle'] = 'Edit' |
|
394 | kwargs['suptitle'] = 'Edit' | |
389 | kwargs['button'] = 'Update' |
|
395 | kwargs['button'] = 'Update' | |
390 |
|
396 | |||
391 | return render(request, 'campaign_edit.html', kwargs) |
|
397 | return render(request, 'campaign_edit.html', kwargs) | |
392 |
|
398 | |||
393 |
|
399 | |||
394 | def campaign_delete(request, id_camp): |
|
400 | def campaign_delete(request, id_camp): | |
395 |
|
401 | |||
396 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
402 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
397 |
|
403 | |||
398 | if request.method=='POST': |
|
404 | if request.method=='POST': | |
399 | if request.user.is_staff: |
|
405 | if request.user.is_staff: | |
400 |
|
406 | |||
401 | for exp in campaign.experiments.all(): |
|
407 | for exp in campaign.experiments.all(): | |
402 | for conf in Configuration.objects.filter(experiment=exp): |
|
408 | for conf in Configuration.objects.filter(experiment=exp): | |
403 | conf.delete() |
|
409 | conf.delete() | |
404 | exp.delete() |
|
410 | exp.delete() | |
405 | campaign.delete() |
|
411 | campaign.delete() | |
406 |
|
412 | |||
407 | return redirect('url_campaigns') |
|
413 | return redirect('url_campaigns') | |
408 |
|
414 | |||
409 | messages.error(request, 'Not enough permission to delete this object') |
|
415 | messages.error(request, 'Not enough permission to delete this object') | |
410 | return redirect(campaign.get_absolute_url()) |
|
416 | return redirect(campaign.get_absolute_url()) | |
411 |
|
417 | |||
412 | kwargs = { |
|
418 | kwargs = { | |
413 | 'title': 'Delete', |
|
419 | 'title': 'Delete', | |
414 | 'suptitle': 'Campaign', |
|
420 | 'suptitle': 'Campaign', | |
415 |
'object': campaign, |
|
421 | 'object': campaign, | |
416 | 'previous': campaign.get_absolute_url(), |
|
422 | 'previous': campaign.get_absolute_url(), | |
417 | 'delete': True |
|
423 | 'delete': True | |
418 | } |
|
424 | } | |
419 |
|
425 | |||
420 | return render(request, 'confirm.html', kwargs) |
|
426 | return render(request, 'confirm.html', kwargs) | |
421 |
|
427 | |||
422 | def campaign_export(request, id_camp): |
|
428 | def campaign_export(request, id_camp): | |
423 |
|
429 | |||
424 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
430 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
425 |
content = campaign.parms_to_dict() |
|
431 | content = campaign.parms_to_dict() | |
426 | content_type = 'application/json' |
|
432 | content_type = 'application/json' | |
427 | filename = '%s_%s.json' %(campaign.name, campaign.id) |
|
433 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
428 |
|
434 | |||
429 | response = HttpResponse(content_type=content_type) |
|
435 | response = HttpResponse(content_type=content_type) | |
430 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
436 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
431 | response.write(content) |
|
437 | response.write(content) | |
432 |
|
438 | |||
433 | return response |
|
439 | return response | |
434 |
|
440 | |||
435 |
|
441 | |||
436 | def campaign_import(request, id_camp): |
|
442 | def campaign_import(request, id_camp): | |
437 |
|
443 | |||
438 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
444 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
439 |
|
445 | |||
440 | if request.method == 'GET': |
|
446 | if request.method == 'GET': | |
441 | file_form = UploadFileForm() |
|
447 | file_form = UploadFileForm() | |
442 |
|
448 | |||
443 | if request.method == 'POST': |
|
449 | if request.method == 'POST': | |
444 | file_form = UploadFileForm(request.POST, request.FILES) |
|
450 | file_form = UploadFileForm(request.POST, request.FILES) | |
445 |
|
451 | |||
446 | if file_form.is_valid(): |
|
452 | if file_form.is_valid(): | |
447 |
|
453 | |||
448 | parms = campaign.import_from_file(request.FILES['file']) |
|
454 | parms = campaign.import_from_file(request.FILES['file']) | |
449 |
|
455 | |||
450 | if parms: |
|
456 | if parms: | |
451 | parms['name'] = parms['campaign'] |
|
457 | parms['name'] = parms['campaign'] | |
452 |
|
458 | |||
453 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) |
|
459 | new_camp = campaign.dict_to_parms(parms, CONF_MODELS) | |
454 |
|
460 | |||
455 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
461 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
456 |
|
462 | |||
457 | return redirect(new_camp.get_absolute_url_edit()) |
|
463 | return redirect(new_camp.get_absolute_url_edit()) | |
458 |
|
464 | |||
459 | messages.error(request, "Could not import parameters from file") |
|
465 | messages.error(request, "Could not import parameters from file") | |
460 |
|
466 | |||
461 | kwargs = {} |
|
467 | kwargs = {} | |
462 | kwargs['title'] = 'Campaign' |
|
468 | kwargs['title'] = 'Campaign' | |
463 | kwargs['form'] = file_form |
|
469 | kwargs['form'] = file_form | |
464 | kwargs['suptitle'] = 'Importing file' |
|
470 | kwargs['suptitle'] = 'Importing file' | |
465 | kwargs['button'] = 'Import' |
|
471 | kwargs['button'] = 'Import' | |
466 |
|
472 | |||
467 | return render(request, 'campaign_import.html', kwargs) |
|
473 | return render(request, 'campaign_import.html', kwargs) | |
468 |
|
474 | |||
469 |
|
475 | |||
470 | def experiments(request): |
|
476 | def experiments(request): | |
471 |
|
477 | |||
472 | page = request.GET.get('page') |
|
478 | page = request.GET.get('page') | |
473 | order = ('location',) |
|
479 | order = ('location',) | |
474 | filters = request.GET.copy() |
|
480 | filters = request.GET.copy() | |
475 |
|
481 | |||
476 | kwargs = get_paginator(Experiment, page, order, filters) |
|
482 | kwargs = get_paginator(Experiment, page, order, filters) | |
477 |
|
483 | |||
478 |
form = FilterForm(initial=request.GET, extra_fields=['tags','template']) |
|
484 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) | |
479 |
|
485 | |||
480 |
kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time'] |
|
486 | kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time'] | |
481 | kwargs['title'] = 'Experiment' |
|
487 | kwargs['title'] = 'Experiment' | |
482 | kwargs['suptitle'] = 'List' |
|
488 | kwargs['suptitle'] = 'List' | |
483 | kwargs['form'] = form |
|
489 | kwargs['form'] = form | |
484 | filters.pop('page', None) |
|
490 | filters.pop('page', None) | |
485 |
kwargs['q'] = |
|
491 | kwargs['q'] = urlencode(filters) | |
486 |
|
492 | |||
487 | return render(request, 'base_list.html', kwargs) |
|
493 | return render(request, 'base_list.html', kwargs) | |
488 |
|
494 | |||
489 |
|
495 | |||
490 | def experiment(request, id_exp): |
|
496 | def experiment(request, id_exp): | |
491 |
|
497 | |||
492 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
498 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
493 |
|
499 | |||
494 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
500 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
495 |
|
501 | |||
496 | kwargs = {} |
|
502 | kwargs = {} | |
497 |
|
503 | |||
498 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] |
|
504 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
499 | kwargs['experiment'] = experiment |
|
505 | kwargs['experiment'] = experiment | |
500 |
|
506 | |||
501 | 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'] | |
502 | kwargs['configurations'] = configurations |
|
508 | kwargs['configurations'] = configurations | |
503 |
|
509 | |||
504 | kwargs['title'] = 'Experiment' |
|
510 | kwargs['title'] = 'Experiment' | |
505 | kwargs['suptitle'] = 'Details' |
|
511 | kwargs['suptitle'] = 'Details' | |
506 |
|
512 | |||
507 | kwargs['button'] = 'Add Configuration' |
|
513 | kwargs['button'] = 'Add Configuration' | |
508 |
|
514 | |||
509 | ###### SIDEBAR ###### |
|
515 | ###### SIDEBAR ###### | |
510 | kwargs.update(sidebar(experiment=experiment)) |
|
516 | kwargs.update(sidebar(experiment=experiment)) | |
511 |
|
517 | |||
512 | return render(request, 'experiment.html', kwargs) |
|
518 | return render(request, 'experiment.html', kwargs) | |
513 |
|
519 | |||
514 |
|
520 | |||
515 | def experiment_new(request, id_camp=None): |
|
521 | def experiment_new(request, id_camp=None): | |
516 |
|
522 | |||
517 | kwargs = {} |
|
523 | kwargs = {} | |
518 |
|
524 | |||
519 | if request.method == 'GET': |
|
525 | if request.method == 'GET': | |
520 | if 'template' in request.GET: |
|
526 | if 'template' in request.GET: | |
521 | if request.GET['template']=='0': |
|
527 | if request.GET['template']=='0': | |
@@ -523,146 +529,145 def experiment_new(request, id_camp=None): | |||||
523 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
529 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
524 | else: |
|
530 | else: | |
525 | kwargs['button'] = 'Create' |
|
531 | kwargs['button'] = 'Create' | |
526 |
kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
532 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |
527 | 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'] | |
528 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
534 | exp=Experiment.objects.get(pk=request.GET['template']) | |
529 |
form = ExperimentForm(instance=exp, |
|
535 | form = ExperimentForm(instance=exp, | |
530 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
536 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
531 |
'template': False}) |
|
537 | 'template': False}) | |
532 | elif 'blank' in request.GET: |
|
538 | elif 'blank' in request.GET: | |
533 | kwargs['button'] = 'Create' |
|
539 | kwargs['button'] = 'Create' | |
534 | form = ExperimentForm() |
|
540 | form = ExperimentForm() | |
535 | else: |
|
541 | else: | |
536 | form = NewForm() |
|
542 | form = NewForm() | |
537 |
|
543 | |||
538 | if request.method == 'POST': |
|
544 | if request.method == 'POST': | |
539 | form = ExperimentForm(request.POST) |
|
545 | form = ExperimentForm(request.POST) | |
540 | print form.data |
|
|||
541 | if form.is_valid(): |
|
546 | if form.is_valid(): | |
542 | experiment = form.save() |
|
547 | experiment = form.save() | |
543 |
|
548 | |||
544 | if 'template' in request.GET: |
|
549 | if 'template' in request.GET: | |
545 |
configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
550 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |
546 | for conf in configurations: |
|
551 | for conf in configurations: | |
547 | conf.clone(experiment=experiment, template=False) |
|
552 | conf.clone(experiment=experiment, template=False) | |
548 |
|
553 | |||
549 | return redirect('url_experiment', id_exp=experiment.id) |
|
554 | return redirect('url_experiment', id_exp=experiment.id) | |
550 |
|
555 | |||
551 | kwargs['form'] = form |
|
556 | kwargs['form'] = form | |
552 | kwargs['title'] = 'Experiment' |
|
557 | kwargs['title'] = 'Experiment' | |
553 | kwargs['suptitle'] = 'New' |
|
558 | kwargs['suptitle'] = 'New' | |
554 |
|
559 | |||
555 | return render(request, 'experiment_edit.html', kwargs) |
|
560 | return render(request, 'experiment_edit.html', kwargs) | |
556 |
|
561 | |||
557 |
|
562 | |||
558 | def experiment_edit(request, id_exp): |
|
563 | def experiment_edit(request, id_exp): | |
559 |
|
564 | |||
560 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
565 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
561 |
|
566 | |||
562 | if request.method == 'GET': |
|
567 | if request.method == 'GET': | |
563 | form = ExperimentForm(instance=experiment) |
|
568 | form = ExperimentForm(instance=experiment) | |
564 |
|
569 | |||
565 | if request.method=='POST': |
|
570 | if request.method=='POST': | |
566 | form = ExperimentForm(request.POST, instance=experiment) |
|
571 | form = ExperimentForm(request.POST, instance=experiment) | |
567 |
|
572 | |||
568 | if form.is_valid(): |
|
573 | if form.is_valid(): | |
569 | experiment = form.save() |
|
574 | experiment = form.save() | |
570 | return redirect('url_experiment', id_exp=experiment.id) |
|
575 | return redirect('url_experiment', id_exp=experiment.id) | |
571 |
|
576 | |||
572 | kwargs = {} |
|
577 | kwargs = {} | |
573 | kwargs['form'] = form |
|
578 | kwargs['form'] = form | |
574 | kwargs['title'] = 'Experiment' |
|
579 | kwargs['title'] = 'Experiment' | |
575 | kwargs['suptitle'] = 'Edit' |
|
580 | kwargs['suptitle'] = 'Edit' | |
576 | kwargs['button'] = 'Update' |
|
581 | kwargs['button'] = 'Update' | |
577 |
|
582 | |||
578 | return render(request, 'experiment_edit.html', kwargs) |
|
583 | return render(request, 'experiment_edit.html', kwargs) | |
579 |
|
584 | |||
580 |
|
585 | |||
581 | def experiment_delete(request, id_exp): |
|
586 | def experiment_delete(request, id_exp): | |
582 |
|
587 | |||
583 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
588 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
584 |
|
589 | |||
585 | if request.method=='POST': |
|
590 | if request.method=='POST': | |
586 | if request.user.is_staff: |
|
591 | if request.user.is_staff: | |
587 | for conf in Configuration.objects.filter(experiment=experiment): |
|
592 | for conf in Configuration.objects.filter(experiment=experiment): | |
588 |
conf.delete() |
|
593 | conf.delete() | |
589 | experiment.delete() |
|
594 | experiment.delete() | |
590 | return redirect('url_experiments') |
|
595 | return redirect('url_experiments') | |
591 |
|
596 | |||
592 | messages.error(request, 'Not enough permission to delete this object') |
|
597 | messages.error(request, 'Not enough permission to delete this object') | |
593 |
return redirect(experiment.get_absolute_url()) |
|
598 | return redirect(experiment.get_absolute_url()) | |
594 |
|
599 | |||
595 | kwargs = { |
|
600 | kwargs = { | |
596 | 'title': 'Delete', |
|
601 | 'title': 'Delete', | |
597 | 'suptitle': 'Experiment', |
|
602 | 'suptitle': 'Experiment', | |
598 |
'object': experiment, |
|
603 | 'object': experiment, | |
599 | 'previous': experiment.get_absolute_url(), |
|
604 | 'previous': experiment.get_absolute_url(), | |
600 | 'delete': True |
|
605 | 'delete': True | |
601 | } |
|
606 | } | |
602 |
|
607 | |||
603 | return render(request, 'confirm.html', kwargs) |
|
608 | return render(request, 'confirm.html', kwargs) | |
604 |
|
609 | |||
605 |
|
610 | |||
606 | def experiment_export(request, id_exp): |
|
611 | def experiment_export(request, id_exp): | |
607 |
|
612 | |||
608 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
613 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
609 |
content = experiment.parms_to_dict() |
|
614 | content = experiment.parms_to_dict() | |
610 | content_type = 'application/json' |
|
615 | content_type = 'application/json' | |
611 | filename = '%s_%s.json' %(experiment.name, experiment.id) |
|
616 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
612 |
|
617 | |||
613 | response = HttpResponse(content_type=content_type) |
|
618 | response = HttpResponse(content_type=content_type) | |
614 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
619 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
615 | response.write(content) |
|
620 | response.write(content) | |
616 |
|
621 | |||
617 | return response |
|
622 | return response | |
618 |
|
623 | |||
619 | def experiment_import(request, id_exp): |
|
624 | def experiment_import(request, id_exp): | |
620 |
|
625 | |||
621 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
626 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
622 | configurations = Configuration.objects.filter(experiment=experiment) |
|
627 | configurations = Configuration.objects.filter(experiment=experiment) | |
623 |
|
628 | |||
624 | if request.method == 'GET': |
|
629 | if request.method == 'GET': | |
625 | file_form = UploadFileForm() |
|
630 | file_form = UploadFileForm() | |
626 |
|
631 | |||
627 | if request.method == 'POST': |
|
632 | if request.method == 'POST': | |
628 | file_form = UploadFileForm(request.POST, request.FILES) |
|
633 | file_form = UploadFileForm(request.POST, request.FILES) | |
629 |
|
634 | |||
630 | if file_form.is_valid(): |
|
635 | if file_form.is_valid(): | |
631 |
|
636 | |||
632 | parms = experiment.import_from_file(request.FILES['file']) |
|
637 | parms = experiment.import_from_file(request.FILES['file']) | |
633 |
|
638 | |||
634 | if parms: |
|
639 | if parms: | |
635 |
|
640 | |||
636 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) |
|
641 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) | |
637 |
|
642 | |||
638 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
643 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
639 |
|
644 | |||
640 |
return redirect(new_exp.get_absolute_url_edit()) |
|
645 | return redirect(new_exp.get_absolute_url_edit()) | |
641 |
|
646 | |||
642 | messages.error(request, "Could not import parameters from file") |
|
647 | messages.error(request, "Could not import parameters from file") | |
643 |
|
648 | |||
644 | kwargs = {} |
|
649 | kwargs = {} | |
645 | kwargs['title'] = 'Experiment' |
|
650 | kwargs['title'] = 'Experiment' | |
646 | kwargs['form'] = file_form |
|
651 | kwargs['form'] = file_form | |
647 | kwargs['suptitle'] = 'Importing file' |
|
652 | kwargs['suptitle'] = 'Importing file' | |
648 | kwargs['button'] = 'Import' |
|
653 | kwargs['button'] = 'Import' | |
649 |
|
654 | |||
650 | kwargs.update(sidebar(experiment=experiment)) |
|
655 | kwargs.update(sidebar(experiment=experiment)) | |
651 |
|
656 | |||
652 | return render(request, 'experiment_import.html', kwargs) |
|
657 | return render(request, 'experiment_import.html', kwargs) | |
653 |
|
658 | |||
654 | def experiment_mix(request, id_exp): |
|
659 | def experiment_mix(request, id_exp): | |
655 |
|
660 | |||
656 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
661 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
657 | 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, | |
658 | mix=False)] |
|
663 | mix=False)] | |
659 |
|
664 | |||
660 | if len(rc_confs)<2: |
|
665 | if len(rc_confs)<2: | |
661 | 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') | |
662 | return redirect(experiment.get_absolute_url()) |
|
667 | return redirect(experiment.get_absolute_url()) | |
663 |
|
668 | |||
664 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) |
|
669 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) | |
665 |
|
670 | |||
666 | if mix_confs: |
|
671 | if mix_confs: | |
667 | mix = mix_confs[0] |
|
672 | mix = mix_confs[0] | |
668 | else: |
|
673 | else: | |
@@ -671,7 +676,7 def experiment_mix(request, id_exp): | |||||
671 | ipp=rc_confs[0].ipp, |
|
676 | ipp=rc_confs[0].ipp, | |
672 | clock_in=rc_confs[0].clock_in, |
|
677 | clock_in=rc_confs[0].clock_in, | |
673 | clock_divider=rc_confs[0].clock_divider, |
|
678 | clock_divider=rc_confs[0].clock_divider, | |
674 |
mix=True, |
|
679 | mix=True, | |
675 | parameters='') |
|
680 | parameters='') | |
676 | mix.save() |
|
681 | mix.save() | |
677 |
|
682 | |||
@@ -679,16 +684,16 def experiment_mix(request, id_exp): | |||||
679 | for i in range(len(rc_confs[0].get_lines())): |
|
684 | for i in range(len(rc_confs[0].get_lines())): | |
680 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) |
|
685 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |
681 | line.save() |
|
686 | line.save() | |
682 |
|
687 | |||
683 | initial = {'name': mix.name, |
|
688 | initial = {'name': mix.name, | |
684 | 'result': parse_mix_result(mix.parameters), |
|
689 | 'result': parse_mix_result(mix.parameters), | |
685 | 'delay': 0, |
|
690 | 'delay': 0, | |
686 | 'mask': [0,1,2,3,4,5,6,7] |
|
691 | 'mask': [0,1,2,3,4,5,6,7] | |
687 | } |
|
692 | } | |
688 |
|
693 | |||
689 |
if request.method=='GET': |
|
694 | if request.method=='GET': | |
690 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) |
|
695 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |
691 |
|
696 | |||
692 | if request.method=='POST': |
|
697 | if request.method=='POST': | |
693 | result = mix.parameters |
|
698 | result = mix.parameters | |
694 |
|
699 | |||
@@ -699,9 +704,9 def experiment_mix(request, id_exp): | |||||
699 | operation = MIX_OPERATIONS[request.POST['operation']] |
|
704 | operation = MIX_OPERATIONS[request.POST['operation']] | |
700 | else: |
|
705 | else: | |
701 | operation = ' ' |
|
706 | operation = ' ' | |
702 |
|
707 | |||
703 | mode = MIX_MODES[request.POST['mode']] |
|
708 | mode = MIX_MODES[request.POST['mode']] | |
704 |
|
709 | |||
705 | if result: |
|
710 | if result: | |
706 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, |
|
711 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, | |
707 | request.POST['experiment'], |
|
712 | request.POST['experiment'], | |
@@ -717,18 +722,18 def experiment_mix(request, id_exp): | |||||
717 | float(request.POST['delay']), |
|
722 | float(request.POST['delay']), | |
718 | parse_mask(request.POST.getlist('mask')) |
|
723 | parse_mask(request.POST.getlist('mask')) | |
719 | ) |
|
724 | ) | |
720 |
|
725 | |||
721 | mix.parameters = result |
|
726 | mix.parameters = result | |
722 | mix.name = request.POST['name'] |
|
727 | mix.name = request.POST['name'] | |
723 | mix.save() |
|
728 | mix.save() | |
724 | mix.update_pulses() |
|
729 | mix.update_pulses() | |
725 |
|
730 | |||
726 | initial['result'] = parse_mix_result(result) |
|
731 | initial['result'] = parse_mix_result(result) | |
727 | initial['name'] = mix.name |
|
732 | initial['name'] = mix.name | |
728 |
|
733 | |||
729 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) |
|
734 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |
730 |
|
735 | |||
731 |
|
736 | |||
732 | kwargs = { |
|
737 | kwargs = { | |
733 | 'title': 'Experiment', |
|
738 | 'title': 'Experiment', | |
734 | 'suptitle': 'Mix Configurations', |
|
739 | 'suptitle': 'Mix Configurations', | |
@@ -740,46 +745,46 def experiment_mix(request, id_exp): | |||||
740 | 'id_exp':id_exp, |
|
745 | 'id_exp':id_exp, | |
741 |
|
746 | |||
742 | } |
|
747 | } | |
743 |
|
748 | |||
744 | return render(request, 'experiment_mix.html', kwargs) |
|
749 | return render(request, 'experiment_mix.html', kwargs) | |
745 |
|
750 | |||
746 |
|
751 | |||
747 | def experiment_mix_delete(request, id_exp): |
|
752 | def experiment_mix_delete(request, id_exp): | |
748 |
|
753 | |||
749 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) |
|
754 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |
750 | values = conf.parameters.split('-') |
|
755 | values = conf.parameters.split('-') | |
751 | conf.parameters = '-'.join(values[:-1]) |
|
756 | conf.parameters = '-'.join(values[:-1]) | |
752 | conf.save() |
|
757 | conf.save() | |
753 |
|
758 | |||
754 | return redirect('url_mix_experiment', id_exp=id_exp) |
|
759 | return redirect('url_mix_experiment', id_exp=id_exp) | |
755 |
|
760 | |||
756 |
|
761 | |||
757 | def experiment_summary(request, id_exp): |
|
762 | def experiment_summary(request, id_exp): | |
758 |
|
763 | |||
759 | import json |
|
764 | import json | |
760 | import ast |
|
765 | import ast | |
761 |
|
766 | |||
762 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
767 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
763 | experiment_data = json.loads(experiment.parms_to_dict()) |
|
768 | experiment_data = json.loads(experiment.parms_to_dict()) | |
764 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
769 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
765 |
|
770 | |||
766 | kwargs = {} |
|
771 | kwargs = {} | |
767 |
|
772 | |||
768 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] |
|
773 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
769 | kwargs['experiment'] = experiment |
|
774 | kwargs['experiment'] = experiment | |
770 |
|
775 | |||
771 | 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'] | |
772 | kwargs['configurations'] = configurations |
|
777 | kwargs['configurations'] = configurations | |
773 | kwargs['experiment_data'] = experiment_data |
|
778 | kwargs['experiment_data'] = experiment_data | |
774 |
|
779 | |||
775 | kwargs['title'] = 'Experiment Summary' |
|
780 | kwargs['title'] = 'Experiment Summary' | |
776 | kwargs['suptitle'] = 'Details' |
|
781 | kwargs['suptitle'] = 'Details' | |
777 |
|
782 | |||
778 | kwargs['button'] = 'Verify Parameters' |
|
783 | kwargs['button'] = 'Verify Parameters' | |
779 |
|
784 | |||
780 | jars_conf = False |
|
785 | jars_conf = False | |
781 | rc_conf = False |
|
786 | rc_conf = False | |
782 |
|
787 | |||
783 | for configuration in configurations: |
|
788 | for configuration in configurations: | |
784 | #-------------------- JARS -----------------------: |
|
789 | #-------------------- JARS -----------------------: | |
785 | if configuration.device.device_type.name == 'jars': |
|
790 | if configuration.device.device_type.name == 'jars': | |
@@ -792,7 +797,7 def experiment_summary(request, id_exp): | |||||
792 | filter_parms = configuration.filter_parms |
|
797 | filter_parms = configuration.filter_parms | |
793 | filter_parms = ast.literal_eval(filter_parms) |
|
798 | filter_parms = ast.literal_eval(filter_parms) | |
794 | spectral_number = configuration.spectral_number |
|
799 | spectral_number = configuration.spectral_number | |
795 |
|
800 | |||
796 | #--------------------- RC ----------------------: |
|
801 | #--------------------- RC ----------------------: | |
797 | if configuration.device.device_type.name == 'rc': |
|
802 | if configuration.device.device_type.name == 'rc': | |
798 | rc_conf = True |
|
803 | rc_conf = True | |
@@ -805,13 +810,13 def experiment_summary(request, id_exp): | |||||
805 | window = '' |
|
810 | window = '' | |
806 | else: |
|
811 | else: | |
807 | code = rc_lines[3]['code'] |
|
812 | code = rc_lines[3]['code'] | |
808 |
|
813 | |||
809 | window_data = rc_lines[6]['params'][0] |
|
814 | window_data = rc_lines[6]['params'][0] | |
810 | h0 = str(window_data['first_height']) |
|
815 | h0 = str(window_data['first_height']) | |
811 | dh = str(window_data['resolution']) |
|
816 | dh = str(window_data['resolution']) | |
812 | nsa = str(window_data['number_of_samples']) |
|
817 | nsa = str(window_data['number_of_samples']) | |
813 | window = 'Ho='+h0+'km\nDH='+dh+'km\nNSA='+nsa |
|
818 | window = 'Ho='+h0+'km\nDH='+dh+'km\nNSA='+nsa | |
814 |
|
819 | |||
815 | tx = '' |
|
820 | tx = '' | |
816 | if float(rc_lines[1]['delays']) == 0: |
|
821 | if float(rc_lines[1]['delays']) == 0: | |
817 | tx = rc_lines[2]['pulse_width'] |
|
822 | tx = rc_lines[2]['pulse_width'] | |
@@ -819,22 +824,22 def experiment_summary(request, id_exp): | |||||
819 | tx = rc_lines[1]['pulse_width'] |
|
824 | tx = rc_lines[1]['pulse_width'] | |
820 | else: |
|
825 | else: | |
821 | tx = rc_lines[1]['pulse_width']+' | '+rc_lines[2]['pulse_width'] |
|
826 | tx = rc_lines[1]['pulse_width']+' | '+rc_lines[2]['pulse_width'] | |
822 |
|
827 | |||
823 | kwargs['tx'] = tx |
|
828 | kwargs['tx'] = tx | |
824 | kwargs['code'] = code |
|
829 | kwargs['code'] = code | |
825 | kwargs['window'] = window |
|
830 | kwargs['window'] = window | |
826 |
|
831 | |||
827 | #-------------------- DDS -----------------------: |
|
832 | #-------------------- DDS -----------------------: | |
828 | if configuration.device.device_type.name == 'dds': |
|
833 | if configuration.device.device_type.name == 'dds': | |
829 | dds_conf = True |
|
834 | dds_conf = True | |
830 | kwargs['dds_conf'] = dds_conf |
|
835 | kwargs['dds_conf'] = dds_conf | |
831 |
|
836 | |||
832 | #------ RC & JARS ------: |
|
837 | #------ RC & JARS ------: | |
833 | ipp = 937.5 # |
|
838 | ipp = 937.5 # | |
834 | nsa = 200# |
|
839 | nsa = 200# | |
835 | dh = 1.5 # |
|
840 | dh = 1.5 # | |
836 | channels_number = 5 # |
|
841 | channels_number = 5 # | |
837 |
|
842 | |||
838 | if rc_conf and jars_conf: |
|
843 | if rc_conf and jars_conf: | |
839 | if exp_type == 0: #Short |
|
844 | if exp_type == 0: #Short | |
840 | bytes = 2 |
|
845 | bytes = 2 | |
@@ -843,7 +848,7 def experiment_summary(request, id_exp): | |||||
843 | bytes = 4 |
|
848 | bytes = 4 | |
844 | channels = channels_number + spectral_number |
|
849 | channels = channels_number + spectral_number | |
845 | b = nsa*2*bytes*fftpoints*channels |
|
850 | b = nsa*2*bytes*fftpoints*channels | |
846 |
|
851 | |||
847 | ipps = (ipp*pow(10,-6))/0.15 |
|
852 | ipps = (ipp*pow(10,-6))/0.15 | |
848 | GB = 1048576.0*1024.0 |
|
853 | GB = 1048576.0*1024.0 | |
849 | Hour = 3600 |
|
854 | Hour = 3600 | |
@@ -852,39 +857,39 def experiment_summary(request, id_exp): | |||||
852 | kwargs['rate'] = str(rate)+" GB/h" |
|
857 | kwargs['rate'] = str(rate)+" GB/h" | |
853 | else: |
|
858 | else: | |
854 | kwargs['rate'] = '' |
|
859 | kwargs['rate'] = '' | |
855 |
|
860 | |||
856 | ###### SIDEBAR ###### |
|
861 | ###### SIDEBAR ###### | |
857 | kwargs.update(sidebar(experiment=experiment)) |
|
862 | kwargs.update(sidebar(experiment=experiment)) | |
858 |
|
863 | |||
859 | return render(request, 'experiment_summary.html', kwargs) |
|
864 | return render(request, 'experiment_summary.html', kwargs) | |
860 |
|
865 | |||
861 | def experiment_verify(request, id_exp): |
|
866 | def experiment_verify(request, id_exp): | |
862 |
|
867 | |||
863 |
import json |
|
868 | import json | |
864 | import ast |
|
869 | import ast | |
865 |
|
870 | |||
866 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
871 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
867 | experiment_data = json.loads(experiment.parms_to_dict()) |
|
872 | experiment_data = json.loads(experiment.parms_to_dict()) | |
868 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
873 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
869 |
|
874 | |||
870 | kwargs = {} |
|
875 | kwargs = {} | |
871 |
|
876 | |||
872 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] |
|
877 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |
873 | kwargs['experiment'] = experiment |
|
878 | kwargs['experiment'] = experiment | |
874 |
|
879 | |||
875 | 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'] | |
876 | kwargs['configurations'] = configurations |
|
881 | kwargs['configurations'] = configurations | |
877 | kwargs['experiment_data'] = experiment_data |
|
882 | kwargs['experiment_data'] = experiment_data | |
878 |
|
883 | |||
879 | kwargs['title'] = 'Verify Experiment' |
|
884 | kwargs['title'] = 'Verify Experiment' | |
880 | kwargs['suptitle'] = 'Parameters' |
|
885 | kwargs['suptitle'] = 'Parameters' | |
881 |
|
886 | |||
882 | kwargs['button'] = 'Update' |
|
887 | kwargs['button'] = 'Update' | |
883 |
|
888 | |||
884 | jars_conf = False |
|
889 | jars_conf = False | |
885 | rc_conf = False |
|
890 | rc_conf = False | |
886 | dds_conf = False |
|
891 | dds_conf = False | |
887 |
|
892 | |||
888 | for configuration in configurations: |
|
893 | for configuration in configurations: | |
889 | #-------------------- JARS -----------------------: |
|
894 | #-------------------- JARS -----------------------: | |
890 | if configuration.device.device_type.name == 'jars': |
|
895 | if configuration.device.device_type.name == 'jars': | |
@@ -899,35 +904,35 def experiment_verify(request, id_exp): | |||||
899 | filter_5 = filter_parms['filter_5'] |
|
904 | filter_5 = filter_parms['filter_5'] | |
900 | filter_fir = filter_parms['filter_fir'] |
|
905 | filter_fir = filter_parms['filter_fir'] | |
901 | samp_freq_jars = clock/filter_2/filter_5/filter_fir |
|
906 | samp_freq_jars = clock/filter_2/filter_5/filter_fir | |
902 |
|
907 | |||
903 | kwargs['samp_freq_jars'] = samp_freq_jars |
|
908 | kwargs['samp_freq_jars'] = samp_freq_jars | |
904 | kwargs['jars'] = configuration |
|
909 | kwargs['jars'] = configuration | |
905 |
|
910 | |||
906 | #--------------------- RC ----------------------: |
|
911 | #--------------------- RC ----------------------: | |
907 | if configuration.device.device_type.name == 'rc': |
|
912 | if configuration.device.device_type.name == 'rc': | |
908 | rc_conf = True |
|
913 | rc_conf = True | |
909 | rc_parms = configuration.parms_to_dict() |
|
914 | rc_parms = configuration.parms_to_dict() | |
910 | if rc_parms['mix'] == 'True': |
|
915 | if rc_parms['mix'] == 'True': | |
911 | pass |
|
916 | pass | |
912 |
else: |
|
917 | else: | |
913 | rc_lines = rc_parms['lines'] |
|
918 | rc_lines = rc_parms['lines'] | |
914 | dh = rc_lines[6]['params'][0]['resolution'] |
|
919 | dh = rc_lines[6]['params'][0]['resolution'] | |
915 | #--Sampling Frequency |
|
920 | #--Sampling Frequency | |
916 |
samp_freq_rc = 0.15/dh |
|
921 | samp_freq_rc = 0.15/dh | |
917 | kwargs['samp_freq_rc'] = samp_freq_rc |
|
922 | kwargs['samp_freq_rc'] = samp_freq_rc | |
918 |
|
923 | |||
919 | kwargs['rc_conf'] = rc_conf |
|
924 | kwargs['rc_conf'] = rc_conf | |
920 | kwargs['rc'] = configuration |
|
925 | kwargs['rc'] = configuration | |
921 |
|
926 | |||
922 | #-------------------- DDS ----------------------: |
|
927 | #-------------------- DDS ----------------------: | |
923 | if configuration.device.device_type.name == 'dds': |
|
928 | if configuration.device.device_type.name == 'dds': | |
924 | dds_conf = True |
|
929 | dds_conf = True | |
925 | dds_parms = configuration.parms_to_dict() |
|
930 | dds_parms = configuration.parms_to_dict() | |
926 |
|
931 | |||
927 | kwargs['dds_conf'] = dds_conf |
|
932 | kwargs['dds_conf'] = dds_conf | |
928 | kwargs['dds'] = configuration |
|
933 | kwargs['dds'] = configuration | |
929 |
|
934 | |||
930 |
|
935 | |||
931 | #------------Validation------------: |
|
936 | #------------Validation------------: | |
932 | #Clock |
|
937 | #Clock | |
933 | if dds_conf and rc_conf and jars_conf: |
|
938 | if dds_conf and rc_conf and jars_conf: | |
@@ -941,34 +946,34 def experiment_verify(request, id_exp): | |||||
941 | messages.warning(request, "Devices don't have the same clock.") |
|
946 | messages.warning(request, "Devices don't have the same clock.") | |
942 | if float(samp_freq_rc) != float(dds_parms['frequencyA']): |
|
947 | if float(samp_freq_rc) != float(dds_parms['frequencyA']): | |
943 | messages.warning(request, "Devices don't have the same Frequency A.") |
|
948 | messages.warning(request, "Devices don't have the same Frequency A.") | |
944 |
|
949 | |||
945 |
|
950 | |||
946 |
|
951 | |||
947 | ###### SIDEBAR ###### |
|
952 | ###### SIDEBAR ###### | |
948 | kwargs.update(sidebar(experiment=experiment)) |
|
953 | kwargs.update(sidebar(experiment=experiment)) | |
949 |
|
954 | |||
950 |
|
955 | |||
951 |
|
956 | |||
952 |
|
957 | |||
953 |
|
958 | |||
954 | return render(request, 'experiment_verify.html', kwargs) |
|
959 | return render(request, 'experiment_verify.html', kwargs) | |
955 |
|
960 | |||
956 |
|
961 | |||
957 | def parse_mix_result(s): |
|
962 | def parse_mix_result(s): | |
958 |
|
963 | |||
959 | values = s.split('-') |
|
964 | values = s.split('-') | |
960 |
html = 'EXP MOD OPE DELAY MASK\r\n' |
|
965 | html = 'EXP MOD OPE DELAY MASK\r\n' | |
961 |
|
966 | |||
962 | if not values or values[0] in ('', ' '): |
|
967 | if not values or values[0] in ('', ' '): | |
963 | return mark_safe(html) |
|
968 | return mark_safe(html) | |
964 |
|
969 | |||
965 | for i, value in enumerate(values): |
|
970 | for i, value in enumerate(values): | |
966 | if not value: |
|
971 | if not value: | |
967 | continue |
|
972 | continue | |
968 | pk, mode, operation, delay, mask = value.split('|') |
|
973 | pk, mode, operation, delay, mask = value.split('|') | |
969 | conf = RCConfiguration.objects.get(pk=pk) |
|
974 | conf = RCConfiguration.objects.get(pk=pk) | |
970 | if i==0: |
|
975 | if i==0: | |
971 |
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
976 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
972 | conf.name, |
|
977 | conf.name, | |
973 | mode, |
|
978 | mode, | |
974 | ' ', |
|
979 | ' ', | |
@@ -981,70 +986,70 def parse_mix_result(s): | |||||
981 | operation, |
|
986 | operation, | |
982 | delay, |
|
987 | delay, | |
983 | mask) |
|
988 | mask) | |
984 |
|
989 | |||
985 | return mark_safe(html) |
|
990 | return mark_safe(html) | |
986 |
|
991 | |||
987 | def parse_mask(l): |
|
992 | def parse_mask(l): | |
988 |
|
993 | |||
989 | values = [] |
|
994 | values = [] | |
990 |
|
995 | |||
991 | for x in range(8): |
|
996 | for x in range(8): | |
992 | if '{}'.format(x) in l: |
|
997 | if '{}'.format(x) in l: | |
993 | values.append(1) |
|
998 | values.append(1) | |
994 | else: |
|
999 | else: | |
995 | values.append(0) |
|
1000 | values.append(0) | |
996 |
|
1001 | |||
997 | values.reverse() |
|
1002 | values.reverse() | |
998 |
|
1003 | |||
999 | return int(''.join([str(x) for x in values]), 2) |
|
1004 | return int(''.join([str(x) for x in values]), 2) | |
1000 |
|
1005 | |||
1001 |
|
1006 | |||
1002 | def dev_confs(request): |
|
1007 | def dev_confs(request): | |
1003 |
|
1008 | |||
1004 |
|
1009 | |||
1005 | page = request.GET.get('page') |
|
1010 | page = request.GET.get('page') | |
1006 | order = ('type', 'device__device_type', 'experiment') |
|
1011 | order = ('type', 'device__device_type', 'experiment') | |
1007 | filters = request.GET.copy() |
|
1012 | filters = request.GET.copy() | |
1008 |
|
1013 | |||
1009 | kwargs = get_paginator(Configuration, page, order, filters) |
|
1014 | kwargs = get_paginator(Configuration, page, order, filters) | |
1010 |
|
1015 | |||
1011 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) |
|
1016 | form = FilterForm(initial=request.GET, extra_fields=['tags','template']) | |
1012 |
kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] |
|
1017 | kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date'] | |
1013 | kwargs['title'] = 'Configuration' |
|
1018 | kwargs['title'] = 'Configuration' | |
1014 | kwargs['suptitle'] = 'List' |
|
1019 | kwargs['suptitle'] = 'List' | |
1015 |
kwargs['form'] = form |
|
1020 | kwargs['form'] = form | |
1016 | filters.pop('page', None) |
|
1021 | filters.pop('page', None) | |
1017 |
kwargs['q'] = |
|
1022 | kwargs['q'] = urlencode(filters) | |
1018 |
|
1023 | |||
1019 | return render(request, 'base_list.html', kwargs) |
|
1024 | return render(request, 'base_list.html', kwargs) | |
1020 |
|
1025 | |||
1021 |
|
1026 | |||
1022 | def dev_conf(request, id_conf): |
|
1027 | def dev_conf(request, id_conf): | |
1023 |
|
1028 | |||
1024 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1029 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1025 |
|
1030 | |||
1026 | return redirect(conf.get_absolute_url()) |
|
1031 | return redirect(conf.get_absolute_url()) | |
1027 |
|
1032 | |||
1028 |
|
1033 | |||
1029 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
1034 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
1030 |
|
1035 | |||
1031 | initial = {} |
|
1036 | initial = {} | |
1032 | kwargs = {} |
|
1037 | kwargs = {} | |
1033 |
|
1038 | |||
1034 |
if id_exp |
|
1039 | if id_exp!=0: | |
1035 | initial['experiment'] = id_exp |
|
1040 | initial['experiment'] = id_exp | |
1036 |
|
1041 | |||
1037 |
if id_dev |
|
1042 | if id_dev!=0: | |
1038 | initial['device'] = id_dev |
|
1043 | initial['device'] = id_dev | |
1039 |
|
1044 | |||
1040 | if request.method == 'GET': |
|
1045 | if request.method == 'GET': | |
1041 |
|
1046 | |||
1042 | if id_dev: |
|
1047 | if id_dev: | |
1043 | kwargs['button'] = 'Create' |
|
1048 | kwargs['button'] = 'Create' | |
1044 | device = Device.objects.get(pk=id_dev) |
|
1049 | device = Device.objects.get(pk=id_dev) | |
1045 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
1050 | DevConfForm = CONF_FORMS[device.device_type.name] | |
1046 |
initial['name'] = request.GET['name'] |
|
1051 | initial['name'] = request.GET['name'] | |
1047 |
form = DevConfForm(initial=initial) |
|
1052 | form = DevConfForm(initial=initial) | |
1048 | else: |
|
1053 | else: | |
1049 | if 'template' in request.GET: |
|
1054 | if 'template' in request.GET: | |
1050 | if request.GET['template']=='0': |
|
1055 | if request.GET['template']=='0': | |
@@ -1052,225 +1057,200 def dev_conf_new(request, id_exp=0, id_dev=0): | |||||
1052 | form = NewForm(initial={'create_from':2}, |
|
1057 | form = NewForm(initial={'create_from':2}, | |
1053 | template_choices=choices) |
|
1058 | template_choices=choices) | |
1054 | else: |
|
1059 | else: | |
1055 |
kwargs['button'] = 'Create' |
|
1060 | kwargs['button'] = 'Create' | |
1056 | conf = Configuration.objects.get(pk=request.GET['template']) |
|
1061 | conf = Configuration.objects.get(pk=request.GET['template']) | |
1057 | id_dev = conf.device.pk |
|
1062 | id_dev = conf.device.pk | |
1058 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1063 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1059 |
form = DevConfForm(instance=conf, |
|
1064 | form = DevConfForm(instance=conf, | |
1060 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), |
|
1065 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), | |
1061 | 'template': False, |
|
1066 | 'template': False, | |
1062 |
'experiment':id_exp}) |
|
1067 | 'experiment':id_exp}) | |
1063 | elif 'blank' in request.GET: |
|
1068 | elif 'blank' in request.GET: | |
1064 |
kwargs['button'] = 'Create' |
|
1069 | kwargs['button'] = 'Create' | |
1065 | form = ConfigurationForm(initial=initial) |
|
1070 | form = ConfigurationForm(initial=initial) | |
1066 | else: |
|
1071 | else: | |
1067 | form = NewForm() |
|
1072 | form = NewForm() | |
1068 |
|
1073 | |||
1069 | if request.method == 'POST': |
|
1074 | if request.method == 'POST': | |
1070 |
|
1075 | |||
1071 | device = Device.objects.get(pk=request.POST['device']) |
|
1076 | device = Device.objects.get(pk=request.POST['device']) | |
1072 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
1077 | DevConfForm = CONF_FORMS[device.device_type.name] | |
1073 |
|
1078 | |||
1074 | form = DevConfForm(request.POST) |
|
1079 | form = DevConfForm(request.POST) | |
1075 | kwargs['button'] = 'Create' |
|
1080 | kwargs['button'] = 'Create' | |
1076 | if form.is_valid(): |
|
1081 | if form.is_valid(): | |
1077 | conf = form.save() |
|
1082 | conf = form.save() | |
1078 |
|
1083 | |||
1079 | 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': | |
1080 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) |
|
1085 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |
1081 | for line in lines: |
|
1086 | for line in lines: | |
1082 | line.clone(rc_configuration=conf) |
|
1087 | line.clone(rc_configuration=conf) | |
1083 |
|
1088 | |||
1084 |
if conf.device.device_type.name=='jars': |
|
1089 | if conf.device.device_type.name=='jars': | |
1085 | conf.add_parms_to_filter() |
|
1090 | conf.add_parms_to_filter() | |
1086 |
|
1091 | |||
1087 |
return redirect('url_dev_conf', id_conf=conf.pk) |
|
1092 | return redirect('url_dev_conf', id_conf=conf.pk) | |
1088 |
|
1093 | |||
1089 | kwargs['id_exp'] = id_exp |
|
1094 | kwargs['id_exp'] = id_exp | |
1090 | kwargs['form'] = form |
|
1095 | kwargs['form'] = form | |
1091 | kwargs['title'] = 'Configuration' |
|
1096 | kwargs['title'] = 'Configuration' | |
1092 | kwargs['suptitle'] = 'New' |
|
1097 | kwargs['suptitle'] = 'New' | |
1093 |
|
1098 | |||
1094 |
|
1099 | |||
1095 | if id_dev != 0: |
|
1100 | if id_dev != 0: | |
1096 | device = Device.objects.get(pk=id_dev) |
|
1101 | device = Device.objects.get(pk=id_dev) | |
1097 | kwargs['device'] = device.device_type.name |
|
1102 | kwargs['device'] = device.device_type.name | |
1098 |
|
1103 | |||
1099 | return render(request, 'dev_conf_edit.html', kwargs) |
|
1104 | return render(request, 'dev_conf_edit.html', kwargs) | |
1100 |
|
1105 | |||
1101 |
|
1106 | |||
1102 | def dev_conf_edit(request, id_conf): |
|
1107 | def dev_conf_edit(request, id_conf): | |
1103 |
|
1108 | |||
1104 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1109 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1105 |
|
1110 | |||
1106 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1107 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1111 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1108 |
|
1112 | |||
1109 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1110 |
|
||||
1111 | if request.method=='GET': |
|
1113 | if request.method=='GET': | |
1112 |
form = DevConfForm(instance= |
|
1114 | form = DevConfForm(instance=conf) | |
1113 |
|
1115 | |||
1114 | if request.method=='POST': |
|
1116 | if request.method=='POST': | |
1115 |
form = DevConfForm(request.POST, instance= |
|
1117 | form = DevConfForm(request.POST, instance=conf) | |
1116 |
|
1118 | |||
1117 | if form.is_valid(): |
|
1119 | if form.is_valid(): | |
1118 | form.save() |
|
1120 | form.save() | |
1119 | return redirect('url_dev_conf', id_conf=id_conf) |
|
1121 | return redirect('url_dev_conf', id_conf=id_conf) | |
1120 |
|
1122 | |||
1121 | kwargs = {} |
|
1123 | kwargs = {} | |
1122 | kwargs['form'] = form |
|
1124 | kwargs['form'] = form | |
1123 | kwargs['title'] = 'Device Configuration' |
|
1125 | kwargs['title'] = 'Device Configuration' | |
1124 | kwargs['suptitle'] = 'Edit' |
|
1126 | kwargs['suptitle'] = 'Edit' | |
1125 | kwargs['button'] = 'Update' |
|
1127 | kwargs['button'] = 'Update' | |
1126 |
|
1128 | |||
1127 | ###### SIDEBAR ###### |
|
1129 | ###### SIDEBAR ###### | |
1128 | kwargs.update(sidebar(conf=conf)) |
|
1130 | kwargs.update(sidebar(conf=conf)) | |
1129 |
|
1131 | |||
1130 | 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) | |
1131 |
|
1133 | |||
1132 |
|
1134 | |||
1133 | def dev_conf_start(request, id_conf): |
|
1135 | def dev_conf_start(request, id_conf): | |
1134 |
|
1136 | |||
1135 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1137 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1136 |
|
1138 | |||
1137 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1138 |
|
||||
1139 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1140 |
|
||||
1141 | if conf.start_device(): |
|
1139 | if conf.start_device(): | |
1142 | messages.success(request, conf.message) |
|
1140 | messages.success(request, conf.message) | |
1143 | else: |
|
1141 | else: | |
1144 | messages.error(request, conf.message) |
|
1142 | messages.error(request, conf.message) | |
1145 |
|
1143 | |||
1146 | conf.status_device() |
|
1144 | conf.status_device() | |
1147 |
|
1145 | |||
1148 | return redirect(conf.get_absolute_url()) |
|
1146 | return redirect(conf.get_absolute_url()) | |
1149 |
|
1147 | |||
1150 |
|
1148 | |||
1151 | def dev_conf_stop(request, id_conf): |
|
1149 | def dev_conf_stop(request, id_conf): | |
1152 |
|
1150 | |||
1153 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1151 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1154 |
|
1152 | |||
1155 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1156 |
|
||||
1157 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1158 |
|
||||
1159 | if conf.stop_device(): |
|
1153 | if conf.stop_device(): | |
1160 | messages.success(request, conf.message) |
|
1154 | messages.success(request, conf.message) | |
1161 | else: |
|
1155 | else: | |
1162 | messages.error(request, conf.message) |
|
1156 | messages.error(request, conf.message) | |
1163 |
|
1157 | |||
1164 | conf.status_device() |
|
1158 | conf.status_device() | |
1165 |
|
1159 | |||
1166 | return redirect(conf.get_absolute_url()) |
|
1160 | return redirect(conf.get_absolute_url()) | |
1167 |
|
1161 | |||
1168 |
|
1162 | |||
1169 | def dev_conf_status(request, id_conf): |
|
1163 | def dev_conf_status(request, id_conf): | |
1170 |
|
1164 | |||
1171 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1165 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1172 |
|
1166 | |||
1173 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1174 |
|
||||
1175 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1176 |
|
||||
1177 | if conf.status_device(): |
|
1167 | if conf.status_device(): | |
1178 | messages.success(request, conf.message) |
|
1168 | messages.success(request, conf.message) | |
1179 | else: |
|
1169 | else: | |
1180 | messages.error(request, conf.message) |
|
1170 | messages.error(request, conf.message) | |
1181 |
|
1171 | |||
1182 | return redirect(conf.get_absolute_url()) |
|
1172 | return redirect(conf.get_absolute_url()) | |
1183 |
|
1173 | |||
1184 |
|
1174 | |||
1185 | def dev_conf_write(request, id_conf): |
|
1175 | def dev_conf_write(request, id_conf): | |
1186 |
|
1176 | |||
1187 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1177 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1188 |
|
1178 | |||
1189 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1190 |
|
||||
1191 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1192 |
|
||||
1193 | answer = conf.write_device() |
|
1179 | answer = conf.write_device() | |
1194 | conf.status_device() |
|
1180 | conf.status_device() | |
1195 |
|
1181 | |||
1196 | if answer: |
|
1182 | if answer: | |
1197 | messages.success(request, conf.message) |
|
1183 | messages.success(request, conf.message) | |
1198 |
|
1184 | |||
1199 |
#Creating a historical configuration |
|
1185 | #Creating a historical configuration | |
1200 | conf.clone(type=1, template=False) |
|
1186 | conf.clone(type=1, template=False) | |
1201 |
|
1187 | |||
1202 | #Original configuration |
|
1188 | #Original configuration | |
1203 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1189 | conf = DevConfModel.objects.get(pk=id_conf) | |
1204 | else: |
|
1190 | else: | |
1205 | messages.error(request, conf.message) |
|
1191 | messages.error(request, conf.message) | |
1206 |
|
1192 | |||
1207 | return redirect(conf.get_absolute_url()) |
|
1193 | return redirect(conf.get_absolute_url()) | |
1208 |
|
1194 | |||
1209 |
|
1195 | |||
1210 | def dev_conf_read(request, id_conf): |
|
1196 | def dev_conf_read(request, id_conf): | |
1211 |
|
1197 | |||
1212 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1198 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1213 |
|
1199 | |||
1214 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1215 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1200 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1216 |
|
1201 | |||
1217 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1218 |
|
||||
1219 | if request.method=='GET': |
|
1202 | if request.method=='GET': | |
1220 |
|
1203 | |||
1221 | parms = conf.read_device() |
|
1204 | parms = conf.read_device() | |
1222 | conf.status_device() |
|
1205 | conf.status_device() | |
1223 |
|
1206 | |||
1224 | if not parms: |
|
1207 | if not parms: | |
1225 | messages.error(request, conf.message) |
|
1208 | messages.error(request, conf.message) | |
1226 | return redirect(conf.get_absolute_url()) |
|
1209 | return redirect(conf.get_absolute_url()) | |
1227 |
|
1210 | |||
1228 | form = DevConfForm(initial=parms, instance=conf) |
|
1211 | form = DevConfForm(initial=parms, instance=conf) | |
1229 |
|
1212 | |||
1230 | if request.method=='POST': |
|
1213 | if request.method=='POST': | |
1231 | form = DevConfForm(request.POST, instance=conf) |
|
1214 | form = DevConfForm(request.POST, instance=conf) | |
1232 |
|
1215 | |||
1233 | if form.is_valid(): |
|
1216 | if form.is_valid(): | |
1234 | form.save() |
|
1217 | form.save() | |
1235 | return redirect(conf.get_absolute_url()) |
|
1218 | return redirect(conf.get_absolute_url()) | |
1236 |
|
1219 | |||
1237 | messages.error(request, "Parameters could not be saved") |
|
1220 | messages.error(request, "Parameters could not be saved") | |
1238 |
|
1221 | |||
1239 | kwargs = {} |
|
1222 | kwargs = {} | |
1240 | kwargs['id_dev'] = conf.id |
|
1223 | kwargs['id_dev'] = conf.id | |
1241 | kwargs['form'] = form |
|
1224 | kwargs['form'] = form | |
1242 | kwargs['title'] = 'Device Configuration' |
|
1225 | kwargs['title'] = 'Device Configuration' | |
1243 | kwargs['suptitle'] = 'Parameters read from device' |
|
1226 | kwargs['suptitle'] = 'Parameters read from device' | |
1244 | kwargs['button'] = 'Save' |
|
1227 | kwargs['button'] = 'Save' | |
1245 |
|
1228 | |||
1246 | ###### SIDEBAR ###### |
|
1229 | ###### SIDEBAR ###### | |
1247 | kwargs.update(sidebar(conf=conf)) |
|
1230 | kwargs.update(sidebar(conf=conf)) | |
1248 |
|
1231 | |||
1249 | 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) | |
1250 |
|
1233 | |||
1251 |
|
1234 | |||
1252 | def dev_conf_import(request, id_conf): |
|
1235 | def dev_conf_import(request, id_conf): | |
1253 |
|
1236 | |||
1254 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1237 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1255 |
|
1238 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | ||
1256 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1239 | ||
1257 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
|||
1258 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1259 |
|
||||
1260 | if request.method == 'GET': |
|
1240 | if request.method == 'GET': | |
1261 | file_form = UploadFileForm() |
|
1241 | file_form = UploadFileForm() | |
1262 |
|
1242 | |||
1263 | if request.method == 'POST': |
|
1243 | if request.method == 'POST': | |
1264 | file_form = UploadFileForm(request.POST, request.FILES) |
|
1244 | file_form = UploadFileForm(request.POST, request.FILES) | |
1265 |
|
1245 | |||
1266 | if file_form.is_valid(): |
|
1246 | if file_form.is_valid(): | |
1267 |
|
1247 | |||
1268 | parms = conf.import_from_file(request.FILES['file']) |
|
1248 | parms = conf.import_from_file(request.FILES['file']) | |
1269 |
|
1249 | |||
1270 | if parms: |
|
1250 | if parms: | |
1271 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
1251 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
1272 | form = DevConfForm(initial=parms, instance=conf) |
|
1252 | form = DevConfForm(initial=parms, instance=conf) | |
1273 |
|
1253 | |||
1274 | kwargs = {} |
|
1254 | kwargs = {} | |
1275 | kwargs['id_dev'] = conf.id |
|
1255 | kwargs['id_dev'] = conf.id | |
1276 | kwargs['form'] = form |
|
1256 | kwargs['form'] = form | |
@@ -1279,94 +1259,90 def dev_conf_import(request, id_conf): | |||||
1279 | kwargs['button'] = 'Save' |
|
1259 | kwargs['button'] = 'Save' | |
1280 | kwargs['action'] = conf.get_absolute_url_edit() |
|
1260 | kwargs['action'] = conf.get_absolute_url_edit() | |
1281 | kwargs['previous'] = conf.get_absolute_url() |
|
1261 | kwargs['previous'] = conf.get_absolute_url() | |
1282 |
|
1262 | |||
1283 | ###### SIDEBAR ###### |
|
1263 | ###### SIDEBAR ###### | |
1284 | kwargs.update(sidebar(conf=conf)) |
|
1264 | kwargs.update(sidebar(conf=conf)) | |
1285 |
|
1265 | |||
1286 | 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) | |
1287 |
|
1267 | |||
1288 | messages.error(request, "Could not import parameters from file") |
|
1268 | messages.error(request, "Could not import parameters from file") | |
1289 |
|
1269 | |||
1290 | kwargs = {} |
|
1270 | kwargs = {} | |
1291 | kwargs['id_dev'] = conf.id |
|
1271 | kwargs['id_dev'] = conf.id | |
1292 | kwargs['title'] = 'Device Configuration' |
|
1272 | kwargs['title'] = 'Device Configuration' | |
1293 | kwargs['form'] = file_form |
|
1273 | kwargs['form'] = file_form | |
1294 | kwargs['suptitle'] = 'Importing file' |
|
1274 | kwargs['suptitle'] = 'Importing file' | |
1295 | kwargs['button'] = 'Import' |
|
1275 | kwargs['button'] = 'Import' | |
1296 |
|
1276 | |||
1297 | kwargs.update(sidebar(conf=conf)) |
|
1277 | kwargs.update(sidebar(conf=conf)) | |
1298 |
|
1278 | |||
1299 | return render(request, 'dev_conf_import.html', kwargs) |
|
1279 | return render(request, 'dev_conf_import.html', kwargs) | |
1300 |
|
1280 | |||
1301 |
|
1281 | |||
1302 | def dev_conf_export(request, id_conf): |
|
1282 | def dev_conf_export(request, id_conf): | |
1303 |
|
1283 | |||
1304 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1284 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1305 |
|
1285 | |||
1306 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
|||
1307 |
|
||||
1308 | conf = DevConfModel.objects.get(pk=id_conf) |
|
|||
1309 |
|
||||
1310 | if request.method == 'GET': |
|
1286 | if request.method == 'GET': | |
1311 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1287 | file_form = DownloadFileForm(conf.device.device_type.name) | |
1312 |
|
1288 | |||
1313 | if request.method == 'POST': |
|
1289 | if request.method == 'POST': | |
1314 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
1290 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
1315 |
|
1291 | |||
1316 | if file_form.is_valid(): |
|
1292 | if file_form.is_valid(): | |
1317 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
1293 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
1318 |
|
1294 | |||
1319 | response = HttpResponse(content_type=fields['content_type']) |
|
1295 | response = HttpResponse(content_type=fields['content_type']) | |
1320 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
1296 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
1321 | response.write(fields['content']) |
|
1297 | response.write(fields['content']) | |
1322 |
|
1298 | |||
1323 | return response |
|
1299 | return response | |
1324 |
|
1300 | |||
1325 | messages.error(request, "Could not export parameters") |
|
1301 | messages.error(request, "Could not export parameters") | |
1326 |
|
1302 | |||
1327 | kwargs = {} |
|
1303 | kwargs = {} | |
1328 | kwargs['id_dev'] = conf.id |
|
1304 | kwargs['id_dev'] = conf.id | |
1329 | kwargs['title'] = 'Device Configuration' |
|
1305 | kwargs['title'] = 'Device Configuration' | |
1330 | kwargs['form'] = file_form |
|
1306 | kwargs['form'] = file_form | |
1331 | kwargs['suptitle'] = 'Exporting file' |
|
1307 | kwargs['suptitle'] = 'Exporting file' | |
1332 | kwargs['button'] = 'Export' |
|
1308 | kwargs['button'] = 'Export' | |
1333 |
|
1309 | |||
1334 | return render(request, 'dev_conf_export.html', kwargs) |
|
1310 | return render(request, 'dev_conf_export.html', kwargs) | |
1335 |
|
1311 | |||
1336 |
|
1312 | |||
1337 | def dev_conf_delete(request, id_conf): |
|
1313 | def dev_conf_delete(request, id_conf): | |
1338 |
|
1314 | |||
1339 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1315 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1340 |
|
1316 | |||
1341 | if request.method=='POST': |
|
1317 | if request.method=='POST': | |
1342 | if request.user.is_staff: |
|
1318 | if request.user.is_staff: | |
1343 | conf.delete() |
|
1319 | conf.delete() | |
1344 | return redirect('url_dev_confs') |
|
1320 | return redirect('url_dev_confs') | |
1345 |
|
1321 | |||
1346 | messages.error(request, 'Not enough permission to delete this object') |
|
1322 | messages.error(request, 'Not enough permission to delete this object') | |
1347 |
return redirect(conf.get_absolute_url()) |
|
1323 | return redirect(conf.get_absolute_url()) | |
1348 |
|
1324 | |||
1349 | kwargs = { |
|
1325 | kwargs = { | |
1350 | 'title': 'Delete', |
|
1326 | 'title': 'Delete', | |
1351 | 'suptitle': 'Experiment', |
|
1327 | 'suptitle': 'Experiment', | |
1352 |
'object': conf, |
|
1328 | 'object': conf, | |
1353 | 'previous': conf.get_absolute_url(), |
|
1329 | 'previous': conf.get_absolute_url(), | |
1354 | 'delete': True |
|
1330 | 'delete': True | |
1355 | } |
|
1331 | } | |
1356 |
|
1332 | |||
1357 | return render(request, 'confirm.html', kwargs) |
|
1333 | return render(request, 'confirm.html', kwargs) | |
1358 |
|
1334 | |||
1359 |
|
1335 | |||
1360 | def sidebar(**kwargs): |
|
1336 | def sidebar(**kwargs): | |
1361 |
|
1337 | |||
1362 | side_data = {} |
|
1338 | side_data = {} | |
1363 |
|
1339 | |||
1364 | conf = kwargs.get('conf', None) |
|
1340 | conf = kwargs.get('conf', None) | |
1365 | experiment = kwargs.get('experiment', None) |
|
1341 | experiment = kwargs.get('experiment', None) | |
1366 |
|
1342 | |||
1367 | if not experiment: |
|
1343 | if not experiment: | |
1368 | experiment = conf.experiment |
|
1344 | experiment = conf.experiment | |
1369 |
|
1345 | |||
1370 | if experiment: |
|
1346 | if experiment: | |
1371 | side_data['experiment'] = experiment |
|
1347 | side_data['experiment'] = experiment | |
1372 | campaign = experiment.campaign_set.all() |
|
1348 | campaign = experiment.campaign_set.all() | |
@@ -1378,126 +1354,109 def sidebar(**kwargs): | |||||
1378 | configurations = experiment.configuration_set.filter(type=0) |
|
1354 | configurations = experiment.configuration_set.filter(type=0) | |
1379 | side_data['side_experiments'] = experiments |
|
1355 | side_data['side_experiments'] = experiments | |
1380 | side_data['side_configurations'] = configurations |
|
1356 | side_data['side_configurations'] = configurations | |
1381 |
|
1357 | |||
1382 | return side_data |
|
1358 | return side_data | |
1383 |
|
1359 | |||
1384 | def get_paginator(model, page, order, filters={}, n=10): |
|
1360 | def get_paginator(model, page, order, filters={}, n=10): | |
1385 |
|
1361 | |||
1386 | kwargs = {} |
|
1362 | kwargs = {} | |
1387 | query = Q() |
|
1363 | query = Q() | |
1388 | if isinstance(filters, QueryDict): |
|
1364 | if isinstance(filters, QueryDict): | |
1389 | filters = filters.dict() |
|
1365 | filters = filters.dict() | |
1390 | [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 ('', ' ')] | |
1391 | filters.pop('page', None) |
|
1367 | filters.pop('page', None) | |
1392 |
|
1368 | |||
1393 | if 'start_date' in filters: |
|
1369 | if 'start_date' in filters: | |
1394 | filters['start_date__gte'] = filters.pop('start_date') |
|
1370 | filters['start_date__gte'] = filters.pop('start_date') | |
1395 | if 'end_date' in filters: |
|
1371 | if 'end_date' in filters: | |
1396 | filters['start_date__lte'] = filters.pop('end_date') |
|
1372 | filters['start_date__lte'] = filters.pop('end_date') | |
1397 | if 'tags' in filters: |
|
1373 | if 'tags' in filters: | |
1398 |
tags = filters.pop('tags') |
|
1374 | tags = filters.pop('tags') | |
1399 | if 'tags' in model._meta.get_all_field_names(): |
|
1375 | if 'tags' in model._meta.get_all_field_names(): | |
1400 |
query = query | Q(tags__icontains=tags) |
|
1376 | query = query | Q(tags__icontains=tags) | |
1401 | if 'name' in model._meta.get_all_field_names(): |
|
1377 | if 'name' in model._meta.get_all_field_names(): | |
1402 |
query = query | Q(name__icontains=tags) |
|
1378 | query = query | Q(name__icontains=tags) | |
1403 | if 'location' in model._meta.get_all_field_names(): |
|
1379 | if 'location' in model._meta.get_all_field_names(): | |
1404 | query = query | Q(location__name__icontains=tags) |
|
1380 | query = query | Q(location__name__icontains=tags) | |
1405 | if 'device' in model._meta.get_all_field_names(): |
|
1381 | if 'device' in model._meta.get_all_field_names(): | |
1406 |
query = query | Q(device__name__icontains=tags) |
|
1382 | query = query | Q(device__name__icontains=tags) | |
1407 |
|
1383 | |||
1408 | object_list = model.objects.filter(query, **filters).order_by(*order) |
|
1384 | object_list = model.objects.filter(query, **filters).order_by(*order) | |
1409 | paginator = Paginator(object_list, n) |
|
1385 | paginator = Paginator(object_list, n) | |
1410 |
|
1386 | |||
1411 | try: |
|
1387 | try: | |
1412 | objects = paginator.page(page) |
|
1388 | objects = paginator.page(page) | |
1413 | except PageNotAnInteger: |
|
1389 | except PageNotAnInteger: | |
1414 | objects = paginator.page(1) |
|
1390 | objects = paginator.page(1) | |
1415 | except EmptyPage: |
|
1391 | except EmptyPage: | |
1416 | objects = paginator.page(paginator.num_pages) |
|
1392 | objects = paginator.page(paginator.num_pages) | |
1417 |
|
1393 | |||
1418 | kwargs['objects'] = objects |
|
1394 | kwargs['objects'] = objects | |
1419 | kwargs['offset'] = (int(page)-1)*n if page else 0 |
|
1395 | kwargs['offset'] = (int(page)-1)*n if page else 0 | |
1420 |
|
1396 | |||
1421 | return kwargs |
|
1397 | return kwargs | |
1422 |
|
1398 | |||
1423 | def operation(request, id_camp=None): |
|
1399 | def operation(request, id_camp=None): | |
|
1400 | ||||
|
1401 | kwargs = {} | |||
|
1402 | campaigns = Campaign.objects.filter(start_date__lte=datetime.now(), | |||
|
1403 | end_date__gte=datetime.now()).order_by('-start_date') | |||
1424 |
|
1404 | |||
1425 | if not id_camp: |
|
|||
1426 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
|||
1427 |
|
||||
1428 | if not campaigns: |
|
|||
1429 | kwargs = {} |
|
|||
1430 | kwargs['title'] = 'No Campaigns' |
|
|||
1431 | kwargs['suptitle'] = 'Empty' |
|
|||
1432 | return render(request, 'operation.html', kwargs) |
|
|||
1433 |
|
||||
1434 | id_camp = campaigns[0].id |
|
|||
1435 |
|
||||
1436 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
|||
1437 |
|
1405 | |||
1438 | if request.method=='GET': |
|
1406 | if id_camp: | |
1439 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
1407 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1440 |
|
1408 | form = OperationForm(initial={'campaign': campaign.id}, campaigns=campaigns) | ||
1441 | if request.method=='POST': |
|
1409 | kwargs['campaign'] = campaign | |
1442 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
1410 | else: | |
|
1411 | form = OperationForm(campaigns=campaigns) | |||
|
1412 | kwargs['form'] = form | |||
|
1413 | return render(request, 'operation.html', kwargs) | |||
|
1414 | ||||
1443 |
|
1415 | |||
1444 | if form.is_valid(): |
|
1416 | ||
1445 | return redirect('url_operation', id_camp=campaign.id) |
|
|||
1446 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
|||
1447 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
|||
1448 | #for exs in experiments: |
|
|||
1449 | # exs.get_status() |
|
|||
1450 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
|||
1451 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
|||
1452 | kwargs = {} |
|
|||
1453 | #---Campaign |
|
|||
1454 | kwargs['campaign'] = campaign |
|
|||
1455 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
|||
1456 | #---Experiment |
|
1417 | #---Experiment | |
1457 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1418 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1458 | kwargs['experiment_keys'] = keys[1:] |
|
1419 | kwargs['experiment_keys'] = keys[1:] | |
1459 | kwargs['experiments'] = experiments |
|
1420 | kwargs['experiments'] = experiments | |
1460 | #---Radar |
|
1421 | #---Radar | |
1461 |
kwargs['locations'] = location |
|
1422 | kwargs['locations'] = campaign.get_experiments_by_location() | |
|
1423 | print kwargs['locations'] | |||
1462 | #---Else |
|
1424 | #---Else | |
1463 | kwargs['title'] = 'Campaign' |
|
1425 | kwargs['title'] = 'Campaign' | |
1464 | kwargs['suptitle'] = campaign.name |
|
1426 | kwargs['suptitle'] = campaign.name | |
1465 | kwargs['form'] = form |
|
1427 | kwargs['form'] = form | |
1466 | kwargs['button'] = 'Search' |
|
1428 | ||
1467 | kwargs['details'] = True |
|
|||
1468 | kwargs['search_button'] = True |
|
|||
1469 |
|
||||
1470 | return render(request, 'operation.html', kwargs) |
|
1429 | return render(request, 'operation.html', kwargs) | |
1471 |
|
1430 | |||
1472 |
|
1431 | |||
1473 | def operation_search(request, id_camp=None): |
|
1432 | def operation_search(request, id_camp=None): | |
1474 |
|
1433 | |||
1475 |
|
1434 | |||
1476 | if not id_camp: |
|
1435 | if not id_camp: | |
1477 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1436 | campaigns = Campaign.objects.all().order_by('-start_date') | |
1478 |
|
1437 | |||
1479 | if not campaigns: |
|
1438 | if not campaigns: | |
1480 | return render(request, 'operation.html', {}) |
|
1439 | return render(request, 'operation.html', {}) | |
1481 |
|
1440 | |||
1482 | id_camp = campaigns[0].id |
|
1441 | id_camp = campaigns[0].id | |
1483 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1442 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1484 |
|
1443 | |||
1485 | if request.method=='GET': |
|
1444 | if request.method=='GET': | |
1486 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1445 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1487 |
|
1446 | |||
1488 | if request.method=='POST': |
|
1447 | if request.method=='POST': | |
1489 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
1448 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
1490 |
|
1449 | |||
1491 | if form.is_valid(): |
|
1450 | if form.is_valid(): | |
1492 | return redirect('url_operation', id_camp=campaign.id) |
|
1451 | return redirect('url_operation', id_camp=campaign.id) | |
1493 |
|
1452 | |||
1494 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1453 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
1495 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1454 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
1496 | #for exs in experiments: |
|
1455 | #for exs in experiments: | |
1497 | # exs.get_status() |
|
1456 | # exs.get_status() | |
1498 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1457 | locations= Location.objects.filter(experiment=experiments).distinct() | |
1499 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1458 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1500 |
|
1459 | |||
1501 | kwargs = {} |
|
1460 | kwargs = {} | |
1502 | #---Campaign |
|
1461 | #---Campaign | |
1503 | kwargs['campaign'] = campaign |
|
1462 | kwargs['campaign'] = campaign | |
@@ -1515,7 +1474,7 def operation_search(request, id_camp=None): | |||||
1515 | kwargs['button'] = 'Select' |
|
1474 | kwargs['button'] = 'Select' | |
1516 | kwargs['details'] = True |
|
1475 | kwargs['details'] = True | |
1517 | kwargs['search_button'] = False |
|
1476 | kwargs['search_button'] = False | |
1518 |
|
1477 | |||
1519 | return render(request, 'operation.html', kwargs) |
|
1478 | return render(request, 'operation.html', kwargs) | |
1520 |
|
1479 | |||
1521 |
|
1480 | |||
@@ -1524,14 +1483,14 def radar_play(request, id_camp, id_radar): | |||||
1524 | radar = get_object_or_404(Location, pk = id_radar) |
|
1483 | radar = get_object_or_404(Location, pk = id_radar) | |
1525 | today = datetime.today() |
|
1484 | today = datetime.today() | |
1526 | now = today.time() |
|
1485 | now = today.time() | |
1527 |
|
1486 | |||
1528 | #--Clear Old Experiments From RunningExperiment Object |
|
1487 | #--Clear Old Experiments From RunningExperiment Object | |
1529 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1488 | running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1530 | if running_experiment: |
|
1489 | if running_experiment: | |
1531 | running_experiment = running_experiment[0] |
|
1490 | running_experiment = running_experiment[0] | |
1532 | running_experiment.running_experiment.clear() |
|
1491 | running_experiment.running_experiment.clear() | |
1533 | running_experiment.save() |
|
1492 | running_experiment.save() | |
1534 |
|
1493 | |||
1535 | #--If campaign datetime is ok: |
|
1494 | #--If campaign datetime is ok: | |
1536 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1495 | if today >= campaign.start_date and today <= campaign.end_date: | |
1537 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1496 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
@@ -1562,7 +1521,7 def radar_play(request, id_camp, id_radar): | |||||
1562 | new_running_experiment.save() |
|
1521 | new_running_experiment.save() | |
1563 | new_running_experiment.running_experiment.add(exp) |
|
1522 | new_running_experiment.running_experiment.add(exp) | |
1564 | new_running_experiment.save() |
|
1523 | new_running_experiment.save() | |
1565 |
|
1524 | |||
1566 | if answer: |
|
1525 | if answer: | |
1567 | messages.success(request, conf.message) |
|
1526 | messages.success(request, conf.message) | |
1568 | exp.status=2 |
|
1527 | exp.status=2 | |
@@ -1573,8 +1532,8 def radar_play(request, id_camp, id_radar): | |||||
1573 | if exp.status == 1 or exp.status == 3: |
|
1532 | if exp.status == 1 or exp.status == 3: | |
1574 | exp.status=3 |
|
1533 | exp.status=3 | |
1575 | exp.save() |
|
1534 | exp.save() | |
1576 |
|
1535 | |||
1577 |
|
1536 | |||
1578 | route = request.META['HTTP_REFERER'] |
|
1537 | route = request.META['HTTP_REFERER'] | |
1579 | route = str(route) |
|
1538 | route = str(route) | |
1580 | if 'search' in route: |
|
1539 | if 'search' in route: | |
@@ -1587,7 +1546,7 def radar_stop(request, id_camp, id_radar): | |||||
1587 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1546 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1588 | radar = get_object_or_404(Location, pk = id_radar) |
|
1547 | radar = get_object_or_404(Location, pk = id_radar) | |
1589 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1548 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1590 |
|
1549 | |||
1591 | for exp in experiments: |
|
1550 | for exp in experiments: | |
1592 | configurations = Configuration.objects.filter(experiment = exp) |
|
1551 | configurations = Configuration.objects.filter(experiment = exp) | |
1593 | for conf in configurations: |
|
1552 | for conf in configurations: | |
@@ -1596,14 +1555,14 def radar_stop(request, id_camp, id_radar): | |||||
1596 | else: |
|
1555 | else: | |
1597 | answer = conf.stop_device() |
|
1556 | answer = conf.stop_device() | |
1598 | conf.status_device() |
|
1557 | conf.status_device() | |
1599 |
|
1558 | |||
1600 | if answer: |
|
1559 | if answer: | |
1601 | messages.success(request, conf.message) |
|
1560 | messages.success(request, conf.message) | |
1602 | exp.status=1 |
|
1561 | exp.status=1 | |
1603 | exp.save() |
|
1562 | exp.save() | |
1604 | else: |
|
1563 | else: | |
1605 | messages.error(request, conf.message) |
|
1564 | messages.error(request, conf.message) | |
1606 |
|
1565 | |||
1607 |
|
1566 | |||
1608 | route = request.META['HTTP_REFERER'] |
|
1567 | route = request.META['HTTP_REFERER'] | |
1609 | route = str(route) |
|
1568 | route = str(route) | |
@@ -1611,10 +1570,10 def radar_stop(request, id_camp, id_radar): | |||||
1611 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1570 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1612 | else: |
|
1571 | else: | |
1613 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1572 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1614 |
|
1573 | |||
1615 |
|
1574 | |||
1616 | def radar_refresh(request, id_camp, id_radar): |
|
1575 | def radar_refresh(request, id_camp, id_radar): | |
1617 |
|
1576 | |||
1618 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1577 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1619 | radar = get_object_or_404(Location, pk = id_radar) |
|
1578 | radar = get_object_or_404(Location, pk = id_radar) | |
1620 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1579 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
@@ -1627,3 +1586,4 def radar_refresh(request, id_camp, id_radar): | |||||
1627 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1586 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1628 | else: |
|
1587 | else: | |
1629 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1588 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
|
1589 |
@@ -1,5 +1,5 | |||||
1 |
from django.conf.urls import |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
3 | urlpatterns = patterns('apps.misc.views', |
|
3 | urlpatterns = ( | |
4 |
|
4 | |||
5 | ) |
|
5 | ) |
@@ -9,7 +9,7 from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |||||
9 | from .widgets import KmUnitWidget, KmUnitHzWidget, KmUnitDcWidget, UnitKmWidget, DefaultWidget, CodesWidget, HiddenWidget, HCheckboxSelectMultiple |
|
9 | from .widgets import KmUnitWidget, KmUnitHzWidget, KmUnitDcWidget, UnitKmWidget, DefaultWidget, CodesWidget, HiddenWidget, HCheckboxSelectMultiple | |
10 |
|
10 | |||
11 | def create_choices_from_model(model, conf_id, all_choice=False): |
|
11 | def create_choices_from_model(model, conf_id, all_choice=False): | |
12 |
|
12 | |||
13 | if model=='RCLine': |
|
13 | if model=='RCLine': | |
14 | instance = RCConfiguration.objects.get(pk=conf_id) |
|
14 | instance = RCConfiguration.objects.get(pk=conf_id) | |
15 | choices = [(line.pk, line.get_name()) for line in instance.get_lines(line_type__name='tx')] |
|
15 | choices = [(line.pk, line.get_name()) for line in instance.get_lines(line_type__name='tx')] | |
@@ -18,7 +18,7 def create_choices_from_model(model, conf_id, all_choice=False): | |||||
18 | else: |
|
18 | else: | |
19 | instance = globals()[model] |
|
19 | instance = globals()[model] | |
20 | choices = instance.objects.all().values_list('pk', 'name') |
|
20 | choices = instance.objects.all().values_list('pk', 'name') | |
21 |
|
21 | |||
22 | return choices |
|
22 | return choices | |
23 |
|
23 | |||
24 |
|
24 | |||
@@ -51,45 +51,45 class ExtFileField(forms.FileField): | |||||
51 | ext = ext.lower() |
|
51 | ext = ext.lower() | |
52 | if ext not in self.extensions: |
|
52 | if ext not in self.extensions: | |
53 | raise forms.ValidationError('Not allowed file type: %s' % ext) |
|
53 | raise forms.ValidationError('Not allowed file type: %s' % ext) | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | class RCConfigurationForm(forms.ModelForm): |
|
56 | class RCConfigurationForm(forms.ModelForm): | |
57 |
|
57 | |||
58 | def __init__(self, *args, **kwargs): |
|
58 | def __init__(self, *args, **kwargs): | |
59 | super(RCConfigurationForm, self).__init__(*args, **kwargs) |
|
59 | super(RCConfigurationForm, self).__init__(*args, **kwargs) | |
60 |
|
60 | |||
61 | instance = getattr(self, 'instance', None) |
|
61 | instance = getattr(self, 'instance', None) | |
62 |
|
62 | |||
63 | if instance and instance.pk: |
|
63 | if instance and instance.pk: | |
64 |
|
64 | |||
65 | devices = Device.objects.filter(device_type__name='rc') |
|
65 | devices = Device.objects.filter(device_type__name='rc') | |
66 | if instance.experiment: |
|
66 | if instance.experiment: | |
67 | self.fields['experiment'].widget.attrs['read_only'] = True |
|
67 | self.fields['experiment'].widget.attrs['read_only'] = True | |
68 |
#self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] |
|
68 | #self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
69 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
69 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
70 | self.fields['ipp'].widget = KmUnitHzWidget(attrs={'km2unit':instance.km2unit}) |
|
70 | self.fields['ipp'].widget = KmUnitHzWidget(attrs={'km2unit':instance.km2unit}) | |
71 | self.fields['clock'].widget.attrs['readonly'] = True |
|
71 | self.fields['clock'].widget.attrs['readonly'] = True | |
72 |
|
72 | |||
73 | self.fields['time_before'].label = mark_safe(self.fields['time_before'].label) |
|
73 | self.fields['time_before'].label = mark_safe(self.fields['time_before'].label) | |
74 | self.fields['time_after'].label = mark_safe(self.fields['time_after'].label) |
|
74 | self.fields['time_after'].label = mark_safe(self.fields['time_after'].label) | |
75 |
|
75 | |||
76 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): |
|
76 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): | |
77 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
77 | self.fields['experiment'].widget.attrs['readonly'] = True | |
78 |
|
78 | |||
79 | class Meta: |
|
79 | class Meta: | |
80 | model = RCConfiguration |
|
80 | model = RCConfiguration | |
81 | exclude = ('type', 'parameters', 'status', 'total_units', 'mix') |
|
81 | exclude = ('type', 'parameters', 'status', 'total_units', 'mix') | |
82 |
|
82 | |||
83 | def clean(self): |
|
83 | def clean(self): | |
84 | form_data = super(RCConfigurationForm, self).clean() |
|
84 | form_data = super(RCConfigurationForm, self).clean() | |
85 |
|
85 | |||
86 | if 'clock_divider' in form_data: |
|
86 | if 'clock_divider' in form_data: | |
87 | if form_data['clock_divider']<1: |
|
87 | if form_data['clock_divider']<1: | |
88 | self.add_error('clock_divider', 'Invalid Value') |
|
88 | self.add_error('clock_divider', 'Invalid Value') | |
89 | else: |
|
89 | else: | |
90 |
if form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider']))%10 |
|
90 | if form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider']))%10!=0: | |
91 | self.add_error('ipp', 'Invalid IPP units={}'.format(form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider'])))) |
|
91 | self.add_error('ipp', 'Invalid IPP units={}'.format(form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider'])))) | |
92 |
|
92 | |||
93 | return form_data |
|
93 | return form_data | |
94 |
|
94 | |||
95 | def save(self): |
|
95 | def save(self): | |
@@ -97,26 +97,26 class RCConfigurationForm(forms.ModelForm): | |||||
97 | conf.total_units = conf.ipp*conf.ntx*conf.km2unit |
|
97 | conf.total_units = conf.ipp*conf.ntx*conf.km2unit | |
98 | conf.save() |
|
98 | conf.save() | |
99 | return conf |
|
99 | return conf | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | class RCMixConfigurationForm(forms.Form): |
|
102 | class RCMixConfigurationForm(forms.Form): | |
103 |
|
103 | |||
104 | clock_in = forms.CharField(widget=forms.HiddenInput()) |
|
104 | clock_in = forms.CharField(widget=forms.HiddenInput()) | |
105 | clock_divider = forms.CharField(widget=forms.HiddenInput()) |
|
105 | clock_divider = forms.CharField(widget=forms.HiddenInput()) | |
106 | name = forms.CharField() |
|
106 | name = forms.CharField() | |
107 | experiment = forms.ChoiceField() |
|
107 | experiment = forms.ChoiceField() | |
108 | mode = forms.ChoiceField(widget=forms.RadioSelect(), |
|
108 | mode = forms.ChoiceField(widget=forms.RadioSelect(), | |
109 |
choices=[(0, 'Parallel'), (1, 'Sequence')], |
|
109 | choices=[(0, 'Parallel'), (1, 'Sequence')], | |
110 | initial=0) |
|
110 | initial=0) | |
111 | operation = forms.ChoiceField(widget=forms.RadioSelect(), |
|
111 | operation = forms.ChoiceField(widget=forms.RadioSelect(), | |
112 |
choices=[(0, 'OR'), (1, 'XOR'), (2, 'AND'), (3, 'NAND')], |
|
112 | choices=[(0, 'OR'), (1, 'XOR'), (2, 'AND'), (3, 'NAND')], | |
113 | initial=1) |
|
113 | initial=1) | |
114 | delay = forms.CharField() |
|
114 | delay = forms.CharField() | |
115 | mask = forms.MultipleChoiceField(choices=[(0, 'L1'),(1, 'L2'),(2, 'L3'),(3, 'L4'),(4, 'L5'),(5, 'L6'),(6, 'L7'),(7, 'L8')], |
|
115 | mask = forms.MultipleChoiceField(choices=[(0, 'L1'),(1, 'L2'),(2, 'L3'),(3, 'L4'),(4, 'L5'),(5, 'L6'),(6, 'L7'),(7, 'L8')], | |
116 | widget=HCheckboxSelectMultiple()) |
|
116 | widget=HCheckboxSelectMultiple()) | |
117 | result = forms.CharField(required=False, |
|
117 | result = forms.CharField(required=False, | |
118 | widget=forms.Textarea(attrs={'readonly':True, 'rows':5, 'class':'tabuled'})) |
|
118 | widget=forms.Textarea(attrs={'readonly':True, 'rows':5, 'class':'tabuled'})) | |
119 |
|
119 | |||
120 | def __init__(self, *args, **kwargs): |
|
120 | def __init__(self, *args, **kwargs): | |
121 | confs = kwargs.pop('confs', []) |
|
121 | confs = kwargs.pop('confs', []) | |
122 | if confs: |
|
122 | if confs: | |
@@ -130,103 +130,103 class RCMixConfigurationForm(forms.Form): | |||||
130 | self.fields['delay'].widget = KmUnitWidget(attrs = {'km2unit':km2unit}) |
|
130 | self.fields['delay'].widget = KmUnitWidget(attrs = {'km2unit':km2unit}) | |
131 | self.fields['clock_in'].initial = clock_in |
|
131 | self.fields['clock_in'].initial = clock_in | |
132 | self.fields['clock_divider'].initial = clock_divider |
|
132 | self.fields['clock_divider'].initial = clock_divider | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | class RCLineForm(forms.ModelForm): |
|
135 | class RCLineForm(forms.ModelForm): | |
136 |
|
136 | |||
137 | def __init__(self, *args, **kwargs): |
|
137 | def __init__(self, *args, **kwargs): | |
138 | self.extra_fields = kwargs.pop('extra_fields', []) |
|
138 | self.extra_fields = kwargs.pop('extra_fields', []) | |
139 | super(RCLineForm, self).__init__(*args, **kwargs) |
|
139 | super(RCLineForm, self).__init__(*args, **kwargs) | |
140 |
|
140 | |||
141 | if 'initial' in kwargs and 'line_type' in kwargs['initial']: |
|
141 | if 'initial' in kwargs and 'line_type' in kwargs['initial']: | |
142 | line_type = RCLineType.objects.get(pk=kwargs['initial']['line_type']) |
|
142 | line_type = RCLineType.objects.get(pk=kwargs['initial']['line_type']) | |
143 |
|
143 | |||
144 | if 'code_id' in kwargs['initial']: |
|
144 | if 'code_id' in kwargs['initial']: | |
145 | model_initial = kwargs['initial']['code_id'] |
|
145 | model_initial = kwargs['initial']['code_id'] | |
146 | else: |
|
146 | else: | |
147 | model_initial = 0 |
|
147 | model_initial = 0 | |
148 |
|
148 | |||
149 | params = json.loads(line_type.params) |
|
149 | params = json.loads(line_type.params) | |
150 |
|
150 | |||
151 | for label, value in self.extra_fields.items(): |
|
151 | for label, value in self.extra_fields.items(): | |
152 | if label=='params': |
|
152 | if label=='params': | |
153 | continue |
|
153 | continue | |
154 |
|
154 | |||
155 | if 'model' in params[label]: |
|
155 | if 'model' in params[label]: | |
156 |
self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], |
|
156 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], | |
157 | kwargs['initial']['rc_configuration']), |
|
157 | kwargs['initial']['rc_configuration']), | |
158 | initial=model_initial) |
|
158 | initial=model_initial) | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | else: |
|
161 | else: | |
162 | if label=='codes' and 'code_id' in kwargs['initial']: |
|
162 | if label=='codes' and 'code_id' in kwargs['initial']: | |
163 | self.fields[label] = forms.CharField(initial=RCLineCode.objects.get(pk=kwargs['initial']['code_id']).codes) |
|
163 | self.fields[label] = forms.CharField(initial=RCLineCode.objects.get(pk=kwargs['initial']['code_id']).codes) | |
164 | else: |
|
164 | else: | |
165 | self.fields[label] = forms.CharField(initial=value['value']) |
|
165 | self.fields[label] = forms.CharField(initial=value['value']) | |
166 |
|
166 | |||
167 | if label=='codes': |
|
167 | if label=='codes': | |
168 | self.fields[label].widget = CodesWidget() |
|
168 | self.fields[label].widget = CodesWidget() | |
169 |
|
169 | |||
170 | if self.data: |
|
170 | if self.data: | |
171 | line_type = RCLineType.objects.get(pk=self.data['line_type']) |
|
171 | line_type = RCLineType.objects.get(pk=self.data['line_type']) | |
172 |
|
172 | |||
173 | if 'code_id' in self.data: |
|
173 | if 'code_id' in self.data: | |
174 | model_initial = self.data['code_id'] |
|
174 | model_initial = self.data['code_id'] | |
175 | else: |
|
175 | else: | |
176 | model_initial = 0 |
|
176 | model_initial = 0 | |
177 |
|
177 | |||
178 | params = json.loads(line_type.params) |
|
178 | params = json.loads(line_type.params) | |
179 |
|
179 | |||
180 | for label, value in self.extra_fields.items(): |
|
180 | for label, value in self.extra_fields.items(): | |
181 | if label=='params': |
|
181 | if label=='params': | |
182 | continue |
|
182 | continue | |
183 |
|
183 | |||
184 | if 'model' in params[label]: |
|
184 | if 'model' in params[label]: | |
185 |
self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], |
|
185 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], | |
186 | self.data['rc_configuration']), |
|
186 | self.data['rc_configuration']), | |
187 | initial=model_initial) |
|
187 | initial=model_initial) | |
188 |
|
188 | |||
189 |
|
189 | |||
190 | else: |
|
190 | else: | |
191 | if label=='codes' and 'code' in self.data: |
|
191 | if label=='codes' and 'code' in self.data: | |
192 |
self.fields[label] = forms.CharField(initial=self.data['codes']) |
|
192 | self.fields[label] = forms.CharField(initial=self.data['codes']) | |
193 | else: |
|
193 | else: | |
194 | self.fields[label] = forms.CharField(initial=self.data[label]) |
|
194 | self.fields[label] = forms.CharField(initial=self.data[label]) | |
195 |
|
195 | |||
196 | if label=='codes': |
|
196 | if label=='codes': | |
197 | self.fields[label].widget = CodesWidget() |
|
197 | self.fields[label].widget = CodesWidget() | |
198 |
|
198 | |||
199 |
|
199 | |||
200 | class Meta: |
|
200 | class Meta: | |
201 | model = RCLine |
|
201 | model = RCLine | |
202 | fields = ('rc_configuration', 'line_type', 'channel') |
|
202 | fields = ('rc_configuration', 'line_type', 'channel') | |
203 | widgets = { |
|
203 | widgets = { | |
204 | 'channel': forms.HiddenInput(), |
|
204 | 'channel': forms.HiddenInput(), | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 |
|
207 | |||
208 | def clean(self): |
|
208 | def clean(self): | |
209 |
|
209 | |||
210 | form_data = self.cleaned_data |
|
210 | form_data = self.cleaned_data | |
211 |
if 'code' in self.data and self.data['TX_ref']=="0": |
|
211 | if 'code' in self.data and self.data['TX_ref']=="0": | |
212 | self.add_error('TX_ref', 'Choose a valid TX reference') |
|
212 | self.add_error('TX_ref', 'Choose a valid TX reference') | |
213 |
|
213 | |||
214 | if RCLineType.objects.get(pk=self.data['line_type']).name=='mix': |
|
214 | if RCLineType.objects.get(pk=self.data['line_type']).name=='mix': | |
215 | self.add_error('line_type', 'Invalid Line type') |
|
215 | self.add_error('line_type', 'Invalid Line type') | |
216 |
|
216 | |||
217 | return form_data |
|
217 | return form_data | |
218 |
|
218 | |||
219 |
|
219 | |||
220 |
def save(self): |
|
220 | def save(self): | |
221 | line = super(RCLineForm, self).save() |
|
221 | line = super(RCLineForm, self).save() | |
222 |
|
222 | |||
223 | #auto add channel |
|
223 | #auto add channel | |
224 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 |
|
224 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 | |
225 |
|
225 | |||
226 | #auto add position for TX, TR & CODE |
|
226 | #auto add position for TX, TR & CODE | |
227 | if line.line_type.name in ('tx', ): |
|
227 | if line.line_type.name in ('tx', ): | |
228 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 |
|
228 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 | |
229 |
|
229 | |||
230 | #save extra fields in params |
|
230 | #save extra fields in params | |
231 | params = {} |
|
231 | params = {} | |
232 | for label, value in self.extra_fields.items(): |
|
232 | for label, value in self.extra_fields.items(): | |
@@ -239,24 +239,24 class RCLineForm(forms.ModelForm): | |||||
239 | line.params = json.dumps(params) |
|
239 | line.params = json.dumps(params) | |
240 | line.save() |
|
240 | line.save() | |
241 | return |
|
241 | return | |
242 |
|
242 | |||
243 |
|
243 | |||
244 | class RCLineViewForm(forms.Form): |
|
244 | class RCLineViewForm(forms.Form): | |
245 |
|
245 | |||
246 | def __init__(self, *args, **kwargs): |
|
246 | def __init__(self, *args, **kwargs): | |
247 |
|
247 | |||
248 | extra_fields = kwargs.pop('extra_fields') |
|
248 | extra_fields = kwargs.pop('extra_fields') | |
249 | line = kwargs.pop('line') |
|
249 | line = kwargs.pop('line') | |
250 | subform = kwargs.pop('subform', False) |
|
250 | subform = kwargs.pop('subform', False) | |
251 | super(RCLineViewForm, self).__init__(*args, **kwargs) |
|
251 | super(RCLineViewForm, self).__init__(*args, **kwargs) | |
252 |
|
252 | |||
253 | if subform: |
|
253 | if subform: | |
254 | params = json.loads(line.line_type.params)['params'] |
|
254 | params = json.loads(line.line_type.params)['params'] | |
255 | else: |
|
255 | else: | |
256 | params = json.loads(line.line_type.params) |
|
256 | params = json.loads(line.line_type.params) | |
257 |
|
257 | |||
258 | for label, value in extra_fields.items(): |
|
258 | for label, value in extra_fields.items(): | |
259 |
|
259 | |||
260 | if label=='params': |
|
260 | if label=='params': | |
261 | continue |
|
261 | continue | |
262 | if 'ref' in label: |
|
262 | if 'ref' in label: | |
@@ -266,9 +266,9 class RCLineViewForm(forms.Form): | |||||
266 | value = RCLine.objects.get(pk=value).get_name() |
|
266 | value = RCLine.objects.get(pk=value).get_name() | |
267 | elif label=='code': |
|
267 | elif label=='code': | |
268 | value = RCLineCode.objects.get(pk=value).name |
|
268 | value = RCLineCode.objects.get(pk=value).name | |
269 |
|
269 | |||
270 |
self.fields[label] = forms.CharField(initial=value) |
|
270 | self.fields[label] = forms.CharField(initial=value) | |
271 |
|
271 | |||
272 | if 'widget' in params[label]: |
|
272 | if 'widget' in params[label]: | |
273 | km2unit = line.rc_configuration.km2unit |
|
273 | km2unit = line.rc_configuration.km2unit | |
274 | if params[label]['widget']=='km': |
|
274 | if params[label]['widget']=='km': | |
@@ -281,35 +281,35 class RCLineViewForm(forms.Form): | |||||
281 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) |
|
281 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) | |
282 | else: |
|
282 | else: | |
283 | self.fields[label].widget = DefaultWidget(attrs={'disabled':True}) |
|
283 | self.fields[label].widget = DefaultWidget(attrs={'disabled':True}) | |
284 |
|
284 | |||
285 |
|
285 | |||
286 | class RCLineEditForm(forms.ModelForm): |
|
286 | class RCLineEditForm(forms.ModelForm): | |
287 |
|
287 | |||
288 | def __init__(self, *args, **kwargs): |
|
288 | def __init__(self, *args, **kwargs): | |
289 |
|
289 | |||
290 | extra_fields = kwargs.pop('extra_fields', []) |
|
290 | extra_fields = kwargs.pop('extra_fields', []) | |
291 | conf = kwargs.pop('conf', False) |
|
291 | conf = kwargs.pop('conf', False) | |
292 | line = kwargs.pop('line') |
|
292 | line = kwargs.pop('line') | |
293 | subform = kwargs.pop('subform', False) |
|
293 | subform = kwargs.pop('subform', False) | |
294 |
|
294 | |||
295 | super(RCLineEditForm, self).__init__(*args, **kwargs) |
|
295 | super(RCLineEditForm, self).__init__(*args, **kwargs) | |
296 |
|
296 | |||
297 | if subform is not False: |
|
297 | if subform is not False: | |
298 | params = json.loads(line.line_type.params)['params'] |
|
298 | params = json.loads(line.line_type.params)['params'] | |
299 | count = subform |
|
299 | count = subform | |
300 | else: |
|
300 | else: | |
301 | params = json.loads(line.line_type.params) |
|
301 | params = json.loads(line.line_type.params) | |
302 |
count = -1 |
|
302 | count = -1 | |
303 |
|
303 | |||
304 | for label, value in extra_fields.items(): |
|
304 | for label, value in extra_fields.items(): | |
305 |
|
305 | |||
306 | if label in ('params',): |
|
306 | if label in ('params',): | |
307 | continue |
|
307 | continue | |
308 | if 'help' in params[label]: |
|
308 | if 'help' in params[label]: | |
309 | help_text = params[label]['help'] |
|
309 | help_text = params[label]['help'] | |
310 | else: |
|
310 | else: | |
311 | help_text = '' |
|
311 | help_text = '' | |
312 |
|
312 | |||
313 | if 'model' in params[label]: |
|
313 | if 'model' in params[label]: | |
314 | if line.line_type.name=='tr': |
|
314 | if line.line_type.name=='tr': | |
315 | all_choice = True |
|
315 | all_choice = True | |
@@ -319,66 +319,64 class RCLineEditForm(forms.ModelForm): | |||||
319 | initial=value, |
|
319 | initial=value, | |
320 | widget=forms.Select(attrs={'name':'%s|%s|%s' % (count, line.id, label)}), |
|
320 | widget=forms.Select(attrs={'name':'%s|%s|%s' % (count, line.id, label)}), | |
321 | help_text=help_text) |
|
321 | help_text=help_text) | |
322 |
|
322 | |||
323 |
else: |
|
323 | else: | |
324 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) |
|
324 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) | |
325 |
|
325 | |||
326 |
if label in ('code', ): |
|
326 | if label in ('code', ): | |
327 |
self.fields[label].widget = HiddenWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) |
|
327 | self.fields[label].widget = HiddenWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) | |
328 |
|
328 | |||
329 | elif 'widget' in params[label]: |
|
329 | elif 'widget' in params[label]: | |
330 |
km2unit = line.rc_configuration.km2unit |
|
330 | km2unit = line.rc_configuration.km2unit | |
331 |
if params[label]['widget']=='km': |
|
331 | if params[label]['widget']=='km': | |
332 | self.fields[label].widget = KmUnitWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
332 | self.fields[label].widget = KmUnitWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
333 | elif params[label]['widget']=='unit': |
|
333 | elif params[label]['widget']=='unit': | |
334 | self.fields[label].widget = UnitKmWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
334 | self.fields[label].widget = UnitKmWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
335 | elif params[label]['widget']=='dc': |
|
335 | elif params[label]['widget']=='dc': | |
336 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
336 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
337 | elif params[label]['widget']=='codes': |
|
337 | elif params[label]['widget']=='codes': | |
338 |
self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
338 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
339 | else: |
|
339 | else: | |
340 | self.fields[label].widget = DefaultWidget(attrs={'line':line, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
340 | self.fields[label].widget = DefaultWidget(attrs={'line':line, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
341 |
|
341 | |||
342 |
|
342 | |||
343 | class Meta: |
|
343 | class Meta: | |
344 | model = RCLine |
|
344 | model = RCLine | |
345 | exclude = ('rc_configuration', 'line_type', 'channel', 'position', 'params', 'pulses') |
|
345 | exclude = ('rc_configuration', 'line_type', 'channel', 'position', 'params', 'pulses') | |
346 |
|
346 | |||
347 |
|
347 | |||
348 | class RCSubLineEditForm(forms.Form): |
|
348 | class RCSubLineEditForm(forms.Form): | |
349 |
|
349 | |||
350 | def __init__(self, *args, **kwargs): |
|
350 | def __init__(self, *args, **kwargs): | |
351 | extra_fields = kwargs.pop('extra_fields') |
|
351 | extra_fields = kwargs.pop('extra_fields') | |
352 | count = kwargs.pop('count') |
|
352 | count = kwargs.pop('count') | |
353 | line = kwargs.pop('line') |
|
353 | line = kwargs.pop('line') | |
354 | super(RCSubLineEditForm, self).__init__(*args, **kwargs) |
|
354 | super(RCSubLineEditForm, self).__init__(*args, **kwargs) | |
355 |
for label, value in extra_fields.items(): |
|
355 | for label, value in extra_fields.items(): | |
356 | self.fields[label] = forms.CharField(initial=value, |
|
356 | self.fields[label] = forms.CharField(initial=value, | |
357 | widget=forms.TextInput(attrs={'name':'%s|%s|%s' % (count, line, label)})) |
|
357 | widget=forms.TextInput(attrs={'name':'%s|%s|%s' % (count, line, label)})) | |
358 |
|
358 | |||
359 |
|
359 | |||
360 | class RCImportForm(forms.Form): |
|
360 | class RCImportForm(forms.Form): | |
361 |
|
361 | |||
362 | file_name = ExtFileField(extensions=['.racp', '.json', '.dat']) |
|
362 | file_name = ExtFileField(extensions=['.racp', '.json', '.dat']) | |
363 |
|
363 | |||
364 |
|
364 | |||
365 |
class RCLineCodesForm(forms.ModelForm): |
|
365 | class RCLineCodesForm(forms.ModelForm): | |
366 |
|
366 | |||
367 | def __init__(self, *args, **kwargs): |
|
367 | def __init__(self, *args, **kwargs): | |
368 | super(RCLineCodesForm, self).__init__(*args, **kwargs) |
|
368 | super(RCLineCodesForm, self).__init__(*args, **kwargs) | |
369 |
|
369 | |||
370 | if 'initial' in kwargs: |
|
370 | if 'initial' in kwargs: | |
371 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), |
|
371 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), | |
372 | initial=kwargs['initial']['code']) |
|
372 | initial=kwargs['initial']['code']) | |
373 | if 'instance' in kwargs: |
|
373 | if 'instance' in kwargs: | |
374 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), |
|
374 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), | |
375 | initial=kwargs['instance'].pk) |
|
375 | initial=kwargs['instance'].pk) | |
376 |
|
376 | |||
377 | self.fields['codes'].widget = CodesWidget() |
|
377 | self.fields['codes'].widget = CodesWidget() | |
378 |
|
378 | |||
379 |
|
379 | |||
380 | class Meta: |
|
380 | class Meta: | |
381 | model = RCLineCode |
|
381 | model = RCLineCode | |
382 | exclude = ('name',) |
|
382 | exclude = ('name',) | |
383 |
|
||||
384 | No newline at end of file |
|
@@ -3,8 +3,6 import ast | |||||
3 | import json |
|
3 | import json | |
4 | import numpy as np |
|
4 | import numpy as np | |
5 |
|
5 | |||
6 | from polymorphic import PolymorphicModel |
|
|||
7 |
|
||||
8 | from django.db import models |
|
6 | from django.db import models | |
9 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
10 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
8 | from django.core.validators import MinValueValidator, MaxValueValidator | |
@@ -39,12 +37,12 DAT_CMDS = { | |||||
39 | # Pulse Design commands |
|
37 | # Pulse Design commands | |
40 | 'DISABLE' : 0, # Disables pulse generation |
|
38 | 'DISABLE' : 0, # Disables pulse generation | |
41 | 'ENABLE' : 24, # Enables pulse generation |
|
39 | 'ENABLE' : 24, # Enables pulse generation | |
42 |
'DELAY_START' : 40, # Write delay status to memory |
|
40 | 'DELAY_START' : 40, # Write delay status to memory | |
43 | 'FLIP_START' : 48, # Write flip status to memory |
|
41 | 'FLIP_START' : 48, # Write flip status to memory | |
44 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period |
|
42 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period | |
45 |
'TX_ONE' : 72, # Output '0' in line TX |
|
43 | 'TX_ONE' : 72, # Output '0' in line TX | |
46 |
'TX_ZERO' : 88, # Output '0' in line TX |
|
44 | 'TX_ZERO' : 88, # Output '0' in line TX | |
47 |
'SW_ONE' : 104, # Output '0' in line SW |
|
45 | 'SW_ONE' : 104, # Output '0' in line SW | |
48 | 'SW_ZERO' : 112, # Output '1' in line SW |
|
46 | 'SW_ZERO' : 112, # Output '1' in line SW | |
49 | 'RESTART': 120, # Restarts CR8 Firmware |
|
47 | 'RESTART': 120, # Restarts CR8 Firmware | |
50 | 'CONTINUE' : 253, # Function Unknown |
|
48 | 'CONTINUE' : 253, # Function Unknown | |
@@ -52,14 +50,14 DAT_CMDS = { | |||||
52 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. |
|
50 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. | |
53 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion |
|
51 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion | |
54 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. |
|
52 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. | |
55 |
'CLOCK_DIVIDER' : 8, |
|
53 | 'CLOCK_DIVIDER' : 8, | |
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 |
|
56 | |||
59 | class RCConfiguration(Configuration): |
|
57 | class RCConfiguration(Configuration): | |
60 |
|
58 | |||
61 | ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1), MaxValueValidator(9000)], default=300) |
|
59 | ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1), MaxValueValidator(9000)], default=300) | |
62 |
ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator(400)], default=1) |
|
60 | ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator(400)], default=1) | |
63 | clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) |
|
61 | clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) | |
64 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) |
|
62 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) | |
65 | clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) |
|
63 | clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) | |
@@ -74,100 +72,100 class RCConfiguration(Configuration): | |||||
74 |
|
72 | |||
75 | class Meta: |
|
73 | class Meta: | |
76 | db_table = 'rc_configurations' |
|
74 | db_table = 'rc_configurations' | |
77 |
|
75 | |||
78 | def get_absolute_url_plot(self): |
|
76 | def get_absolute_url_plot(self): | |
79 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) |
|
77 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) | |
80 |
|
78 | |||
81 | def get_absolute_url_import(self): |
|
79 | def get_absolute_url_import(self): | |
82 | return reverse('url_import_rc_conf', args=[str(self.id)]) |
|
80 | return reverse('url_import_rc_conf', args=[str(self.id)]) | |
83 |
|
81 | |||
84 | @property |
|
82 | @property | |
85 | def ipp_unit(self): |
|
83 | def ipp_unit(self): | |
86 |
|
84 | |||
87 | return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit)) |
|
85 | return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit)) | |
88 |
|
86 | |||
89 | @property |
|
87 | @property | |
90 | def us2unit(self): |
|
88 | def us2unit(self): | |
91 |
|
89 | |||
92 | return self.clock_in/self.clock_divider |
|
90 | return self.clock_in/self.clock_divider | |
93 |
|
91 | |||
94 | @property |
|
92 | @property | |
95 | def km2unit(self): |
|
93 | def km2unit(self): | |
96 |
|
94 | |||
97 | return 20./3*(self.clock_in/self.clock_divider) |
|
95 | return 20./3*(self.clock_in/self.clock_divider) | |
98 |
|
96 | |||
99 | def clone(self, **kwargs): |
|
97 | def clone(self, **kwargs): | |
100 |
|
98 | |||
101 | lines = self.get_lines() |
|
99 | lines = self.get_lines() | |
102 | self.pk = None |
|
100 | self.pk = None | |
103 | self.id = None |
|
101 | self.id = None | |
104 | for attr, value in kwargs.items(): |
|
102 | for attr, value in kwargs.items(): | |
105 | setattr(self, attr, value) |
|
103 | setattr(self, attr, value) | |
106 | self.save() |
|
104 | self.save() | |
107 |
|
105 | |||
108 | for line in lines: |
|
106 | for line in lines: | |
109 | line.clone(rc_configuration=self) |
|
107 | line.clone(rc_configuration=self) | |
110 |
|
108 | |||
111 |
return self |
|
109 | return self | |
112 |
|
110 | |||
113 | def get_lines(self, **kwargs): |
|
111 | def get_lines(self, **kwargs): | |
114 | ''' |
|
112 | ''' | |
115 |
Retrieve configuration lines |
|
113 | Retrieve configuration lines | |
116 | ''' |
|
114 | ''' | |
117 |
|
115 | |||
118 | return RCLine.objects.filter(rc_configuration=self.pk, **kwargs) |
|
116 | return RCLine.objects.filter(rc_configuration=self.pk, **kwargs) | |
119 |
|
117 | |||
120 |
|
118 | |||
121 | def clean_lines(self): |
|
119 | def clean_lines(self): | |
122 | ''' |
|
120 | ''' | |
123 | ''' |
|
121 | ''' | |
124 |
|
122 | |||
125 | empty_line = RCLineType.objects.get(name='none') |
|
123 | empty_line = RCLineType.objects.get(name='none') | |
126 |
|
124 | |||
127 | for line in self.get_lines(): |
|
125 | for line in self.get_lines(): | |
128 | line.line_type = empty_line |
|
126 | line.line_type = empty_line | |
129 | line.params = '{}' |
|
127 | line.params = '{}' | |
130 | line.save() |
|
128 | line.save() | |
131 |
|
129 | |||
132 | def parms_to_dict(self): |
|
130 | def parms_to_dict(self): | |
133 | ''' |
|
|||
134 |
|
|
131 | ''' | |
135 |
|
|
132 | ''' | |
|
133 | ||||
136 | ignored = ('parameters', 'type', 'polymorphic_ctype', 'configuration_ptr', |
|
134 | ignored = ('parameters', 'type', 'polymorphic_ctype', 'configuration_ptr', | |
137 | 'created_date', 'programmed_date') |
|
135 | 'created_date', 'programmed_date') | |
138 |
|
136 | |||
139 | data = {} |
|
137 | data = {} | |
140 | for field in self._meta.fields: |
|
138 | for field in self._meta.fields: | |
141 | if field.name in ignored: |
|
139 | if field.name in ignored: | |
142 | continue |
|
140 | continue | |
143 | data[field.name] = '{}'.format(field.value_from_object(self)) |
|
141 | data[field.name] = '{}'.format(field.value_from_object(self)) | |
144 |
|
142 | |||
145 | data['device_id'] = data.pop('device') |
|
143 | data['device_id'] = data.pop('device') | |
146 | data['lines'] = [] |
|
144 | data['lines'] = [] | |
147 |
|
145 | |||
148 | for line in self.get_lines(): |
|
146 | for line in self.get_lines(): | |
149 |
line_data = json.loads(line.params) |
|
147 | line_data = json.loads(line.params) | |
150 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): |
|
148 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): | |
151 | line_data['TX_ref'] = line.get_name() |
|
149 | line_data['TX_ref'] = RCLine.objects.get(pk=line_data['TX_ref']).get_name() | |
152 | if 'code' in line_data: |
|
150 | if 'code' in line_data: | |
153 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name |
|
151 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name | |
154 | line_data['type'] = line.line_type.name |
|
152 | line_data['type'] = line.line_type.name | |
155 | line_data['name'] = line.get_name() |
|
153 | line_data['name'] = line.get_name() | |
156 | data['lines'].append(line_data) |
|
154 | data['lines'].append(line_data) | |
157 |
|
155 | |||
158 | data['delays'] = self.get_delays() |
|
156 | data['delays'] = self.get_delays() | |
159 | data['pulses'] = self.get_pulses() |
|
157 | data['pulses'] = self.get_pulses() | |
160 |
|
158 | |||
161 | return data |
|
159 | return data | |
162 |
|
160 | |||
163 | def dict_to_parms(self, data): |
|
161 | def dict_to_parms(self, data): | |
164 | ''' |
|
162 | ''' | |
165 | ''' |
|
163 | ''' | |
166 |
|
164 | |||
167 | self.name = data['name'] |
|
165 | self.name = data['name'] | |
168 | self.ipp = float(data['ipp']) |
|
166 | self.ipp = float(data['ipp']) | |
169 | self.ntx = int(data['ntx']) |
|
167 | self.ntx = int(data['ntx']) | |
170 |
self.clock_in = float(data['clock_in']) |
|
168 | self.clock_in = float(data['clock_in']) | |
171 | self.clock_divider = int(data['clock_divider']) |
|
169 | self.clock_divider = int(data['clock_divider']) | |
172 | self.clock = float(data['clock']) |
|
170 | self.clock = float(data['clock']) | |
173 | self.time_before = data['time_before'] |
|
171 | self.time_before = data['time_before'] | |
@@ -177,36 +175,37 class RCConfiguration(Configuration): | |||||
177 | self.total_units = self.ipp*self.ntx*self.km2unit |
|
175 | self.total_units = self.ipp*self.ntx*self.km2unit | |
178 | self.save() |
|
176 | self.save() | |
179 | self.clean_lines() |
|
177 | self.clean_lines() | |
180 |
|
178 | |||
181 | lines = [] |
|
179 | lines = [] | |
182 |
positions = {'tx':0, 'tr':0} |
|
180 | positions = {'tx':0, 'tr':0} | |
183 |
|
181 | |||
184 |
for i, line_data in enumerate(data['lines']): |
|
182 | for i, line_data in enumerate(data['lines']): | |
|
183 | name = line_data.pop('name', '') | |||
185 | line_type = RCLineType.objects.get(name=line_data.pop('type')) |
|
184 | line_type = RCLineType.objects.get(name=line_data.pop('type')) | |
186 | if line_type.name=='codes': |
|
185 | if line_type.name=='codes': | |
187 | code = RCLineCode.objects.get(name=line_data['code']) |
|
186 | code = RCLineCode.objects.get(name=line_data['code']) | |
188 |
line_data['code'] = code.pk |
|
187 | line_data['code'] = code.pk | |
189 | line = RCLine.objects.filter(rc_configuration=self, channel=i) |
|
188 | line = RCLine.objects.filter(rc_configuration=self, channel=i) | |
190 | if line: |
|
189 | if line: | |
191 | line = line[0] |
|
190 | line = line[0] | |
192 | line.line_type = line_type |
|
191 | line.line_type = line_type | |
193 | line.params = json.dumps(line_data) |
|
192 | line.params = json.dumps(line_data) | |
194 | else: |
|
193 | else: | |
195 |
line = RCLine(rc_configuration=self, line_type=line_type, |
|
194 | line = RCLine(rc_configuration=self, line_type=line_type, | |
196 | params=json.dumps(line_data), |
|
195 | params=json.dumps(line_data), | |
197 | channel=i) |
|
196 | channel=i) | |
198 |
|
197 | |||
199 | if line_type.name=='tx': |
|
198 | if line_type.name=='tx': | |
200 | line.position = positions['tx'] |
|
199 | line.position = positions['tx'] | |
201 | positions['tx'] += 1 |
|
200 | positions['tx'] += 1 | |
202 |
|
201 | |||
203 | if line_type.name=='tr': |
|
202 | if line_type.name=='tr': | |
204 | line.position = positions['tr'] |
|
203 | line.position = positions['tr'] | |
205 | positions['tr'] += 1 |
|
204 | positions['tr'] += 1 | |
206 |
|
205 | |||
207 | line.save() |
|
206 | line.save() | |
208 | lines.append(line) |
|
207 | lines.append(line) | |
209 |
|
208 | |||
210 | for line, line_data in zip(lines, data['lines']): |
|
209 | for line, line_data in zip(lines, data['lines']): | |
211 | if 'TX_ref' in line_data: |
|
210 | if 'TX_ref' in line_data: | |
212 | params = json.loads(line.params) |
|
211 | params = json.loads(line.params) | |
@@ -216,101 +215,101 class RCConfiguration(Configuration): | |||||
216 | params['TX_ref'] = [l.pk for l in lines if l.line_type.name=='tx' and line_data['TX_ref'] in l.get_name()][0] |
|
215 | params['TX_ref'] = [l.pk for l in lines if l.line_type.name=='tx' and line_data['TX_ref'] in l.get_name()][0] | |
217 | line.params = json.dumps(params) |
|
216 | line.params = json.dumps(params) | |
218 | line.save() |
|
217 | line.save() | |
219 |
|
218 | |||
220 |
|
219 | |||
221 | def get_delays(self): |
|
220 | def get_delays(self): | |
222 |
|
221 | |||
223 | pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
222 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
224 | points = [tup for tups in pulses for tup in tups] |
|
223 | points = [tup for tups in pulses for tup in tups] | |
225 | points = set([x for tup in points for x in tup]) |
|
224 | points = set([x for tup in points for x in tup]) | |
226 | points = list(points) |
|
225 | points = list(points) | |
227 |
points.sort() |
|
226 | points.sort() | |
228 |
|
227 | |||
229 |
if points[0] |
|
228 | if points[0]!=0: | |
230 | points.insert(0, 0) |
|
229 | points.insert(0, 0) | |
231 |
|
230 | |||
232 | return [points[i+1]-points[i] for i in range(len(points)-1)] |
|
231 | return [points[i+1]-points[i] for i in range(len(points)-1)] | |
233 |
|
232 | |||
234 |
|
233 | |||
235 | def get_pulses(self, binary=True): |
|
234 | def get_pulses(self, binary=True): | |
236 |
|
235 | |||
237 | pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
236 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
238 | points = [tup for tups in pulses for tup in tups] |
|
237 | points = [tup for tups in pulses for tup in tups] | |
239 | points = set([x for tup in points for x in tup]) |
|
238 | points = set([x for tup in points for x in tup]) | |
240 | points = list(points) |
|
239 | points = list(points) | |
241 |
points.sort() |
|
240 | points.sort() | |
242 |
|
241 | |||
243 | line_points = [line.pulses_as_points() for line in self.get_lines()] |
|
242 | line_points = [line.pulses_as_points() for line in self.get_lines()] | |
244 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] |
|
243 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] | |
245 |
line_points = [[t for x in tups for t in x] for tups in line_points] |
|
244 | line_points = [[t for x in tups for t in x] for tups in line_points] | |
246 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] |
|
245 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] | |
247 |
|
246 | |||
248 | if binary: |
|
247 | if binary: | |
249 | states.reverse() |
|
248 | states.reverse() | |
250 | states = [int(''.join([str(x) for x in flips]), 2) for flips in states] |
|
249 | states = [int(''.join([str(x) for x in flips]), 2) for flips in states] | |
251 |
|
250 | |||
252 | return states[:-1] |
|
251 | return states[:-1] | |
253 |
|
252 | |||
254 | def add_cmd(self, cmd): |
|
253 | def add_cmd(self, cmd): | |
255 |
|
254 | |||
256 | if cmd in DAT_CMDS: |
|
255 | if cmd in DAT_CMDS: | |
257 | return (255, DAT_CMDS[cmd]) |
|
256 | return (255, DAT_CMDS[cmd]) | |
258 |
|
257 | |||
259 |
def add_data(self, value): |
|
258 | def add_data(self, value): | |
260 |
|
259 | |||
261 | return (254, value-1) |
|
260 | return (254, value-1) | |
262 |
|
261 | |||
263 | def parms_to_binary(self): |
|
262 | def parms_to_binary(self): | |
264 | ''' |
|
263 | ''' | |
265 | Create "dat" stream to be send to CR |
|
264 | Create "dat" stream to be send to CR | |
266 | ''' |
|
265 | ''' | |
267 |
|
266 | |||
268 | data = [] |
|
267 | data = [] | |
269 | # create header |
|
268 | # create header | |
270 | data.append(self.add_cmd('DISABLE')) |
|
269 | data.append(self.add_cmd('DISABLE')) | |
271 | data.append(self.add_cmd('CONTINUE')) |
|
270 | data.append(self.add_cmd('CONTINUE')) | |
272 | data.append(self.add_cmd('RESTART')) |
|
271 | data.append(self.add_cmd('RESTART')) | |
273 |
|
272 | |||
274 | if self.control_sw: |
|
273 | if self.control_sw: | |
275 | data.append(self.add_cmd('SW_ONE')) |
|
274 | data.append(self.add_cmd('SW_ONE')) | |
276 | else: |
|
275 | else: | |
277 | data.append(self.add_cmd('SW_ZERO')) |
|
276 | data.append(self.add_cmd('SW_ZERO')) | |
278 |
|
277 | |||
279 | if self.control_tx: |
|
278 | if self.control_tx: | |
280 | data.append(self.add_cmd('TX_ONE')) |
|
279 | data.append(self.add_cmd('TX_ONE')) | |
281 | else: |
|
280 | else: | |
282 | data.append(self.add_cmd('TX_ZERO')) |
|
281 | data.append(self.add_cmd('TX_ZERO')) | |
283 |
|
282 | |||
284 | # write divider |
|
283 | # write divider | |
285 | data.append(self.add_cmd('CLOCK_DIVIDER')) |
|
284 | data.append(self.add_cmd('CLOCK_DIVIDER')) | |
286 | data.append(self.add_data(self.clock_divider)) |
|
285 | data.append(self.add_data(self.clock_divider)) | |
287 |
|
286 | |||
288 | # write delays |
|
287 | # write delays | |
289 | data.append(self.add_cmd('DELAY_START')) |
|
288 | data.append(self.add_cmd('DELAY_START')) | |
290 | # first delay is always zero |
|
289 | # first delay is always zero | |
291 | data.append(self.add_data(1)) |
|
290 | data.append(self.add_data(1)) | |
292 |
|
291 | |||
293 | delays = self.get_delays() |
|
292 | delays = self.get_delays() | |
294 |
|
293 | |||
295 |
for delay in delays: |
|
294 | for delay in delays: | |
296 |
while delay>252: |
|
295 | while delay>252: | |
297 | data.append(self.add_data(253)) |
|
296 | data.append(self.add_data(253)) | |
298 | delay -= 253 |
|
297 | delay -= 253 | |
299 | data.append(self.add_data(delay)) |
|
298 | data.append(self.add_data(delay)) | |
300 |
|
299 | |||
301 | # write flips |
|
300 | # write flips | |
302 |
data.append(self.add_cmd('FLIP_START')) |
|
301 | data.append(self.add_cmd('FLIP_START')) | |
303 |
|
302 | |||
304 | states = self.get_pulses(binary=False) |
|
303 | states = self.get_pulses(binary=False) | |
305 |
|
304 | |||
306 | for flips, delay in zip(states, delays): |
|
305 | for flips, delay in zip(states, delays): | |
307 | flips.reverse() |
|
306 | flips.reverse() | |
308 |
flip = int(''.join([str(x) for x in flips]), 2) |
|
307 | flip = int(''.join([str(x) for x in flips]), 2) | |
309 | data.append(self.add_data(flip+1)) |
|
308 | data.append(self.add_data(flip+1)) | |
310 | while delay>252: |
|
309 | while delay>252: | |
311 | data.append(self.add_data(1)) |
|
310 | data.append(self.add_data(1)) | |
312 | delay -= 253 |
|
311 | delay -= 253 | |
313 |
|
312 | |||
314 | # write sampling period |
|
313 | # write sampling period | |
315 | data.append(self.add_cmd('SAMPLING_PERIOD')) |
|
314 | data.append(self.add_cmd('SAMPLING_PERIOD')) | |
316 | wins = self.get_lines(line_type__name='windows') |
|
315 | wins = self.get_lines(line_type__name='windows') | |
@@ -323,91 +322,92 class RCConfiguration(Configuration): | |||||
323 | else: |
|
322 | else: | |
324 | dh = 1 |
|
323 | dh = 1 | |
325 | data.append(self.add_data(dh)) |
|
324 | data.append(self.add_data(dh)) | |
326 |
|
325 | |||
327 | # write enable |
|
326 | # write enable | |
328 | data.append(self.add_cmd('ENABLE')) |
|
327 | data.append(self.add_cmd('ENABLE')) | |
329 |
|
328 | |||
330 | return '\n'.join(['{}'.format(x) for tup in data for x in tup]) |
|
329 | return '\n'.join(['{}'.format(x) for tup in data for x in tup]) | |
331 |
|
330 | |||
332 | def update_from_file(self, filename): |
|
331 | def update_from_file(self, filename): | |
333 | ''' |
|
332 | ''' | |
334 | Update instance from file |
|
333 | Update instance from file | |
335 | ''' |
|
334 | ''' | |
336 |
|
335 | |||
337 | f = RCFile(filename) |
|
336 | f = RCFile(filename) | |
338 | self.dict_to_parms(f.data) |
|
337 | self.dict_to_parms(f.data) | |
339 | self.update_pulses() |
|
338 | self.update_pulses() | |
340 |
|
339 | |||
341 | def update_pulses(self): |
|
340 | def update_pulses(self): | |
342 |
|
341 | |||
343 | for line in self.get_lines(): |
|
342 | for line in self.get_lines(): | |
344 | line.update_pulses() |
|
343 | line.update_pulses() | |
345 |
|
344 | |||
346 | def plot_pulses(self, km=False): |
|
345 | def plot_pulses(self, km=False): | |
347 |
|
346 | |||
348 | import matplotlib.pyplot as plt |
|
347 | import matplotlib.pyplot as plt | |
349 | from bokeh.resources import CDN |
|
348 | from bokeh.resources import CDN | |
350 | from bokeh.embed import components |
|
349 | from bokeh.embed import components | |
351 |
from bokeh.mpl import to_bokeh |
|
350 | from bokeh.mpl import to_bokeh | |
352 |
from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, |
|
351 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool | |
353 |
|
352 | |||
354 |
lines = self.get_lines() |
|
353 | lines = self.get_lines() | |
355 |
|
354 | |||
356 | N = len(lines) |
|
355 | N = len(lines) | |
357 |
npoints = self.total_units/self.km2unit if km else self.total_units |
|
356 | npoints = self.total_units/self.km2unit if km else self.total_units | |
358 | fig = plt.figure(figsize=(10, 2+N*0.5)) |
|
357 | fig = plt.figure(figsize=(10, 2+N*0.5)) | |
359 | ax = fig.add_subplot(111) |
|
358 | ax = fig.add_subplot(111) | |
360 |
labels = ['IPP'] |
|
359 | labels = ['IPP'] | |
361 |
|
360 | |||
362 | for i, line in enumerate(lines): |
|
361 | for i, line in enumerate(lines): | |
363 |
labels.append(line.get_name(channel=True)) |
|
362 | labels.append(line.get_name(channel=True)) | |
364 | l = ax.plot((0, npoints),(N-i-1, N-i-1)) |
|
363 | l = ax.plot((0, npoints),(N-i-1, N-i-1)) | |
365 |
points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points(km=km) if tup |
|
364 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points(km=km) if tup!=(0,0)] | |
366 |
ax.broken_barh(points, (N-i-1, 0.5), |
|
365 | ax.broken_barh(points, (N-i-1, 0.5), | |
367 | edgecolor=l[0].get_color(), facecolor='none') |
|
366 | edgecolor=l[0].get_color(), facecolor='none') | |
368 |
|
367 | |||
369 | n = 0 |
|
368 | n = 0 | |
370 | f = ((self.ntx+50)/100)*5 if ((self.ntx+50)/100)*10>0 else 2 |
|
369 | f = ((self.ntx+50)/100)*5 if ((self.ntx+50)/100)*10>0 else 2 | |
371 | for x in np.arange(0, npoints, self.ipp if km else self.ipp*self.km2unit): |
|
370 | for x in np.arange(0, npoints, self.ipp if km else self.ipp*self.km2unit): | |
372 | if n%f==0: |
|
371 | if n%f==0: | |
373 | ax.text(x, N, '%s' % n, size=10) |
|
372 | ax.text(x, N, '%s' % n, size=10) | |
374 | n += 1 |
|
373 | n += 1 | |
375 |
|
374 | |||
376 |
|
375 | |||
377 | labels.reverse() |
|
376 | labels.reverse() | |
|
377 | ax.set_yticks(range(len(labels))) | |||
378 | ax.set_yticklabels(labels) |
|
378 | ax.set_yticklabels(labels) | |
379 |
|
||||
380 | ax.set_xlabel = 'Units' |
|
379 | ax.set_xlabel = 'Units' | |
381 |
plot = to_bokeh(fig, use_pandas=False) |
|
380 | plot = to_bokeh(fig, use_pandas=False) | |
382 |
plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), |
|
381 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), SaveTool()] | |
383 |
|
382 | plot.toolbar_location="above" | ||
|
383 | ||||
384 | return components(plot, CDN) |
|
384 | return components(plot, CDN) | |
385 |
|
385 | |||
386 | def status_device(self): |
|
386 | def status_device(self): | |
387 |
|
387 | |||
388 | return 0 |
|
388 | return 0 | |
389 |
|
389 | |||
390 | def stop_device(self): |
|
390 | def stop_device(self): | |
391 |
|
391 | |||
392 | answer = api.disable(ip = self.device.ip_address, |
|
392 | answer = api.disable(ip = self.device.ip_address, | |
393 | port = self.device.port_address) |
|
393 | port = self.device.port_address) | |
394 |
|
394 | |||
395 | if answer[0] != "1": |
|
395 | if answer[0] != "1": | |
396 | self.message = answer[0:] |
|
396 | self.message = answer[0:] | |
397 | return 0 |
|
397 | return 0 | |
398 |
|
398 | |||
399 | self.message = answer[2:] |
|
399 | self.message = answer[2:] | |
400 | return 1 |
|
400 | return 1 | |
401 |
|
401 | |||
402 | def start_device(self): |
|
402 | def start_device(self): | |
403 |
|
403 | |||
404 | answer = api.enable(ip = self.device.ip_address, |
|
404 | answer = api.enable(ip = self.device.ip_address, | |
405 | port = self.device.port_address) |
|
405 | port = self.device.port_address) | |
406 |
|
406 | |||
407 | if answer[0] != "1": |
|
407 | if answer[0] != "1": | |
408 | self.message = answer[0:] |
|
408 | self.message = answer[0:] | |
409 | return 0 |
|
409 | return 0 | |
410 |
|
410 | |||
411 | self.message = answer[2:] |
|
411 | self.message = answer[2:] | |
412 | return 1 |
|
412 | return 1 | |
413 |
|
413 | |||
@@ -415,138 +415,138 class RCConfiguration(Configuration): | |||||
415 | answer = api.write_config(ip = self.device.ip_address, |
|
415 | answer = api.write_config(ip = self.device.ip_address, | |
416 | port = self.device.port_address, |
|
416 | port = self.device.port_address, | |
417 | parms = self.parms_to_dict()) |
|
417 | parms = self.parms_to_dict()) | |
418 |
|
418 | |||
419 | if answer[0] != "1": |
|
419 | if answer[0] != "1": | |
420 | self.message = answer[0:] |
|
420 | self.message = answer[0:] | |
421 | return 0 |
|
421 | return 0 | |
422 |
|
422 | |||
423 | self.message = answer[2:] |
|
423 | self.message = answer[2:] | |
424 | return 1 |
|
424 | return 1 | |
425 |
|
425 | |||
426 |
|
426 | |||
427 | class RCLineCode(models.Model): |
|
427 | class RCLineCode(models.Model): | |
428 |
|
428 | |||
429 | name = models.CharField(max_length=40) |
|
429 | name = models.CharField(max_length=40) | |
430 | bits_per_code = models.PositiveIntegerField(default=0) |
|
430 | bits_per_code = models.PositiveIntegerField(default=0) | |
431 | number_of_codes = models.PositiveIntegerField(default=0) |
|
431 | number_of_codes = models.PositiveIntegerField(default=0) | |
432 | codes = models.TextField(blank=True, null=True) |
|
432 | codes = models.TextField(blank=True, null=True) | |
433 |
|
433 | |||
434 | class Meta: |
|
434 | class Meta: | |
435 | db_table = 'rc_line_codes' |
|
435 | db_table = 'rc_line_codes' | |
436 | ordering = ('name',) |
|
436 | ordering = ('name',) | |
437 |
|
437 | |||
438 |
def __ |
|
438 | def __str__(self): | |
439 |
return u'%s' % self.name |
|
439 | return u'%s' % self.name | |
440 |
|
440 | |||
441 |
|
441 | |||
442 | class RCLineType(models.Model): |
|
442 | class RCLineType(models.Model): | |
443 |
|
443 | |||
444 | name = models.CharField(choices=LINE_TYPES, max_length=40) |
|
444 | name = models.CharField(choices=LINE_TYPES, max_length=40) | |
445 | description = models.TextField(blank=True, null=True) |
|
445 | description = models.TextField(blank=True, null=True) | |
446 | params = models.TextField(default='[]') |
|
446 | params = models.TextField(default='[]') | |
447 |
|
447 | |||
448 | class Meta: |
|
448 | class Meta: | |
449 | db_table = 'rc_line_types' |
|
449 | db_table = 'rc_line_types' | |
450 |
|
450 | |||
451 |
def __ |
|
451 | def __str__(self): | |
452 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) |
|
452 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) | |
453 |
|
453 | |||
454 |
|
454 | |||
455 | class RCLine(models.Model): |
|
455 | class RCLine(models.Model): | |
456 |
|
456 | |||
457 | rc_configuration = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE) |
|
457 | rc_configuration = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE) | |
458 | line_type = models.ForeignKey(RCLineType) |
|
458 | line_type = models.ForeignKey(RCLineType) | |
459 | channel = models.PositiveIntegerField(default=0) |
|
459 | channel = models.PositiveIntegerField(default=0) | |
460 | position = models.PositiveIntegerField(default=0) |
|
460 | position = models.PositiveIntegerField(default=0) | |
461 | params = models.TextField(default='{}') |
|
461 | params = models.TextField(default='{}') | |
462 | pulses = models.TextField(default='') |
|
462 | pulses = models.TextField(default='') | |
463 |
|
463 | |||
464 | class Meta: |
|
464 | class Meta: | |
465 | db_table = 'rc_lines' |
|
465 | db_table = 'rc_lines' | |
466 | ordering = ['channel'] |
|
466 | ordering = ['channel'] | |
467 |
|
467 | |||
468 |
def __ |
|
468 | def __str__(self): | |
469 | if self.rc_configuration: |
|
469 | if self.rc_configuration: | |
470 | return u'%s - %s' % (self.rc_configuration, self.get_name()) |
|
470 | return u'%s - %s' % (self.rc_configuration, self.get_name()) | |
471 |
|
471 | |||
472 | def clone(self, **kwargs): |
|
472 | def clone(self, **kwargs): | |
473 |
|
473 | |||
474 | self.pk = None |
|
474 | self.pk = None | |
475 |
|
475 | |||
476 | for attr, value in kwargs.items(): |
|
476 | for attr, value in kwargs.items(): | |
477 | setattr(self, attr, value) |
|
477 | setattr(self, attr, value) | |
478 |
|
478 | |||
479 |
self.save() |
|
479 | self.save() | |
480 |
|
480 | |||
481 | return self |
|
481 | return self | |
482 |
|
482 | |||
483 | def get_name(self, channel=False): |
|
483 | def get_name(self, channel=False): | |
484 |
|
484 | |||
485 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
485 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
486 |
s = '' |
|
486 | s = '' | |
487 |
|
487 | |||
488 | if self.line_type.name in ('tx',): |
|
488 | if self.line_type.name in ('tx',): | |
489 | s = chars[self.position] |
|
489 | s = chars[self.position] | |
490 | elif self.line_type.name in ('codes', 'windows', 'tr'): |
|
490 | elif self.line_type.name in ('codes', 'windows', 'tr'): | |
491 | if 'TX_ref' in json.loads(self.params): |
|
491 | if 'TX_ref' in json.loads(self.params): | |
492 | pk = json.loads(self.params)['TX_ref'] |
|
492 | pk = json.loads(self.params)['TX_ref'] | |
493 | if pk in (0, '0'): |
|
493 | if pk in (0, '0'): | |
494 |
s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx')) |
|
494 | s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx')) | |
495 | else: |
|
495 | else: | |
496 | ref = RCLine.objects.get(pk=pk) |
|
496 | ref = RCLine.objects.get(pk=pk) | |
497 | s = chars[ref.position] |
|
497 | s = chars[ref.position] | |
498 | s = '({})'.format(s) |
|
498 | s = '({})'.format(s) | |
499 |
|
499 | |||
500 | s = '{}{}'.format(self.line_type.name.upper(), s) |
|
500 | s = '{}{}'.format(self.line_type.name.upper(), s) | |
501 |
|
501 | |||
502 | if channel: |
|
502 | if channel: | |
503 | return '{} {}'.format(s, self.channel) |
|
503 | return '{} {}'.format(s, self.channel) | |
504 | else: |
|
504 | else: | |
505 | return s |
|
505 | return s | |
506 |
|
506 | |||
507 | def get_lines(self, **kwargs): |
|
507 | def get_lines(self, **kwargs): | |
508 |
|
508 | |||
509 |
return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs) |
|
509 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs) | |
510 |
|
510 | |||
511 | def pulses_as_array(self): |
|
511 | def pulses_as_array(self): | |
512 |
|
512 | |||
513 | y = np.zeros(self.rc_configuration.total_units) |
|
513 | y = np.zeros(self.rc_configuration.total_units) | |
514 |
|
514 | |||
515 | for tup in ast.literal_eval(self.pulses): |
|
515 | for tup in ast.literal_eval(self.pulses): | |
516 | y[tup[0]:tup[1]] = 1 |
|
516 | y[tup[0]:tup[1]] = 1 | |
517 |
|
517 | |||
518 | return y.astype(np.int8) |
|
518 | return y.astype(np.int8) | |
519 |
|
519 | |||
520 | def pulses_as_points(self, km=False): |
|
520 | def pulses_as_points(self, km=False): | |
521 |
|
521 | |||
522 | if km: |
|
522 | if km: | |
523 | unit2km = 1/self.rc_configuration.km2unit |
|
523 | unit2km = 1/self.rc_configuration.km2unit | |
524 | return [(tup[0]*unit2km, tup[1]*unit2km) for tup in ast.literal_eval(self.pulses)] |
|
524 | return [(tup[0]*unit2km, tup[1]*unit2km) for tup in ast.literal_eval(self.pulses)] | |
525 | else: |
|
525 | else: | |
526 | return ast.literal_eval(self.pulses) |
|
526 | return ast.literal_eval(self.pulses) | |
527 |
|
527 | |||
528 | def get_win_ref(self, params, tx_id, km2unit): |
|
528 | def get_win_ref(self, params, tx_id, km2unit): | |
529 |
|
529 | |||
530 | ref = self.rc_configuration.sampling_reference |
|
530 | ref = self.rc_configuration.sampling_reference | |
531 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] |
|
531 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] | |
532 |
|
532 | |||
533 |
if codes: |
|
533 | if codes: | |
534 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) |
|
534 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) | |
535 | else: |
|
535 | else: | |
536 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit |
|
536 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit | |
537 |
|
537 | |||
538 | if ref=='first_baud': |
|
538 | if ref=='first_baud': | |
539 | return int(1 + (tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit) |
|
539 | return int(1 + (tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit) | |
540 | elif ref=='sub_baud': |
|
540 | elif ref=='sub_baud': | |
541 | return int(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) |
|
541 | return int(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) | |
542 | else: |
|
542 | else: | |
543 | return 0 |
|
543 | return 0 | |
544 |
|
544 | |||
545 | def update_pulses(self): |
|
545 | def update_pulses(self): | |
546 | ''' |
|
546 | ''' | |
547 |
Update pulses field |
|
547 | Update pulses field | |
548 | ''' |
|
548 | ''' | |
549 |
|
549 | |||
550 | km2unit = self.rc_configuration.km2unit |
|
550 | km2unit = self.rc_configuration.km2unit | |
551 | us2unit = self.rc_configuration.us2unit |
|
551 | us2unit = self.rc_configuration.us2unit | |
552 | ipp = self.rc_configuration.ipp |
|
552 | ipp = self.rc_configuration.ipp | |
@@ -554,89 +554,89 class RCLine(models.Model): | |||||
554 | ipp_u = int(ipp*km2unit) |
|
554 | ipp_u = int(ipp*km2unit) | |
555 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units |
|
555 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units | |
556 | y = [] |
|
556 | y = [] | |
557 |
|
557 | |||
558 | if self.line_type.name=='tr': |
|
558 | if self.line_type.name=='tr': | |
559 | tr_params = json.loads(self.params) |
|
559 | tr_params = json.loads(self.params) | |
560 |
|
560 | |||
561 | if tr_params['TX_ref'] in ('0', 0): |
|
561 | if tr_params['TX_ref'] in ('0', 0): | |
562 | txs = self.get_lines(line_type__name='tx') |
|
562 | txs = self.get_lines(line_type__name='tx') | |
563 | else: |
|
563 | else: | |
564 | txs = RCLine.objects.filter(pk=tr_params['TX_ref']) |
|
564 | txs = RCLine.objects.filter(pk=tr_params['TX_ref']) | |
565 |
|
565 | |||
566 | for tx in txs: |
|
566 | for tx in txs: | |
567 | params = json.loads(tx.params) |
|
567 | params = json.loads(tx.params) | |
568 |
|
568 | |||
569 | if float(params['pulse_width'])==0: |
|
569 | if float(params['pulse_width'])==0: | |
570 | continue |
|
570 | continue | |
571 |
delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
571 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
572 | width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit) |
|
572 | width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit) | |
573 | before = 0 |
|
573 | before = 0 | |
574 | after = int(self.rc_configuration.time_after*us2unit) |
|
574 | after = int(self.rc_configuration.time_after*us2unit) | |
575 |
|
575 | |||
576 | y_tx = self.points(ntx, ipp_u, width, |
|
576 | y_tx = self.points(ntx, ipp_u, width, | |
577 | delay=delays, |
|
577 | delay=delays, | |
578 | before=before, |
|
578 | before=before, | |
579 | after=after, |
|
579 | after=after, | |
580 | sync=self.rc_configuration.sync) |
|
580 | sync=self.rc_configuration.sync) | |
581 |
|
581 | |||
582 | ranges = params['range'].split(',') |
|
582 | ranges = params['range'].split(',') | |
583 |
|
583 | |||
584 |
if len(ranges)>0 and ranges[0] |
|
584 | if len(ranges)>0 and ranges[0]!='0': | |
585 | y_tx = self.mask_ranges(y_tx, ranges) |
|
585 | y_tx = self.mask_ranges(y_tx, ranges) | |
586 |
|
586 | |||
587 | tr_ranges = tr_params['range'].split(',') |
|
587 | tr_ranges = tr_params['range'].split(',') | |
588 |
|
588 | |||
589 |
if len(tr_ranges)>0 and tr_ranges[0] |
|
589 | if len(tr_ranges)>0 and tr_ranges[0]!='0': | |
590 | y_tx = self.mask_ranges(y_tx, tr_ranges) |
|
590 | y_tx = self.mask_ranges(y_tx, tr_ranges) | |
591 |
|
591 | |||
592 | y.extend(y_tx) |
|
592 | y.extend(y_tx) | |
593 |
|
593 | |||
594 |
self.pulses = |
|
594 | self.pulses = str(y) | |
595 | y = self.array_to_points(self.pulses_as_array()) |
|
595 | y = self.array_to_points(self.pulses_as_array()) | |
596 |
|
596 | |||
597 | elif self.line_type.name=='tx': |
|
597 | elif self.line_type.name=='tx': | |
598 |
params = json.loads(self.params) |
|
598 | params = json.loads(self.params) | |
599 |
delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
599 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
600 | width = float(params['pulse_width'])*km2unit |
|
600 | width = float(params['pulse_width'])*km2unit | |
601 |
|
601 | |||
602 |
if width>0: |
|
602 | if width>0: | |
603 | before = int(self.rc_configuration.time_before*us2unit) |
|
603 | before = int(self.rc_configuration.time_before*us2unit) | |
604 | after = 0 |
|
604 | after = 0 | |
605 |
|
605 | |||
606 | y = self.points(ntx, ipp_u, width, |
|
606 | y = self.points(ntx, ipp_u, width, | |
607 | delay=delays, |
|
607 | delay=delays, | |
608 | before=before, |
|
608 | before=before, | |
609 | after=after, |
|
609 | after=after, | |
610 |
sync=self.rc_configuration.sync) |
|
610 | sync=self.rc_configuration.sync) | |
611 |
|
611 | |||
612 | ranges = params['range'].split(',') |
|
612 | ranges = params['range'].split(',') | |
613 |
|
613 | |||
614 |
if len(ranges)>0 and ranges[0] |
|
614 | if len(ranges)>0 and ranges[0]!='0': | |
615 | y = self.mask_ranges(y, ranges) |
|
615 | y = self.mask_ranges(y, ranges) | |
616 |
|
616 | |||
617 | elif self.line_type.name=='flip': |
|
617 | elif self.line_type.name=='flip': | |
618 | n = float(json.loads(self.params)['number_of_flips']) |
|
618 | n = float(json.loads(self.params)['number_of_flips']) | |
619 | width = n*ipp*km2unit |
|
619 | width = n*ipp*km2unit | |
620 | y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width) |
|
620 | y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width) | |
621 |
|
621 | |||
622 | elif self.line_type.name=='codes': |
|
622 | elif self.line_type.name=='codes': | |
623 | params = json.loads(self.params) |
|
623 | params = json.loads(self.params) | |
624 | tx = RCLine.objects.get(pk=params['TX_ref']) |
|
624 | tx = RCLine.objects.get(pk=params['TX_ref']) | |
625 | tx_params = json.loads(tx.params) |
|
625 | tx_params = json.loads(tx.params) | |
626 |
delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] |
|
626 | delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] | |
627 |
f = int(float(tx_params['pulse_width'])*km2unit |
|
627 | f = int(float(tx_params['pulse_width'])*km2unit/len(params['codes'][0])) | |
628 |
codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] |
|
628 | codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] | |
629 | codes = [self.array_to_points(code) for code in codes] |
|
629 | codes = [self.array_to_points(code) for code in codes] | |
630 | n = len(codes) |
|
630 | n = len(codes) | |
631 |
|
631 | |||
632 | for i, tup in enumerate(tx.pulses_as_points()): |
|
632 | for i, tup in enumerate(tx.pulses_as_points()): | |
633 | code = codes[i%n] |
|
633 | code = codes[i%n] | |
634 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) |
|
634 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) | |
635 |
|
635 | |||
636 | ranges = tx_params['range'].split(',') |
|
636 | ranges = tx_params['range'].split(',') | |
637 |
if len(ranges)>0 and ranges[0] |
|
637 | if len(ranges)>0 and ranges[0]!='0': | |
638 | y = self.mask_ranges(y, ranges) |
|
638 | y = self.mask_ranges(y, ranges) | |
639 |
|
639 | |||
640 | elif self.line_type.name=='sync': |
|
640 | elif self.line_type.name=='sync': | |
641 | params = json.loads(self.params) |
|
641 | params = json.loads(self.params) | |
642 | n = ipp_u*ntx |
|
642 | n = ipp_u*ntx | |
@@ -644,7 +644,7 class RCLine(models.Model): | |||||
644 | y = [(n-1, n)] |
|
644 | y = [(n-1, n)] | |
645 | else: |
|
645 | else: | |
646 | y = [(0, 1)] |
|
646 | y = [(0, 1)] | |
647 |
|
647 | |||
648 | elif self.line_type.name=='prog_pulses': |
|
648 | elif self.line_type.name=='prog_pulses': | |
649 | params = json.loads(self.params) |
|
649 | params = json.loads(self.params) | |
650 | if int(params['periodic'])==0: |
|
650 | if int(params['periodic'])==0: | |
@@ -653,32 +653,32 class RCLine(models.Model): | |||||
653 | else: |
|
653 | else: | |
654 | nntx = ntx |
|
654 | nntx = ntx | |
655 | nipp = ipp_u |
|
655 | nipp = ipp_u | |
656 |
|
656 | |||
657 |
if 'params' in params and len(params['params'])>0: |
|
657 | if 'params' in params and len(params['params'])>0: | |
658 | for p in params['params']: |
|
658 | for p in params['params']: | |
659 |
y_pp = self.points(nntx, nipp, |
|
659 | y_pp = self.points(nntx, nipp, | |
660 |
p['end']-p['begin'], |
|
660 | p['end']-p['begin'], | |
661 |
before=p['begin']) |
|
661 | before=p['begin']) | |
662 |
|
662 | |||
663 |
y.extend(y_pp) |
|
663 | y.extend(y_pp) | |
664 |
|
664 | |||
665 | elif self.line_type.name=='windows': |
|
665 | elif self.line_type.name=='windows': | |
666 |
params = json.loads(self.params) |
|
666 | params = json.loads(self.params) | |
667 |
|
667 | |||
668 | if 'params' in params and len(params['params'])>0: |
|
668 | if 'params' in params and len(params['params'])>0: | |
669 | tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) |
|
669 | tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) | |
670 | tr_ranges = tr_params['range'].split(',') |
|
670 | tr_ranges = tr_params['range'].split(',') | |
671 | for p in params['params']: |
|
671 | for p in params['params']: | |
672 |
y_win = self.points(ntx, ipp_u, |
|
672 | y_win = self.points(ntx, ipp_u, | |
673 |
p['resolution']*p['number_of_samples']*km2unit, |
|
673 | p['resolution']*p['number_of_samples']*km2unit, | |
674 | before=int(self.rc_configuration.time_before*us2unit)+self.get_win_ref(p, params['TX_ref'], km2unit), |
|
674 | before=int(self.rc_configuration.time_before*us2unit)+self.get_win_ref(p, params['TX_ref'], km2unit), | |
675 | sync=self.rc_configuration.sync) |
|
675 | sync=self.rc_configuration.sync) | |
676 |
|
676 | |||
677 |
if len(tr_ranges)>0 and tr_ranges[0] |
|
677 | if len(tr_ranges)>0 and tr_ranges[0]!='0': | |
678 | y_win = self.mask_ranges(y_win, tr_ranges) |
|
678 | y_win = self.mask_ranges(y_win, tr_ranges) | |
679 |
|
679 | |||
680 |
y.extend(y_win) |
|
680 | y.extend(y_win) | |
681 |
|
681 | |||
682 | elif self.line_type.name=='mix': |
|
682 | elif self.line_type.name=='mix': | |
683 | values = self.rc_configuration.parameters.split('-') |
|
683 | values = self.rc_configuration.parameters.split('-') | |
684 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] |
|
684 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] | |
@@ -692,19 +692,19 class RCLine(models.Model): | |||||
692 | y = np.zeros(confs[0].total_units, dtype=np.int8) |
|
692 | y = np.zeros(confs[0].total_units, dtype=np.int8) | |
693 | else: |
|
693 | else: | |
694 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() |
|
694 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() | |
695 |
|
695 | |||
696 | for i in range(1, len(values)): |
|
696 | for i in range(1, len(values)): | |
697 | mask = list('{:8b}'.format(int(masks[i]))) |
|
697 | mask = list('{:8b}'.format(int(masks[i]))) | |
698 |
mask.reverse() |
|
698 | mask.reverse() | |
699 |
|
699 | |||
700 | if mask[self.channel] in ('0', '', ' '): |
|
700 | if mask[self.channel] in ('0', '', ' '): | |
701 | continue |
|
701 | continue | |
702 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() |
|
702 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() | |
703 | delay = float(delays[i])*km2unit |
|
703 | delay = float(delays[i])*km2unit | |
704 |
|
704 | |||
705 | if modes[i]=='P': |
|
705 | if modes[i]=='P': | |
706 | if delay>0: |
|
706 | if delay>0: | |
707 |
if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): |
|
707 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): | |
708 | y_temp = np.empty_like(Y) |
|
708 | y_temp = np.empty_like(Y) | |
709 | y_temp[:delay] = 0 |
|
709 | y_temp[:delay] = 0 | |
710 | y_temp[delay:] = Y[:-delay] |
|
710 | y_temp[delay:] = Y[:-delay] | |
@@ -720,7 +720,7 class RCLine(models.Model): | |||||
720 | elif delay+len(Y)<len(y): |
|
720 | elif delay+len(Y)<len(y): | |
721 | y_temp = np.zeros(len(y), dtype=np.int8) |
|
721 | y_temp = np.zeros(len(y), dtype=np.int8) | |
722 | y_temp[delay:delay+len(Y)] = Y |
|
722 | y_temp[delay:delay+len(Y)] = Y | |
723 |
|
723 | |||
724 | if ops[i]=='OR': |
|
724 | if ops[i]=='OR': | |
725 | y = y | y_temp |
|
725 | y = y | y_temp | |
726 | elif ops[i]=='XOR': |
|
726 | elif ops[i]=='XOR': | |
@@ -729,58 +729,58 class RCLine(models.Model): | |||||
729 | y = y & y_temp |
|
729 | y = y & y_temp | |
730 | elif ops[i]=='NAND': |
|
730 | elif ops[i]=='NAND': | |
731 | y = y & ~y_temp |
|
731 | y = y & ~y_temp | |
732 |
else: |
|
732 | else: | |
733 | y = np.concatenate([y, Y]) |
|
733 | y = np.concatenate([y, Y]) | |
734 |
|
734 | |||
735 | total = len(y) |
|
735 | total = len(y) | |
736 | y = self.array_to_points(y) |
|
736 | y = self.array_to_points(y) | |
737 |
|
737 | |||
738 | else: |
|
738 | else: | |
739 | y = [] |
|
739 | y = [] | |
740 |
|
740 | |||
741 |
if self.rc_configuration.total_units |
|
741 | if self.rc_configuration.total_units != total: | |
742 | self.rc_configuration.total_units = total |
|
742 | self.rc_configuration.total_units = total | |
743 | self.rc_configuration.save() |
|
743 | self.rc_configuration.save() | |
744 |
|
744 | |||
745 |
self.pulses = |
|
745 | self.pulses = str(y) | |
746 | self.save() |
|
746 | self.save() | |
747 |
|
747 | |||
748 | @staticmethod |
|
748 | @staticmethod | |
749 | def array_to_points(X): |
|
749 | def array_to_points(X): | |
750 |
|
750 | |||
751 | d = X[1:]-X[:-1] |
|
751 | d = X[1:]-X[:-1] | |
752 |
|
752 | |||
753 | up = np.where(d==1)[0] |
|
753 | up = np.where(d==1)[0] | |
754 | if X[0]==1: |
|
754 | if X[0]==1: | |
755 | up = np.concatenate((np.array([-1]), up)) |
|
755 | up = np.concatenate((np.array([-1]), up)) | |
756 | up += 1 |
|
756 | up += 1 | |
757 |
|
757 | |||
758 | dw = np.where(d==-1)[0] |
|
758 | dw = np.where(d==-1)[0] | |
759 | if X[-1]==1: |
|
759 | if X[-1]==1: | |
760 | dw = np.concatenate((dw, np.array([len(X)-1]))) |
|
760 | dw = np.concatenate((dw, np.array([len(X)-1]))) | |
761 | dw += 1 |
|
761 | dw += 1 | |
762 |
|
762 | |||
763 | return [(tup[0], tup[1]) for tup in zip(up, dw)] |
|
763 | return [(tup[0], tup[1]) for tup in zip(up, dw)] | |
764 |
|
764 | |||
765 | @staticmethod |
|
765 | @staticmethod | |
766 | def mask_ranges(Y, ranges): |
|
766 | def mask_ranges(Y, ranges): | |
767 |
|
767 | |||
768 | y = [(0, 0) for __ in Y] |
|
768 | y = [(0, 0) for __ in Y] | |
769 |
|
769 | |||
770 | for index in ranges: |
|
770 | for index in ranges: | |
771 | if '-' in index: |
|
771 | if '-' in index: | |
772 | args = [int(a) for a in index.split('-')] |
|
772 | args = [int(a) for a in index.split('-')] | |
773 |
y[args[0]-1:args[1]] = Y[args[0]-1:args[1]] |
|
773 | y[args[0]-1:args[1]] = Y[args[0]-1:args[1]] | |
774 | else: |
|
774 | else: | |
775 |
y[int(index-1)] = Y[int(index-1)] |
|
775 | y[int(index-1)] = Y[int(index-1)] | |
776 |
|
776 | |||
777 | return y |
|
777 | return y | |
778 |
|
778 | |||
779 | @staticmethod |
|
779 | @staticmethod | |
780 | def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0): |
|
780 | def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0): | |
781 |
|
781 | |||
782 | delays = len(delay) |
|
782 | delays = len(delay) | |
783 |
|
783 | |||
784 | Y = [(ipp*x+before+delay[x%delays], ipp*x+width+before+delay[x%delays]+after) for x in range(ntx)] |
|
784 | Y = [(ipp*x+before+delay[x%delays], ipp*x+width+before+delay[x%delays]+after) for x in range(ntx)] | |
785 |
|
785 | |||
786 |
return Y |
|
786 | return Y |
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 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
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 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
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 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
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 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
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 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
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 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now