@@ -0,0 +1,6 | |||||
|
1 | from django.contrib import admin | |||
|
2 | from .models import ATRADConfiguration | |||
|
3 | ||||
|
4 | # Register your models here. | |||
|
5 | ||||
|
6 | admin.site.register(ATRADConfiguration) |
@@ -0,0 +1,6 | |||||
|
1 | #from django.apps import AppConfig | |||
|
2 | ||||
|
3 | ||||
|
4 | #class AtradConfig(AppConfig):# | |||
|
5 | # default_auto_field = 'django.db.models.BigAutoField' | |||
|
6 | # name = 'atrad' |
@@ -0,0 +1,19 | |||||
|
1 | import json | |||
|
2 | ||||
|
3 | def read_json_file(fp): | |||
|
4 | ||||
|
5 | kwargs = {} | |||
|
6 | ||||
|
7 | json_data = fp | |||
|
8 | data = json.load(json_data) | |||
|
9 | json_data.close() | |||
|
10 | ||||
|
11 | topic = data["topic"][0][1] | |||
|
12 | ||||
|
13 | kwargs['topic'] = topic | |||
|
14 | ||||
|
15 | return kwargs | |||
|
16 | ||||
|
17 | ||||
|
18 | def write_json_file(filename): | |||
|
19 | pass No newline at end of file |
@@ -0,0 +1,27 | |||||
|
1 | from django import forms | |||
|
2 | from apps.main.models import Device | |||
|
3 | from .models import ATRADConfiguration | |||
|
4 | ||||
|
5 | class ATRADConfigurationForm(forms.ModelForm): | |||
|
6 | ||||
|
7 | def __init__(self, *args, **kwargs): | |||
|
8 | super(ATRADConfigurationForm, self).__init__(*args, **kwargs) | |||
|
9 | instance = getattr(self, 'instance', None) | |||
|
10 | ||||
|
11 | if instance and instance.pk: | |||
|
12 | devices = Device.objects.filter(device_type__name='atrad') | |||
|
13 | if instance.experiment: | |||
|
14 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |||
|
15 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
|
16 | ||||
|
17 | def clean(self): | |||
|
18 | return | |||
|
19 | ||||
|
20 | class Meta: | |||
|
21 | model = ATRADConfiguration | |||
|
22 | exclude = ('type', 'parameters', 'status', 'author', 'hash') | |||
|
23 | ||||
|
24 | ||||
|
25 | class UploadFileForm(forms.Form): | |||
|
26 | title = forms.CharField(label='Extension Type', widget=forms.TextInput(attrs={'readonly':'readonly'})) | |||
|
27 | file = forms.FileField() |
@@ -0,0 +1,175 | |||||
|
1 | from django.db import models | |||
|
2 | from apps.main.models import Configuration | |||
|
3 | from apps.main.utils import Params | |||
|
4 | from django.core.validators import MinValueValidator, MaxValueValidator | |||
|
5 | ||||
|
6 | from .files import read_json_file | |||
|
7 | import requests | |||
|
8 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |||
|
9 | ||||
|
10 | class ATRADConfiguration(Configuration): | |||
|
11 | ||||
|
12 | topic = models.PositiveIntegerField(verbose_name='Topic',validators=[MaxValueValidator(10)], default = 0) | |||
|
13 | ||||
|
14 | def verify_frequencies(self): | |||
|
15 | ||||
|
16 | return True | |||
|
17 | ||||
|
18 | ||||
|
19 | def status_device(self): | |||
|
20 | ||||
|
21 | ip=self.device.ip_address | |||
|
22 | port=self.device.port_address | |||
|
23 | ||||
|
24 | route = "http://" + str(ip) + ":" + str(port) + "/status/" | |||
|
25 | try: | |||
|
26 | r = requests.get(route, timeout=0.7) | |||
|
27 | except Exception as e: | |||
|
28 | self.device.status = 0 | |||
|
29 | self.device.save() | |||
|
30 | self.message = 'Could not read TX status: ' + str(e) | |||
|
31 | return False | |||
|
32 | ||||
|
33 | response = r.json() | |||
|
34 | self.device.status = response['status'] | |||
|
35 | self.message = response['message'] | |||
|
36 | self.device.save() | |||
|
37 | ||||
|
38 | if response['components_status']==0: | |||
|
39 | return False | |||
|
40 | ||||
|
41 | return True | |||
|
42 | ||||
|
43 | ||||
|
44 | def start_device(self): | |||
|
45 | ||||
|
46 | ip=self.device.ip_address | |||
|
47 | port=self.device.port_address | |||
|
48 | ||||
|
49 | #---Device must be configured | |||
|
50 | if not self.device.status == 2: | |||
|
51 | self.message = 'TX Device must be configured.' | |||
|
52 | return False | |||
|
53 | #---Frequencies from form | |||
|
54 | post_data = self.parms_to_dict() | |||
|
55 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |||
|
56 | ||||
|
57 | try: | |||
|
58 | r = requests.post(route, post_data, timeout=0.7) | |||
|
59 | except Exception as e: | |||
|
60 | self.message = "Could not start TX device. "+str(e) | |||
|
61 | return False | |||
|
62 | ||||
|
63 | response = r.json() | |||
|
64 | if response['status']==1: | |||
|
65 | self.device.status = 1 | |||
|
66 | self.device.save() | |||
|
67 | self.message = response['message'] | |||
|
68 | return False | |||
|
69 | ||||
|
70 | self.device.status = response['status'] | |||
|
71 | self.device.save() | |||
|
72 | self.message = response['message'] | |||
|
73 | ||||
|
74 | return True | |||
|
75 | ||||
|
76 | ||||
|
77 | def stop_device(self): | |||
|
78 | ||||
|
79 | ip=self.device.ip_address | |||
|
80 | port=self.device.port_address | |||
|
81 | ||||
|
82 | if self.device.status == 2: #Configured | |||
|
83 | self.message = 'TX device is already stopped.' | |||
|
84 | return False | |||
|
85 | ||||
|
86 | post_data = {"topic":0} | |||
|
87 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |||
|
88 | ||||
|
89 | try: | |||
|
90 | r = requests.post(route, post_data, timeout=0.7) | |||
|
91 | except Exception as e: | |||
|
92 | self.message = "Could not write TX parameters. "+str(e) | |||
|
93 | self.device.status = 0 | |||
|
94 | self.device.save() | |||
|
95 | return False | |||
|
96 | ||||
|
97 | response = r.json() | |||
|
98 | status = response['status'] | |||
|
99 | if status == 1: | |||
|
100 | self.device.status = status | |||
|
101 | self.device.save() | |||
|
102 | self.message = 'Could not stop TX device.' | |||
|
103 | return False | |||
|
104 | ||||
|
105 | self.message = 'TX device has been stopped successfully.' | |||
|
106 | self.device.status = 2 | |||
|
107 | self.device.save() | |||
|
108 | ||||
|
109 | return True | |||
|
110 | ||||
|
111 | ||||
|
112 | def read_device(self): | |||
|
113 | ||||
|
114 | ip=self.device.ip_address | |||
|
115 | port=self.device.port_address | |||
|
116 | ||||
|
117 | route = "http://" + str(ip) + ":" + str(port) + "/read/" | |||
|
118 | try: | |||
|
119 | frequencies = requests.get(route,timeout=0.7) | |||
|
120 | except: | |||
|
121 | self.message = "Could not read TX parameters from this device" | |||
|
122 | return None | |||
|
123 | ||||
|
124 | frequencies = frequencies.json() | |||
|
125 | if frequencies: | |||
|
126 | frequencies = frequencies.get("Frequencies") | |||
|
127 | topic = frequencies.get("topic") | |||
|
128 | ||||
|
129 | parms = {'topic': topic} | |||
|
130 | ||||
|
131 | self.message = "TX parameters have been successfully read" | |||
|
132 | return parms | |||
|
133 | else: | |||
|
134 | self.message = "Error reading TX parameters" | |||
|
135 | return None | |||
|
136 | ||||
|
137 | ||||
|
138 | def write_device(self): | |||
|
139 | ||||
|
140 | ip=self.device.ip_address | |||
|
141 | port=self.device.port_address | |||
|
142 | ||||
|
143 | #---Frequencies from form | |||
|
144 | parms = self.parms_to_dict()['configurations'] | |||
|
145 | for parm in parms['allIds']: | |||
|
146 | byid = parm | |||
|
147 | frequencies = parms['byId'][byid] | |||
|
148 | post_data = {} | |||
|
149 | for data in frequencies: | |||
|
150 | if data in ['topic']: | |||
|
151 | post_data[data] = frequencies[data] | |||
|
152 | ||||
|
153 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |||
|
154 | print (post_data) | |||
|
155 | try: | |||
|
156 | r = requests.post(route, post_data, timeout=0.7) | |||
|
157 | except: | |||
|
158 | self.message = "Could not write TX parameters" | |||
|
159 | self.device.status = 0 | |||
|
160 | self.device.save() | |||
|
161 | return False | |||
|
162 | ||||
|
163 | response = r.json() | |||
|
164 | self.message = response['message'] | |||
|
165 | self.device.status = response['status'] | |||
|
166 | self.device.save() | |||
|
167 | ||||
|
168 | if self.device.status==1: | |||
|
169 | return False | |||
|
170 | ||||
|
171 | return True | |||
|
172 | ||||
|
173 | ||||
|
174 | class Meta: | |||
|
175 | db_table = 'atrad_configurations' No newline at end of file |
@@ -0,0 +1,38 | |||||
|
1 | import paho.mqtt.client as mqtt | |||
|
2 | from radarsys import settings | |||
|
3 | from radarsys.socketconfig import sio as sio | |||
|
4 | import numpy as np | |||
|
5 | ||||
|
6 | def on_connect(mqtt_client, userdata, flags, rc): | |||
|
7 | if rc == 0: | |||
|
8 | print('Connected successfully') | |||
|
9 | mqtt_client.subscribe('atrad/test3') | |||
|
10 | else: | |||
|
11 | print('Bad connection. Code:', rc) | |||
|
12 | ||||
|
13 | def maxima_temp(trs): | |||
|
14 | np_array = [np.array(i) for i in trs] | |||
|
15 | temps = [max(i[i<40]) for i in np_array] | |||
|
16 | return max(temps) | |||
|
17 | ||||
|
18 | def on_message(mqtt_client, userdata, msg): | |||
|
19 | print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True) | |||
|
20 | trsi = [[],[],[],[]] | |||
|
21 | mensaje = str(msg.payload) | |||
|
22 | datos = [i for i in mensaje[21:-1].split("*")] | |||
|
23 | status=''.join([datos[i][3] for i in [0,1,2,3]]) | |||
|
24 | for trs,i in zip(datos,[0,1,2,3]) : | |||
|
25 | trsi[i]= [int(i) for i in trs[1:-1].split(",")] | |||
|
26 | potencias = [trsi[0][34],trsi[0][36],trsi[2][32],trsi[2][34]] | |||
|
27 | tmax = maxima_temp(trsi) | |||
|
28 | sio.emit('test', data={'time':mensaje[2:21],'num':trsi[0][0],'pow':potencias,'tmax':str(tmax),'status':status}) | |||
|
29 | ||||
|
30 | client = mqtt.Client() | |||
|
31 | client.on_connect = on_connect | |||
|
32 | client.on_message = on_message | |||
|
33 | client.username_pw_set(settings.MQTT_USER, settings.MQTT_PASSWORD) | |||
|
34 | client.connect( | |||
|
35 | host=settings.MQTT_SERVER, | |||
|
36 | port=settings.MQTT_PORT, | |||
|
37 | keepalive=settings.MQTT_KEEPALIVE | |||
|
38 | ) No newline at end of file |
@@ -0,0 +1,288 | |||||
|
1 | {% extends "dev_conf.html" %} | |||
|
2 | {% block extra-head %} | |||
|
3 | <style> | |||
|
4 | .dot { | |||
|
5 | height: 25px; | |||
|
6 | width: 25px; | |||
|
7 | background-color: #b0b3af; | |||
|
8 | border-radius: 50%; | |||
|
9 | display: inline-block; | |||
|
10 | } | |||
|
11 | </style> | |||
|
12 | {% endblock %} | |||
|
13 | ||||
|
14 | {% block extra-content %} | |||
|
15 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> | |||
|
16 | <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script> | |||
|
17 | ||||
|
18 | <div class="container-fluid"> | |||
|
19 | <div class="row"> | |||
|
20 | <div class="col-xs-12"> | |||
|
21 | <h1>Atrad Monitor</h1> | |||
|
22 | </div> | |||
|
23 | </div> | |||
|
24 | ||||
|
25 | <div class="row "> | |||
|
26 | <!-- Potencia --> | |||
|
27 | <div class="col col-xs-12"> | |||
|
28 | <div class="row"> | |||
|
29 | <div class="panel panel-default" style="width:100%;"> | |||
|
30 | <div class="panel-heading"> | |||
|
31 | <h3 class="panel-title">Potencia</h3> | |||
|
32 | </div> | |||
|
33 | <div class="panel-body"> | |||
|
34 | <div class="col-xs-12"> | |||
|
35 | <div class="row"> | |||
|
36 | <div id="plot-pot"></div> | |||
|
37 | </div> | |||
|
38 | </div> | |||
|
39 | </div> | |||
|
40 | <div class="panel-footer"> | |||
|
41 | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Pot1">T1</button> | |||
|
42 | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Pot2">T2</button> | |||
|
43 | </div> | |||
|
44 | </div> | |||
|
45 | </div> | |||
|
46 | </div> | |||
|
47 | <div class="col col-xs-12"> | |||
|
48 | <div class="panel panel-default"> | |||
|
49 | <div class="panel-heading"> | |||
|
50 | <h3 class="panel-title">Status</h3> | |||
|
51 | </div> | |||
|
52 | <div class="panel-body"> | |||
|
53 | <table class="table table-borderless" style="max-width: 300px;"> | |||
|
54 | <tbody> | |||
|
55 | <tr> | |||
|
56 | <th scope="row">Tx1</th> | |||
|
57 | <td><span id="status1" class="dot"></span></td> | |||
|
58 | <td><p id="status-text1" class="font-weight-bold">Sin envio de datos</p></td> | |||
|
59 | </tr> | |||
|
60 | <tr> | |||
|
61 | <th scope="row">Tx2</th> | |||
|
62 | <td><span id="status2" class="dot"></span></td> | |||
|
63 | <td><p id="status-text2" class="font-weight-bold">Sin envio de datos</p></td> | |||
|
64 | </tr> | |||
|
65 | </tbody> | |||
|
66 | </table> | |||
|
67 | </div> | |||
|
68 | </div> | |||
|
69 | </div> | |||
|
70 | </div> | |||
|
71 | ||||
|
72 | <!-- Temperatura --> | |||
|
73 | <div class="row"> | |||
|
74 | <div class="col-xs-12"> | |||
|
75 | <div class="panel panel-default"> | |||
|
76 | <div class="panel-heading"> | |||
|
77 | <h3 class="panel-title">Temperatura</h3> | |||
|
78 | </div> | |||
|
79 | <div class="panel-body"> | |||
|
80 | <div class="col-xs-12"> | |||
|
81 | <div class="row"> | |||
|
82 | <div id="plot-temp"></div> | |||
|
83 | </div> | |||
|
84 | </div> | |||
|
85 | </div> | |||
|
86 | </div> | |||
|
87 | </div> | |||
|
88 | </div> | |||
|
89 | ||||
|
90 | <div class="row"> | |||
|
91 | <!-- Controles --> | |||
|
92 | <div class="col-xs-6"> | |||
|
93 | <div class="panel panel-default"> | |||
|
94 | <div class="panel-heading"> | |||
|
95 | <h3 class="panel-title">Control</h3> | |||
|
96 | </div> | |||
|
97 | <div class="panel-body"> | |||
|
98 | <div class="col-xs-12"> | |||
|
99 | <div class="form-row"> | |||
|
100 | <div class="form-group col-xs-6"> | |||
|
101 | <form id="controlON" method="POST" action=''> | |||
|
102 | <button type="summit" class="btn btn-secondary btn-lg">Prender</button> | |||
|
103 | </form> | |||
|
104 | </div> | |||
|
105 | <div class="form-group col-xs-6"> | |||
|
106 | <form id="controlOFF" method="POST" action=''> | |||
|
107 | <button type="summit" class="btn btn-secondary btn-lg">Apagar</button> | |||
|
108 | </form> | |||
|
109 | </div> | |||
|
110 | </div> | |||
|
111 | </div> | |||
|
112 | </div> | |||
|
113 | </div> | |||
|
114 | </div> | |||
|
115 | ||||
|
116 | <div class="col-xs-6"> | |||
|
117 | <div class="panel panel-default"> | |||
|
118 | <div class="panel-heading"> | |||
|
119 | </div> | |||
|
120 | </div> | |||
|
121 | </div> | |||
|
122 | </div> | |||
|
123 | </div> | |||
|
124 | ||||
|
125 | <!--Modales--> | |||
|
126 | <div class="modal fade" id="Pot1" role="dialog"> | |||
|
127 | <div class="modal-dialog modal-md" style="min-width:760px"> | |||
|
128 | <div class="modal-content"> | |||
|
129 | <div class="modal-header"> | |||
|
130 | <h4 class="modal-title">Potencia incidente - Transmisor 1</h4> | |||
|
131 | <button type="button" class="close" data-dismiss="modal">×</button> | |||
|
132 | </div> | |||
|
133 | <div class="modal-body"> | |||
|
134 | <div class="col-xs-12"> | |||
|
135 | <div id="plot-pot-t1"></div> | |||
|
136 | </div> | |||
|
137 | <div clas="col-xs-12"> | |||
|
138 | <table class="table table-borderless"> | |||
|
139 | <tbody> | |||
|
140 | <tr> | |||
|
141 | <th scope="row">P1</th> | |||
|
142 | <td>e</td> | |||
|
143 | <td>e</td> | |||
|
144 | </tr> | |||
|
145 | <tr> | |||
|
146 | <th scope="row">P2</th> | |||
|
147 | <td>e</td> | |||
|
148 | <td>e</td> | |||
|
149 | </tr> | |||
|
150 | <tr> | |||
|
151 | <th scope="row">P3</th> | |||
|
152 | <td>e</td> | |||
|
153 | <td>e</td> | |||
|
154 | </tr> | |||
|
155 | <tr> | |||
|
156 | <th scope="row">P4</th> | |||
|
157 | <td>e</td> | |||
|
158 | <td>e</td> | |||
|
159 | </tr> | |||
|
160 | </tbody> | |||
|
161 | </table> | |||
|
162 | </div> | |||
|
163 | </div> | |||
|
164 | </div> | |||
|
165 | </div> | |||
|
166 | </div> | |||
|
167 | ||||
|
168 | <div class="modal fade" id="Pot2" role="dialog"> | |||
|
169 | <div class="modal-dialog modal-md" style="min-width:760px"> | |||
|
170 | <div class="modal-content"> | |||
|
171 | <div class="modal-header"> | |||
|
172 | <h4 class="modal-title">Potencia incidente - Transmisor 2</h4> | |||
|
173 | <button type="button" class="close" data-dismiss="modal">×</button> | |||
|
174 | </div> | |||
|
175 | <div class="modal-body"> | |||
|
176 | <div class="col-xs-12"> | |||
|
177 | <div id="plot-pot-t2"></div> | |||
|
178 | </div> | |||
|
179 | </div> | |||
|
180 | </div> | |||
|
181 | </div> | |||
|
182 | </div> | |||
|
183 | ||||
|
184 | <script type="text/javascript" charset="utf-8"> | |||
|
185 | $(document).ready(function() { | |||
|
186 | var socket = io.connect('http://' + document.domain + ':' + location.port); | |||
|
187 | ||||
|
188 | socket.on('connect', function(data) { | |||
|
189 | console.log('Connecting... OK'); | |||
|
190 | makePlot("plot-temp",2,["T1","T2"],[14, 45]) | |||
|
191 | makePlot("plot-pot",2,["T1","T2"],[70,100]) | |||
|
192 | makePlot("plot-pot-t1",4,["P1","P2","P3","P4"],[0,26]) | |||
|
193 | makePlot("plot-pot-t2",4,["P1","P2","P3","P4"],[0,26]) | |||
|
194 | }) | |||
|
195 | ||||
|
196 | socket.on('test', function(data) { | |||
|
197 | let total = data.pow.reduce((a, b) => a + b, 0); | |||
|
198 | var id = (data.num/4)>>0; | |||
|
199 | streamPlot("plot-pot",data.time,total/1000.0,id,81); | |||
|
200 | streamPlot("plot-temp",data.time,data.tmax,id>>0,40); | |||
|
201 | if(id == 0){streamPlot2("plot-pot-t1",data.time,data.pow);ligthStatus('status1','status-text1',data.status);} | |||
|
202 | if(id == 1){streamPlot2("plot-pot-t2",data.time,data.pow);ligthStatus('status2','status-text2',data.status);} | |||
|
203 | }) | |||
|
204 | $('form#controlON').submit(function(event) { | |||
|
205 | socket.emit('control_event', {data: 1}); | |||
|
206 | return false; | |||
|
207 | }); | |||
|
208 | $('form#controlOFF').submit(function(event) { | |||
|
209 | socket.emit('control_event', {data: 0}); | |||
|
210 | return false; | |||
|
211 | }); | |||
|
212 | $("#btn1").click(function(){ | |||
|
213 | $("#box").animate({height: "300px"}); | |||
|
214 | }); | |||
|
215 | $("#btn2").click(function(){ | |||
|
216 | $("#box").animate({height: "100px"}); | |||
|
217 | }); | |||
|
218 | }); | |||
|
219 | ||||
|
220 | function makePlot(div, n=1, names=["", ""],ranges){ | |||
|
221 | var plotDiv = document.getElementById(div); | |||
|
222 | var traces = []; | |||
|
223 | for (let i = 0; i < n; i++) { | |||
|
224 | traces.push({x: [], y: [],mode: 'lines', name: names[i]}); | |||
|
225 | } | |||
|
226 | traces.push({x: [], y: [],mode: 'lines',line: {color:'rgb(219, 64, 82)',dash: 'dot',width: 2},name:"nominal",showlegend: false}); | |||
|
227 | var yrange = ranges; | |||
|
228 | var layout = { | |||
|
229 | height: 350, | |||
|
230 | font: {size: 12}, | |||
|
231 | margin: { t: 10, b:50}, | |||
|
232 | xaxis: { | |||
|
233 | type: 'date' | |||
|
234 | }, | |||
|
235 | yaxis: { | |||
|
236 | range: yrange, | |||
|
237 | }, | |||
|
238 | }; | |||
|
239 | ||||
|
240 | Plotly.plot(plotDiv, traces, layout); | |||
|
241 | }; | |||
|
242 | ||||
|
243 | function streamPlot(div,x,y,ind,val){ | |||
|
244 | var plotDiv = document.getElementById(div); | |||
|
245 | if (plotDiv.data[ind].x.length > 8){ | |||
|
246 | plotDiv.data[2].x = plotDiv.data[2].x.slice(-23) | |||
|
247 | plotDiv.data[2].y = plotDiv.data[2].y.slice(-23) | |||
|
248 | plotDiv.data[ind].x = plotDiv.data[ind].x.slice(-11) | |||
|
249 | plotDiv.data[ind].y = plotDiv.data[ind].y.slice(-11) | |||
|
250 | } | |||
|
251 | var tm = [x]; | |||
|
252 | var values = [y]; | |||
|
253 | var data_update = {x: [tm,tm], y: [values,[val]]} | |||
|
254 | Plotly.extendTraces(plotDiv, data_update,[ind,2]) | |||
|
255 | }; | |||
|
256 | function streamPlot2(div,x,y){ | |||
|
257 | var plotDiv = document.getElementById(div); | |||
|
258 | if (plotDiv.data[0].x.length > 8){ | |||
|
259 | for(let i=0;i<4;i++){ | |||
|
260 | plotDiv.data[i].x = plotDiv.data[i].x.slice(-11) | |||
|
261 | plotDiv.data[i].y = plotDiv.data[i].y.slice(-11) | |||
|
262 | } | |||
|
263 | } | |||
|
264 | var tm = [x]; | |||
|
265 | var values = []; | |||
|
266 | for(let i=0;i<4;i++){ | |||
|
267 | values[i]=[y[i]/1000.0]; | |||
|
268 | } | |||
|
269 | var data_update = {x: [tm,tm,tm,tm], y: values} | |||
|
270 | Plotly.extendTraces(plotDiv, data_update,[0,1,2,3]) | |||
|
271 | }; | |||
|
272 | function ligthStatus(div1,div2,status){ | |||
|
273 | if(status==='0000'){ | |||
|
274 | document.getElementById(div1).style.backgroundColor = "green"; | |||
|
275 | document.getElementById(div2).innerHTML = "Desabilitado"; | |||
|
276 | } | |||
|
277 | else if(status==='1111'){ | |||
|
278 | document.getElementById(div1).style.backgroundColor = "green"; | |||
|
279 | document.getElementById(div2).innerHTML = "Habilitado"; | |||
|
280 | } | |||
|
281 | else{ | |||
|
282 | document.getElementById(div1).style.backgroundColor = "yellow"; | |||
|
283 | document.getElementById(div2).innerHTML = "Incompleto"; | |||
|
284 | } | |||
|
285 | } | |||
|
286 | ||||
|
287 | </script> | |||
|
288 | {% endblock %} No newline at end of file |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,7 | |||||
|
1 | {% extends "dev_conf_edit.html" %} | |||
|
2 | {% load django_bootstrap5 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | ||||
|
6 | {% block extra-js%} | |||
|
7 | {% endblock %} No newline at end of file |
@@ -0,0 +1,15 | |||||
|
1 | {% extends "base.html" %} | |||
|
2 | {% block mainactive %}active{% endblock %} | |||
|
3 | ||||
|
4 | {% block content-title %}TITLE{% endblock %} | |||
|
5 | {% block content-suptitle %}Suptitle{% endblock %} | |||
|
6 | ||||
|
7 | {% block content %} | |||
|
8 | <p class="text-justify"> | |||
|
9 | {% lorem %} | |||
|
10 | </p> | |||
|
11 | {% endblock %} | |||
|
12 | ||||
|
13 | {% block sidebar%} | |||
|
14 | ||||
|
15 | {% endblock %} |
@@ -0,0 +1,46 | |||||
|
1 | {% extends "base.html" %} | |||
|
2 | {% load django_bootstrap5 %} | |||
|
3 | {% block mainactive %}active{% endblock %} | |||
|
4 | ||||
|
5 | {% block content-title %}DEVICE CGS{% endblock %} | |||
|
6 | {% block content-suptitle %}CLOCK GENERATOR AND SYNCHRONIZER{% endblock %} | |||
|
7 | ||||
|
8 | {% block content %} | |||
|
9 | <p class="text-justify"> | |||
|
10 | Ingresar Frecuencias | |||
|
11 | </p> | |||
|
12 | ||||
|
13 | ||||
|
14 | ||||
|
15 | <!-- Agregado 30-11-2015 --> | |||
|
16 | {% if form.is_multipart %} | |||
|
17 | ||||
|
18 | <script type="text/javascript"> | |||
|
19 | ||||
|
20 | </script> | |||
|
21 | ||||
|
22 | <form id="{{ idform }}" enctype="multipart/form-data" method="{{ submit_method|default:'post' }}" action="" class="form"> | |||
|
23 | {% else %} | |||
|
24 | <form method="{{ submit_method|default:'post' }}" action="" class="form"> | |||
|
25 | {% endif %} | |||
|
26 | ||||
|
27 | {% if step_field %} | |||
|
28 | <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> | |||
|
29 | {% endif %} | |||
|
30 | ||||
|
31 | {% if submit_method != 'GET' and submit_method != 'get' %} | |||
|
32 | {% csrf_token %} | |||
|
33 | {% endif %} | |||
|
34 | <!-- Agregado 30-11-2015 --> | |||
|
35 | ||||
|
36 | ||||
|
37 | ||||
|
38 | <div class='col-md-8'> | |||
|
39 | {% bootstrap_form form size='md' %} | |||
|
40 | <button type="submit" class="btn btn-primary pull-right">Submit</button> | |||
|
41 | </div> | |||
|
42 | {% endblock %} | |||
|
43 | ||||
|
44 | {% block sidebar%} | |||
|
45 | ||||
|
46 | {% endblock %} No newline at end of file |
@@ -0,0 +1,8 | |||||
|
1 | from django.urls import path | |||
|
2 | ||||
|
3 | from . import views | |||
|
4 | ||||
|
5 | urlpatterns = ( | |||
|
6 | path('<int:id_conf>/', views.atrad_conf, name='url_atrad_conf'), | |||
|
7 | path('<int:id_conf>/edit/', views.atrad_conf_edit, name='url_edit_atrad_conf'), | |||
|
8 | ) No newline at end of file |
@@ -0,0 +1,108 | |||||
|
1 | from django.shortcuts import redirect, render, get_object_or_404 | |||
|
2 | from django.contrib import messages | |||
|
3 | from django.http import HttpResponse | |||
|
4 | ||||
|
5 | from apps.main.models import Experiment | |||
|
6 | from .models import ATRADConfiguration | |||
|
7 | ||||
|
8 | from .forms import ATRADConfigurationForm, UploadFileForm | |||
|
9 | from apps.main.views import sidebar | |||
|
10 | ||||
|
11 | import requests | |||
|
12 | import json | |||
|
13 | ||||
|
14 | import os | |||
|
15 | from django.http import JsonResponse | |||
|
16 | from .mqtt import client as mqtt_client | |||
|
17 | from radarsys.socketconfig import sio as sio | |||
|
18 | ||||
|
19 | ||||
|
20 | def atrad_conf(request, id_conf): | |||
|
21 | ||||
|
22 | conf = get_object_or_404(ATRADConfiguration, pk=id_conf) | |||
|
23 | ||||
|
24 | ip=conf.device.ip_address | |||
|
25 | port=conf.device.port_address | |||
|
26 | ||||
|
27 | kwargs = {} | |||
|
28 | ||||
|
29 | kwargs['status'] = conf.device.get_status_display() | |||
|
30 | ||||
|
31 | kwargs['dev_conf'] = conf | |||
|
32 | kwargs['dev_conf_keys'] = ['label', | |||
|
33 | 'topic'] | |||
|
34 | ||||
|
35 | kwargs['title'] = 'ATRAD Configuration' | |||
|
36 | kwargs['suptitle'] = 'Details' | |||
|
37 | ||||
|
38 | kwargs['button'] = 'Edit Configuration' | |||
|
39 | ||||
|
40 | #kwargs['no_play'] = True | |||
|
41 | ||||
|
42 | ###### SIDEBAR ###### | |||
|
43 | kwargs.update(sidebar(conf=conf)) | |||
|
44 | ||||
|
45 | return render(request, 'atrad_conf.html', kwargs) | |||
|
46 | ||||
|
47 | def atrad_conf_edit(request, id_conf): | |||
|
48 | ||||
|
49 | conf = get_object_or_404(ATRADConfiguration, pk=id_conf) | |||
|
50 | ||||
|
51 | if request.method=='GET': | |||
|
52 | form = ATRADConfigurationForm(instance=conf) | |||
|
53 | ||||
|
54 | if request.method=='POST': | |||
|
55 | form = ATRADConfigurationForm(request.POST, instance=conf) | |||
|
56 | ||||
|
57 | if form.is_valid(): | |||
|
58 | if conf.topic == None: conf.topic = 0 | |||
|
59 | ||||
|
60 | conf = form.save(commit=False) | |||
|
61 | ||||
|
62 | if conf.verify_frequencies(): | |||
|
63 | conf.save() | |||
|
64 | return redirect('url_atrad_conf', id_conf=conf.id) | |||
|
65 | ||||
|
66 | kwargs = {} | |||
|
67 | kwargs['id_dev'] = conf.id | |||
|
68 | kwargs['form'] = form | |||
|
69 | kwargs['title'] = 'Device Configuration' | |||
|
70 | kwargs['suptitle'] = 'Edit' | |||
|
71 | kwargs['button'] = 'Save' | |||
|
72 | ||||
|
73 | return render(request, 'atrad_conf_edit.html', kwargs) | |||
|
74 | ||||
|
75 | import os | |||
|
76 | from django.http import HttpResponse# | |||
|
77 | ||||
|
78 | def publish_message(request): | |||
|
79 | rc, mid = mqtt_client.publish('test/data2',1) | |||
|
80 | return JsonResponse({'code1': 'HIKA', 'code2': 'LUCAS'}) | |||
|
81 | ||||
|
82 | def monitor(request): | |||
|
83 | kwargs = {'no_sidebar': True} | |||
|
84 | return render(request, 'monitor.html', kwargs) | |||
|
85 | ||||
|
86 | def prueba(request): | |||
|
87 | kwargs = {'no_sidebar': True} | |||
|
88 | return render(request, 'prueba.html', kwargs) | |||
|
89 | ||||
|
90 | @sio.on('connection-bind') | |||
|
91 | def connection_bind(sid, data): | |||
|
92 | print("sid:",sid,"data",data) | |||
|
93 | ||||
|
94 | @sio.on('disconnect') | |||
|
95 | def test_disconnect(sid): | |||
|
96 | print("Disconnected") | |||
|
97 | ||||
|
98 | @sio.event | |||
|
99 | def control_event(sid,message): | |||
|
100 | mqtt_client.publish('test/data2',message['data']) | |||
|
101 | ||||
|
102 | def hello(data): | |||
|
103 | try: | |||
|
104 | rc, mid = mqtt_client.publish('test/data2', 'Hello') | |||
|
105 | sio.emit('test', data={'topic':mid, 'status': 'Not Running'}) | |||
|
106 | except: | |||
|
107 | print('ERROR', flush=True) | |||
|
108 | return HttpResponse("Hello") No newline at end of file |
@@ -0,0 +1,6 | |||||
|
1 | import os | |||
|
2 | import socketio | |||
|
3 | async_mode = None | |||
|
4 | ||||
|
5 | basedir = os.path.dirname(os.path.realpath(__file__)) | |||
|
6 | sio = socketio.Server(async_mode='eventlet') No newline at end of file |
@@ -1,138 +1,146 | |||||
1 | [ |
|
1 | [ | |
2 | { |
|
2 | { | |
3 | "fields": { |
|
3 | "fields": { | |
4 | "name": "JRO", |
|
4 | "name": "JRO", | |
5 | "description": "" |
|
5 | "description": "" | |
6 | }, |
|
6 | }, | |
7 | "model": "main.location", |
|
7 | "model": "main.location", | |
8 | "pk": 1 |
|
8 | "pk": 1 | |
9 | }, |
|
9 | }, | |
10 | { |
|
10 | { | |
11 | "fields": { |
|
11 | "fields": { | |
12 | "name": "JASMET", |
|
12 | "name": "JASMET", | |
13 | "description": "" |
|
13 | "description": "" | |
14 | }, |
|
14 | }, | |
15 | "model": "main.location", |
|
15 | "model": "main.location", | |
16 | "pk": 2 |
|
16 | "pk": 2 | |
17 | }, |
|
17 | }, | |
18 | { |
|
18 | { | |
19 | "fields": { |
|
19 | "fields": { | |
20 | "name": "SOUSY", |
|
20 | "name": "SOUSY", | |
21 | "description": "" |
|
21 | "description": "" | |
22 | }, |
|
22 | }, | |
23 | "model": "main.location", |
|
23 | "model": "main.location", | |
24 | "pk": 3 |
|
24 | "pk": 3 | |
25 | }, |
|
25 | }, | |
26 | { |
|
26 | { | |
27 | "fields": { |
|
27 | "fields": { | |
28 | "name": "JULIA", |
|
28 | "name": "JULIA", | |
29 | "description": "" |
|
29 | "description": "" | |
30 | }, |
|
30 | }, | |
31 | "model": "main.location", |
|
31 | "model": "main.location", | |
32 | "pk": 4 |
|
32 | "pk": 4 | |
33 | }, |
|
33 | }, | |
34 | { |
|
34 | { | |
35 | "fields": { |
|
35 | "fields": { | |
36 | "name": "CLAIRE", |
|
36 | "name": "CLAIRE", | |
37 | "description": "" |
|
37 | "description": "" | |
38 | }, |
|
38 | }, | |
39 | "model": "main.location", |
|
39 | "model": "main.location", | |
40 | "pk": 5 |
|
40 | "pk": 5 | |
41 | }, |
|
41 | }, | |
42 | { |
|
42 | { | |
43 | "fields": { |
|
43 | "fields": { | |
44 | "name": "IDI", |
|
44 | "name": "IDI", | |
45 | "description": "" |
|
45 | "description": "" | |
46 | }, |
|
46 | }, | |
47 | "model": "main.location", |
|
47 | "model": "main.location", | |
48 | "pk": 6 |
|
48 | "pk": 6 | |
49 | }, |
|
49 | }, | |
50 | { |
|
50 | { | |
51 | "fields": { |
|
51 | "fields": { | |
52 | "name": "rc", |
|
52 | "name": "rc", | |
53 | "description": "" |
|
53 | "description": "" | |
54 | }, |
|
54 | }, | |
55 | "model": "main.devicetype", |
|
55 | "model": "main.devicetype", | |
56 | "pk": 1 |
|
56 | "pk": 1 | |
57 | }, |
|
57 | }, | |
58 | { |
|
58 | { | |
59 | "fields": { |
|
59 | "fields": { | |
60 | "name": "dds", |
|
60 | "name": "dds", | |
61 | "description": "" |
|
61 | "description": "" | |
62 | }, |
|
62 | }, | |
63 | "model": "main.devicetype", |
|
63 | "model": "main.devicetype", | |
64 | "pk": 2 |
|
64 | "pk": 2 | |
65 | }, |
|
65 | }, | |
66 | { |
|
66 | { | |
67 | "fields": { |
|
67 | "fields": { | |
68 | "name": "cgs", |
|
68 | "name": "cgs", | |
69 | "description": "" |
|
69 | "description": "" | |
70 | }, |
|
70 | }, | |
71 | "model": "main.devicetype", |
|
71 | "model": "main.devicetype", | |
72 | "pk": 3 |
|
72 | "pk": 3 | |
73 | }, |
|
73 | }, | |
74 | { |
|
74 | { | |
75 | "fields": { |
|
75 | "fields": { | |
76 | "name": "jars", |
|
76 | "name": "jars", | |
77 | "description": "" |
|
77 | "description": "" | |
78 | }, |
|
78 | }, | |
79 | "model": "main.devicetype", |
|
79 | "model": "main.devicetype", | |
80 | "pk": 4 |
|
80 | "pk": 4 | |
81 | }, |
|
81 | }, | |
82 | { |
|
82 | { | |
83 | "fields": { |
|
83 | "fields": { | |
84 | "name": "abs", |
|
84 | "name": "abs", | |
85 | "description": "" |
|
85 | "description": "" | |
86 | }, |
|
86 | }, | |
87 | "model": "main.devicetype", |
|
87 | "model": "main.devicetype", | |
88 | "pk": 5 |
|
88 | "pk": 5 | |
89 | }, |
|
89 | }, | |
90 | { |
|
90 | { | |
91 | "fields": { |
|
91 | "fields": { | |
92 | "name": "dds_rest", |
|
92 | "name": "dds_rest", | |
93 | "description": "" |
|
93 | "description": "" | |
94 | }, |
|
94 | }, | |
95 | "model": "main.devicetype", |
|
95 | "model": "main.devicetype", | |
96 | "pk": 6 |
|
96 | "pk": 6 | |
|
97 | }, | |||
|
98 | { | |||
|
99 | "fields": { | |||
|
100 | "name": "atrad", | |||
|
101 | "description": "" | |||
|
102 | }, | |||
|
103 | "model": "main.devicetype", | |||
|
104 | "pk": 7 | |||
97 | }, |
|
105 | }, | |
98 | { |
|
106 | { | |
99 | "fields": { |
|
107 | "fields": { | |
100 | "name": "Operator" |
|
108 | "name": "Operator" | |
101 | }, |
|
109 | }, | |
102 | "model": "auth.group", |
|
110 | "model": "auth.group", | |
103 | "pk": 1 |
|
111 | "pk": 1 | |
104 | }, |
|
112 | }, | |
105 | { |
|
113 | { | |
106 | "fields": { |
|
114 | "fields": { | |
107 | "name": "Developer" |
|
115 | "name": "Developer" | |
108 | }, |
|
116 | }, | |
109 | "model": "auth.group", |
|
117 | "model": "auth.group", | |
110 | "pk": 2 |
|
118 | "pk": 2 | |
111 | }, |
|
119 | }, | |
112 | { |
|
120 | { | |
113 | "fields": { |
|
121 | "fields": { | |
114 | "password": "pbkdf2_sha256$24000$6RRL7xETgdgN$ORRPhrITZKzTTZHCm8T+Er6ght415kYKeU7QP3rry5M=", |
|
122 | "password": "pbkdf2_sha256$24000$6RRL7xETgdgN$ORRPhrITZKzTTZHCm8T+Er6ght415kYKeU7QP3rry5M=", | |
115 | "last_login": null, |
|
123 | "last_login": null, | |
116 | "is_superuser": true, |
|
124 | "is_superuser": true, | |
117 | "username": "admin", |
|
125 | "username": "admin", | |
118 | "first_name": "Administrador", |
|
126 | "first_name": "Administrador", | |
119 | "last_name": "IDI", |
|
127 | "last_name": "IDI", | |
120 | "email": "admin@admin.com", |
|
128 | "email": "admin@admin.com", | |
121 | "is_staff": true, |
|
129 | "is_staff": true, | |
122 | "is_active": true, |
|
130 | "is_active": true, | |
123 | "date_joined": "2017-01-12T16:10:24.383", |
|
131 | "date_joined": "2017-01-12T16:10:24.383", | |
124 | "groups": [], |
|
132 | "groups": [], | |
125 | "user_permissions": [] |
|
133 | "user_permissions": [] | |
126 | }, |
|
134 | }, | |
127 | "model": "auth.user", |
|
135 | "model": "auth.user", | |
128 | "pk": 1 |
|
136 | "pk": 1 | |
129 | }, |
|
137 | }, | |
130 | { |
|
138 | { | |
131 | "fields": { |
|
139 | "fields": { | |
132 | "user": 1, |
|
140 | "user": 1, | |
133 | "theme": "spacelab" |
|
141 | "theme": "spacelab" | |
134 | }, |
|
142 | }, | |
135 | "model": "main.profile", |
|
143 | "model": "main.profile", | |
136 | "pk": 1 |
|
144 | "pk": 1 | |
137 | } |
|
145 | } | |
138 | ] |
|
146 | ] |
@@ -1,818 +1,819 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import json |
|
3 | import json | |
4 | import requests |
|
4 | import requests | |
5 | import time |
|
5 | import time | |
6 | from datetime import datetime |
|
6 | from datetime import datetime | |
7 |
|
7 | |||
8 | try: |
|
8 | try: | |
9 | from polymorphic.models import PolymorphicModel |
|
9 | from polymorphic.models import PolymorphicModel | |
10 | except: |
|
10 | except: | |
11 | from polymorphic import PolymorphicModel |
|
11 | from polymorphic import PolymorphicModel | |
12 |
|
12 | |||
13 | from django.template.base import kwarg_re |
|
13 | from django.template.base import kwarg_re | |
14 | from django.db import models |
|
14 | from django.db import models | |
15 | from django.urls import reverse |
|
15 | from django.urls import reverse | |
16 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
16 | from django.core.validators import MinValueValidator, MaxValueValidator | |
17 | from django.shortcuts import get_object_or_404 |
|
17 | from django.shortcuts import get_object_or_404 | |
18 | from django.contrib.auth.models import User |
|
18 | from django.contrib.auth.models import User | |
19 | from django.db.models.signals import post_save |
|
19 | from django.db.models.signals import post_save | |
20 | from django.dispatch import receiver |
|
20 | from django.dispatch import receiver | |
21 |
|
21 | |||
22 | from apps.main.utils import Params |
|
22 | from apps.main.utils import Params | |
23 | from apps.rc.utils import RCFile |
|
23 | from apps.rc.utils import RCFile | |
24 | from apps.jars.utils import RacpFile |
|
24 | from apps.jars.utils import RacpFile | |
25 | from devices.dds import api as dds_api |
|
25 | from devices.dds import api as dds_api | |
26 | from devices.dds import data as dds_data |
|
26 | from devices.dds import data as dds_data | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | DEV_PORTS = { |
|
29 | DEV_PORTS = { | |
30 | 'rc' : 2000, |
|
30 | 'rc' : 2000, | |
31 | 'dds' : 2000, |
|
31 | 'dds' : 2000, | |
32 | 'jars' : 2000, |
|
32 | 'jars' : 2000, | |
33 | 'usrp' : 2000, |
|
33 | 'usrp' : 2000, | |
34 | 'cgs' : 8080, |
|
34 | 'cgs' : 8080, | |
35 | 'abs' : 8080, |
|
35 | 'abs' : 8080, | |
36 | 'dds_rest': 80 |
|
36 | 'dds_rest': 80 | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | RADAR_STATES = ( |
|
39 | RADAR_STATES = ( | |
40 | (0, 'No connected'), |
|
40 | (0, 'No connected'), | |
41 | (1, 'Connected'), |
|
41 | (1, 'Connected'), | |
42 | (2, 'Configured'), |
|
42 | (2, 'Configured'), | |
43 | (3, 'Running'), |
|
43 | (3, 'Running'), | |
44 | (4, 'Scheduled'), |
|
44 | (4, 'Scheduled'), | |
45 | ) |
|
45 | ) | |
46 |
|
46 | |||
47 | EXPERIMENT_TYPE = ( |
|
47 | EXPERIMENT_TYPE = ( | |
48 | (0, 'RAW_DATA'), |
|
48 | (0, 'RAW_DATA'), | |
49 | (1, 'PDATA'), |
|
49 | (1, 'PDATA'), | |
50 | ) |
|
50 | ) | |
51 |
|
51 | |||
52 | DECODE_TYPE = ( |
|
52 | DECODE_TYPE = ( | |
53 | (0, 'None'), |
|
53 | (0, 'None'), | |
54 | (1, 'TimeDomain'), |
|
54 | (1, 'TimeDomain'), | |
55 | (2, 'FreqDomain'), |
|
55 | (2, 'FreqDomain'), | |
56 | (3, 'InvFreqDomain'), |
|
56 | (3, 'InvFreqDomain'), | |
57 | ) |
|
57 | ) | |
58 |
|
58 | |||
59 | DEV_STATES = ( |
|
59 | DEV_STATES = ( | |
60 | (0, 'No connected'), |
|
60 | (0, 'No connected'), | |
61 | (1, 'Connected'), |
|
61 | (1, 'Connected'), | |
62 | (2, 'Configured'), |
|
62 | (2, 'Configured'), | |
63 | (3, 'Running'), |
|
63 | (3, 'Running'), | |
64 | (4, 'Unknown'), |
|
64 | (4, 'Unknown'), | |
65 | ) |
|
65 | ) | |
66 |
|
66 | |||
67 | DEV_TYPES = ( |
|
67 | DEV_TYPES = ( | |
68 | ('', 'Select a device type'), |
|
68 | ('', 'Select a device type'), | |
69 | ('rc', 'Radar Controller'), |
|
69 | ('rc', 'Radar Controller'), | |
70 | ('dds', 'Direct Digital Synthesizer'), |
|
70 | ('dds', 'Direct Digital Synthesizer'), | |
71 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
71 | ('jars', 'Jicamarca Radar Acquisition System'), | |
72 | ('usrp', 'Universal Software Radio Peripheral'), |
|
72 | ('usrp', 'Universal Software Radio Peripheral'), | |
73 | ('cgs', 'Clock Generator System'), |
|
73 | ('cgs', 'Clock Generator System'), | |
74 | ('abs', 'Automatic Beam Switching'), |
|
74 | ('abs', 'Automatic Beam Switching'), | |
75 | ('dds_rest', 'Direct Digital Synthesizer_REST'), |
|
75 | ('dds_rest', 'Direct Digital Synthesizer_REST'), | |
|
76 | ('atrad', 'Transmitter ATRAD'), | |||
76 | ) |
|
77 | ) | |
77 |
|
78 | |||
78 | EXP_STATES = ( |
|
79 | EXP_STATES = ( | |
79 | (0,'Error'), #RED |
|
80 | (0,'Error'), #RED | |
80 | (1,'Cancelled'), #YELLOW |
|
81 | (1,'Cancelled'), #YELLOW | |
81 | (2,'Running'), #GREEN |
|
82 | (2,'Running'), #GREEN | |
82 | (3,'Scheduled'), #BLUE |
|
83 | (3,'Scheduled'), #BLUE | |
83 | (4,'Unknown'), #WHITE |
|
84 | (4,'Unknown'), #WHITE | |
84 | ) |
|
85 | ) | |
85 |
|
86 | |||
86 | CONF_TYPES = ( |
|
87 | CONF_TYPES = ( | |
87 | (0, 'Active'), |
|
88 | (0, 'Active'), | |
88 | (1, 'Historical'), |
|
89 | (1, 'Historical'), | |
89 | ) |
|
90 | ) | |
90 |
|
91 | |||
91 | class Profile(models.Model): |
|
92 | class Profile(models.Model): | |
92 | user = models.OneToOneField(User, on_delete=models.CASCADE) |
|
93 | user = models.OneToOneField(User, on_delete=models.CASCADE) | |
93 | theme = models.CharField(max_length=30, default='spacelab') |
|
94 | theme = models.CharField(max_length=30, default='spacelab') | |
94 |
|
95 | |||
95 |
|
96 | |||
96 | @receiver(post_save, sender=User) |
|
97 | @receiver(post_save, sender=User) | |
97 | def create_user_profile(sender, instance, created, **kwargs): |
|
98 | def create_user_profile(sender, instance, created, **kwargs): | |
98 | if created: |
|
99 | if created: | |
99 | Profile.objects.create(user=instance) |
|
100 | Profile.objects.create(user=instance) | |
100 |
|
101 | |||
101 | @receiver(post_save, sender=User) |
|
102 | @receiver(post_save, sender=User) | |
102 | def save_user_profile(sender, instance, **kwargs): |
|
103 | def save_user_profile(sender, instance, **kwargs): | |
103 | instance.profile.save() |
|
104 | instance.profile.save() | |
104 |
|
105 | |||
105 |
|
106 | |||
106 | class Location(models.Model): |
|
107 | class Location(models.Model): | |
107 |
|
108 | |||
108 | name = models.CharField(max_length = 30) |
|
109 | name = models.CharField(max_length = 30) | |
109 | description = models.TextField(blank=True, null=True) |
|
110 | description = models.TextField(blank=True, null=True) | |
110 |
|
111 | |||
111 | class Meta: |
|
112 | class Meta: | |
112 | db_table = 'db_location' |
|
113 | db_table = 'db_location' | |
113 |
|
114 | |||
114 | def __str__(self): |
|
115 | def __str__(self): | |
115 | return u'%s' % self.name |
|
116 | return u'%s' % self.name | |
116 |
|
117 | |||
117 | def get_absolute_url(self): |
|
118 | def get_absolute_url(self): | |
118 | return reverse('url_location', args=[str(self.id)]) |
|
119 | return reverse('url_location', args=[str(self.id)]) | |
119 |
|
120 | |||
120 |
|
121 | |||
121 | class DeviceType(models.Model): |
|
122 | class DeviceType(models.Model): | |
122 |
|
123 | |||
123 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'dds_rest') |
|
124 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'dds_rest') | |
124 | sequence = models.PositiveSmallIntegerField(default=55) |
|
125 | sequence = models.PositiveSmallIntegerField(default=55) | |
125 | description = models.TextField(blank=True, null=True) |
|
126 | description = models.TextField(blank=True, null=True) | |
126 |
|
127 | |||
127 | class Meta: |
|
128 | class Meta: | |
128 | db_table = 'db_device_types' |
|
129 | db_table = 'db_device_types' | |
129 |
|
130 | |||
130 | def __str__(self): |
|
131 | def __str__(self): | |
131 | return u'%s' % self.get_name_display() |
|
132 | return u'%s' % self.get_name_display() | |
132 |
|
133 | |||
133 | class Device(models.Model): |
|
134 | class Device(models.Model): | |
134 |
|
135 | |||
135 | device_type = models.ForeignKey('DeviceType', on_delete=models.CASCADE) |
|
136 | device_type = models.ForeignKey('DeviceType', on_delete=models.CASCADE) | |
136 | location = models.ForeignKey('Location', on_delete=models.CASCADE) |
|
137 | location = models.ForeignKey('Location', on_delete=models.CASCADE) | |
137 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
138 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
138 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
139 | port_address = models.PositiveSmallIntegerField(default=2000) | |
139 | description = models.TextField(blank=True, null=True) |
|
140 | description = models.TextField(blank=True, null=True) | |
140 | status = models.PositiveSmallIntegerField(default=4, choices=DEV_STATES) |
|
141 | status = models.PositiveSmallIntegerField(default=4, choices=DEV_STATES) | |
141 | conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration') |
|
142 | conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration') | |
142 |
|
143 | |||
143 | class Meta: |
|
144 | class Meta: | |
144 | db_table = 'db_devices' |
|
145 | db_table = 'db_devices' | |
145 |
|
146 | |||
146 | def __str__(self): |
|
147 | def __str__(self): | |
147 | ret = u'{} [{}]'.format(self.device_type.name.upper(), self.location.name) |
|
148 | ret = u'{} [{}]'.format(self.device_type.name.upper(), self.location.name) | |
148 |
|
149 | |||
149 | return ret |
|
150 | return ret | |
150 |
|
151 | |||
151 | @property |
|
152 | @property | |
152 | def name(self): |
|
153 | def name(self): | |
153 | return str(self) |
|
154 | return str(self) | |
154 |
|
155 | |||
155 | def get_status(self): |
|
156 | def get_status(self): | |
156 | return self.status |
|
157 | return self.status | |
157 |
|
158 | |||
158 | @property |
|
159 | @property | |
159 | def status_color(self): |
|
160 | def status_color(self): | |
160 | color = 'muted' |
|
161 | color = 'muted' | |
161 | if self.status == 0: |
|
162 | if self.status == 0: | |
162 | color = "danger" |
|
163 | color = "danger" | |
163 | elif self.status == 1: |
|
164 | elif self.status == 1: | |
164 | color = "warning" |
|
165 | color = "warning" | |
165 | elif self.status == 2: |
|
166 | elif self.status == 2: | |
166 | color = "info" |
|
167 | color = "info" | |
167 | elif self.status == 3: |
|
168 | elif self.status == 3: | |
168 | color = "success" |
|
169 | color = "success" | |
169 |
|
170 | |||
170 | return color |
|
171 | return color | |
171 |
|
172 | |||
172 | def url(self, path=None): |
|
173 | def url(self, path=None): | |
173 |
|
174 | |||
174 | if path: |
|
175 | if path: | |
175 | return 'http://{}:{}/{}/'.format(self.ip_address, self.port_address, path) |
|
176 | return 'http://{}:{}/{}/'.format(self.ip_address, self.port_address, path) | |
176 | else: |
|
177 | else: | |
177 | return 'http://{}:{}/'.format(self.ip_address, self.port_address) |
|
178 | return 'http://{}:{}/'.format(self.ip_address, self.port_address) | |
178 |
|
179 | |||
179 | def get_absolute_url(self): |
|
180 | def get_absolute_url(self): | |
180 | return reverse('url_device', args=[str(self.id)]) |
|
181 | return reverse('url_device', args=[str(self.id)]) | |
181 |
|
182 | |||
182 | def get_absolute_url_edit(self): |
|
183 | def get_absolute_url_edit(self): | |
183 | return reverse('url_edit_device', args=[str(self.id)]) |
|
184 | return reverse('url_edit_device', args=[str(self.id)]) | |
184 |
|
185 | |||
185 | def get_absolute_url_delete(self): |
|
186 | def get_absolute_url_delete(self): | |
186 | return reverse('url_delete_device', args=[str(self.id)]) |
|
187 | return reverse('url_delete_device', args=[str(self.id)]) | |
187 |
|
188 | |||
188 | def change_ip(self, ip_address, mask, gateway, dns, **kwargs): |
|
189 | def change_ip(self, ip_address, mask, gateway, dns, **kwargs): | |
189 |
|
190 | |||
190 | if self.device_type.name=='dds': |
|
191 | if self.device_type.name=='dds': | |
191 | try: |
|
192 | try: | |
192 | answer = dds_api.change_ip(ip = self.ip_address, |
|
193 | answer = dds_api.change_ip(ip = self.ip_address, | |
193 | port = self.port_address, |
|
194 | port = self.port_address, | |
194 | new_ip = ip_address, |
|
195 | new_ip = ip_address, | |
195 | mask = mask, |
|
196 | mask = mask, | |
196 | gateway = gateway) |
|
197 | gateway = gateway) | |
197 | if answer[0]=='1': |
|
198 | if answer[0]=='1': | |
198 | self.message = '25|DDS - {}'.format(answer) |
|
199 | self.message = '25|DDS - {}'.format(answer) | |
199 | self.ip_address = ip_address |
|
200 | self.ip_address = ip_address | |
200 | self.save() |
|
201 | self.save() | |
201 | else: |
|
202 | else: | |
202 | self.message = '30|DDS - {}'.format(answer) |
|
203 | self.message = '30|DDS - {}'.format(answer) | |
203 | return False |
|
204 | return False | |
204 | except Exception as e: |
|
205 | except Exception as e: | |
205 | self.message = '40|{}'.format(str(e)) |
|
206 | self.message = '40|{}'.format(str(e)) | |
206 | return False |
|
207 | return False | |
207 |
|
208 | |||
208 | elif self.device_type.name=='rc': |
|
209 | elif self.device_type.name=='rc': | |
209 | headers = {'content-type': "application/json", |
|
210 | headers = {'content-type': "application/json", | |
210 | 'cache-control': "no-cache"} |
|
211 | 'cache-control': "no-cache"} | |
211 |
|
212 | |||
212 | ip = [int(x) for x in ip_address.split('.')] |
|
213 | ip = [int(x) for x in ip_address.split('.')] | |
213 | dns = [int(x) for x in dns.split('.')] |
|
214 | dns = [int(x) for x in dns.split('.')] | |
214 | gateway = [int(x) for x in gateway.split('.')] |
|
215 | gateway = [int(x) for x in gateway.split('.')] | |
215 | subnet = [int(x) for x in mask.split('.')] |
|
216 | subnet = [int(x) for x in mask.split('.')] | |
216 |
|
217 | |||
217 | payload = { |
|
218 | payload = { | |
218 | "ip": ip, |
|
219 | "ip": ip, | |
219 | "dns": dns, |
|
220 | "dns": dns, | |
220 | "gateway": gateway, |
|
221 | "gateway": gateway, | |
221 | "subnet": subnet |
|
222 | "subnet": subnet | |
222 | } |
|
223 | } | |
223 |
|
224 | |||
224 | req = requests.post(self.url('changeip'), data=json.dumps(payload), headers=headers) |
|
225 | req = requests.post(self.url('changeip'), data=json.dumps(payload), headers=headers) | |
225 | try: |
|
226 | try: | |
226 | answer = req.json() |
|
227 | answer = req.json() | |
227 | if answer['changeip']=='ok': |
|
228 | if answer['changeip']=='ok': | |
228 | self.message = '25|IP succesfully changed' |
|
229 | self.message = '25|IP succesfully changed' | |
229 | self.ip_address = ip_address |
|
230 | self.ip_address = ip_address | |
230 | self.save() |
|
231 | self.save() | |
231 | else: |
|
232 | else: | |
232 | self.message = '30|An error ocuur when changing IP' |
|
233 | self.message = '30|An error ocuur when changing IP' | |
233 | except Exception as e: |
|
234 | except Exception as e: | |
234 | self.message = '40|{}'.format(str(e)) |
|
235 | self.message = '40|{}'.format(str(e)) | |
235 | else: |
|
236 | else: | |
236 | self.message = 'Not implemented' |
|
237 | self.message = 'Not implemented' | |
237 | return False |
|
238 | return False | |
238 |
|
239 | |||
239 | return True |
|
240 | return True | |
240 |
|
241 | |||
241 |
|
242 | |||
242 | class Campaign(models.Model): |
|
243 | class Campaign(models.Model): | |
243 |
|
244 | |||
244 | template = models.BooleanField(default=False) |
|
245 | template = models.BooleanField(default=False) | |
245 | name = models.CharField(max_length=60, unique=True) |
|
246 | name = models.CharField(max_length=60, unique=True) | |
246 | start_date = models.DateTimeField(blank=True, null=True) |
|
247 | start_date = models.DateTimeField(blank=True, null=True) | |
247 | end_date = models.DateTimeField(blank=True, null=True) |
|
248 | end_date = models.DateTimeField(blank=True, null=True) | |
248 | tags = models.CharField(max_length=40, blank=True, null=True) |
|
249 | tags = models.CharField(max_length=40, blank=True, null=True) | |
249 | description = models.TextField(blank=True, null=True) |
|
250 | description = models.TextField(blank=True, null=True) | |
250 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
251 | experiments = models.ManyToManyField('Experiment', blank=True) | |
251 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) |
|
252 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
252 |
|
253 | |||
253 | class Meta: |
|
254 | class Meta: | |
254 | db_table = 'db_campaigns' |
|
255 | db_table = 'db_campaigns' | |
255 | ordering = ('name',) |
|
256 | ordering = ('name',) | |
256 |
|
257 | |||
257 | def __str__(self): |
|
258 | def __str__(self): | |
258 | if self.template: |
|
259 | if self.template: | |
259 | return u'{} (template)'.format(self.name) |
|
260 | return u'{} (template)'.format(self.name) | |
260 | else: |
|
261 | else: | |
261 | return u'{}'.format(self.name) |
|
262 | return u'{}'.format(self.name) | |
262 |
|
263 | |||
263 | def jsonify(self): |
|
264 | def jsonify(self): | |
264 |
|
265 | |||
265 | data = {} |
|
266 | data = {} | |
266 |
|
267 | |||
267 | ignored = ('template') |
|
268 | ignored = ('template') | |
268 |
|
269 | |||
269 | for field in self._meta.fields: |
|
270 | for field in self._meta.fields: | |
270 | if field.name in ignored: |
|
271 | if field.name in ignored: | |
271 | continue |
|
272 | continue | |
272 | data[field.name] = field.value_from_object(self) |
|
273 | data[field.name] = field.value_from_object(self) | |
273 |
|
274 | |||
274 | data['start_date'] = data['start_date'].strftime('%Y-%m-%d') |
|
275 | data['start_date'] = data['start_date'].strftime('%Y-%m-%d') | |
275 | data['end_date'] = data['end_date'].strftime('%Y-%m-%d') |
|
276 | data['end_date'] = data['end_date'].strftime('%Y-%m-%d') | |
276 |
|
277 | |||
277 | return data |
|
278 | return data | |
278 |
|
279 | |||
279 | def parms_to_dict(self): |
|
280 | def parms_to_dict(self): | |
280 |
|
281 | |||
281 | params = Params({}) |
|
282 | params = Params({}) | |
282 | params.add(self.jsonify(), 'campaigns') |
|
283 | params.add(self.jsonify(), 'campaigns') | |
283 |
|
284 | |||
284 | for exp in Experiment.objects.filter(campaign = self): |
|
285 | for exp in Experiment.objects.filter(campaign = self): | |
285 | params.add(exp.jsonify(), 'experiments') |
|
286 | params.add(exp.jsonify(), 'experiments') | |
286 | configurations = Configuration.objects.filter(experiment=exp, type=0) |
|
287 | configurations = Configuration.objects.filter(experiment=exp, type=0) | |
287 |
|
288 | |||
288 | for conf in configurations: |
|
289 | for conf in configurations: | |
289 | params.add(conf.jsonify(), 'configurations') |
|
290 | params.add(conf.jsonify(), 'configurations') | |
290 | if conf.device.device_type.name=='rc': |
|
291 | if conf.device.device_type.name=='rc': | |
291 | for line in conf.get_lines(): |
|
292 | for line in conf.get_lines(): | |
292 | params.add(line.jsonify(), 'lines') |
|
293 | params.add(line.jsonify(), 'lines') | |
293 |
|
294 | |||
294 | return params.data |
|
295 | return params.data | |
295 |
|
296 | |||
296 | def dict_to_parms(self, parms, CONF_MODELS): |
|
297 | def dict_to_parms(self, parms, CONF_MODELS): | |
297 |
|
298 | |||
298 | experiments = Experiment.objects.filter(campaign = self) |
|
299 | experiments = Experiment.objects.filter(campaign = self) | |
299 |
|
300 | |||
300 | if experiments: |
|
301 | if experiments: | |
301 | for experiment in experiments: |
|
302 | for experiment in experiments: | |
302 | experiment.delete() |
|
303 | experiment.delete() | |
303 |
|
304 | |||
304 | for id_exp in parms['experiments']['allIds']: |
|
305 | for id_exp in parms['experiments']['allIds']: | |
305 | exp_parms = parms['experiments']['byId'][id_exp] |
|
306 | exp_parms = parms['experiments']['byId'][id_exp] | |
306 | dum = (datetime.now() - datetime(1970, 1, 1)).total_seconds() |
|
307 | dum = (datetime.now() - datetime(1970, 1, 1)).total_seconds() | |
307 | exp = Experiment(name='{}'.format(dum)) |
|
308 | exp = Experiment(name='{}'.format(dum)) | |
308 | exp.save() |
|
309 | exp.save() | |
309 | exp.dict_to_parms(parms, CONF_MODELS, id_exp=id_exp) |
|
310 | exp.dict_to_parms(parms, CONF_MODELS, id_exp=id_exp) | |
310 | self.experiments.add(exp) |
|
311 | self.experiments.add(exp) | |
311 |
|
312 | |||
312 | camp_parms = parms['campaigns']['byId'][parms['campaigns']['allIds'][0]] |
|
313 | camp_parms = parms['campaigns']['byId'][parms['campaigns']['allIds'][0]] | |
313 |
|
314 | |||
314 | self.name = '{}-{}'.format(camp_parms['name'], datetime.now().strftime('%y%m%d')) |
|
315 | self.name = '{}-{}'.format(camp_parms['name'], datetime.now().strftime('%y%m%d')) | |
315 | self.start_date = camp_parms['start_date'] |
|
316 | self.start_date = camp_parms['start_date'] | |
316 | self.end_date = camp_parms['end_date'] |
|
317 | self.end_date = camp_parms['end_date'] | |
317 | self.tags = camp_parms['tags'] |
|
318 | self.tags = camp_parms['tags'] | |
318 | self.save() |
|
319 | self.save() | |
319 |
|
320 | |||
320 | return self |
|
321 | return self | |
321 |
|
322 | |||
322 | def get_experiments_by_radar(self, radar=None): |
|
323 | def get_experiments_by_radar(self, radar=None): | |
323 |
|
324 | |||
324 | ret = [] |
|
325 | ret = [] | |
325 | if radar: |
|
326 | if radar: | |
326 | locations = Location.objects.filter(pk=radar) |
|
327 | locations = Location.objects.filter(pk=radar) | |
327 | else: |
|
328 | else: | |
328 | locations = set([e.location for e in self.experiments.all()]) |
|
329 | locations = set([e.location for e in self.experiments.all()]) | |
329 |
|
330 | |||
330 | for loc in locations: |
|
331 | for loc in locations: | |
331 | dum = {} |
|
332 | dum = {} | |
332 | dum['name'] = loc.name |
|
333 | dum['name'] = loc.name | |
333 | dum['id'] = loc.pk |
|
334 | dum['id'] = loc.pk | |
334 | dum['experiments'] = [e for e in self.experiments.all() if e.location==loc] |
|
335 | dum['experiments'] = [e for e in self.experiments.all() if e.location==loc] | |
335 | ret.append(dum) |
|
336 | ret.append(dum) | |
336 |
|
337 | |||
337 | return ret |
|
338 | return ret | |
338 |
|
339 | |||
339 | def get_absolute_url(self): |
|
340 | def get_absolute_url(self): | |
340 | return reverse('url_campaign', args=[str(self.id)]) |
|
341 | return reverse('url_campaign', args=[str(self.id)]) | |
341 |
|
342 | |||
342 | def get_absolute_url_edit(self): |
|
343 | def get_absolute_url_edit(self): | |
343 | return reverse('url_edit_campaign', args=[str(self.id)]) |
|
344 | return reverse('url_edit_campaign', args=[str(self.id)]) | |
344 |
|
345 | |||
345 | def get_absolute_url_delete(self): |
|
346 | def get_absolute_url_delete(self): | |
346 | return reverse('url_delete_campaign', args=[str(self.id)]) |
|
347 | return reverse('url_delete_campaign', args=[str(self.id)]) | |
347 |
|
348 | |||
348 | def get_absolute_url_export(self): |
|
349 | def get_absolute_url_export(self): | |
349 | return reverse('url_export_campaign', args=[str(self.id)]) |
|
350 | return reverse('url_export_campaign', args=[str(self.id)]) | |
350 |
|
351 | |||
351 | def get_absolute_url_import(self): |
|
352 | def get_absolute_url_import(self): | |
352 | return reverse('url_import_campaign', args=[str(self.id)]) |
|
353 | return reverse('url_import_campaign', args=[str(self.id)]) | |
353 |
|
354 | |||
354 |
|
355 | |||
355 | class RunningExperiment(models.Model): |
|
356 | class RunningExperiment(models.Model): | |
356 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
357 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
357 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
358 | running_experiment = models.ManyToManyField('Experiment', blank = True) | |
358 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
359 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
359 |
|
360 | |||
360 |
|
361 | |||
361 | class Experiment(models.Model): |
|
362 | class Experiment(models.Model): | |
362 |
|
363 | |||
363 | template = models.BooleanField(default=False) |
|
364 | template = models.BooleanField(default=False) | |
364 | name = models.CharField(max_length=40, default='', unique=True) |
|
365 | name = models.CharField(max_length=40, default='', unique=True) | |
365 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
366 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
366 | freq = models.FloatField(verbose_name='Operating Freq. (MHz)', validators=[MinValueValidator(1), MaxValueValidator(10000)], default=49.9200) |
|
367 | freq = models.FloatField(verbose_name='Operating Freq. (MHz)', validators=[MinValueValidator(1), MaxValueValidator(10000)], default=49.9200) | |
367 | start_time = models.TimeField(default='00:00:00') |
|
368 | start_time = models.TimeField(default='00:00:00') | |
368 | end_time = models.TimeField(default='23:59:59') |
|
369 | end_time = models.TimeField(default='23:59:59') | |
369 | task = models.CharField(max_length=36, default='', blank=True, null=True) |
|
370 | task = models.CharField(max_length=36, default='', blank=True, null=True) | |
370 | status = models.PositiveSmallIntegerField(default=4, choices=EXP_STATES) |
|
371 | status = models.PositiveSmallIntegerField(default=4, choices=EXP_STATES) | |
371 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) |
|
372 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
372 | hash = models.CharField(default='', max_length=64, null=True, blank=True) |
|
373 | hash = models.CharField(default='', max_length=64, null=True, blank=True) | |
373 |
|
374 | |||
374 | class Meta: |
|
375 | class Meta: | |
375 | db_table = 'db_experiments' |
|
376 | db_table = 'db_experiments' | |
376 | ordering = ('template', 'name') |
|
377 | ordering = ('template', 'name') | |
377 |
|
378 | |||
378 | def __str__(self): |
|
379 | def __str__(self): | |
379 | if self.template: |
|
380 | if self.template: | |
380 | return u'%s (template)' % (self.name) |
|
381 | return u'%s (template)' % (self.name) | |
381 | else: |
|
382 | else: | |
382 | return u'%s' % (self.name) |
|
383 | return u'%s' % (self.name) | |
383 |
|
384 | |||
384 | def jsonify(self): |
|
385 | def jsonify(self): | |
385 |
|
386 | |||
386 | data = {} |
|
387 | data = {} | |
387 |
|
388 | |||
388 | ignored = ('template') |
|
389 | ignored = ('template') | |
389 |
|
390 | |||
390 | for field in self._meta.fields: |
|
391 | for field in self._meta.fields: | |
391 | if field.name in ignored: |
|
392 | if field.name in ignored: | |
392 | continue |
|
393 | continue | |
393 | data[field.name] = field.value_from_object(self) |
|
394 | data[field.name] = field.value_from_object(self) | |
394 |
|
395 | |||
395 | data['start_time'] = data['start_time'].strftime('%H:%M:%S') |
|
396 | data['start_time'] = data['start_time'].strftime('%H:%M:%S') | |
396 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') |
|
397 | data['end_time'] = data['end_time'].strftime('%H:%M:%S') | |
397 | data['location'] = self.location.name |
|
398 | data['location'] = self.location.name | |
398 | data['configurations'] = ['{}'.format(conf.pk) for |
|
399 | data['configurations'] = ['{}'.format(conf.pk) for | |
399 | conf in Configuration.objects.filter(experiment=self, type=0)] |
|
400 | conf in Configuration.objects.filter(experiment=self, type=0)] | |
400 |
|
401 | |||
401 | return data |
|
402 | return data | |
402 |
|
403 | |||
403 | @property |
|
404 | @property | |
404 | def radar_system(self): |
|
405 | def radar_system(self): | |
405 | return self.location |
|
406 | return self.location | |
406 |
|
407 | |||
407 | def clone(self, **kwargs): |
|
408 | def clone(self, **kwargs): | |
408 |
|
409 | |||
409 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
410 | confs = Configuration.objects.filter(experiment=self, type=0) | |
410 | self.pk = None |
|
411 | self.pk = None | |
411 | self.name = '{}_{:%y%m%d%H%M%S}'.format(self.name, datetime.now()) |
|
412 | self.name = '{}_{:%y%m%d%H%M%S}'.format(self.name, datetime.now()) | |
412 | for attr, value in kwargs.items(): |
|
413 | for attr, value in kwargs.items(): | |
413 | setattr(self, attr, value) |
|
414 | setattr(self, attr, value) | |
414 |
|
415 | |||
415 | self.save() |
|
416 | self.save() | |
416 |
|
417 | |||
417 | for conf in confs: |
|
418 | for conf in confs: | |
418 | conf.clone(experiment=self, template=False) |
|
419 | conf.clone(experiment=self, template=False) | |
419 |
|
420 | |||
420 | return self |
|
421 | return self | |
421 |
|
422 | |||
422 | def start(self): |
|
423 | def start(self): | |
423 | ''' |
|
424 | ''' | |
424 | Configure and start experiments's devices |
|
425 | Configure and start experiments's devices | |
425 | ABS-CGS-DDS-RC-JARS |
|
426 | ABS-CGS-DDS-RC-JARS | |
426 | ''' |
|
427 | ''' | |
427 |
|
428 | |||
428 | confs = [] |
|
429 | confs = [] | |
429 | allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') |
|
430 | allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') | |
430 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] |
|
431 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] | |
431 | if rc_mix: |
|
432 | if rc_mix: | |
432 | for conf in allconfs: |
|
433 | for conf in allconfs: | |
433 | if conf.device.device_type.name == 'rc' and not conf.mix: |
|
434 | if conf.device.device_type.name == 'rc' and not conf.mix: | |
434 | continue |
|
435 | continue | |
435 | confs.append(conf) |
|
436 | confs.append(conf) | |
436 | else: |
|
437 | else: | |
437 | confs = allconfs |
|
438 | confs = allconfs | |
438 |
|
439 | |||
439 | print("confs: ",confs) |
|
440 | print("confs: ",confs) | |
440 | #try: |
|
441 | #try: | |
441 | for conf in confs: |
|
442 | for conf in confs: | |
442 | print("conf->",conf) |
|
443 | print("conf->",conf) | |
443 | conf.stop_device() |
|
444 | conf.stop_device() | |
444 | conf.write_device() |
|
445 | conf.write_device() | |
445 | conf.device.conf_active = conf.pk |
|
446 | conf.device.conf_active = conf.pk | |
446 | conf.device.save() |
|
447 | conf.device.save() | |
447 | conf.start_device() |
|
448 | conf.start_device() | |
448 | time.sleep(1) |
|
449 | time.sleep(1) | |
449 | #except: |
|
450 | #except: | |
450 | #return 0 |
|
451 | #return 0 | |
451 | return 2 |
|
452 | return 2 | |
452 |
|
453 | |||
453 |
|
454 | |||
454 | def stop(self): |
|
455 | def stop(self): | |
455 | ''' |
|
456 | ''' | |
456 | Stop experiments's devices |
|
457 | Stop experiments's devices | |
457 | DDS-JARS-RC-CGS-ABS |
|
458 | DDS-JARS-RC-CGS-ABS | |
458 | ''' |
|
459 | ''' | |
459 |
|
460 | |||
460 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') |
|
461 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') | |
461 | confs = confs.exclude(device__device_type__name='cgs') |
|
462 | confs = confs.exclude(device__device_type__name='cgs') | |
462 | try: |
|
463 | try: | |
463 | for conf in confs: |
|
464 | for conf in confs: | |
464 | conf.stop_device() |
|
465 | conf.stop_device() | |
465 | except: |
|
466 | except: | |
466 | return 0 |
|
467 | return 0 | |
467 | return 1 |
|
468 | return 1 | |
468 |
|
469 | |||
469 | def get_status(self): |
|
470 | def get_status(self): | |
470 |
|
471 | |||
471 | if self.status == 3: |
|
472 | if self.status == 3: | |
472 | return |
|
473 | return | |
473 |
|
474 | |||
474 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
475 | confs = Configuration.objects.filter(experiment=self, type=0) | |
475 |
|
476 | |||
476 | for conf in confs: |
|
477 | for conf in confs: | |
477 | conf.status_device() |
|
478 | conf.status_device() | |
478 |
|
479 | |||
479 | total = confs.aggregate(models.Sum('device__status'))['device__status__sum'] |
|
480 | total = confs.aggregate(models.Sum('device__status'))['device__status__sum'] | |
480 |
|
481 | |||
481 | if total==2*confs.count(): |
|
482 | if total==2*confs.count(): | |
482 | status = 1 |
|
483 | status = 1 | |
483 | elif total == 3*confs.count(): |
|
484 | elif total == 3*confs.count(): | |
484 | status = 2 |
|
485 | status = 2 | |
485 | else: |
|
486 | else: | |
486 | status = 0 |
|
487 | status = 0 | |
487 |
|
488 | |||
488 | self.status = status |
|
489 | self.status = status | |
489 | self.save() |
|
490 | self.save() | |
490 |
|
491 | |||
491 | def status_color(self): |
|
492 | def status_color(self): | |
492 | color = 'muted' |
|
493 | color = 'muted' | |
493 | if self.status == 0: |
|
494 | if self.status == 0: | |
494 | color = "danger" |
|
495 | color = "danger" | |
495 | elif self.status == 1: |
|
496 | elif self.status == 1: | |
496 | color = "warning" |
|
497 | color = "warning" | |
497 | elif self.status == 2: |
|
498 | elif self.status == 2: | |
498 | color = "success" |
|
499 | color = "success" | |
499 | elif self.status == 3: |
|
500 | elif self.status == 3: | |
500 | color = "info" |
|
501 | color = "info" | |
501 |
|
502 | |||
502 | return color |
|
503 | return color | |
503 |
|
504 | |||
504 | def parms_to_dict(self): |
|
505 | def parms_to_dict(self): | |
505 |
|
506 | |||
506 | params = Params({}) |
|
507 | params = Params({}) | |
507 | params.add(self.jsonify(), 'experiments') |
|
508 | params.add(self.jsonify(), 'experiments') | |
508 |
|
509 | |||
509 | configurations = Configuration.objects.filter(experiment=self, type=0) |
|
510 | configurations = Configuration.objects.filter(experiment=self, type=0) | |
510 |
|
511 | |||
511 | for conf in configurations: |
|
512 | for conf in configurations: | |
512 | params.add(conf.jsonify(), 'configurations') |
|
513 | params.add(conf.jsonify(), 'configurations') | |
513 | if conf.device.device_type.name=='rc': |
|
514 | if conf.device.device_type.name=='rc': | |
514 | for line in conf.get_lines(): |
|
515 | for line in conf.get_lines(): | |
515 | params.add(line.jsonify(), 'lines') |
|
516 | params.add(line.jsonify(), 'lines') | |
516 |
|
517 | |||
517 | return params.data |
|
518 | return params.data | |
518 |
|
519 | |||
519 | def dict_to_parms(self, parms, CONF_MODELS, id_exp=None): |
|
520 | def dict_to_parms(self, parms, CONF_MODELS, id_exp=None): | |
520 |
|
521 | |||
521 | configurations = Configuration.objects.filter(experiment=self) |
|
522 | configurations = Configuration.objects.filter(experiment=self) | |
522 |
|
523 | |||
523 | if id_exp is not None: |
|
524 | if id_exp is not None: | |
524 | exp_parms = parms['experiments']['byId'][id_exp] |
|
525 | exp_parms = parms['experiments']['byId'][id_exp] | |
525 | else: |
|
526 | else: | |
526 | exp_parms = parms['experiments']['byId'][parms['experiments']['allIds'][0]] |
|
527 | exp_parms = parms['experiments']['byId'][parms['experiments']['allIds'][0]] | |
527 |
|
528 | |||
528 | if configurations: |
|
529 | if configurations: | |
529 | for configuration in configurations: |
|
530 | for configuration in configurations: | |
530 | configuration.delete() |
|
531 | configuration.delete() | |
531 |
|
532 | |||
532 | for id_conf in exp_parms['configurations']: |
|
533 | for id_conf in exp_parms['configurations']: | |
533 | conf_parms = parms['configurations']['byId'][id_conf] |
|
534 | conf_parms = parms['configurations']['byId'][id_conf] | |
534 | device = Device.objects.filter(device_type__name=conf_parms['device_type'])[0] |
|
535 | device = Device.objects.filter(device_type__name=conf_parms['device_type'])[0] | |
535 | model = CONF_MODELS[conf_parms['device_type']] |
|
536 | model = CONF_MODELS[conf_parms['device_type']] | |
536 | conf = model( |
|
537 | conf = model( | |
537 | experiment = self, |
|
538 | experiment = self, | |
538 | device = device, |
|
539 | device = device, | |
539 | ) |
|
540 | ) | |
540 | conf.dict_to_parms(parms, id=id_conf) |
|
541 | conf.dict_to_parms(parms, id=id_conf) | |
541 |
|
542 | |||
542 |
|
543 | |||
543 | location, created = Location.objects.get_or_create(name=exp_parms['location']) |
|
544 | location, created = Location.objects.get_or_create(name=exp_parms['location']) | |
544 | self.name = '{}-{}'.format(exp_parms['name'], datetime.now().strftime('%y%m%d')) |
|
545 | self.name = '{}-{}'.format(exp_parms['name'], datetime.now().strftime('%y%m%d')) | |
545 | self.location = location |
|
546 | self.location = location | |
546 | self.start_time = exp_parms['start_time'] |
|
547 | self.start_time = exp_parms['start_time'] | |
547 | self.end_time = exp_parms['end_time'] |
|
548 | self.end_time = exp_parms['end_time'] | |
548 | self.save() |
|
549 | self.save() | |
549 |
|
550 | |||
550 | return self |
|
551 | return self | |
551 |
|
552 | |||
552 | def get_absolute_url(self): |
|
553 | def get_absolute_url(self): | |
553 | return reverse('url_experiment', args=[str(self.id)]) |
|
554 | return reverse('url_experiment', args=[str(self.id)]) | |
554 |
|
555 | |||
555 | def get_absolute_url_edit(self): |
|
556 | def get_absolute_url_edit(self): | |
556 | return reverse('url_edit_experiment', args=[str(self.id)]) |
|
557 | return reverse('url_edit_experiment', args=[str(self.id)]) | |
557 |
|
558 | |||
558 | def get_absolute_url_delete(self): |
|
559 | def get_absolute_url_delete(self): | |
559 | return reverse('url_delete_experiment', args=[str(self.id)]) |
|
560 | return reverse('url_delete_experiment', args=[str(self.id)]) | |
560 |
|
561 | |||
561 | def get_absolute_url_import(self): |
|
562 | def get_absolute_url_import(self): | |
562 | return reverse('url_import_experiment', args=[str(self.id)]) |
|
563 | return reverse('url_import_experiment', args=[str(self.id)]) | |
563 |
|
564 | |||
564 | def get_absolute_url_export(self): |
|
565 | def get_absolute_url_export(self): | |
565 | return reverse('url_export_experiment', args=[str(self.id)]) |
|
566 | return reverse('url_export_experiment', args=[str(self.id)]) | |
566 |
|
567 | |||
567 | def get_absolute_url_start(self): |
|
568 | def get_absolute_url_start(self): | |
568 | return reverse('url_start_experiment', args=[str(self.id)]) |
|
569 | return reverse('url_start_experiment', args=[str(self.id)]) | |
569 |
|
570 | |||
570 | def get_absolute_url_stop(self): |
|
571 | def get_absolute_url_stop(self): | |
571 | return reverse('url_stop_experiment', args=[str(self.id)]) |
|
572 | return reverse('url_stop_experiment', args=[str(self.id)]) | |
572 |
|
573 | |||
573 |
|
574 | |||
574 | class Configuration(PolymorphicModel): |
|
575 | class Configuration(PolymorphicModel): | |
575 |
|
576 | |||
576 | template = models.BooleanField(default=False) |
|
577 | template = models.BooleanField(default=False) | |
577 | # name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
578 | # name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
578 | device = models.ForeignKey('Device', verbose_name='Device', null=True, on_delete=models.CASCADE) |
|
579 | device = models.ForeignKey('Device', verbose_name='Device', null=True, on_delete=models.CASCADE) | |
579 | label = models.CharField(verbose_name="Label", max_length=40, default='', blank=True, null=True) |
|
580 | label = models.CharField(verbose_name="Label", max_length=40, default='', blank=True, null=True) | |
580 | experiment = models.ForeignKey('Experiment', verbose_name='Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
581 | experiment = models.ForeignKey('Experiment', verbose_name='Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
581 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
582 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
582 | created_date = models.DateTimeField(auto_now_add=True) |
|
583 | created_date = models.DateTimeField(auto_now_add=True) | |
583 | programmed_date = models.DateTimeField(auto_now=True) |
|
584 | programmed_date = models.DateTimeField(auto_now=True) | |
584 | parameters = models.TextField(default='{}') |
|
585 | parameters = models.TextField(default='{}') | |
585 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) |
|
586 | author = models.ForeignKey(User, null=True, blank=True,on_delete=models.CASCADE) | |
586 | hash = models.CharField(default='', max_length=64, null=True, blank=True) |
|
587 | hash = models.CharField(default='', max_length=64, null=True, blank=True) | |
587 | message = "" |
|
588 | message = "" | |
588 |
|
589 | |||
589 | class Meta: |
|
590 | class Meta: | |
590 | db_table = 'db_configurations' |
|
591 | db_table = 'db_configurations' | |
591 | ordering = ('device__device_type__name',) |
|
592 | ordering = ('device__device_type__name',) | |
592 |
|
593 | |||
593 | def __str__(self): |
|
594 | def __str__(self): | |
594 |
|
595 | |||
595 | ret = u'{} '.format(self.device.device_type.name.upper()) |
|
596 | ret = u'{} '.format(self.device.device_type.name.upper()) | |
596 |
|
597 | |||
597 | if 'mix' in [f.name for f in self._meta.get_fields()]: |
|
598 | if 'mix' in [f.name for f in self._meta.get_fields()]: | |
598 | if self.mix: |
|
599 | if self.mix: | |
599 | ret = '{} MIX '.format(self.device.device_type.name.upper()) |
|
600 | ret = '{} MIX '.format(self.device.device_type.name.upper()) | |
600 |
|
601 | |||
601 | if 'label' in [f.name for f in self._meta.get_fields()]: |
|
602 | if 'label' in [f.name for f in self._meta.get_fields()]: | |
602 | ret += '{}'.format(self.label) |
|
603 | ret += '{}'.format(self.label) | |
603 |
|
604 | |||
604 | if self.template: |
|
605 | if self.template: | |
605 | ret += ' (template)' |
|
606 | ret += ' (template)' | |
606 |
|
607 | |||
607 | return ret |
|
608 | return ret | |
608 |
|
609 | |||
609 | @property |
|
610 | @property | |
610 | def name(self): |
|
611 | def name(self): | |
611 |
|
612 | |||
612 | return str(self) |
|
613 | return str(self) | |
613 |
|
614 | |||
614 | def jsonify(self): |
|
615 | def jsonify(self): | |
615 |
|
616 | |||
616 | data = {} |
|
617 | data = {} | |
617 |
|
618 | |||
618 | ignored = ('type', 'polymorphic_ctype', 'configuration_ptr', |
|
619 | ignored = ('type', 'polymorphic_ctype', 'configuration_ptr', | |
619 | 'created_date', 'programmed_date', 'template', 'device', |
|
620 | 'created_date', 'programmed_date', 'template', 'device', | |
620 | 'experiment') |
|
621 | 'experiment') | |
621 |
|
622 | |||
622 | for field in self._meta.fields: |
|
623 | for field in self._meta.fields: | |
623 | if field.name in ignored: |
|
624 | if field.name in ignored: | |
624 | continue |
|
625 | continue | |
625 | data[field.name] = field.value_from_object(self) |
|
626 | data[field.name] = field.value_from_object(self) | |
626 |
|
627 | |||
627 | data['device_type'] = self.device.device_type.name |
|
628 | data['device_type'] = self.device.device_type.name | |
628 |
|
629 | |||
629 | if self.device.device_type.name == 'rc': |
|
630 | if self.device.device_type.name == 'rc': | |
630 | data['lines'] = ['{}'.format(line.pk) for line in self.get_lines()] |
|
631 | data['lines'] = ['{}'.format(line.pk) for line in self.get_lines()] | |
631 | data['delays'] = self.get_delays() |
|
632 | data['delays'] = self.get_delays() | |
632 | data['pulses'] = self.get_pulses() |
|
633 | data['pulses'] = self.get_pulses() | |
633 |
|
634 | |||
634 | elif self.device.device_type.name == 'jars': |
|
635 | elif self.device.device_type.name == 'jars': | |
635 | data['decode_type'] = DECODE_TYPE[self.decode_data][1] |
|
636 | data['decode_type'] = DECODE_TYPE[self.decode_data][1] | |
636 |
|
637 | |||
637 | elif self.device.device_type.name == 'dds': |
|
638 | elif self.device.device_type.name == 'dds': | |
638 | data['frequencyA_Mhz'] = float(data['frequencyA_Mhz']) |
|
639 | data['frequencyA_Mhz'] = float(data['frequencyA_Mhz']) | |
639 | data['frequencyB_Mhz'] = float(data['frequencyB_Mhz']) |
|
640 | data['frequencyB_Mhz'] = float(data['frequencyB_Mhz']) | |
640 | data['phaseA'] = dds_data.phase_to_binary(data['phaseA_degrees']) |
|
641 | data['phaseA'] = dds_data.phase_to_binary(data['phaseA_degrees']) | |
641 | data['phaseB'] = dds_data.phase_to_binary(data['phaseB_degrees']) |
|
642 | data['phaseB'] = dds_data.phase_to_binary(data['phaseB_degrees']) | |
642 |
|
643 | |||
643 | elif self.device.device_type.name == 'dds_rest': |
|
644 | elif self.device.device_type.name == 'dds_rest': | |
644 | data['frequencyA_Mhz'] = float(data['frequencyA_Mhz']) |
|
645 | data['frequencyA_Mhz'] = float(data['frequencyA_Mhz']) | |
645 | data['frequencyB_Mhz'] = float(data['frequencyB_Mhz']) |
|
646 | data['frequencyB_Mhz'] = float(data['frequencyB_Mhz']) | |
646 | data['phaseA'] = dds_data.phase_to_binary(data['phaseA_degrees']) |
|
647 | data['phaseA'] = dds_data.phase_to_binary(data['phaseA_degrees']) | |
647 | data['phaseB'] = dds_data.phase_to_binary(data['phaseB_degrees']) |
|
648 | data['phaseB'] = dds_data.phase_to_binary(data['phaseB_degrees']) | |
648 | data['delta_frequency_Mhz'] = float(data['delta_frequency_Mhz'] or 0.00) |
|
649 | data['delta_frequency_Mhz'] = float(data['delta_frequency_Mhz'] or 0.00) | |
649 | data['update_clock_Mhz'] = float(data['update_clock_Mhz'] or 0.00) |
|
650 | data['update_clock_Mhz'] = float(data['update_clock_Mhz'] or 0.00) | |
650 | data['ramp_rate_clock_Mhz'] = float(data['ramp_rate_clock_Mhz'] or 0.0) |
|
651 | data['ramp_rate_clock_Mhz'] = float(data['ramp_rate_clock_Mhz'] or 0.0) | |
651 | return data |
|
652 | return data | |
652 |
|
653 | |||
653 | def clone(self, **kwargs): |
|
654 | def clone(self, **kwargs): | |
654 |
|
655 | |||
655 | self.pk = None |
|
656 | self.pk = None | |
656 | self.id = None |
|
657 | self.id = None | |
657 | for attr, value in kwargs.items(): |
|
658 | for attr, value in kwargs.items(): | |
658 | setattr(self, attr, value) |
|
659 | setattr(self, attr, value) | |
659 |
|
660 | |||
660 | self.save() |
|
661 | self.save() | |
661 |
|
662 | |||
662 | return self |
|
663 | return self | |
663 |
|
664 | |||
664 | def parms_to_dict(self): |
|
665 | def parms_to_dict(self): | |
665 |
|
666 | |||
666 | params = Params({}) |
|
667 | params = Params({}) | |
667 | params.add(self.jsonify(), 'configurations') |
|
668 | params.add(self.jsonify(), 'configurations') | |
668 |
|
669 | |||
669 | if self.device.device_type.name=='rc': |
|
670 | if self.device.device_type.name=='rc': | |
670 | for line in self.get_lines(): |
|
671 | for line in self.get_lines(): | |
671 | params.add(line.jsonify(), 'lines') |
|
672 | params.add(line.jsonify(), 'lines') | |
672 |
|
673 | |||
673 | return params.data |
|
674 | return params.data | |
674 |
|
675 | |||
675 | def parms_to_text(self): |
|
676 | def parms_to_text(self): | |
676 |
|
677 | |||
677 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) |
|
678 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
678 |
|
679 | |||
679 |
|
680 | |||
680 | def parms_to_binary(self): |
|
681 | def parms_to_binary(self): | |
681 |
|
682 | |||
682 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) |
|
683 | raise NotImplementedError("This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()) | |
683 |
|
684 | |||
684 |
|
685 | |||
685 | def dict_to_parms(self, parameters, id=None): |
|
686 | def dict_to_parms(self, parameters, id=None): | |
686 |
|
687 | |||
687 | params = Params(parameters) |
|
688 | params = Params(parameters) | |
688 |
|
689 | |||
689 | if id: |
|
690 | if id: | |
690 | data = params.get_conf(id_conf=id) |
|
691 | data = params.get_conf(id_conf=id) | |
691 | else: |
|
692 | else: | |
692 | data = params.get_conf(dtype=self.device.device_type.name) |
|
693 | data = params.get_conf(dtype=self.device.device_type.name) | |
693 |
|
694 | |||
694 | if data['device_type']=='rc': |
|
695 | if data['device_type']=='rc': | |
695 | self.clean_lines() |
|
696 | self.clean_lines() | |
696 | lines = data.pop('lines', None) |
|
697 | lines = data.pop('lines', None) | |
697 | for line_id in lines: |
|
698 | for line_id in lines: | |
698 | pass |
|
699 | pass | |
699 |
|
700 | |||
700 | for key, value in data.items(): |
|
701 | for key, value in data.items(): | |
701 | if key not in ('id', 'device_type'): |
|
702 | if key not in ('id', 'device_type'): | |
702 | setattr(self, key, value) |
|
703 | setattr(self, key, value) | |
703 |
|
704 | |||
704 | self.save() |
|
705 | self.save() | |
705 |
|
706 | |||
706 |
|
707 | |||
707 | def export_to_file(self, format="json"): |
|
708 | def export_to_file(self, format="json"): | |
708 |
|
709 | |||
709 | content_type = '' |
|
710 | content_type = '' | |
710 |
|
711 | |||
711 | if format == 'racp': |
|
712 | if format == 'racp': | |
712 | content_type = 'text/plain' |
|
713 | content_type = 'text/plain' | |
713 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, 'racp') |
|
714 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, 'racp') | |
714 | content = self.parms_to_text(file_format = 'racp') |
|
715 | content = self.parms_to_text(file_format = 'racp') | |
715 |
|
716 | |||
716 | if format == 'text': |
|
717 | if format == 'text': | |
717 | content_type = 'text/plain' |
|
718 | content_type = 'text/plain' | |
718 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
719 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
719 | content = self.parms_to_text() |
|
720 | content = self.parms_to_text() | |
720 |
|
721 | |||
721 | if format == 'binary': |
|
722 | if format == 'binary': | |
722 | content_type = 'application/octet-stream' |
|
723 | content_type = 'application/octet-stream' | |
723 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
724 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
724 | content = self.parms_to_binary() |
|
725 | content = self.parms_to_binary() | |
725 |
|
726 | |||
726 | if not content_type: |
|
727 | if not content_type: | |
727 | content_type = 'application/json' |
|
728 | content_type = 'application/json' | |
728 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
729 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |
729 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
730 | content = json.dumps(self.parms_to_dict(), indent=2) | |
730 |
|
731 | |||
731 | fields = {'content_type':content_type, |
|
732 | fields = {'content_type':content_type, | |
732 | 'filename':filename, |
|
733 | 'filename':filename, | |
733 | 'content':content |
|
734 | 'content':content | |
734 | } |
|
735 | } | |
735 |
|
736 | |||
736 | return fields |
|
737 | return fields | |
737 |
|
738 | |||
738 | def import_from_file(self, fp): |
|
739 | def import_from_file(self, fp): | |
739 |
|
740 | |||
740 | parms = {} |
|
741 | parms = {} | |
741 |
|
742 | |||
742 | path, ext = os.path.splitext(fp.name) |
|
743 | path, ext = os.path.splitext(fp.name) | |
743 |
|
744 | |||
744 | if ext == '.json': |
|
745 | if ext == '.json': | |
745 | parms = json.load(fp) |
|
746 | parms = json.load(fp) | |
746 |
|
747 | |||
747 | if ext == '.dds': |
|
748 | if ext == '.dds': | |
748 | lines = fp.readlines() |
|
749 | lines = fp.readlines() | |
749 | parms = dds_data.text_to_dict(lines) |
|
750 | parms = dds_data.text_to_dict(lines) | |
750 |
|
751 | |||
751 | if ext == '.racp': |
|
752 | if ext == '.racp': | |
752 | if self.device.device_type.name == 'jars': |
|
753 | if self.device.device_type.name == 'jars': | |
753 | parms = RacpFile(fp).to_dict() |
|
754 | parms = RacpFile(fp).to_dict() | |
754 | parms['filter_parms'] = json.loads(self.filter_parms) |
|
755 | parms['filter_parms'] = json.loads(self.filter_parms) | |
755 | return parms |
|
756 | return parms | |
756 | parms = RCFile(fp).to_dict() |
|
757 | parms = RCFile(fp).to_dict() | |
757 |
|
758 | |||
758 | return parms |
|
759 | return parms | |
759 |
|
760 | |||
760 | def status_device(self): |
|
761 | def status_device(self): | |
761 |
|
762 | |||
762 | self.message = 'Function not implemented' |
|
763 | self.message = 'Function not implemented' | |
763 | return False |
|
764 | return False | |
764 |
|
765 | |||
765 |
|
766 | |||
766 | def stop_device(self): |
|
767 | def stop_device(self): | |
767 |
|
768 | |||
768 | self.message = 'Function not implemented' |
|
769 | self.message = 'Function not implemented' | |
769 | return False |
|
770 | return False | |
770 |
|
771 | |||
771 |
|
772 | |||
772 | def start_device(self): |
|
773 | def start_device(self): | |
773 |
|
774 | |||
774 | self.message = 'Function not implemented' |
|
775 | self.message = 'Function not implemented' | |
775 | return False |
|
776 | return False | |
776 |
|
777 | |||
777 |
|
778 | |||
778 | def write_device(self, parms): |
|
779 | def write_device(self, parms): | |
779 |
|
780 | |||
780 | self.message = 'Function not implemented' |
|
781 | self.message = 'Function not implemented' | |
781 | return False |
|
782 | return False | |
782 |
|
783 | |||
783 |
|
784 | |||
784 | def read_device(self): |
|
785 | def read_device(self): | |
785 |
|
786 | |||
786 | self.message = 'Function not implemented' |
|
787 | self.message = 'Function not implemented' | |
787 | return False |
|
788 | return False | |
788 |
|
789 | |||
789 |
|
790 | |||
790 | def get_absolute_url(self): |
|
791 | def get_absolute_url(self): | |
791 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
792 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
792 |
|
793 | |||
793 | def get_absolute_url_edit(self): |
|
794 | def get_absolute_url_edit(self): | |
794 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
795 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
795 |
|
796 | |||
796 | def get_absolute_url_delete(self): |
|
797 | def get_absolute_url_delete(self): | |
797 | return reverse('url_delete_dev_conf', args=[str(self.id)]) |
|
798 | return reverse('url_delete_dev_conf', args=[str(self.id)]) | |
798 |
|
799 | |||
799 | def get_absolute_url_import(self): |
|
800 | def get_absolute_url_import(self): | |
800 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
801 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
801 |
|
802 | |||
802 | def get_absolute_url_export(self): |
|
803 | def get_absolute_url_export(self): | |
803 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
804 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
804 |
|
805 | |||
805 | def get_absolute_url_write(self): |
|
806 | def get_absolute_url_write(self): | |
806 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
807 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
807 |
|
808 | |||
808 | def get_absolute_url_read(self): |
|
809 | def get_absolute_url_read(self): | |
809 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
810 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
810 |
|
811 | |||
811 | def get_absolute_url_start(self): |
|
812 | def get_absolute_url_start(self): | |
812 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
813 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
813 |
|
814 | |||
814 | def get_absolute_url_stop(self): |
|
815 | def get_absolute_url_stop(self): | |
815 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
816 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
816 |
|
817 | |||
817 | def get_absolute_url_status(self): |
|
818 | def get_absolute_url_status(self): | |
818 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
|
819 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,2029 +1,2033 | |||||
1 | import ast |
|
1 | import ast | |
2 | import json |
|
2 | import json | |
3 | import hashlib |
|
3 | import hashlib | |
4 | from datetime import datetime, timedelta |
|
4 | from datetime import datetime, timedelta | |
5 |
|
5 | |||
6 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
6 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
7 | from django.utils.safestring import mark_safe |
|
7 | from django.utils.safestring import mark_safe | |
8 | from django.http import HttpResponseRedirect |
|
8 | from django.http import HttpResponseRedirect | |
9 | from django.urls import reverse |
|
9 | from django.urls import reverse | |
10 | from django.db.models import Q |
|
10 | from django.db.models import Q | |
11 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
|
11 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | |
12 | from django.contrib import messages |
|
12 | from django.contrib import messages | |
13 | from django.http.request import QueryDict |
|
13 | from django.http.request import QueryDict | |
14 | from django.contrib.auth.decorators import login_required, user_passes_test |
|
14 | from django.contrib.auth.decorators import login_required, user_passes_test | |
15 |
|
15 | |||
16 | from django.utils.timezone import is_aware |
|
16 | from django.utils.timezone import is_aware | |
17 |
|
17 | |||
18 | try: |
|
18 | try: | |
19 | from urllib.parse import urlencode |
|
19 | from urllib.parse import urlencode | |
20 | except ImportError: |
|
20 | except ImportError: | |
21 | from urllib import urlencode |
|
21 | from urllib import urlencode | |
22 |
|
22 | |||
23 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
23 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
24 | from .forms import OperationSearchForm, FilterForm, ChangeIpForm |
|
24 | from .forms import OperationSearchForm, FilterForm, ChangeIpForm | |
25 |
|
25 | |||
26 | from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm |
|
26 | from apps.rc.forms import RCConfigurationForm, RCLineCode, RCMixConfigurationForm | |
27 | from apps.dds.forms import DDSConfigurationForm |
|
27 | from apps.dds.forms import DDSConfigurationForm | |
28 | from apps.jars.forms import JARSConfigurationForm |
|
28 | from apps.jars.forms import JARSConfigurationForm | |
29 | from apps.cgs.forms import CGSConfigurationForm |
|
29 | from apps.cgs.forms import CGSConfigurationForm | |
30 | from apps.abs.forms import ABSConfigurationForm |
|
30 | from apps.abs.forms import ABSConfigurationForm | |
31 | from apps.usrp.forms import USRPConfigurationForm |
|
31 | from apps.usrp.forms import USRPConfigurationForm | |
32 | from apps.dds_rest.forms import DDSRestConfigurationForm |
|
32 | from apps.dds_rest.forms import DDSRestConfigurationForm | |
|
33 | from apps.atrad.forms import ATRADConfigurationForm | |||
33 | from .utils import Params |
|
34 | from .utils import Params | |
34 |
|
35 | |||
35 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES |
|
36 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES | |
36 | from apps.cgs.models import CGSConfiguration |
|
37 | from apps.cgs.models import CGSConfiguration | |
37 | from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE |
|
38 | from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE | |
38 | from apps.usrp.models import USRPConfiguration |
|
39 | from apps.usrp.models import USRPConfiguration | |
39 | from apps.abs.models import ABSConfiguration |
|
40 | from apps.abs.models import ABSConfiguration | |
40 | from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock |
|
41 | from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock | |
41 | from apps.dds.models import DDSConfiguration |
|
42 | from apps.dds.models import DDSConfiguration | |
42 | from apps.dds_rest.models import DDSRestConfiguration |
|
43 | from apps.dds_rest.models import DDSRestConfiguration | |
|
44 | from apps.atrad.models import ATRADConfiguration | |||
43 |
|
45 | |||
44 | #from .tasks import task_start |
|
46 | #from .tasks import task_start | |
45 | from radarsys.celery import app |
|
47 | from radarsys.celery import app | |
46 |
|
48 | |||
47 | #comentario test |
|
49 | #comentario test | |
48 | CONF_FORMS = { |
|
50 | CONF_FORMS = { | |
49 | 'rc': RCConfigurationForm, |
|
51 | 'rc': RCConfigurationForm, | |
50 | 'dds': DDSConfigurationForm, |
|
52 | 'dds': DDSConfigurationForm, | |
51 | 'dds_rest': DDSRestConfigurationForm, |
|
53 | 'dds_rest': DDSRestConfigurationForm, | |
52 | 'jars': JARSConfigurationForm, |
|
54 | 'jars': JARSConfigurationForm, | |
53 | 'cgs': CGSConfigurationForm, |
|
55 | 'cgs': CGSConfigurationForm, | |
54 | 'abs': ABSConfigurationForm, |
|
56 | 'abs': ABSConfigurationForm, | |
55 | 'usrp': USRPConfigurationForm, |
|
57 | 'usrp': USRPConfigurationForm, | |
|
58 | 'atrad': ATRADConfigurationForm, | |||
56 | } |
|
59 | } | |
57 |
|
60 | |||
58 | CONF_MODELS = { |
|
61 | CONF_MODELS = { | |
59 | 'rc': RCConfiguration, |
|
62 | 'rc': RCConfiguration, | |
60 | 'dds': DDSConfiguration, |
|
63 | 'dds': DDSConfiguration, | |
61 | 'dds_rest': DDSRestConfiguration, |
|
64 | 'dds_rest': DDSRestConfiguration, | |
62 | 'jars': JARSConfiguration, |
|
65 | 'jars': JARSConfiguration, | |
63 | 'cgs': CGSConfiguration, |
|
66 | 'cgs': CGSConfiguration, | |
64 | 'abs': ABSConfiguration, |
|
67 | 'abs': ABSConfiguration, | |
65 | 'usrp': USRPConfiguration, |
|
68 | 'usrp': USRPConfiguration, | |
|
69 | 'atrad': ATRADConfiguration, | |||
66 | } |
|
70 | } | |
67 |
|
71 | |||
68 | MIX_MODES = { |
|
72 | MIX_MODES = { | |
69 | '0': 'P', |
|
73 | '0': 'P', | |
70 | '1': 'S', |
|
74 | '1': 'S', | |
71 | } |
|
75 | } | |
72 |
|
76 | |||
73 | MIX_OPERATIONS = { |
|
77 | MIX_OPERATIONS = { | |
74 | '0': 'OR', |
|
78 | '0': 'OR', | |
75 | '1': 'XOR', |
|
79 | '1': 'XOR', | |
76 | '2': 'AND', |
|
80 | '2': 'AND', | |
77 | '3': 'NAND', |
|
81 | '3': 'NAND', | |
78 | } |
|
82 | } | |
79 |
|
83 | |||
80 |
|
84 | |||
81 | def is_developer(user): |
|
85 | def is_developer(user): | |
82 |
|
86 | |||
83 | groups = [str(g.name) for g in user.groups.all()] |
|
87 | groups = [str(g.name) for g in user.groups.all()] | |
84 | return 'Developer' in groups or user.is_staff |
|
88 | return 'Developer' in groups or user.is_staff | |
85 |
|
89 | |||
86 |
|
90 | |||
87 | def is_operator(user): |
|
91 | def is_operator(user): | |
88 |
|
92 | |||
89 | groups = [str(g.name) for g in user.groups.all()] |
|
93 | groups = [str(g.name) for g in user.groups.all()] | |
90 | return 'Operator' in groups or user.is_staff |
|
94 | return 'Operator' in groups or user.is_staff | |
91 |
|
95 | |||
92 |
|
96 | |||
93 | def has_been_modified(model): |
|
97 | def has_been_modified(model): | |
94 |
|
98 | |||
95 | prev_hash = model.hash |
|
99 | prev_hash = model.hash | |
96 | new_hash = hashlib.sha256(str(model.parms_to_dict).encode()).hexdigest() |
|
100 | new_hash = hashlib.sha256(str(model.parms_to_dict).encode()).hexdigest() | |
97 | if prev_hash != new_hash: |
|
101 | if prev_hash != new_hash: | |
98 | model.hash = new_hash |
|
102 | model.hash = new_hash | |
99 | model.save() |
|
103 | model.save() | |
100 | return True |
|
104 | return True | |
101 | return False |
|
105 | return False | |
102 |
|
106 | |||
103 |
|
107 | |||
104 | def index(request): |
|
108 | def index(request): | |
105 | kwargs = {'no_sidebar': True} |
|
109 | kwargs = {'no_sidebar': True} | |
106 |
|
110 | |||
107 | return render(request, 'index.html', kwargs) |
|
111 | return render(request, 'index.html', kwargs) | |
108 |
|
112 | |||
109 |
|
113 | |||
110 | def locations(request): |
|
114 | def locations(request): | |
111 |
|
115 | |||
112 | page = request.GET.get('page') |
|
116 | page = request.GET.get('page') | |
113 | order = ('name',) |
|
117 | order = ('name',) | |
114 |
|
118 | |||
115 | kwargs = get_paginator(Location, page, order) |
|
119 | kwargs = get_paginator(Location, page, order) | |
116 |
|
120 | |||
117 | kwargs['keys'] = ['name', 'description'] |
|
121 | kwargs['keys'] = ['name', 'description'] | |
118 | kwargs['title'] = 'Radar System' |
|
122 | kwargs['title'] = 'Radar System' | |
119 | kwargs['suptitle'] = 'List' |
|
123 | kwargs['suptitle'] = 'List' | |
120 | kwargs['no_sidebar'] = True |
|
124 | kwargs['no_sidebar'] = True | |
121 |
|
125 | |||
122 | return render(request, 'base_list.html', kwargs) |
|
126 | return render(request, 'base_list.html', kwargs) | |
123 |
|
127 | |||
124 |
|
128 | |||
125 | def location(request, id_loc): |
|
129 | def location(request, id_loc): | |
126 |
|
130 | |||
127 | location = get_object_or_404(Location, pk=id_loc) |
|
131 | location = get_object_or_404(Location, pk=id_loc) | |
128 |
|
132 | |||
129 | kwargs = {} |
|
133 | kwargs = {} | |
130 | kwargs['location'] = location |
|
134 | kwargs['location'] = location | |
131 | kwargs['location_keys'] = ['name', 'description'] |
|
135 | kwargs['location_keys'] = ['name', 'description'] | |
132 |
|
136 | |||
133 | kwargs['title'] = 'Location' |
|
137 | kwargs['title'] = 'Location' | |
134 | kwargs['suptitle'] = 'Details' |
|
138 | kwargs['suptitle'] = 'Details' | |
135 |
|
139 | |||
136 | return render(request, 'location.html', kwargs) |
|
140 | return render(request, 'location.html', kwargs) | |
137 |
|
141 | |||
138 |
|
142 | |||
139 | @login_required |
|
143 | @login_required | |
140 | def location_new(request): |
|
144 | def location_new(request): | |
141 |
|
145 | |||
142 | if request.method == 'GET': |
|
146 | if request.method == 'GET': | |
143 | form = LocationForm() |
|
147 | form = LocationForm() | |
144 |
|
148 | |||
145 | if request.method == 'POST': |
|
149 | if request.method == 'POST': | |
146 | form = LocationForm(request.POST) |
|
150 | form = LocationForm(request.POST) | |
147 |
|
151 | |||
148 | if form.is_valid(): |
|
152 | if form.is_valid(): | |
149 | form.save() |
|
153 | form.save() | |
150 | return redirect('url_locations') |
|
154 | return redirect('url_locations') | |
151 |
|
155 | |||
152 | kwargs = {} |
|
156 | kwargs = {} | |
153 | kwargs['form'] = form |
|
157 | kwargs['form'] = form | |
154 | kwargs['title'] = 'Radar System' |
|
158 | kwargs['title'] = 'Radar System' | |
155 | kwargs['suptitle'] = 'New' |
|
159 | kwargs['suptitle'] = 'New' | |
156 | kwargs['button'] = 'Create' |
|
160 | kwargs['button'] = 'Create' | |
157 |
|
161 | |||
158 | return render(request, 'base_edit.html', kwargs) |
|
162 | return render(request, 'base_edit.html', kwargs) | |
159 |
|
163 | |||
160 |
|
164 | |||
161 | @login_required |
|
165 | @login_required | |
162 | def location_edit(request, id_loc): |
|
166 | def location_edit(request, id_loc): | |
163 |
|
167 | |||
164 | location = get_object_or_404(Location, pk=id_loc) |
|
168 | location = get_object_or_404(Location, pk=id_loc) | |
165 |
|
169 | |||
166 | if request.method == 'GET': |
|
170 | if request.method == 'GET': | |
167 | form = LocationForm(instance=location) |
|
171 | form = LocationForm(instance=location) | |
168 |
|
172 | |||
169 | if request.method == 'POST': |
|
173 | if request.method == 'POST': | |
170 | form = LocationForm(request.POST, instance=location) |
|
174 | form = LocationForm(request.POST, instance=location) | |
171 |
|
175 | |||
172 | if form.is_valid(): |
|
176 | if form.is_valid(): | |
173 | form.save() |
|
177 | form.save() | |
174 | return redirect('url_locations') |
|
178 | return redirect('url_locations') | |
175 |
|
179 | |||
176 | kwargs = {} |
|
180 | kwargs = {} | |
177 | kwargs['form'] = form |
|
181 | kwargs['form'] = form | |
178 | kwargs['title'] = 'Location' |
|
182 | kwargs['title'] = 'Location' | |
179 | kwargs['suptitle'] = 'Edit' |
|
183 | kwargs['suptitle'] = 'Edit' | |
180 | kwargs['button'] = 'Update' |
|
184 | kwargs['button'] = 'Update' | |
181 |
|
185 | |||
182 | return render(request, 'base_edit.html', kwargs) |
|
186 | return render(request, 'base_edit.html', kwargs) | |
183 |
|
187 | |||
184 |
|
188 | |||
185 | @login_required |
|
189 | @login_required | |
186 | def location_delete(request, id_loc): |
|
190 | def location_delete(request, id_loc): | |
187 |
|
191 | |||
188 | location = get_object_or_404(Location, pk=id_loc) |
|
192 | location = get_object_or_404(Location, pk=id_loc) | |
189 |
|
193 | |||
190 | if request.method == 'POST': |
|
194 | if request.method == 'POST': | |
191 |
|
195 | |||
192 | if is_developer(request.user): |
|
196 | if is_developer(request.user): | |
193 | location.delete() |
|
197 | location.delete() | |
194 | return redirect('url_locations') |
|
198 | return redirect('url_locations') | |
195 |
|
199 | |||
196 | messages.error(request, 'Not enough permission to delete this object') |
|
200 | messages.error(request, 'Not enough permission to delete this object') | |
197 | return redirect(location.get_absolute_url()) |
|
201 | return redirect(location.get_absolute_url()) | |
198 |
|
202 | |||
199 | kwargs = { |
|
203 | kwargs = { | |
200 | 'title': 'Delete', |
|
204 | 'title': 'Delete', | |
201 | 'suptitle': 'Location', |
|
205 | 'suptitle': 'Location', | |
202 | 'object': location, |
|
206 | 'object': location, | |
203 | 'delete': True |
|
207 | 'delete': True | |
204 | } |
|
208 | } | |
205 |
|
209 | |||
206 | return render(request, 'confirm.html', kwargs) |
|
210 | return render(request, 'confirm.html', kwargs) | |
207 |
|
211 | |||
208 |
|
212 | |||
209 | def devices(request): |
|
213 | def devices(request): | |
210 |
|
214 | |||
211 | page = request.GET.get('page') |
|
215 | page = request.GET.get('page') | |
212 | order = ('location', 'device_type') |
|
216 | order = ('location', 'device_type') | |
213 |
|
217 | |||
214 | filters = request.GET.copy() |
|
218 | filters = request.GET.copy() | |
215 | kwargs = get_paginator(Device, page, order, filters) |
|
219 | kwargs = get_paginator(Device, page, order, filters) | |
216 | form = FilterForm(initial=request.GET, extra_fields=['tags']) |
|
220 | form = FilterForm(initial=request.GET, extra_fields=['tags']) | |
217 |
|
221 | |||
218 | kwargs['keys'] = ['device_type', 'location', |
|
222 | kwargs['keys'] = ['device_type', 'location', | |
219 | 'ip_address', 'port_address', 'actions'] |
|
223 | 'ip_address', 'port_address', 'actions'] | |
220 | kwargs['title'] = 'Device' |
|
224 | kwargs['title'] = 'Device' | |
221 | kwargs['suptitle'] = 'List' |
|
225 | kwargs['suptitle'] = 'List' | |
222 | kwargs['no_sidebar'] = True |
|
226 | kwargs['no_sidebar'] = True | |
223 | kwargs['form'] = form |
|
227 | kwargs['form'] = form | |
224 | kwargs['add_url'] = reverse('url_add_device') |
|
228 | kwargs['add_url'] = reverse('url_add_device') | |
225 | filters.pop('page', None) |
|
229 | filters.pop('page', None) | |
226 | kwargs['q'] = urlencode(filters) |
|
230 | kwargs['q'] = urlencode(filters) | |
227 | kwargs['menu_devices'] = 'active' |
|
231 | kwargs['menu_devices'] = 'active' | |
228 | return render(request, 'base_list.html', kwargs) |
|
232 | return render(request, 'base_list.html', kwargs) | |
229 |
|
233 | |||
230 |
|
234 | |||
231 | def device(request, id_dev): |
|
235 | def device(request, id_dev): | |
232 |
|
236 | |||
233 | device = get_object_or_404(Device, pk=id_dev) |
|
237 | device = get_object_or_404(Device, pk=id_dev) | |
234 |
|
238 | |||
235 | kwargs = {} |
|
239 | kwargs = {} | |
236 | kwargs['device'] = device |
|
240 | kwargs['device'] = device | |
237 | kwargs['device_keys'] = ['device_type', |
|
241 | kwargs['device_keys'] = ['device_type', | |
238 | 'ip_address', 'port_address', 'description'] |
|
242 | 'ip_address', 'port_address', 'description'] | |
239 |
|
243 | |||
240 | kwargs['title'] = 'Device' |
|
244 | kwargs['title'] = 'Device' | |
241 | kwargs['suptitle'] = 'Details' |
|
245 | kwargs['suptitle'] = 'Details' | |
242 | kwargs['menu_devices'] = 'active' |
|
246 | kwargs['menu_devices'] = 'active' | |
243 |
|
247 | |||
244 | return render(request, 'device.html', kwargs) |
|
248 | return render(request, 'device.html', kwargs) | |
245 |
|
249 | |||
246 |
|
250 | |||
247 | @login_required |
|
251 | @login_required | |
248 | def device_new(request): |
|
252 | def device_new(request): | |
249 |
|
253 | |||
250 | if request.method == 'GET': |
|
254 | if request.method == 'GET': | |
251 | form = DeviceForm() |
|
255 | form = DeviceForm() | |
252 |
|
256 | |||
253 | if request.method == 'POST': |
|
257 | if request.method == 'POST': | |
254 | form = DeviceForm(request.POST) |
|
258 | form = DeviceForm(request.POST) | |
255 |
|
259 | |||
256 | if form.is_valid(): |
|
260 | if form.is_valid(): | |
257 | form.save() |
|
261 | form.save() | |
258 | return redirect('url_devices') |
|
262 | return redirect('url_devices') | |
259 |
|
263 | |||
260 | kwargs = {} |
|
264 | kwargs = {} | |
261 | kwargs['form'] = form |
|
265 | kwargs['form'] = form | |
262 | kwargs['title'] = 'Device' |
|
266 | kwargs['title'] = 'Device' | |
263 | kwargs['suptitle'] = 'New_2' |
|
267 | kwargs['suptitle'] = 'New_2' | |
264 | kwargs['button'] = 'Create' |
|
268 | kwargs['button'] = 'Create' | |
265 | kwargs['menu_devices'] = 'active' |
|
269 | kwargs['menu_devices'] = 'active' | |
266 |
|
270 | |||
267 | return render(request, 'base_edit.html', kwargs) |
|
271 | return render(request, 'base_edit.html', kwargs) | |
268 |
|
272 | |||
269 |
|
273 | |||
270 | @login_required |
|
274 | @login_required | |
271 | def device_edit(request, id_dev): |
|
275 | def device_edit(request, id_dev): | |
272 |
|
276 | |||
273 | device = get_object_or_404(Device, pk=id_dev) |
|
277 | device = get_object_or_404(Device, pk=id_dev) | |
274 |
|
278 | |||
275 | if request.method == 'GET': |
|
279 | if request.method == 'GET': | |
276 | form = DeviceForm(instance=device) |
|
280 | form = DeviceForm(instance=device) | |
277 |
|
281 | |||
278 | if request.method == 'POST': |
|
282 | if request.method == 'POST': | |
279 | form = DeviceForm(request.POST, instance=device) |
|
283 | form = DeviceForm(request.POST, instance=device) | |
280 |
|
284 | |||
281 | if form.is_valid(): |
|
285 | if form.is_valid(): | |
282 | form.save() |
|
286 | form.save() | |
283 | return redirect(device.get_absolute_url()) |
|
287 | return redirect(device.get_absolute_url()) | |
284 |
|
288 | |||
285 | kwargs = {} |
|
289 | kwargs = {} | |
286 | kwargs['form'] = form |
|
290 | kwargs['form'] = form | |
287 | kwargs['title'] = 'Device' |
|
291 | kwargs['title'] = 'Device' | |
288 | kwargs['suptitle'] = 'Edit' |
|
292 | kwargs['suptitle'] = 'Edit' | |
289 | kwargs['button'] = 'Update' |
|
293 | kwargs['button'] = 'Update' | |
290 | kwargs['menu_devices'] = 'active' |
|
294 | kwargs['menu_devices'] = 'active' | |
291 |
|
295 | |||
292 | return render(request, 'base_edit.html', kwargs) |
|
296 | return render(request, 'base_edit.html', kwargs) | |
293 |
|
297 | |||
294 |
|
298 | |||
295 | @login_required |
|
299 | @login_required | |
296 | def device_delete(request, id_dev): |
|
300 | def device_delete(request, id_dev): | |
297 |
|
301 | |||
298 | device = get_object_or_404(Device, pk=id_dev) |
|
302 | device = get_object_or_404(Device, pk=id_dev) | |
299 |
|
303 | |||
300 | if request.method == 'POST': |
|
304 | if request.method == 'POST': | |
301 |
|
305 | |||
302 | if is_developer(request.user): |
|
306 | if is_developer(request.user): | |
303 | device.delete() |
|
307 | device.delete() | |
304 | return redirect('url_devices') |
|
308 | return redirect('url_devices') | |
305 |
|
309 | |||
306 | messages.error(request, 'Not enough permission to delete this object') |
|
310 | messages.error(request, 'Not enough permission to delete this object') | |
307 | return redirect(device.get_absolute_url()) |
|
311 | return redirect(device.get_absolute_url()) | |
308 |
|
312 | |||
309 | kwargs = { |
|
313 | kwargs = { | |
310 | 'title': 'Delete', |
|
314 | 'title': 'Delete', | |
311 | 'suptitle': 'Device', |
|
315 | 'suptitle': 'Device', | |
312 | 'object': device, |
|
316 | 'object': device, | |
313 | 'delete': True |
|
317 | 'delete': True | |
314 | } |
|
318 | } | |
315 | kwargs['menu_devices'] = 'active' |
|
319 | kwargs['menu_devices'] = 'active' | |
316 |
|
320 | |||
317 | return render(request, 'confirm.html', kwargs) |
|
321 | return render(request, 'confirm.html', kwargs) | |
318 |
|
322 | |||
319 |
|
323 | |||
320 | @login_required |
|
324 | @login_required | |
321 | def device_change_ip(request, id_dev): |
|
325 | def device_change_ip(request, id_dev): | |
322 |
|
326 | |||
323 | device = get_object_or_404(Device, pk=id_dev) |
|
327 | device = get_object_or_404(Device, pk=id_dev) | |
324 |
|
328 | |||
325 | if request.method == 'POST': |
|
329 | if request.method == 'POST': | |
326 |
|
330 | |||
327 | if is_developer(request.user): |
|
331 | if is_developer(request.user): | |
328 | device.change_ip(**request.POST.dict()) |
|
332 | device.change_ip(**request.POST.dict()) | |
329 |
|
333 | |||
330 | print(device.ip_address, device.message) |
|
334 | print(device.ip_address, device.message) | |
331 |
|
335 | |||
332 | level, message = device.message.split('|') |
|
336 | level, message = device.message.split('|') | |
333 | messages.add_message(request, level, message) |
|
337 | messages.add_message(request, level, message) | |
334 | else: |
|
338 | else: | |
335 | messages.error( |
|
339 | messages.error( | |
336 | request, 'Not enough permission to delete this object') |
|
340 | request, 'Not enough permission to delete this object') | |
337 | return redirect(device.get_absolute_url()) |
|
341 | return redirect(device.get_absolute_url()) | |
338 |
|
342 | |||
339 | kwargs = { |
|
343 | kwargs = { | |
340 | 'title': 'Device', |
|
344 | 'title': 'Device', | |
341 | 'suptitle': 'Change IP', |
|
345 | 'suptitle': 'Change IP', | |
342 | 'object': device, |
|
346 | 'object': device, | |
343 | 'previous': device.get_absolute_url(), |
|
347 | 'previous': device.get_absolute_url(), | |
344 | 'form': ChangeIpForm(initial={'ip_address': device.ip_address}), |
|
348 | 'form': ChangeIpForm(initial={'ip_address': device.ip_address}), | |
345 | 'message': ' ', |
|
349 | 'message': ' ', | |
346 | } |
|
350 | } | |
347 | kwargs['menu_devices'] = 'active' |
|
351 | kwargs['menu_devices'] = 'active' | |
348 |
|
352 | |||
349 | return render(request, 'confirm.html', kwargs) |
|
353 | return render(request, 'confirm.html', kwargs) | |
350 |
|
354 | |||
351 |
|
355 | |||
352 | def campaigns(request): |
|
356 | def campaigns(request): | |
353 |
|
357 | |||
354 | page = request.GET.get('page') |
|
358 | page = request.GET.get('page') | |
355 | order = ('-start_date',) |
|
359 | order = ('-start_date',) | |
356 | filters = request.GET.copy() |
|
360 | filters = request.GET.copy() | |
357 |
|
361 | |||
358 | kwargs = get_paginator(Campaign, page, order, filters) |
|
362 | kwargs = get_paginator(Campaign, page, order, filters) | |
359 |
|
363 | |||
360 | form = FilterForm(initial=request.GET, extra_fields=[ |
|
364 | form = FilterForm(initial=request.GET, extra_fields=[ | |
361 | 'range_date', 'tags', 'template']) |
|
365 | 'range_date', 'tags', 'template']) | |
362 | kwargs['keys'] = ['name', 'start_date', 'end_date', 'actions'] |
|
366 | kwargs['keys'] = ['name', 'start_date', 'end_date', 'actions'] | |
363 | kwargs['title'] = 'Campaign' |
|
367 | kwargs['title'] = 'Campaign' | |
364 | kwargs['suptitle'] = 'List' |
|
368 | kwargs['suptitle'] = 'List' | |
365 | kwargs['no_sidebar'] = True |
|
369 | kwargs['no_sidebar'] = True | |
366 | kwargs['form'] = form |
|
370 | kwargs['form'] = form | |
367 | kwargs['add_url'] = reverse('url_add_campaign') |
|
371 | kwargs['add_url'] = reverse('url_add_campaign') | |
368 | filters.pop('page', None) |
|
372 | filters.pop('page', None) | |
369 | kwargs['q'] = urlencode(filters) |
|
373 | kwargs['q'] = urlencode(filters) | |
370 | kwargs['menu_campaigns'] = 'active' |
|
374 | kwargs['menu_campaigns'] = 'active' | |
371 |
|
375 | |||
372 | return render(request, 'base_list.html', kwargs) |
|
376 | return render(request, 'base_list.html', kwargs) | |
373 |
|
377 | |||
374 |
|
378 | |||
375 | def campaign(request, id_camp): |
|
379 | def campaign(request, id_camp): | |
376 |
|
380 | |||
377 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
381 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
378 | experiments = Experiment.objects.filter(campaign=campaign) |
|
382 | experiments = Experiment.objects.filter(campaign=campaign) | |
379 |
|
383 | |||
380 | form = CampaignForm(instance=campaign) |
|
384 | form = CampaignForm(instance=campaign) | |
381 |
|
385 | |||
382 | kwargs = {} |
|
386 | kwargs = {} | |
383 | kwargs['campaign'] = campaign |
|
387 | kwargs['campaign'] = campaign | |
384 | kwargs['campaign_keys'] = ['template', 'name', |
|
388 | kwargs['campaign_keys'] = ['template', 'name', | |
385 | 'start_date', 'end_date', 'tags', 'description'] |
|
389 | 'start_date', 'end_date', 'tags', 'description'] | |
386 |
|
390 | |||
387 | kwargs['experiments'] = experiments |
|
391 | kwargs['experiments'] = experiments | |
388 | kwargs['experiment_keys'] = [ |
|
392 | kwargs['experiment_keys'] = [ | |
389 | 'name', 'radar_system', 'start_time', 'end_time'] |
|
393 | 'name', 'radar_system', 'start_time', 'end_time'] | |
390 |
|
394 | |||
391 | kwargs['title'] = 'Campaign' |
|
395 | kwargs['title'] = 'Campaign' | |
392 | kwargs['suptitle'] = 'Details' |
|
396 | kwargs['suptitle'] = 'Details' | |
393 |
|
397 | |||
394 | kwargs['form'] = form |
|
398 | kwargs['form'] = form | |
395 | kwargs['button'] = 'Add Experiment' |
|
399 | kwargs['button'] = 'Add Experiment' | |
396 | kwargs['menu_campaigns'] = 'active' |
|
400 | kwargs['menu_campaigns'] = 'active' | |
397 |
|
401 | |||
398 | return render(request, 'campaign.html', kwargs) |
|
402 | return render(request, 'campaign.html', kwargs) | |
399 |
|
403 | |||
400 |
|
404 | |||
401 | @login_required |
|
405 | @login_required | |
402 | def campaign_new(request): |
|
406 | def campaign_new(request): | |
403 |
|
407 | |||
404 | kwargs = {} |
|
408 | kwargs = {} | |
405 |
|
409 | |||
406 | if request.method == 'GET': |
|
410 | if request.method == 'GET': | |
407 |
|
411 | |||
408 | if 'template' in request.GET: |
|
412 | if 'template' in request.GET: | |
409 | if request.GET['template'] == '0': |
|
413 | if request.GET['template'] == '0': | |
410 | form = NewForm(initial={'create_from': 2}, |
|
414 | form = NewForm(initial={'create_from': 2}, | |
411 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
415 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
412 | else: |
|
416 | else: | |
413 | kwargs['button'] = 'Create' |
|
417 | kwargs['button'] = 'Create' | |
414 | kwargs['experiments'] = Configuration.objects.filter( |
|
418 | kwargs['experiments'] = Configuration.objects.filter( | |
415 | experiment=request.GET['template']) |
|
419 | experiment=request.GET['template']) | |
416 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
420 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
417 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
421 | camp = Campaign.objects.get(pk=request.GET['template']) | |
418 | form = CampaignForm(instance=camp, |
|
422 | form = CampaignForm(instance=camp, | |
419 | initial={'name': '{}_{:%Y%m%d%H%M%S}'.format(camp.name, datetime.now()), |
|
423 | initial={'name': '{}_{:%Y%m%d%H%M%S}'.format(camp.name, datetime.now()), | |
420 | 'template': False}) |
|
424 | 'template': False}) | |
421 | elif 'blank' in request.GET: |
|
425 | elif 'blank' in request.GET: | |
422 | kwargs['button'] = 'Create' |
|
426 | kwargs['button'] = 'Create' | |
423 | form = CampaignForm() |
|
427 | form = CampaignForm() | |
424 | else: |
|
428 | else: | |
425 | form = NewForm() |
|
429 | form = NewForm() | |
426 |
|
430 | |||
427 | if request.method == 'POST': |
|
431 | if request.method == 'POST': | |
428 | kwargs['button'] = 'Create' |
|
432 | kwargs['button'] = 'Create' | |
429 | post = request.POST.copy() |
|
433 | post = request.POST.copy() | |
430 | experiments = [] |
|
434 | experiments = [] | |
431 |
|
435 | |||
432 | for id_exp in post.getlist('experiments'): |
|
436 | for id_exp in post.getlist('experiments'): | |
433 | exp = Experiment.objects.get(pk=id_exp) |
|
437 | exp = Experiment.objects.get(pk=id_exp) | |
434 | new_exp = exp.clone(template=False) |
|
438 | new_exp = exp.clone(template=False) | |
435 | experiments.append(new_exp) |
|
439 | experiments.append(new_exp) | |
436 |
|
440 | |||
437 | post.setlist('experiments', []) |
|
441 | post.setlist('experiments', []) | |
438 |
|
442 | |||
439 | form = CampaignForm(post) |
|
443 | form = CampaignForm(post) | |
440 |
|
444 | |||
441 | if form.is_valid(): |
|
445 | if form.is_valid(): | |
442 | campaign = form.save(commit=False) |
|
446 | campaign = form.save(commit=False) | |
443 | campaign.author = request.user |
|
447 | campaign.author = request.user | |
444 | campaign.save() |
|
448 | campaign.save() | |
445 | for exp in experiments: |
|
449 | for exp in experiments: | |
446 | campaign.experiments.add(exp) |
|
450 | campaign.experiments.add(exp) | |
447 |
|
451 | |||
448 | return redirect('url_campaign', id_camp=campaign.id) |
|
452 | return redirect('url_campaign', id_camp=campaign.id) | |
449 |
|
453 | |||
450 | kwargs['form'] = form |
|
454 | kwargs['form'] = form | |
451 | kwargs['title'] = 'Campaign' |
|
455 | kwargs['title'] = 'Campaign' | |
452 | kwargs['suptitle'] = 'New' |
|
456 | kwargs['suptitle'] = 'New' | |
453 | kwargs['menu_campaigns'] = 'active' |
|
457 | kwargs['menu_campaigns'] = 'active' | |
454 |
|
458 | |||
455 | return render(request, 'campaign_edit.html', kwargs) |
|
459 | return render(request, 'campaign_edit.html', kwargs) | |
456 |
|
460 | |||
457 |
|
461 | |||
458 | @login_required |
|
462 | @login_required | |
459 | def campaign_edit(request, id_camp): |
|
463 | def campaign_edit(request, id_camp): | |
460 |
|
464 | |||
461 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
465 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
462 |
|
466 | |||
463 | if request.method == 'GET': |
|
467 | if request.method == 'GET': | |
464 | form = CampaignForm(instance=campaign) |
|
468 | form = CampaignForm(instance=campaign) | |
465 |
|
469 | |||
466 | if request.method == 'POST': |
|
470 | if request.method == 'POST': | |
467 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
471 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
468 | post = request.POST.copy() |
|
472 | post = request.POST.copy() | |
469 | new_exps = post.getlist('experiments') |
|
473 | new_exps = post.getlist('experiments') | |
470 | post.setlist('experiments', []) |
|
474 | post.setlist('experiments', []) | |
471 | form = CampaignForm(post, instance=campaign) |
|
475 | form = CampaignForm(post, instance=campaign) | |
472 |
|
476 | |||
473 | if form.is_valid(): |
|
477 | if form.is_valid(): | |
474 | camp = form.save() |
|
478 | camp = form.save() | |
475 | for id_exp in new_exps: |
|
479 | for id_exp in new_exps: | |
476 | if int(id_exp) in exps: |
|
480 | if int(id_exp) in exps: | |
477 | exps.pop(id_exp) |
|
481 | exps.pop(id_exp) | |
478 | else: |
|
482 | else: | |
479 | exp = Experiment.objects.get(pk=id_exp) |
|
483 | exp = Experiment.objects.get(pk=id_exp) | |
480 | if exp.template: |
|
484 | if exp.template: | |
481 | camp.experiments.add(exp.clone(template=False)) |
|
485 | camp.experiments.add(exp.clone(template=False)) | |
482 | else: |
|
486 | else: | |
483 | camp.experiments.add(exp) |
|
487 | camp.experiments.add(exp) | |
484 |
|
488 | |||
485 | for id_exp in exps: |
|
489 | for id_exp in exps: | |
486 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
490 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
487 |
|
491 | |||
488 | return redirect('url_campaign', id_camp=id_camp) |
|
492 | return redirect('url_campaign', id_camp=id_camp) | |
489 |
|
493 | |||
490 | kwargs = {} |
|
494 | kwargs = {} | |
491 | kwargs['form'] = form |
|
495 | kwargs['form'] = form | |
492 | kwargs['title'] = 'Campaign' |
|
496 | kwargs['title'] = 'Campaign' | |
493 | kwargs['suptitle'] = 'Edit' |
|
497 | kwargs['suptitle'] = 'Edit' | |
494 | kwargs['button'] = 'Update' |
|
498 | kwargs['button'] = 'Update' | |
495 | kwargs['menu_campaigns'] = 'active' |
|
499 | kwargs['menu_campaigns'] = 'active' | |
496 |
|
500 | |||
497 | return render(request, 'campaign_edit.html', kwargs) |
|
501 | return render(request, 'campaign_edit.html', kwargs) | |
498 |
|
502 | |||
499 |
|
503 | |||
500 | @login_required |
|
504 | @login_required | |
501 | def campaign_delete(request, id_camp): |
|
505 | def campaign_delete(request, id_camp): | |
502 |
|
506 | |||
503 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
507 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
504 |
|
508 | |||
505 | if request.method == 'POST': |
|
509 | if request.method == 'POST': | |
506 | if is_developer(request.user): |
|
510 | if is_developer(request.user): | |
507 |
|
511 | |||
508 | for exp in campaign.experiments.all(): |
|
512 | for exp in campaign.experiments.all(): | |
509 | for conf in Configuration.objects.filter(experiment=exp): |
|
513 | for conf in Configuration.objects.filter(experiment=exp): | |
510 | conf.delete() |
|
514 | conf.delete() | |
511 | exp.delete() |
|
515 | exp.delete() | |
512 | campaign.delete() |
|
516 | campaign.delete() | |
513 |
|
517 | |||
514 | return redirect('url_campaigns') |
|
518 | return redirect('url_campaigns') | |
515 |
|
519 | |||
516 | messages.error(request, 'Not enough permission to delete this object') |
|
520 | messages.error(request, 'Not enough permission to delete this object') | |
517 | return redirect(campaign.get_absolute_url()) |
|
521 | return redirect(campaign.get_absolute_url()) | |
518 |
|
522 | |||
519 | kwargs = { |
|
523 | kwargs = { | |
520 | 'title': 'Delete', |
|
524 | 'title': 'Delete', | |
521 | 'suptitle': 'Campaign', |
|
525 | 'suptitle': 'Campaign', | |
522 | 'object': campaign, |
|
526 | 'object': campaign, | |
523 | 'delete': True |
|
527 | 'delete': True | |
524 | } |
|
528 | } | |
525 | kwargs['menu_campaigns'] = 'active' |
|
529 | kwargs['menu_campaigns'] = 'active' | |
526 |
|
530 | |||
527 | return render(request, 'confirm.html', kwargs) |
|
531 | return render(request, 'confirm.html', kwargs) | |
528 |
|
532 | |||
529 |
|
533 | |||
530 | @login_required |
|
534 | @login_required | |
531 | def campaign_export(request, id_camp): |
|
535 | def campaign_export(request, id_camp): | |
532 |
|
536 | |||
533 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
537 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
534 | content = campaign.parms_to_dict() |
|
538 | content = campaign.parms_to_dict() | |
535 | content_type = 'application/json' |
|
539 | content_type = 'application/json' | |
536 | filename = '%s_%s.json' % (campaign.name, campaign.id) |
|
540 | filename = '%s_%s.json' % (campaign.name, campaign.id) | |
537 |
|
541 | |||
538 | response = HttpResponse(content_type=content_type) |
|
542 | response = HttpResponse(content_type=content_type) | |
539 | response['Content-Disposition'] = 'attachment; filename="%s"' % filename |
|
543 | response['Content-Disposition'] = 'attachment; filename="%s"' % filename | |
540 | response.write(json.dumps(content, indent=2)) |
|
544 | response.write(json.dumps(content, indent=2)) | |
541 |
|
545 | |||
542 | return response |
|
546 | return response | |
543 |
|
547 | |||
544 |
|
548 | |||
545 | @login_required |
|
549 | @login_required | |
546 | def campaign_import(request, id_camp): |
|
550 | def campaign_import(request, id_camp): | |
547 |
|
551 | |||
548 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
552 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
549 |
|
553 | |||
550 | if request.method == 'GET': |
|
554 | if request.method == 'GET': | |
551 | file_form = UploadFileForm() |
|
555 | file_form = UploadFileForm() | |
552 |
|
556 | |||
553 | if request.method == 'POST': |
|
557 | if request.method == 'POST': | |
554 | file_form = UploadFileForm(request.POST, request.FILES) |
|
558 | file_form = UploadFileForm(request.POST, request.FILES) | |
555 |
|
559 | |||
556 | if file_form.is_valid(): |
|
560 | if file_form.is_valid(): | |
557 | new_camp = campaign.dict_to_parms( |
|
561 | new_camp = campaign.dict_to_parms( | |
558 | json.load(request.FILES['file']), CONF_MODELS) |
|
562 | json.load(request.FILES['file']), CONF_MODELS) | |
559 | messages.success( |
|
563 | messages.success( | |
560 | request, "Parameters imported from: '%s'." % request.FILES['file'].name) |
|
564 | request, "Parameters imported from: '%s'." % request.FILES['file'].name) | |
561 | return redirect(new_camp.get_absolute_url_edit()) |
|
565 | return redirect(new_camp.get_absolute_url_edit()) | |
562 |
|
566 | |||
563 | messages.error(request, "Could not import parameters from file") |
|
567 | messages.error(request, "Could not import parameters from file") | |
564 |
|
568 | |||
565 | kwargs = {} |
|
569 | kwargs = {} | |
566 | kwargs['title'] = 'Campaign' |
|
570 | kwargs['title'] = 'Campaign' | |
567 | kwargs['form'] = file_form |
|
571 | kwargs['form'] = file_form | |
568 | kwargs['suptitle'] = 'Importing file' |
|
572 | kwargs['suptitle'] = 'Importing file' | |
569 | kwargs['button'] = 'Import' |
|
573 | kwargs['button'] = 'Import' | |
570 | kwargs['menu_campaigns'] = 'active' |
|
574 | kwargs['menu_campaigns'] = 'active' | |
571 |
|
575 | |||
572 | return render(request, 'campaign_import.html', kwargs) |
|
576 | return render(request, 'campaign_import.html', kwargs) | |
573 |
|
577 | |||
574 |
|
578 | |||
575 | def experiments(request): |
|
579 | def experiments(request): | |
576 |
|
580 | |||
577 | page = request.GET.get('page') |
|
581 | page = request.GET.get('page') | |
578 | order = ('location',) |
|
582 | order = ('location',) | |
579 | filters = request.GET.copy() |
|
583 | filters = request.GET.copy() | |
580 |
|
584 | |||
581 | if 'my experiments' in filters: |
|
585 | if 'my experiments' in filters: | |
582 | filters.pop('my experiments', None) |
|
586 | filters.pop('my experiments', None) | |
583 | filters['mine'] = request.user.id |
|
587 | filters['mine'] = request.user.id | |
584 |
|
588 | |||
585 | kwargs = get_paginator(Experiment, page, order, filters) |
|
589 | kwargs = get_paginator(Experiment, page, order, filters) | |
586 |
|
590 | |||
587 | fields = ['tags', 'template'] |
|
591 | fields = ['tags', 'template'] | |
588 | if request.user.is_authenticated: |
|
592 | if request.user.is_authenticated: | |
589 | fields.append('my experiments') |
|
593 | fields.append('my experiments') | |
590 |
|
594 | |||
591 | form = FilterForm(initial=request.GET, extra_fields=fields) |
|
595 | form = FilterForm(initial=request.GET, extra_fields=fields) | |
592 |
|
596 | |||
593 | kwargs['keys'] = ['name', 'radar_system', |
|
597 | kwargs['keys'] = ['name', 'radar_system', | |
594 | 'start_time', 'end_time', 'actions'] |
|
598 | 'start_time', 'end_time', 'actions'] | |
595 | kwargs['title'] = 'Experiment' |
|
599 | kwargs['title'] = 'Experiment' | |
596 | kwargs['suptitle'] = 'List' |
|
600 | kwargs['suptitle'] = 'List' | |
597 | kwargs['no_sidebar'] = True |
|
601 | kwargs['no_sidebar'] = True | |
598 | kwargs['form'] = form |
|
602 | kwargs['form'] = form | |
599 | kwargs['add_url'] = reverse('url_add_experiment') |
|
603 | kwargs['add_url'] = reverse('url_add_experiment') | |
600 | filters = request.GET.copy() |
|
604 | filters = request.GET.copy() | |
601 | filters.pop('page', None) |
|
605 | filters.pop('page', None) | |
602 | kwargs['q'] = urlencode(filters) |
|
606 | kwargs['q'] = urlencode(filters) | |
603 | kwargs['menu_experiments'] = 'active' |
|
607 | kwargs['menu_experiments'] = 'active' | |
604 |
|
608 | |||
605 | return render(request, 'base_list.html', kwargs) |
|
609 | return render(request, 'base_list.html', kwargs) | |
606 |
|
610 | |||
607 |
|
611 | |||
608 | def experiment(request, id_exp): |
|
612 | def experiment(request, id_exp): | |
609 |
|
613 | |||
610 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
614 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
611 |
|
615 | |||
612 | configurations = Configuration.objects.filter( |
|
616 | configurations = Configuration.objects.filter( | |
613 | experiment=experiment, type=0) |
|
617 | experiment=experiment, type=0) | |
614 |
|
618 | |||
615 | kwargs = {} |
|
619 | kwargs = {} | |
616 |
|
620 | |||
617 | kwargs['experiment_keys'] = ['template', 'radar_system', |
|
621 | kwargs['experiment_keys'] = ['template', 'radar_system', | |
618 | 'name', 'freq', 'start_time', 'end_time'] |
|
622 | 'name', 'freq', 'start_time', 'end_time'] | |
619 | kwargs['experiment'] = experiment |
|
623 | kwargs['experiment'] = experiment | |
620 | kwargs['configuration_keys'] = ['name', 'device__ip_address', |
|
624 | kwargs['configuration_keys'] = ['name', 'device__ip_address', | |
621 | 'device__port_address', 'device__status'] |
|
625 | 'device__port_address', 'device__status'] | |
622 | kwargs['configurations'] = configurations |
|
626 | kwargs['configurations'] = configurations | |
623 | kwargs['title'] = 'Experiment' |
|
627 | kwargs['title'] = 'Experiment' | |
624 | kwargs['suptitle'] = 'Details' |
|
628 | kwargs['suptitle'] = 'Details' | |
625 | kwargs['button'] = 'Add Configuration' |
|
629 | kwargs['button'] = 'Add Configuration' | |
626 | kwargs['menu_experiments'] = 'active' |
|
630 | kwargs['menu_experiments'] = 'active' | |
627 |
|
631 | |||
628 | ###### SIDEBAR ###### |
|
632 | ###### SIDEBAR ###### | |
629 | kwargs.update(sidebar(experiment=experiment)) |
|
633 | kwargs.update(sidebar(experiment=experiment)) | |
630 |
|
634 | |||
631 | return render(request, 'experiment.html', kwargs) |
|
635 | return render(request, 'experiment.html', kwargs) | |
632 |
|
636 | |||
633 |
|
637 | |||
634 | @login_required |
|
638 | @login_required | |
635 | def experiment_new(request, id_camp=None): |
|
639 | def experiment_new(request, id_camp=None): | |
636 |
|
640 | |||
637 | if not is_developer(request.user): |
|
641 | if not is_developer(request.user): | |
638 | messages.error( |
|
642 | messages.error( | |
639 | request, 'Developer required, to create new Experiments') |
|
643 | request, 'Developer required, to create new Experiments') | |
640 | return redirect('index') |
|
644 | return redirect('index') | |
641 | kwargs = {} |
|
645 | kwargs = {} | |
642 |
|
646 | |||
643 | if request.method == 'GET': |
|
647 | if request.method == 'GET': | |
644 | if 'template' in request.GET: |
|
648 | if 'template' in request.GET: | |
645 | if request.GET['template'] == '0': |
|
649 | if request.GET['template'] == '0': | |
646 | form = NewForm(initial={'create_from': 2}, |
|
650 | form = NewForm(initial={'create_from': 2}, | |
647 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
651 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
648 | else: |
|
652 | else: | |
649 | kwargs['button'] = 'Create' |
|
653 | kwargs['button'] = 'Create' | |
650 | kwargs['configurations'] = Configuration.objects.filter( |
|
654 | kwargs['configurations'] = Configuration.objects.filter( | |
651 | experiment=request.GET['template']) |
|
655 | experiment=request.GET['template']) | |
652 | kwargs['configuration_keys'] = ['name', 'device__name', |
|
656 | kwargs['configuration_keys'] = ['name', 'device__name', | |
653 | 'device__ip_address', 'device__port_address'] |
|
657 | 'device__ip_address', 'device__port_address'] | |
654 | exp = Experiment.objects.get(pk=request.GET['template']) |
|
658 | exp = Experiment.objects.get(pk=request.GET['template']) | |
655 | form = ExperimentForm(instance=exp, |
|
659 | form = ExperimentForm(instance=exp, | |
656 | initial={'name': '{}_{:%y%m%d}'.format(exp.name, datetime.now()), |
|
660 | initial={'name': '{}_{:%y%m%d}'.format(exp.name, datetime.now()), | |
657 | 'template': False}) |
|
661 | 'template': False}) | |
658 | elif 'blank' in request.GET: |
|
662 | elif 'blank' in request.GET: | |
659 | kwargs['button'] = 'Create' |
|
663 | kwargs['button'] = 'Create' | |
660 | form = ExperimentForm() |
|
664 | form = ExperimentForm() | |
661 | else: |
|
665 | else: | |
662 | form = NewForm() |
|
666 | form = NewForm() | |
663 |
|
667 | |||
664 | if request.method == 'POST': |
|
668 | if request.method == 'POST': | |
665 | form = ExperimentForm(request.POST) |
|
669 | form = ExperimentForm(request.POST) | |
666 | if form.is_valid(): |
|
670 | if form.is_valid(): | |
667 | experiment = form.save(commit=False) |
|
671 | experiment = form.save(commit=False) | |
668 | experiment.author = request.user |
|
672 | experiment.author = request.user | |
669 | experiment.save() |
|
673 | experiment.save() | |
670 |
|
674 | |||
671 | if 'template' in request.GET: |
|
675 | if 'template' in request.GET: | |
672 | configurations = Configuration.objects.filter( |
|
676 | configurations = Configuration.objects.filter( | |
673 | experiment=request.GET['template'], type=0) |
|
677 | experiment=request.GET['template'], type=0) | |
674 | for conf in configurations: |
|
678 | for conf in configurations: | |
675 | conf.clone(experiment=experiment, template=False) |
|
679 | conf.clone(experiment=experiment, template=False) | |
676 |
|
680 | |||
677 | return redirect('url_experiment', id_exp=experiment.id) |
|
681 | return redirect('url_experiment', id_exp=experiment.id) | |
678 |
|
682 | |||
679 | kwargs['form'] = form |
|
683 | kwargs['form'] = form | |
680 | kwargs['title'] = 'Experiment' |
|
684 | kwargs['title'] = 'Experiment' | |
681 | kwargs['suptitle'] = 'New' |
|
685 | kwargs['suptitle'] = 'New' | |
682 | kwargs['menu_experiments'] = 'active' |
|
686 | kwargs['menu_experiments'] = 'active' | |
683 |
|
687 | |||
684 | return render(request, 'experiment_edit.html', kwargs) |
|
688 | return render(request, 'experiment_edit.html', kwargs) | |
685 |
|
689 | |||
686 |
|
690 | |||
687 | @login_required |
|
691 | @login_required | |
688 | def experiment_edit(request, id_exp): |
|
692 | def experiment_edit(request, id_exp): | |
689 |
|
693 | |||
690 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
694 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
691 |
|
695 | |||
692 | if request.method == 'GET': |
|
696 | if request.method == 'GET': | |
693 | form = ExperimentForm(instance=experiment) |
|
697 | form = ExperimentForm(instance=experiment) | |
694 |
|
698 | |||
695 | if request.method == 'POST': |
|
699 | if request.method == 'POST': | |
696 | form = ExperimentForm(request.POST, instance=experiment) |
|
700 | form = ExperimentForm(request.POST, instance=experiment) | |
697 |
|
701 | |||
698 | if form.is_valid(): |
|
702 | if form.is_valid(): | |
699 | experiment = form.save() |
|
703 | experiment = form.save() | |
700 | return redirect('url_experiment', id_exp=experiment.id) |
|
704 | return redirect('url_experiment', id_exp=experiment.id) | |
701 |
|
705 | |||
702 | kwargs = {} |
|
706 | kwargs = {} | |
703 | kwargs['form'] = form |
|
707 | kwargs['form'] = form | |
704 | kwargs['title'] = 'Experiment' |
|
708 | kwargs['title'] = 'Experiment' | |
705 | kwargs['suptitle'] = 'Edit' |
|
709 | kwargs['suptitle'] = 'Edit' | |
706 | kwargs['button'] = 'Update' |
|
710 | kwargs['button'] = 'Update' | |
707 | kwargs['menu_experiments'] = 'active' |
|
711 | kwargs['menu_experiments'] = 'active' | |
708 |
|
712 | |||
709 | return render(request, 'experiment_edit.html', kwargs) |
|
713 | return render(request, 'experiment_edit.html', kwargs) | |
710 |
|
714 | |||
711 |
|
715 | |||
712 | @login_required |
|
716 | @login_required | |
713 | def experiment_delete(request, id_exp): |
|
717 | def experiment_delete(request, id_exp): | |
714 |
|
718 | |||
715 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
719 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
716 |
|
720 | |||
717 | if request.method == 'POST': |
|
721 | if request.method == 'POST': | |
718 | if is_developer(request.user): |
|
722 | if is_developer(request.user): | |
719 | for conf in Configuration.objects.filter(experiment=experiment): |
|
723 | for conf in Configuration.objects.filter(experiment=experiment): | |
720 | conf.delete() |
|
724 | conf.delete() | |
721 | experiment.delete() |
|
725 | experiment.delete() | |
722 | return redirect('url_experiments') |
|
726 | return redirect('url_experiments') | |
723 |
|
727 | |||
724 | messages.error(request, 'Not enough permission to delete this object') |
|
728 | messages.error(request, 'Not enough permission to delete this object') | |
725 | return redirect(experiment.get_absolute_url()) |
|
729 | return redirect(experiment.get_absolute_url()) | |
726 |
|
730 | |||
727 | kwargs = { |
|
731 | kwargs = { | |
728 | 'title': 'Delete', |
|
732 | 'title': 'Delete', | |
729 | 'suptitle': 'Experiment', |
|
733 | 'suptitle': 'Experiment', | |
730 | 'object': experiment, |
|
734 | 'object': experiment, | |
731 | 'delete': True |
|
735 | 'delete': True | |
732 | } |
|
736 | } | |
733 |
|
737 | |||
734 | return render(request, 'confirm.html', kwargs) |
|
738 | return render(request, 'confirm.html', kwargs) | |
735 |
|
739 | |||
736 |
|
740 | |||
737 | @login_required |
|
741 | @login_required | |
738 | def experiment_export(request, id_exp): |
|
742 | def experiment_export(request, id_exp): | |
739 |
|
743 | |||
740 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
744 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
741 | content = experiment.parms_to_dict() |
|
745 | content = experiment.parms_to_dict() | |
742 | content_type = 'application/json' |
|
746 | content_type = 'application/json' | |
743 | filename = '%s_%s.json' % (experiment.name, experiment.id) |
|
747 | filename = '%s_%s.json' % (experiment.name, experiment.id) | |
744 |
|
748 | |||
745 | response = HttpResponse(content_type=content_type) |
|
749 | response = HttpResponse(content_type=content_type) | |
746 | response['Content-Disposition'] = 'attachment; filename="%s"' % filename |
|
750 | response['Content-Disposition'] = 'attachment; filename="%s"' % filename | |
747 | response.write(json.dumps(content, indent=2)) |
|
751 | response.write(json.dumps(content, indent=2)) | |
748 |
|
752 | |||
749 | return response |
|
753 | return response | |
750 |
|
754 | |||
751 |
|
755 | |||
752 | @login_required |
|
756 | @login_required | |
753 | def experiment_import(request, id_exp): |
|
757 | def experiment_import(request, id_exp): | |
754 |
|
758 | |||
755 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
759 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
756 | configurations = Configuration.objects.filter(experiment=experiment) |
|
760 | configurations = Configuration.objects.filter(experiment=experiment) | |
757 |
|
761 | |||
758 | if request.method == 'GET': |
|
762 | if request.method == 'GET': | |
759 | file_form = UploadFileForm() |
|
763 | file_form = UploadFileForm() | |
760 |
|
764 | |||
761 | if request.method == 'POST': |
|
765 | if request.method == 'POST': | |
762 | file_form = UploadFileForm(request.POST, request.FILES) |
|
766 | file_form = UploadFileForm(request.POST, request.FILES) | |
763 |
|
767 | |||
764 | if file_form.is_valid(): |
|
768 | if file_form.is_valid(): | |
765 | new_exp = experiment.dict_to_parms( |
|
769 | new_exp = experiment.dict_to_parms( | |
766 | json.load(request.FILES['file']), CONF_MODELS) |
|
770 | json.load(request.FILES['file']), CONF_MODELS) | |
767 | messages.success( |
|
771 | messages.success( | |
768 | request, "Parameters imported from: '%s'." % request.FILES['file'].name) |
|
772 | request, "Parameters imported from: '%s'." % request.FILES['file'].name) | |
769 | return redirect(new_exp.get_absolute_url_edit()) |
|
773 | return redirect(new_exp.get_absolute_url_edit()) | |
770 |
|
774 | |||
771 | messages.error(request, "Could not import parameters from file") |
|
775 | messages.error(request, "Could not import parameters from file") | |
772 |
|
776 | |||
773 | kwargs = {} |
|
777 | kwargs = {} | |
774 | kwargs['title'] = 'Experiment' |
|
778 | kwargs['title'] = 'Experiment' | |
775 | kwargs['form'] = file_form |
|
779 | kwargs['form'] = file_form | |
776 | kwargs['suptitle'] = 'Importing file' |
|
780 | kwargs['suptitle'] = 'Importing file' | |
777 | kwargs['button'] = 'Import' |
|
781 | kwargs['button'] = 'Import' | |
778 | kwargs['menu_experiments'] = 'active' |
|
782 | kwargs['menu_experiments'] = 'active' | |
779 |
|
783 | |||
780 | kwargs.update(sidebar(experiment=experiment)) |
|
784 | kwargs.update(sidebar(experiment=experiment)) | |
781 |
|
785 | |||
782 | return render(request, 'experiment_import.html', kwargs) |
|
786 | return render(request, 'experiment_import.html', kwargs) | |
783 |
|
787 | |||
784 |
|
788 | |||
785 | @login_required |
|
789 | @login_required | |
786 | def experiment_start(request, id_exp): |
|
790 | def experiment_start(request, id_exp): | |
787 |
|
791 | |||
788 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
792 | exp = get_object_or_404(Experiment, pk=id_exp) | |
789 |
|
793 | |||
790 | if exp.status == 2: |
|
794 | if exp.status == 2: | |
791 | messages.warning(request, 'Experiment {} already runnnig'.format(exp)) |
|
795 | messages.warning(request, 'Experiment {} already runnnig'.format(exp)) | |
792 | else: |
|
796 | else: | |
793 | exp.status = exp.start() |
|
797 | exp.status = exp.start() | |
794 | if exp.status == 0: |
|
798 | if exp.status == 0: | |
795 | messages.error(request, 'Experiment {} not start'.format(exp)) |
|
799 | messages.error(request, 'Experiment {} not start'.format(exp)) | |
796 | if exp.status == 2: |
|
800 | if exp.status == 2: | |
797 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
801 | messages.success(request, 'Experiment {} started'.format(exp)) | |
798 |
|
802 | |||
799 | exp.save() |
|
803 | exp.save() | |
800 |
|
804 | |||
801 | return redirect(exp.get_absolute_url()) |
|
805 | return redirect(exp.get_absolute_url()) | |
802 |
|
806 | |||
803 |
|
807 | |||
804 | @login_required |
|
808 | @login_required | |
805 | def experiment_stop(request, id_exp): |
|
809 | def experiment_stop(request, id_exp): | |
806 |
|
810 | |||
807 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
811 | exp = get_object_or_404(Experiment, pk=id_exp) | |
808 |
|
812 | |||
809 | if exp.status == 2: |
|
813 | if exp.status == 2: | |
810 | exp.status = exp.stop() |
|
814 | exp.status = exp.stop() | |
811 | exp.save() |
|
815 | exp.save() | |
812 | messages.success(request, 'Experiment {} stopped'.format(exp)) |
|
816 | messages.success(request, 'Experiment {} stopped'.format(exp)) | |
813 | else: |
|
817 | else: | |
814 | messages.error(request, 'Experiment {} not running'.format(exp)) |
|
818 | messages.error(request, 'Experiment {} not running'.format(exp)) | |
815 |
|
819 | |||
816 | return redirect(exp.get_absolute_url()) |
|
820 | return redirect(exp.get_absolute_url()) | |
817 |
|
821 | |||
818 |
|
822 | |||
819 | def experiment_status(request, id_exp): |
|
823 | def experiment_status(request, id_exp): | |
820 |
|
824 | |||
821 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
825 | exp = get_object_or_404(Experiment, pk=id_exp) | |
822 |
|
826 | |||
823 | exp.get_status() |
|
827 | exp.get_status() | |
824 |
|
828 | |||
825 | return redirect(exp.get_absolute_url()) |
|
829 | return redirect(exp.get_absolute_url()) | |
826 |
|
830 | |||
827 |
|
831 | |||
828 | @login_required |
|
832 | @login_required | |
829 | def experiment_mix(request, id_exp): |
|
833 | def experiment_mix(request, id_exp): | |
830 |
|
834 | |||
831 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
835 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
832 | rc_confs = [conf for conf in RCConfiguration.objects.filter( |
|
836 | rc_confs = [conf for conf in RCConfiguration.objects.filter( | |
833 | experiment=id_exp, |
|
837 | experiment=id_exp, | |
834 | type=0, |
|
838 | type=0, | |
835 | mix=False)] |
|
839 | mix=False)] | |
836 |
|
840 | |||
837 | if len(rc_confs) < 2: |
|
841 | if len(rc_confs) < 2: | |
838 | messages.warning( |
|
842 | messages.warning( | |
839 | request, 'You need at least two RC Configurations to make a mix') |
|
843 | request, 'You need at least two RC Configurations to make a mix') | |
840 | return redirect(experiment.get_absolute_url()) |
|
844 | return redirect(experiment.get_absolute_url()) | |
841 |
|
845 | |||
842 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True, type=0) |
|
846 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True, type=0) | |
843 |
|
847 | |||
844 | if mix_confs: |
|
848 | if mix_confs: | |
845 | mix = mix_confs[0] |
|
849 | mix = mix_confs[0] | |
846 | else: |
|
850 | else: | |
847 | mix = RCConfiguration(experiment=experiment, |
|
851 | mix = RCConfiguration(experiment=experiment, | |
848 | device=rc_confs[0].device, |
|
852 | device=rc_confs[0].device, | |
849 | ipp=rc_confs[0].ipp, |
|
853 | ipp=rc_confs[0].ipp, | |
850 | clock_in=rc_confs[0].clock_in, |
|
854 | clock_in=rc_confs[0].clock_in, | |
851 | clock_divider=rc_confs[0].clock_divider, |
|
855 | clock_divider=rc_confs[0].clock_divider, | |
852 | mix=True, |
|
856 | mix=True, | |
853 | parameters='') |
|
857 | parameters='') | |
854 | mix.save() |
|
858 | mix.save() | |
855 |
|
859 | |||
856 | line_type = RCLineType.objects.get(name='mix') |
|
860 | line_type = RCLineType.objects.get(name='mix') | |
857 | print("VIew obteniendo len getlines") |
|
861 | print("VIew obteniendo len getlines") | |
858 | print(len(rc_confs[0].get_lines())) |
|
862 | print(len(rc_confs[0].get_lines())) | |
859 | for i in range(len(rc_confs[0].get_lines())): |
|
863 | for i in range(len(rc_confs[0].get_lines())): | |
860 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) |
|
864 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |
861 | line.save() |
|
865 | line.save() | |
862 |
|
866 | |||
863 | initial = {'name': mix.name, |
|
867 | initial = {'name': mix.name, | |
864 | 'result': parse_mix_result(mix.parameters), |
|
868 | 'result': parse_mix_result(mix.parameters), | |
865 | 'delay': 0, |
|
869 | 'delay': 0, | |
866 | 'mask': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] |
|
870 | 'mask': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] | |
867 | } |
|
871 | } | |
868 |
|
872 | |||
869 | if request.method == 'GET': |
|
873 | if request.method == 'GET': | |
870 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) |
|
874 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |
871 |
|
875 | |||
872 | if request.method == 'POST': |
|
876 | if request.method == 'POST': | |
873 | result = mix.parameters |
|
877 | result = mix.parameters | |
874 |
|
878 | |||
875 | if '{}|'.format(request.POST['experiment']) in result: |
|
879 | if '{}|'.format(request.POST['experiment']) in result: | |
876 | messages.error(request, 'Configuration already added') |
|
880 | messages.error(request, 'Configuration already added') | |
877 | else: |
|
881 | else: | |
878 | if 'operation' in request.POST: |
|
882 | if 'operation' in request.POST: | |
879 | operation = MIX_OPERATIONS[request.POST['operation']] |
|
883 | operation = MIX_OPERATIONS[request.POST['operation']] | |
880 | else: |
|
884 | else: | |
881 | operation = ' ' |
|
885 | operation = ' ' | |
882 |
|
886 | |||
883 | mode = MIX_MODES[request.POST['mode']] |
|
887 | mode = MIX_MODES[request.POST['mode']] | |
884 |
|
888 | |||
885 | if result: |
|
889 | if result: | |
886 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, |
|
890 | result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters, | |
887 | request.POST['experiment'], |
|
891 | request.POST['experiment'], | |
888 | mode, |
|
892 | mode, | |
889 | operation, |
|
893 | operation, | |
890 | float( |
|
894 | float( | |
891 | request.POST['delay']), |
|
895 | request.POST['delay']), | |
892 | parse_mask( |
|
896 | parse_mask( | |
893 | request.POST.getlist('mask')) |
|
897 | request.POST.getlist('mask')) | |
894 | ) |
|
898 | ) | |
895 | else: |
|
899 | else: | |
896 | result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'], |
|
900 | result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'], | |
897 | mode, |
|
901 | mode, | |
898 | operation, |
|
902 | operation, | |
899 | float(request.POST['delay']), |
|
903 | float(request.POST['delay']), | |
900 | parse_mask( |
|
904 | parse_mask( | |
901 | request.POST.getlist('mask')) |
|
905 | request.POST.getlist('mask')) | |
902 | ) |
|
906 | ) | |
903 |
|
907 | |||
904 | mix.parameters = result |
|
908 | mix.parameters = result | |
905 | mix.save() |
|
909 | mix.save() | |
906 | mix.update_pulses() |
|
910 | mix.update_pulses() | |
907 |
|
911 | |||
908 | initial['result'] = parse_mix_result(result) |
|
912 | initial['result'] = parse_mix_result(result) | |
909 | initial['name'] = mix.name |
|
913 | initial['name'] = mix.name | |
910 |
|
914 | |||
911 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) |
|
915 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |
912 |
|
916 | |||
913 | kwargs = { |
|
917 | kwargs = { | |
914 | 'title': 'Experiment', |
|
918 | 'title': 'Experiment', | |
915 | 'suptitle': 'Mix Configurations', |
|
919 | 'suptitle': 'Mix Configurations', | |
916 | 'form': form, |
|
920 | 'form': form, | |
917 | 'extra_button': 'Delete', |
|
921 | 'extra_button': 'Delete', | |
918 | 'button': 'Add', |
|
922 | 'button': 'Add', | |
919 | 'cancel': 'Back', |
|
923 | 'cancel': 'Back', | |
920 | 'previous': experiment.get_absolute_url(), |
|
924 | 'previous': experiment.get_absolute_url(), | |
921 | 'id_exp': id_exp, |
|
925 | 'id_exp': id_exp, | |
922 |
|
926 | |||
923 | } |
|
927 | } | |
924 | kwargs['menu_experiments'] = 'active' |
|
928 | kwargs['menu_experiments'] = 'active' | |
925 |
|
929 | |||
926 | return render(request, 'experiment_mix.html', kwargs) |
|
930 | return render(request, 'experiment_mix.html', kwargs) | |
927 |
|
931 | |||
928 |
|
932 | |||
929 | @login_required |
|
933 | @login_required | |
930 | def experiment_mix_delete(request, id_exp): |
|
934 | def experiment_mix_delete(request, id_exp): | |
931 |
|
935 | |||
932 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True, type=0) |
|
936 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True, type=0) | |
933 | values = conf.parameters.split('-') |
|
937 | values = conf.parameters.split('-') | |
934 | conf.parameters = '-'.join(values[:-1]) |
|
938 | conf.parameters = '-'.join(values[:-1]) | |
935 | conf.save() |
|
939 | conf.save() | |
936 |
|
940 | |||
937 | return redirect('url_mix_experiment', id_exp=id_exp) |
|
941 | return redirect('url_mix_experiment', id_exp=id_exp) | |
938 |
|
942 | |||
939 |
|
943 | |||
940 | def experiment_summary(request, id_exp): |
|
944 | def experiment_summary(request, id_exp): | |
941 |
|
945 | |||
942 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
946 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
943 | configurations = Configuration.objects.filter( |
|
947 | configurations = Configuration.objects.filter( | |
944 | experiment=experiment, type=0) |
|
948 | experiment=experiment, type=0) | |
945 |
|
949 | |||
946 | kwargs = {} |
|
950 | kwargs = {} | |
947 | kwargs['experiment_keys'] = ['radar_system', |
|
951 | kwargs['experiment_keys'] = ['radar_system', | |
948 | 'name', 'freq', 'start_time', 'end_time'] |
|
952 | 'name', 'freq', 'start_time', 'end_time'] | |
949 | kwargs['experiment'] = experiment |
|
953 | kwargs['experiment'] = experiment | |
950 | kwargs['configurations'] = [] |
|
954 | kwargs['configurations'] = [] | |
951 | kwargs['title'] = 'Experiment Summary' |
|
955 | kwargs['title'] = 'Experiment Summary' | |
952 | kwargs['suptitle'] = 'Details' |
|
956 | kwargs['suptitle'] = 'Details' | |
953 | kwargs['button'] = 'Verify Parameters' |
|
957 | kwargs['button'] = 'Verify Parameters' | |
954 |
|
958 | |||
955 | c_vel = 3.0*(10**8) # m/s |
|
959 | c_vel = 3.0*(10**8) # m/s | |
956 | ope_freq = experiment.freq*(10**6) # 1/s |
|
960 | ope_freq = experiment.freq*(10**6) # 1/s | |
957 | radar_lambda = c_vel/ope_freq # m |
|
961 | radar_lambda = c_vel/ope_freq # m | |
958 | kwargs['radar_lambda'] = radar_lambda |
|
962 | kwargs['radar_lambda'] = radar_lambda | |
959 |
|
963 | |||
960 | ipp = None |
|
964 | ipp = None | |
961 | nsa = 1 |
|
965 | nsa = 1 | |
962 | code_id = 0 |
|
966 | code_id = 0 | |
963 | tx_line = {} |
|
967 | tx_line = {} | |
964 |
|
968 | |||
965 | for configuration in configurations.filter(device__device_type__name = 'rc'): |
|
969 | for configuration in configurations.filter(device__device_type__name = 'rc'): | |
966 |
|
970 | |||
967 | if configuration.mix: |
|
971 | if configuration.mix: | |
968 | continue |
|
972 | continue | |
969 | conf = {'conf': configuration} |
|
973 | conf = {'conf': configuration} | |
970 | conf['keys'] = [] |
|
974 | conf['keys'] = [] | |
971 | conf['NTxs'] = configuration.ntx |
|
975 | conf['NTxs'] = configuration.ntx | |
972 | conf['keys'].append('NTxs') |
|
976 | conf['keys'].append('NTxs') | |
973 | ipp = configuration.ipp |
|
977 | ipp = configuration.ipp | |
974 | conf['IPP'] = ipp |
|
978 | conf['IPP'] = ipp | |
975 | conf['keys'].append('IPP') |
|
979 | conf['keys'].append('IPP') | |
976 | lines = configuration.get_lines(line_type__name='tx') |
|
980 | lines = configuration.get_lines(line_type__name='tx') | |
977 |
|
981 | |||
978 | for tx_line in lines: |
|
982 | for tx_line in lines: | |
979 | tx_params = json.loads(tx_line.params) |
|
983 | tx_params = json.loads(tx_line.params) | |
980 | conf[tx_line.get_name()] = '{} Km'.format(tx_params['pulse_width']) |
|
984 | conf[tx_line.get_name()] = '{} Km'.format(tx_params['pulse_width']) | |
981 | conf['keys'].append(tx_line.get_name()) |
|
985 | conf['keys'].append(tx_line.get_name()) | |
982 | delays = tx_params['delays'] |
|
986 | delays = tx_params['delays'] | |
983 | if delays not in ('', '0'): |
|
987 | if delays not in ('', '0'): | |
984 | n = len(delays.split(',')) |
|
988 | n = len(delays.split(',')) | |
985 | taus = '{} Taus: {}'.format(n, delays) |
|
989 | taus = '{} Taus: {}'.format(n, delays) | |
986 | else: |
|
990 | else: | |
987 | taus = '-' |
|
991 | taus = '-' | |
988 | conf['Taus ({})'.format(tx_line.get_name())] = taus |
|
992 | conf['Taus ({})'.format(tx_line.get_name())] = taus | |
989 | conf['keys'].append('Taus ({})'.format(tx_line.get_name())) |
|
993 | conf['keys'].append('Taus ({})'.format(tx_line.get_name())) | |
990 | for code_line in configuration.get_lines(line_type__name='codes'): |
|
994 | for code_line in configuration.get_lines(line_type__name='codes'): | |
991 | code_params = json.loads(code_line.params) |
|
995 | code_params = json.loads(code_line.params) | |
992 | code_id = code_params['code'] |
|
996 | code_id = code_params['code'] | |
993 | if tx_line.pk == int(code_params['TX_ref']): |
|
997 | if tx_line.pk == int(code_params['TX_ref']): | |
994 | conf['Code ({})'.format(tx_line.get_name())] = '{}:{}'.format(RCLineCode.objects.get(pk=code_params['code']), |
|
998 | conf['Code ({})'.format(tx_line.get_name())] = '{}:{}'.format(RCLineCode.objects.get(pk=code_params['code']), | |
995 | '-'.join(code_params['codes'])) |
|
999 | '-'.join(code_params['codes'])) | |
996 | conf['keys'].append('Code ({})'.format(tx_line.get_name())) |
|
1000 | conf['keys'].append('Code ({})'.format(tx_line.get_name())) | |
997 |
|
1001 | |||
998 | for windows_line in configuration.get_lines(line_type__name='windows'): |
|
1002 | for windows_line in configuration.get_lines(line_type__name='windows'): | |
999 | win_params = json.loads(windows_line.params) |
|
1003 | win_params = json.loads(windows_line.params) | |
1000 | if tx_line.pk == int(win_params['TX_ref']): |
|
1004 | if tx_line.pk == int(win_params['TX_ref']): | |
1001 | windows = '' |
|
1005 | windows = '' | |
1002 | nsa = win_params['params'][0]['number_of_samples'] |
|
1006 | nsa = win_params['params'][0]['number_of_samples'] | |
1003 | for i, params in enumerate(win_params['params']): |
|
1007 | for i, params in enumerate(win_params['params']): | |
1004 | windows += 'W{}: Ho={first_height} km DH={resolution} km NSA={number_of_samples}<br>'.format( |
|
1008 | windows += 'W{}: Ho={first_height} km DH={resolution} km NSA={number_of_samples}<br>'.format( | |
1005 | i, **params) |
|
1009 | i, **params) | |
1006 | conf['Window'] = mark_safe(windows) |
|
1010 | conf['Window'] = mark_safe(windows) | |
1007 | conf['keys'].append('Window') |
|
1011 | conf['keys'].append('Window') | |
1008 |
|
1012 | |||
1009 | kwargs['configurations'].append(conf) |
|
1013 | kwargs['configurations'].append(conf) | |
1010 |
|
1014 | |||
1011 | for configuration in configurations.filter(device__device_type__name = 'jars'): |
|
1015 | for configuration in configurations.filter(device__device_type__name = 'jars'): | |
1012 |
|
1016 | |||
1013 | conf = {'conf': configuration} |
|
1017 | conf = {'conf': configuration} | |
1014 | conf['keys'] = [] |
|
1018 | conf['keys'] = [] | |
1015 | conf['Type of Data'] = EXPERIMENT_TYPE[configuration.exp_type][1] |
|
1019 | conf['Type of Data'] = EXPERIMENT_TYPE[configuration.exp_type][1] | |
1016 | conf['keys'].append('Type of Data') |
|
1020 | conf['keys'].append('Type of Data') | |
1017 | channels_number = configuration.channels_number |
|
1021 | channels_number = configuration.channels_number | |
1018 | exp_type = configuration.exp_type |
|
1022 | exp_type = configuration.exp_type | |
1019 | fftpoints = configuration.fftpoints |
|
1023 | fftpoints = configuration.fftpoints | |
1020 | filter_parms = json.loads(configuration.filter_parms) |
|
1024 | filter_parms = json.loads(configuration.filter_parms) | |
1021 | spectral_number = configuration.spectral_number |
|
1025 | spectral_number = configuration.spectral_number | |
1022 | acq_profiles = configuration.acq_profiles |
|
1026 | acq_profiles = configuration.acq_profiles | |
1023 | cohe_integr = configuration.cohe_integr |
|
1027 | cohe_integr = configuration.cohe_integr | |
1024 | profiles_block = configuration.profiles_block |
|
1028 | profiles_block = configuration.profiles_block | |
1025 |
|
1029 | |||
1026 | conf['Num of Profiles'] = acq_profiles |
|
1030 | conf['Num of Profiles'] = acq_profiles | |
1027 | conf['keys'].append('Num of Profiles') |
|
1031 | conf['keys'].append('Num of Profiles') | |
1028 |
|
1032 | |||
1029 | conf['Prof per Block'] = profiles_block |
|
1033 | conf['Prof per Block'] = profiles_block | |
1030 | conf['keys'].append('Prof per Block') |
|
1034 | conf['keys'].append('Prof per Block') | |
1031 |
|
1035 | |||
1032 | conf['Blocks per File'] = configuration.raw_data_blocks |
|
1036 | conf['Blocks per File'] = configuration.raw_data_blocks | |
1033 | conf['keys'].append('Blocks per File') |
|
1037 | conf['keys'].append('Blocks per File') | |
1034 |
|
1038 | |||
1035 | if exp_type == 0: # Short |
|
1039 | if exp_type == 0: # Short | |
1036 | bytes_ = 2 |
|
1040 | bytes_ = 2 | |
1037 | b = nsa*2*bytes_*channels_number |
|
1041 | b = nsa*2*bytes_*channels_number | |
1038 | else: # Float |
|
1042 | else: # Float | |
1039 | bytes_ = 4 |
|
1043 | bytes_ = 4 | |
1040 | channels = channels_number + spectral_number |
|
1044 | channels = channels_number + spectral_number | |
1041 | b = nsa*2*bytes_*fftpoints*channels |
|
1045 | b = nsa*2*bytes_*fftpoints*channels | |
1042 |
|
1046 | |||
1043 | codes_num = 7 |
|
1047 | codes_num = 7 | |
1044 | if code_id == 2: |
|
1048 | if code_id == 2: | |
1045 | codes_num = 7 |
|
1049 | codes_num = 7 | |
1046 | elif code_id == 12: |
|
1050 | elif code_id == 12: | |
1047 | codes_num = 15 |
|
1051 | codes_num = 15 | |
1048 |
|
1052 | |||
1049 | #Jars filter values: |
|
1053 | #Jars filter values: | |
1050 |
|
1054 | |||
1051 | clock = float(filter_parms['clock']) |
|
1055 | clock = float(filter_parms['clock']) | |
1052 | filter_2 = int(filter_parms['cic_2']) |
|
1056 | filter_2 = int(filter_parms['cic_2']) | |
1053 | filter_5 = int(filter_parms['cic_5']) |
|
1057 | filter_5 = int(filter_parms['cic_5']) | |
1054 | filter_fir = int(filter_parms['fir']) |
|
1058 | filter_fir = int(filter_parms['fir']) | |
1055 | Fs_MHz = clock/(filter_2*filter_5*filter_fir) |
|
1059 | Fs_MHz = clock/(filter_2*filter_5*filter_fir) | |
1056 |
|
1060 | |||
1057 | #Jars values: |
|
1061 | #Jars values: | |
1058 | if ipp is not None: |
|
1062 | if ipp is not None: | |
1059 | IPP_units = ipp/0.15*Fs_MHz |
|
1063 | IPP_units = ipp/0.15*Fs_MHz | |
1060 | IPP_us = IPP_units / Fs_MHz |
|
1064 | IPP_us = IPP_units / Fs_MHz | |
1061 | IPP_s = IPP_units / (Fs_MHz * (10**6)) |
|
1065 | IPP_s = IPP_units / (Fs_MHz * (10**6)) | |
1062 | Ts = 1/(Fs_MHz*(10**6)) |
|
1066 | Ts = 1/(Fs_MHz*(10**6)) | |
1063 |
|
1067 | |||
1064 | Va = radar_lambda/(4*Ts*cohe_integr) |
|
1068 | Va = radar_lambda/(4*Ts*cohe_integr) | |
1065 | rate_bh = ((nsa-codes_num)*channels_number*2 * |
|
1069 | rate_bh = ((nsa-codes_num)*channels_number*2 * | |
1066 | bytes_/IPP_us)*(36*(10**8)/cohe_integr) |
|
1070 | bytes_/IPP_us)*(36*(10**8)/cohe_integr) | |
1067 | rate_gh = rate_bh/(1024*1024*1024) |
|
1071 | rate_gh = rate_bh/(1024*1024*1024) | |
1068 |
|
1072 | |||
1069 | conf['Time per Block'] = IPP_s * profiles_block * cohe_integr |
|
1073 | conf['Time per Block'] = IPP_s * profiles_block * cohe_integr | |
1070 | conf['keys'].append('Time per Block') |
|
1074 | conf['keys'].append('Time per Block') | |
1071 | conf['Acq time'] = IPP_s * acq_profiles |
|
1075 | conf['Acq time'] = IPP_s * acq_profiles | |
1072 | conf['keys'].append('Acq time') |
|
1076 | conf['keys'].append('Acq time') | |
1073 | conf['Data rate'] = str(rate_gh)+" (GB/h)" |
|
1077 | conf['Data rate'] = str(rate_gh)+" (GB/h)" | |
1074 | conf['keys'].append('Data rate') |
|
1078 | conf['keys'].append('Data rate') | |
1075 | conf['Va (m/s)'] = Va |
|
1079 | conf['Va (m/s)'] = Va | |
1076 | conf['keys'].append('Va (m/s)') |
|
1080 | conf['keys'].append('Va (m/s)') | |
1077 | conf['Vrange (m/s)'] = 3/(2*IPP_s*cohe_integr) |
|
1081 | conf['Vrange (m/s)'] = 3/(2*IPP_s*cohe_integr) | |
1078 | conf['keys'].append('Vrange (m/s)') |
|
1082 | conf['keys'].append('Vrange (m/s)') | |
1079 |
|
1083 | |||
1080 | kwargs['configurations'].append(conf) |
|
1084 | kwargs['configurations'].append(conf) | |
1081 | kwargs['menu_experiments'] = 'active' |
|
1085 | kwargs['menu_experiments'] = 'active' | |
1082 |
|
1086 | |||
1083 | ###### SIDEBAR ###### |
|
1087 | ###### SIDEBAR ###### | |
1084 | kwargs.update(sidebar(experiment=experiment)) |
|
1088 | kwargs.update(sidebar(experiment=experiment)) | |
1085 |
|
1089 | |||
1086 | return render(request, 'experiment_summary.html', kwargs) |
|
1090 | return render(request, 'experiment_summary.html', kwargs) | |
1087 |
|
1091 | |||
1088 |
|
1092 | |||
1089 | @login_required |
|
1093 | @login_required | |
1090 | def experiment_verify(request, id_exp): |
|
1094 | def experiment_verify(request, id_exp): | |
1091 |
|
1095 | |||
1092 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
1096 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
1093 | experiment_data = experiment.parms_to_dict() |
|
1097 | experiment_data = experiment.parms_to_dict() | |
1094 | configurations = Configuration.objects.filter( |
|
1098 | configurations = Configuration.objects.filter( | |
1095 | experiment=experiment, type=0) |
|
1099 | experiment=experiment, type=0) | |
1096 |
|
1100 | |||
1097 | kwargs = {} |
|
1101 | kwargs = {} | |
1098 |
|
1102 | |||
1099 | kwargs['experiment_keys'] = ['template', |
|
1103 | kwargs['experiment_keys'] = ['template', | |
1100 | 'radar_system', 'name', 'start_time', 'end_time'] |
|
1104 | 'radar_system', 'name', 'start_time', 'end_time'] | |
1101 | kwargs['experiment'] = experiment |
|
1105 | kwargs['experiment'] = experiment | |
1102 |
|
1106 | |||
1103 | kwargs['configuration_keys'] = ['name', 'device__ip_address', |
|
1107 | kwargs['configuration_keys'] = ['name', 'device__ip_address', | |
1104 | 'device__port_address', 'device__status'] |
|
1108 | 'device__port_address', 'device__status'] | |
1105 | kwargs['configurations'] = configurations |
|
1109 | kwargs['configurations'] = configurations | |
1106 | kwargs['experiment_data'] = experiment_data |
|
1110 | kwargs['experiment_data'] = experiment_data | |
1107 |
|
1111 | |||
1108 | kwargs['title'] = 'Verify Experiment' |
|
1112 | kwargs['title'] = 'Verify Experiment' | |
1109 | kwargs['suptitle'] = 'Parameters' |
|
1113 | kwargs['suptitle'] = 'Parameters' | |
1110 |
|
1114 | |||
1111 | kwargs['button'] = 'Update' |
|
1115 | kwargs['button'] = 'Update' | |
1112 |
|
1116 | |||
1113 | jars_conf = False |
|
1117 | jars_conf = False | |
1114 | rc_conf = False |
|
1118 | rc_conf = False | |
1115 | dds_conf = False |
|
1119 | dds_conf = False | |
1116 |
|
1120 | |||
1117 | for configuration in configurations: |
|
1121 | for configuration in configurations: | |
1118 | #-------------------- JARS -----------------------: |
|
1122 | #-------------------- JARS -----------------------: | |
1119 | if configuration.device.device_type.name == 'jars': |
|
1123 | if configuration.device.device_type.name == 'jars': | |
1120 | jars_conf = True |
|
1124 | jars_conf = True | |
1121 | jars = configuration |
|
1125 | jars = configuration | |
1122 | kwargs['jars_conf'] = jars_conf |
|
1126 | kwargs['jars_conf'] = jars_conf | |
1123 | filter_parms = json.loads(jars.filter_parms) |
|
1127 | filter_parms = json.loads(jars.filter_parms) | |
1124 | kwargs['filter_parms'] = filter_parms |
|
1128 | kwargs['filter_parms'] = filter_parms | |
1125 | #--Sampling Frequency |
|
1129 | #--Sampling Frequency | |
1126 | clock = filter_parms['clock'] |
|
1130 | clock = filter_parms['clock'] | |
1127 | filter_2 = filter_parms['cic_2'] |
|
1131 | filter_2 = filter_parms['cic_2'] | |
1128 | filter_5 = filter_parms['cic_5'] |
|
1132 | filter_5 = filter_parms['cic_5'] | |
1129 | filter_fir = filter_parms['fir'] |
|
1133 | filter_fir = filter_parms['fir'] | |
1130 | samp_freq_jars = clock/filter_2/filter_5/filter_fir |
|
1134 | samp_freq_jars = clock/filter_2/filter_5/filter_fir | |
1131 |
|
1135 | |||
1132 | kwargs['samp_freq_jars'] = samp_freq_jars |
|
1136 | kwargs['samp_freq_jars'] = samp_freq_jars | |
1133 | kwargs['jars'] = configuration |
|
1137 | kwargs['jars'] = configuration | |
1134 |
|
1138 | |||
1135 | #--------------------- RC ----------------------: |
|
1139 | #--------------------- RC ----------------------: | |
1136 | if configuration.device.device_type.name == 'rc' and not configuration.mix: |
|
1140 | if configuration.device.device_type.name == 'rc' and not configuration.mix: | |
1137 | rc_conf = True |
|
1141 | rc_conf = True | |
1138 | rc = configuration |
|
1142 | rc = configuration | |
1139 |
|
1143 | |||
1140 | rc_parms = configuration.parms_to_dict() |
|
1144 | rc_parms = configuration.parms_to_dict() | |
1141 |
|
1145 | |||
1142 | win_lines = rc.get_lines(line_type__name='windows') |
|
1146 | win_lines = rc.get_lines(line_type__name='windows') | |
1143 | if win_lines: |
|
1147 | if win_lines: | |
1144 | dh = json.loads(win_lines[0].params)['params'][0]['resolution'] |
|
1148 | dh = json.loads(win_lines[0].params)['params'][0]['resolution'] | |
1145 | #--Sampling Frequency |
|
1149 | #--Sampling Frequency | |
1146 | samp_freq_rc = 0.15/dh |
|
1150 | samp_freq_rc = 0.15/dh | |
1147 | kwargs['samp_freq_rc'] = samp_freq_rc |
|
1151 | kwargs['samp_freq_rc'] = samp_freq_rc | |
1148 |
|
1152 | |||
1149 | kwargs['rc_conf'] = rc_conf |
|
1153 | kwargs['rc_conf'] = rc_conf | |
1150 | kwargs['rc'] = configuration |
|
1154 | kwargs['rc'] = configuration | |
1151 |
|
1155 | |||
1152 | #-------------------- DDS ----------------------: |
|
1156 | #-------------------- DDS ----------------------: | |
1153 | if configuration.device.device_type.name == 'dds': |
|
1157 | if configuration.device.device_type.name == 'dds': | |
1154 | dds_conf = True |
|
1158 | dds_conf = True | |
1155 | dds = configuration |
|
1159 | dds = configuration | |
1156 | dds_parms = configuration.parms_to_dict() |
|
1160 | dds_parms = configuration.parms_to_dict() | |
1157 |
|
1161 | |||
1158 | kwargs['dds_conf'] = dds_conf |
|
1162 | kwargs['dds_conf'] = dds_conf | |
1159 | kwargs['dds'] = configuration |
|
1163 | kwargs['dds'] = configuration | |
1160 |
|
1164 | |||
1161 | #------------Validation------------: |
|
1165 | #------------Validation------------: | |
1162 | #Clock |
|
1166 | #Clock | |
1163 | if dds_conf and rc_conf and jars_conf: |
|
1167 | if dds_conf and rc_conf and jars_conf: | |
1164 | if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) and float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']): |
|
1168 | if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) and float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']): | |
1165 | messages.warning(request, "Devices don't have the same clock.") |
|
1169 | messages.warning(request, "Devices don't have the same clock.") | |
1166 | elif rc_conf and jars_conf: |
|
1170 | elif rc_conf and jars_conf: | |
1167 | if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']): |
|
1171 | if float(filter_parms['clock']) != float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']): | |
1168 | messages.warning(request, "Devices don't have the same clock.") |
|
1172 | messages.warning(request, "Devices don't have the same clock.") | |
1169 | elif rc_conf and dds_conf: |
|
1173 | elif rc_conf and dds_conf: | |
1170 | if float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']): |
|
1174 | if float(rc_parms['configurations']['byId'][str(rc.pk)]['clock_in']) != float(dds_parms['configurations']['byId'][str(dds.pk)]['clock']): | |
1171 | messages.warning(request, "Devices don't have the same clock.") |
|
1175 | messages.warning(request, "Devices don't have the same clock.") | |
1172 | if float(samp_freq_rc) != float(dds_parms['configurations']['byId'][str(dds.pk)]['frequencyA']): |
|
1176 | if float(samp_freq_rc) != float(dds_parms['configurations']['byId'][str(dds.pk)]['frequencyA']): | |
1173 | messages.warning( |
|
1177 | messages.warning( | |
1174 | request, "Devices don't have the same Frequency A.") |
|
1178 | request, "Devices don't have the same Frequency A.") | |
1175 |
|
1179 | |||
1176 | #------------POST METHOD------------: |
|
1180 | #------------POST METHOD------------: | |
1177 | if request.method == 'POST': |
|
1181 | if request.method == 'POST': | |
1178 | if request.POST['suggest_clock']: |
|
1182 | if request.POST['suggest_clock']: | |
1179 | try: |
|
1183 | try: | |
1180 | suggest_clock = float(request.POST['suggest_clock']) |
|
1184 | suggest_clock = float(request.POST['suggest_clock']) | |
1181 | except: |
|
1185 | except: | |
1182 | messages.warning(request, "Invalid value in CLOCK IN.") |
|
1186 | messages.warning(request, "Invalid value in CLOCK IN.") | |
1183 | return redirect('url_verify_experiment', id_exp=experiment.id) |
|
1187 | return redirect('url_verify_experiment', id_exp=experiment.id) | |
1184 | else: |
|
1188 | else: | |
1185 | suggest_clock = "" |
|
1189 | suggest_clock = "" | |
1186 | if suggest_clock: |
|
1190 | if suggest_clock: | |
1187 | if rc_conf: |
|
1191 | if rc_conf: | |
1188 | rc.clock_in = suggest_clock |
|
1192 | rc.clock_in = suggest_clock | |
1189 | rc.save() |
|
1193 | rc.save() | |
1190 | if jars_conf: |
|
1194 | if jars_conf: | |
1191 | filter_parms = jars.filter_parms |
|
1195 | filter_parms = jars.filter_parms | |
1192 | filter_parms = ast.literal_eval(filter_parms) |
|
1196 | filter_parms = ast.literal_eval(filter_parms) | |
1193 | filter_parms['clock'] = suggest_clock |
|
1197 | filter_parms['clock'] = suggest_clock | |
1194 | jars.filter_parms = json.dumps(filter_parms) |
|
1198 | jars.filter_parms = json.dumps(filter_parms) | |
1195 | jars.save() |
|
1199 | jars.save() | |
1196 | kwargs['filter_parms'] = filter_parms |
|
1200 | kwargs['filter_parms'] = filter_parms | |
1197 | if dds_conf: |
|
1201 | if dds_conf: | |
1198 | dds.clock = suggest_clock |
|
1202 | dds.clock = suggest_clock | |
1199 | dds.save() |
|
1203 | dds.save() | |
1200 |
|
1204 | |||
1201 | if request.POST['suggest_frequencyA']: |
|
1205 | if request.POST['suggest_frequencyA']: | |
1202 | try: |
|
1206 | try: | |
1203 | suggest_frequencyA = float(request.POST['suggest_frequencyA']) |
|
1207 | suggest_frequencyA = float(request.POST['suggest_frequencyA']) | |
1204 | except: |
|
1208 | except: | |
1205 | messages.warning(request, "Invalid value in FREQUENCY A.") |
|
1209 | messages.warning(request, "Invalid value in FREQUENCY A.") | |
1206 | return redirect('url_verify_experiment', id_exp=experiment.id) |
|
1210 | return redirect('url_verify_experiment', id_exp=experiment.id) | |
1207 | else: |
|
1211 | else: | |
1208 | suggest_frequencyA = "" |
|
1212 | suggest_frequencyA = "" | |
1209 | if suggest_frequencyA: |
|
1213 | if suggest_frequencyA: | |
1210 | if jars_conf: |
|
1214 | if jars_conf: | |
1211 | filter_parms = jars.filter_parms |
|
1215 | filter_parms = jars.filter_parms | |
1212 | filter_parms = ast.literal_eval(filter_parms) |
|
1216 | filter_parms = ast.literal_eval(filter_parms) | |
1213 | filter_parms['fch'] = suggest_frequencyA |
|
1217 | filter_parms['fch'] = suggest_frequencyA | |
1214 | jars.filter_parms = json.dumps(filter_parms) |
|
1218 | jars.filter_parms = json.dumps(filter_parms) | |
1215 | jars.save() |
|
1219 | jars.save() | |
1216 | kwargs['filter_parms'] = filter_parms |
|
1220 | kwargs['filter_parms'] = filter_parms | |
1217 | if dds_conf: |
|
1221 | if dds_conf: | |
1218 | dds.frequencyA_Mhz = request.POST['suggest_frequencyA'] |
|
1222 | dds.frequencyA_Mhz = request.POST['suggest_frequencyA'] | |
1219 | dds.save() |
|
1223 | dds.save() | |
1220 |
|
1224 | |||
1221 | kwargs['menu_experiments'] = 'active' |
|
1225 | kwargs['menu_experiments'] = 'active' | |
1222 | kwargs.update(sidebar(experiment=experiment)) |
|
1226 | kwargs.update(sidebar(experiment=experiment)) | |
1223 | return render(request, 'experiment_verify.html', kwargs) |
|
1227 | return render(request, 'experiment_verify.html', kwargs) | |
1224 |
|
1228 | |||
1225 |
|
1229 | |||
1226 | def parse_mix_result(s): |
|
1230 | def parse_mix_result(s): | |
1227 |
|
1231 | |||
1228 | values = s.split('-') |
|
1232 | values = s.split('-') | |
1229 | html = 'EXP MOD OPE DELAY MASK\r\n' |
|
1233 | html = 'EXP MOD OPE DELAY MASK\r\n' | |
1230 |
|
1234 | |||
1231 | if not values or values[0] in ('', ' '): |
|
1235 | if not values or values[0] in ('', ' '): | |
1232 | return mark_safe(html) |
|
1236 | return mark_safe(html) | |
1233 |
|
1237 | |||
1234 | for i, value in enumerate(values): |
|
1238 | for i, value in enumerate(values): | |
1235 | if not value: |
|
1239 | if not value: | |
1236 | continue |
|
1240 | continue | |
1237 | pk, mode, operation, delay, mask = value.split('|') |
|
1241 | pk, mode, operation, delay, mask = value.split('|') | |
1238 | conf = RCConfiguration.objects.get(pk=pk) |
|
1242 | conf = RCConfiguration.objects.get(pk=pk) | |
1239 | if i == 0: |
|
1243 | if i == 0: | |
1240 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
1244 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
1241 | conf.name, |
|
1245 | conf.name, | |
1242 | mode, |
|
1246 | mode, | |
1243 | ' ', |
|
1247 | ' ', | |
1244 | delay, |
|
1248 | delay, | |
1245 | mask) |
|
1249 | mask) | |
1246 | else: |
|
1250 | else: | |
1247 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( |
|
1251 | html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format( | |
1248 | conf.name, |
|
1252 | conf.name, | |
1249 | mode, |
|
1253 | mode, | |
1250 | operation, |
|
1254 | operation, | |
1251 | delay, |
|
1255 | delay, | |
1252 | mask) |
|
1256 | mask) | |
1253 |
|
1257 | |||
1254 | return mark_safe(html) |
|
1258 | return mark_safe(html) | |
1255 |
|
1259 | |||
1256 |
|
1260 | |||
1257 | def parse_mask(l): |
|
1261 | def parse_mask(l): | |
1258 |
|
1262 | |||
1259 | values = [] |
|
1263 | values = [] | |
1260 |
|
1264 | |||
1261 | for x in range(16): |
|
1265 | for x in range(16): | |
1262 | if '{}'.format(x) in l: |
|
1266 | if '{}'.format(x) in l: | |
1263 | values.append(1) |
|
1267 | values.append(1) | |
1264 | else: |
|
1268 | else: | |
1265 | values.append(0) |
|
1269 | values.append(0) | |
1266 |
|
1270 | |||
1267 | values.reverse() |
|
1271 | values.reverse() | |
1268 |
|
1272 | |||
1269 | return int(''.join([str(x) for x in values]), 2) |
|
1273 | return int(''.join([str(x) for x in values]), 2) | |
1270 |
|
1274 | |||
1271 |
|
1275 | |||
1272 | def dev_confs(request): |
|
1276 | def dev_confs(request): | |
1273 |
|
1277 | |||
1274 | page = request.GET.get('page') |
|
1278 | page = request.GET.get('page') | |
1275 | order = ('-programmed_date', ) |
|
1279 | order = ('-programmed_date', ) | |
1276 | filters = request.GET.copy() |
|
1280 | filters = request.GET.copy() | |
1277 | if 'my configurations' in filters: |
|
1281 | if 'my configurations' in filters: | |
1278 | filters.pop('my configurations', None) |
|
1282 | filters.pop('my configurations', None) | |
1279 | filters['mine'] = request.user.id |
|
1283 | filters['mine'] = request.user.id | |
1280 | kwargs = get_paginator(Configuration, page, order, filters) |
|
1284 | kwargs = get_paginator(Configuration, page, order, filters) | |
1281 | fields = ['tags', 'template', 'historical'] |
|
1285 | fields = ['tags', 'template', 'historical'] | |
1282 | if request.user.is_authenticated: |
|
1286 | if request.user.is_authenticated: | |
1283 | fields.append('my configurations') |
|
1287 | fields.append('my configurations') | |
1284 | form = FilterForm(initial=request.GET, extra_fields=fields) |
|
1288 | form = FilterForm(initial=request.GET, extra_fields=fields) | |
1285 | kwargs['keys'] = ['name', 'experiment', |
|
1289 | kwargs['keys'] = ['name', 'experiment', | |
1286 | 'type', 'programmed_date', 'actions'] |
|
1290 | 'type', 'programmed_date', 'actions'] | |
1287 | kwargs['title'] = 'Configuration' |
|
1291 | kwargs['title'] = 'Configuration' | |
1288 | kwargs['suptitle'] = 'List' |
|
1292 | kwargs['suptitle'] = 'List' | |
1289 | kwargs['no_sidebar'] = True |
|
1293 | kwargs['no_sidebar'] = True | |
1290 | kwargs['form'] = form |
|
1294 | kwargs['form'] = form | |
1291 | kwargs['add_url'] = reverse('url_add_dev_conf', args=[0]) |
|
1295 | kwargs['add_url'] = reverse('url_add_dev_conf', args=[0]) | |
1292 | filters = request.GET.copy() |
|
1296 | filters = request.GET.copy() | |
1293 | filters.pop('page', None) |
|
1297 | filters.pop('page', None) | |
1294 | kwargs['q'] = urlencode(filters) |
|
1298 | kwargs['q'] = urlencode(filters) | |
1295 | kwargs['menu_configurations'] = 'active' |
|
1299 | kwargs['menu_configurations'] = 'active' | |
1296 |
|
1300 | |||
1297 | return render(request, 'base_list.html', kwargs) |
|
1301 | return render(request, 'base_list.html', kwargs) | |
1298 |
|
1302 | |||
1299 |
|
1303 | |||
1300 | def dev_conf(request, id_conf): |
|
1304 | def dev_conf(request, id_conf): | |
1301 |
|
1305 | |||
1302 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1306 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1303 |
|
1307 | |||
1304 | return redirect(conf.get_absolute_url()) |
|
1308 | return redirect(conf.get_absolute_url()) | |
1305 |
|
1309 | |||
1306 |
|
1310 | |||
1307 | @login_required |
|
1311 | @login_required | |
1308 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
1312 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
1309 |
|
1313 | |||
1310 | if not is_developer(request.user): |
|
1314 | if not is_developer(request.user): | |
1311 | messages.error( |
|
1315 | messages.error( | |
1312 | request, 'Developer required, to create new configurations') |
|
1316 | request, 'Developer required, to create new configurations') | |
1313 | return redirect('index') |
|
1317 | return redirect('index') | |
1314 |
|
1318 | |||
1315 | initial = {} |
|
1319 | initial = {} | |
1316 | kwargs = {} |
|
1320 | kwargs = {} | |
1317 |
|
1321 | |||
1318 | if id_exp != 0: |
|
1322 | if id_exp != 0: | |
1319 | initial['experiment'] = id_exp |
|
1323 | initial['experiment'] = id_exp | |
1320 |
|
1324 | |||
1321 | if id_dev != 0: |
|
1325 | if id_dev != 0: | |
1322 | initial['device'] = id_dev |
|
1326 | initial['device'] = id_dev | |
1323 |
|
1327 | |||
1324 | if request.method == 'GET': |
|
1328 | if request.method == 'GET': | |
1325 |
|
1329 | |||
1326 | if id_dev: |
|
1330 | if id_dev: | |
1327 | kwargs['button'] = 'Create' |
|
1331 | kwargs['button'] = 'Create' | |
1328 | device = Device.objects.get(pk=id_dev) |
|
1332 | device = Device.objects.get(pk=id_dev) | |
1329 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
1333 | DevConfForm = CONF_FORMS[device.device_type.name] | |
1330 | initial['name'] = request.GET['name'] |
|
1334 | initial['name'] = request.GET['name'] | |
1331 | form = DevConfForm(initial=initial) |
|
1335 | form = DevConfForm(initial=initial) | |
1332 | else: |
|
1336 | else: | |
1333 | if 'template' in request.GET: |
|
1337 | if 'template' in request.GET: | |
1334 | if request.GET['template'] == '0': |
|
1338 | if request.GET['template'] == '0': | |
1335 | choices = [(conf.pk, '{}'.format(conf)) |
|
1339 | choices = [(conf.pk, '{}'.format(conf)) | |
1336 | for conf in Configuration.objects.filter(template=True)] |
|
1340 | for conf in Configuration.objects.filter(template=True)] | |
1337 | form = NewForm(initial={'create_from': 2}, |
|
1341 | form = NewForm(initial={'create_from': 2}, | |
1338 | template_choices=choices) |
|
1342 | template_choices=choices) | |
1339 | else: |
|
1343 | else: | |
1340 | kwargs['button'] = 'Create' |
|
1344 | kwargs['button'] = 'Create' | |
1341 | conf = Configuration.objects.get( |
|
1345 | conf = Configuration.objects.get( | |
1342 | pk=request.GET['template']) |
|
1346 | pk=request.GET['template']) | |
1343 | id_dev = conf.device.pk |
|
1347 | id_dev = conf.device.pk | |
1344 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1348 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1345 | form = DevConfForm(instance=conf, |
|
1349 | form = DevConfForm(instance=conf, | |
1346 | initial={'name': '{}_{:%y%m%d}'.format(conf.name, datetime.now()), |
|
1350 | initial={'name': '{}_{:%y%m%d}'.format(conf.name, datetime.now()), | |
1347 | 'template': False, |
|
1351 | 'template': False, | |
1348 | 'experiment': id_exp}) |
|
1352 | 'experiment': id_exp}) | |
1349 | elif 'blank' in request.GET: |
|
1353 | elif 'blank' in request.GET: | |
1350 | kwargs['button'] = 'Create' |
|
1354 | kwargs['button'] = 'Create' | |
1351 | form = ConfigurationForm(initial=initial) |
|
1355 | form = ConfigurationForm(initial=initial) | |
1352 | else: |
|
1356 | else: | |
1353 | form = NewForm() |
|
1357 | form = NewForm() | |
1354 |
|
1358 | |||
1355 | if request.method == 'POST': |
|
1359 | if request.method == 'POST': | |
1356 |
|
1360 | |||
1357 | device = Device.objects.get(pk=request.POST['device']) |
|
1361 | device = Device.objects.get(pk=request.POST['device']) | |
1358 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
1362 | DevConfForm = CONF_FORMS[device.device_type.name] | |
1359 |
|
1363 | |||
1360 | form = DevConfForm(request.POST) |
|
1364 | form = DevConfForm(request.POST) | |
1361 | kwargs['button'] = 'Create' |
|
1365 | kwargs['button'] = 'Create' | |
1362 | if form.is_valid(): |
|
1366 | if form.is_valid(): | |
1363 | conf = form.save(commit=False) |
|
1367 | conf = form.save(commit=False) | |
1364 | conf.author = request.user |
|
1368 | conf.author = request.user | |
1365 | conf.save() |
|
1369 | conf.save() | |
1366 |
|
1370 | |||
1367 | if 'template' in request.GET and conf.device.device_type.name == 'rc': |
|
1371 | if 'template' in request.GET and conf.device.device_type.name == 'rc': | |
1368 | lines = RCLine.objects.filter( |
|
1372 | lines = RCLine.objects.filter( | |
1369 | rc_configuration=request.GET['template']) |
|
1373 | rc_configuration=request.GET['template']) | |
1370 | for line in lines: |
|
1374 | for line in lines: | |
1371 | line.clone(rc_configuration=conf) |
|
1375 | line.clone(rc_configuration=conf) | |
1372 |
|
1376 | |||
1373 | new_lines = conf.get_lines() |
|
1377 | new_lines = conf.get_lines() | |
1374 | for line in new_lines: |
|
1378 | for line in new_lines: | |
1375 | line_params = json.loads(line.params) |
|
1379 | line_params = json.loads(line.params) | |
1376 | if 'TX_ref' in line_params: |
|
1380 | if 'TX_ref' in line_params: | |
1377 | ref_line = RCLine.objects.get(pk=line_params['TX_ref']) |
|
1381 | ref_line = RCLine.objects.get(pk=line_params['TX_ref']) | |
1378 | line_params['TX_ref'] = ['{}'.format( |
|
1382 | line_params['TX_ref'] = ['{}'.format( | |
1379 | l.pk) for l in new_lines if l.get_name() == ref_line.get_name()][0] |
|
1383 | l.pk) for l in new_lines if l.get_name() == ref_line.get_name()][0] | |
1380 | line.params = json.dumps(line_params) |
|
1384 | line.params = json.dumps(line_params) | |
1381 | line.save() |
|
1385 | line.save() | |
1382 | elif conf.device.device_type.name == 'rc': |
|
1386 | elif conf.device.device_type.name == 'rc': | |
1383 | clk = RCClock(rc_configuration=conf) |
|
1387 | clk = RCClock(rc_configuration=conf) | |
1384 | clk.save() |
|
1388 | clk.save() | |
1385 |
|
1389 | |||
1386 | return redirect('url_dev_conf', id_conf=conf.pk) |
|
1390 | return redirect('url_dev_conf', id_conf=conf.pk) | |
1387 |
|
1391 | |||
1388 | kwargs['id_exp'] = id_exp |
|
1392 | kwargs['id_exp'] = id_exp | |
1389 | kwargs['form'] = form |
|
1393 | kwargs['form'] = form | |
1390 | kwargs['title'] = 'Configuration' |
|
1394 | kwargs['title'] = 'Configuration' | |
1391 | kwargs['suptitle'] = 'New' |
|
1395 | kwargs['suptitle'] = 'New' | |
1392 | kwargs['menu_configurations'] = 'active' |
|
1396 | kwargs['menu_configurations'] = 'active' | |
1393 |
|
1397 | |||
1394 | if id_dev != 0: |
|
1398 | if id_dev != 0: | |
1395 | device = Device.objects.get(pk=id_dev) |
|
1399 | device = Device.objects.get(pk=id_dev) | |
1396 | kwargs['device'] = device.device_type.name |
|
1400 | kwargs['device'] = device.device_type.name | |
1397 | print(id_exp) |
|
1401 | print(id_exp) | |
1398 | return render(request, 'dev_conf_edit.html', kwargs) |
|
1402 | return render(request, 'dev_conf_edit.html', kwargs) | |
1399 |
|
1403 | |||
1400 |
|
1404 | |||
1401 | @login_required |
|
1405 | @login_required | |
1402 | def dev_conf_edit(request, id_conf): |
|
1406 | def dev_conf_edit(request, id_conf): | |
1403 |
|
1407 | |||
1404 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1408 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1405 |
|
1409 | |||
1406 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1410 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1407 |
|
1411 | |||
1408 | if request.method == 'GET': |
|
1412 | if request.method == 'GET': | |
1409 | form = DevConfForm(instance=conf) |
|
1413 | form = DevConfForm(instance=conf) | |
1410 |
|
1414 | |||
1411 | if request.method == 'POST': |
|
1415 | if request.method == 'POST': | |
1412 | form = DevConfForm(request.POST, instance=conf) |
|
1416 | form = DevConfForm(request.POST, instance=conf) | |
1413 |
|
1417 | |||
1414 | if form.is_valid(): |
|
1418 | if form.is_valid(): | |
1415 | form.save() |
|
1419 | form.save() | |
1416 | return redirect('url_dev_conf', id_conf=id_conf) |
|
1420 | return redirect('url_dev_conf', id_conf=id_conf) | |
1417 |
|
1421 | |||
1418 | kwargs = {} |
|
1422 | kwargs = {} | |
1419 | kwargs['form'] = form |
|
1423 | kwargs['form'] = form | |
1420 | kwargs['title'] = 'Device Configuration' |
|
1424 | kwargs['title'] = 'Device Configuration' | |
1421 | kwargs['suptitle'] = 'Edit' |
|
1425 | kwargs['suptitle'] = 'Edit' | |
1422 | kwargs['button'] = 'Update' |
|
1426 | kwargs['button'] = 'Update' | |
1423 | kwargs['menu_configurations'] = 'active' |
|
1427 | kwargs['menu_configurations'] = 'active' | |
1424 |
|
1428 | |||
1425 | ###### SIDEBAR ###### |
|
1429 | ###### SIDEBAR ###### | |
1426 | kwargs.update(sidebar(conf=conf)) |
|
1430 | kwargs.update(sidebar(conf=conf)) | |
1427 |
|
1431 | |||
1428 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1432 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1429 |
|
1433 | |||
1430 |
|
1434 | |||
1431 | @login_required |
|
1435 | @login_required | |
1432 | def dev_conf_start(request, id_conf): |
|
1436 | def dev_conf_start(request, id_conf): | |
1433 |
|
1437 | |||
1434 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1438 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1435 |
|
1439 | |||
1436 | if conf.start_device(): |
|
1440 | if conf.start_device(): | |
1437 | messages.success(request, conf.message) |
|
1441 | messages.success(request, conf.message) | |
1438 | else: |
|
1442 | else: | |
1439 | messages.error(request, conf.message) |
|
1443 | messages.error(request, conf.message) | |
1440 |
|
1444 | |||
1441 | #conf.status_device() |
|
1445 | #conf.status_device() | |
1442 |
|
1446 | |||
1443 | return redirect(conf.get_absolute_url()) |
|
1447 | return redirect(conf.get_absolute_url()) | |
1444 |
|
1448 | |||
1445 |
|
1449 | |||
1446 | @login_required |
|
1450 | @login_required | |
1447 | def dev_conf_stop(request, id_conf): |
|
1451 | def dev_conf_stop(request, id_conf): | |
1448 |
|
1452 | |||
1449 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1453 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1450 |
|
1454 | |||
1451 | if conf.stop_device(): |
|
1455 | if conf.stop_device(): | |
1452 | messages.success(request, conf.message) |
|
1456 | messages.success(request, conf.message) | |
1453 | else: |
|
1457 | else: | |
1454 | messages.error(request, conf.message) |
|
1458 | messages.error(request, conf.message) | |
1455 |
|
1459 | |||
1456 | #conf.status_device() |
|
1460 | #conf.status_device() | |
1457 |
|
1461 | |||
1458 | return redirect(conf.get_absolute_url()) |
|
1462 | return redirect(conf.get_absolute_url()) | |
1459 |
|
1463 | |||
1460 |
|
1464 | |||
1461 | @login_required |
|
1465 | @login_required | |
1462 | def dev_conf_status(request, id_conf): |
|
1466 | def dev_conf_status(request, id_conf): | |
1463 |
|
1467 | |||
1464 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1468 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1465 |
|
1469 | |||
1466 | conf_active = Configuration.objects.filter(pk=conf.device.conf_active).first() |
|
1470 | conf_active = Configuration.objects.filter(pk=conf.device.conf_active).first() | |
1467 | if conf_active!=conf: |
|
1471 | if conf_active!=conf: | |
1468 | url = '#' if conf_active is None else conf_active.get_absolute_url() |
|
1472 | url = '#' if conf_active is None else conf_active.get_absolute_url() | |
1469 | label = 'None' if conf_active is None else conf_active.label |
|
1473 | label = 'None' if conf_active is None else conf_active.label | |
1470 | messages.warning( |
|
1474 | messages.warning( | |
1471 | request, |
|
1475 | request, | |
1472 | mark_safe('The current configuration has not been written to device, the active configuration is <a href="{}">{}</a>'.format( |
|
1476 | mark_safe('The current configuration has not been written to device, the active configuration is <a href="{}">{}</a>'.format( | |
1473 | url, |
|
1477 | url, | |
1474 | label |
|
1478 | label | |
1475 | )) |
|
1479 | )) | |
1476 | ) |
|
1480 | ) | |
1477 |
|
1481 | |||
1478 | return redirect(conf.get_absolute_url()) |
|
1482 | return redirect(conf.get_absolute_url()) | |
1479 |
|
1483 | |||
1480 | if conf.status_device(): |
|
1484 | if conf.status_device(): | |
1481 | messages.success(request, conf.message) |
|
1485 | messages.success(request, conf.message) | |
1482 | else: |
|
1486 | else: | |
1483 | messages.error(request, conf.message) |
|
1487 | messages.error(request, conf.message) | |
1484 |
|
1488 | |||
1485 | return redirect(conf.get_absolute_url()) |
|
1489 | return redirect(conf.get_absolute_url()) | |
1486 |
|
1490 | |||
1487 |
|
1491 | |||
1488 | @login_required |
|
1492 | @login_required | |
1489 | def dev_conf_reset(request, id_conf): |
|
1493 | def dev_conf_reset(request, id_conf): | |
1490 |
|
1494 | |||
1491 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1495 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1492 |
|
1496 | |||
1493 | if conf.reset_device(): |
|
1497 | if conf.reset_device(): | |
1494 | messages.success(request, conf.message) |
|
1498 | messages.success(request, conf.message) | |
1495 | else: |
|
1499 | else: | |
1496 | messages.error(request, conf.message) |
|
1500 | messages.error(request, conf.message) | |
1497 |
|
1501 | |||
1498 | return redirect(conf.get_absolute_url()) |
|
1502 | return redirect(conf.get_absolute_url()) | |
1499 |
|
1503 | |||
1500 |
|
1504 | |||
1501 | @login_required |
|
1505 | @login_required | |
1502 | def dev_conf_write(request, id_conf): |
|
1506 | def dev_conf_write(request, id_conf): | |
1503 |
|
1507 | |||
1504 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1508 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1505 |
|
1509 | |||
1506 | if request.method == 'POST': |
|
1510 | if request.method == 'POST': | |
1507 | if conf.write_device(): |
|
1511 | if conf.write_device(): | |
1508 | conf.device.conf_active = conf.pk |
|
1512 | conf.device.conf_active = conf.pk | |
1509 | conf.device.save() |
|
1513 | conf.device.save() | |
1510 | messages.success(request, conf.message) |
|
1514 | messages.success(request, conf.message) | |
1511 | if has_been_modified(conf): |
|
1515 | if has_been_modified(conf): | |
1512 | conf.clone(type=1, template=False) |
|
1516 | conf.clone(type=1, template=False) | |
1513 | else: |
|
1517 | else: | |
1514 | messages.error(request, conf.message) |
|
1518 | messages.error(request, conf.message) | |
1515 |
|
1519 | |||
1516 | return redirect(get_object_or_404(Configuration, pk=id_conf).get_absolute_url()) |
|
1520 | return redirect(get_object_or_404(Configuration, pk=id_conf).get_absolute_url()) | |
1517 |
|
1521 | |||
1518 | kwargs = { |
|
1522 | kwargs = { | |
1519 | 'title': 'Write Configuration', |
|
1523 | 'title': 'Write Configuration', | |
1520 | 'suptitle': conf.label, |
|
1524 | 'suptitle': conf.label, | |
1521 | 'message': 'Are you sure yo want to write this {} configuration?'.format(conf.device), |
|
1525 | 'message': 'Are you sure yo want to write this {} configuration?'.format(conf.device), | |
1522 | 'delete': False |
|
1526 | 'delete': False | |
1523 | } |
|
1527 | } | |
1524 | kwargs['menu_configurations'] = 'active' |
|
1528 | kwargs['menu_configurations'] = 'active' | |
1525 |
|
1529 | |||
1526 | return render(request, 'confirm.html', kwargs) |
|
1530 | return render(request, 'confirm.html', kwargs) | |
1527 |
|
1531 | |||
1528 |
|
1532 | |||
1529 | @login_required |
|
1533 | @login_required | |
1530 | def dev_conf_read(request, id_conf): |
|
1534 | def dev_conf_read(request, id_conf): | |
1531 |
|
1535 | |||
1532 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1536 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1533 |
|
1537 | |||
1534 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1538 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1535 |
|
1539 | |||
1536 | if request.method == 'GET': |
|
1540 | if request.method == 'GET': | |
1537 |
|
1541 | |||
1538 | parms = conf.read_device() |
|
1542 | parms = conf.read_device() | |
1539 | #conf.status_device() |
|
1543 | #conf.status_device() | |
1540 |
|
1544 | |||
1541 | if not parms: |
|
1545 | if not parms: | |
1542 | messages.error(request, conf.message) |
|
1546 | messages.error(request, conf.message) | |
1543 | return redirect(conf.get_absolute_url()) |
|
1547 | return redirect(conf.get_absolute_url()) | |
1544 |
|
1548 | |||
1545 | form = DevConfForm(initial=parms, instance=conf) |
|
1549 | form = DevConfForm(initial=parms, instance=conf) | |
1546 |
|
1550 | |||
1547 | if request.method == 'POST': |
|
1551 | if request.method == 'POST': | |
1548 | form = DevConfForm(request.POST, instance=conf) |
|
1552 | form = DevConfForm(request.POST, instance=conf) | |
1549 |
|
1553 | |||
1550 | if form.is_valid(): |
|
1554 | if form.is_valid(): | |
1551 | form.save() |
|
1555 | form.save() | |
1552 | return redirect(conf.get_absolute_url()) |
|
1556 | return redirect(conf.get_absolute_url()) | |
1553 |
|
1557 | |||
1554 | messages.error(request, "Parameters could not be saved") |
|
1558 | messages.error(request, "Parameters could not be saved") | |
1555 |
|
1559 | |||
1556 | kwargs = {} |
|
1560 | kwargs = {} | |
1557 | kwargs['id_dev'] = conf.id |
|
1561 | kwargs['id_dev'] = conf.id | |
1558 | kwargs['form'] = form |
|
1562 | kwargs['form'] = form | |
1559 | kwargs['title'] = 'Device Configuration' |
|
1563 | kwargs['title'] = 'Device Configuration' | |
1560 | kwargs['suptitle'] = 'Parameters read from device' |
|
1564 | kwargs['suptitle'] = 'Parameters read from device' | |
1561 | kwargs['button'] = 'Save' |
|
1565 | kwargs['button'] = 'Save' | |
1562 |
|
1566 | |||
1563 | ###### SIDEBAR ###### |
|
1567 | ###### SIDEBAR ###### | |
1564 | kwargs.update(sidebar(conf=conf)) |
|
1568 | kwargs.update(sidebar(conf=conf)) | |
1565 |
|
1569 | |||
1566 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1570 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1567 |
|
1571 | |||
1568 |
|
1572 | |||
1569 | @login_required |
|
1573 | @login_required | |
1570 | def dev_conf_import(request, id_conf): |
|
1574 | def dev_conf_import(request, id_conf): | |
1571 |
|
1575 | |||
1572 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1576 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1573 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1577 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
1574 |
|
1578 | |||
1575 | if request.method == 'GET': |
|
1579 | if request.method == 'GET': | |
1576 | file_form = UploadFileForm() |
|
1580 | file_form = UploadFileForm() | |
1577 |
|
1581 | |||
1578 | if request.method == 'POST': |
|
1582 | if request.method == 'POST': | |
1579 | file_form = UploadFileForm(request.POST, request.FILES) |
|
1583 | file_form = UploadFileForm(request.POST, request.FILES) | |
1580 |
|
1584 | |||
1581 | if file_form.is_valid(): |
|
1585 | if file_form.is_valid(): | |
1582 |
|
1586 | |||
1583 | data = conf.import_from_file(request.FILES['file']) |
|
1587 | data = conf.import_from_file(request.FILES['file']) | |
1584 | parms = Params(data=data).get_conf( |
|
1588 | parms = Params(data=data).get_conf( | |
1585 | dtype=conf.device.device_type.name) |
|
1589 | dtype=conf.device.device_type.name) | |
1586 |
|
1590 | |||
1587 | if parms: |
|
1591 | if parms: | |
1588 |
|
1592 | |||
1589 | form = DevConfForm(initial=parms, instance=conf) |
|
1593 | form = DevConfForm(initial=parms, instance=conf) | |
1590 |
|
1594 | |||
1591 | kwargs = {} |
|
1595 | kwargs = {} | |
1592 | kwargs['id_dev'] = conf.id |
|
1596 | kwargs['id_dev'] = conf.id | |
1593 | kwargs['form'] = form |
|
1597 | kwargs['form'] = form | |
1594 | kwargs['title'] = 'Device Configuration' |
|
1598 | kwargs['title'] = 'Device Configuration' | |
1595 | kwargs['suptitle'] = 'Parameters imported' |
|
1599 | kwargs['suptitle'] = 'Parameters imported' | |
1596 | kwargs['button'] = 'Save' |
|
1600 | kwargs['button'] = 'Save' | |
1597 | kwargs['action'] = conf.get_absolute_url_edit() |
|
1601 | kwargs['action'] = conf.get_absolute_url_edit() | |
1598 | kwargs['previous'] = conf.get_absolute_url() |
|
1602 | kwargs['previous'] = conf.get_absolute_url() | |
1599 |
|
1603 | |||
1600 | ###### SIDEBAR ###### |
|
1604 | ###### SIDEBAR ###### | |
1601 | kwargs.update(sidebar(conf=conf)) |
|
1605 | kwargs.update(sidebar(conf=conf)) | |
1602 |
|
1606 | |||
1603 | messages.success( |
|
1607 | messages.success( | |
1604 | request, "Parameters imported from: '%s'." % request.FILES['file'].name) |
|
1608 | request, "Parameters imported from: '%s'." % request.FILES['file'].name) | |
1605 |
|
1609 | |||
1606 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1610 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
1607 |
|
1611 | |||
1608 | messages.error(request, "Could not import parameters from file") |
|
1612 | messages.error(request, "Could not import parameters from file") | |
1609 |
|
1613 | |||
1610 | kwargs = {} |
|
1614 | kwargs = {} | |
1611 | kwargs['id_dev'] = conf.id |
|
1615 | kwargs['id_dev'] = conf.id | |
1612 | kwargs['title'] = 'Device Configuration' |
|
1616 | kwargs['title'] = 'Device Configuration' | |
1613 | kwargs['form'] = file_form |
|
1617 | kwargs['form'] = file_form | |
1614 | kwargs['suptitle'] = 'Importing file' |
|
1618 | kwargs['suptitle'] = 'Importing file' | |
1615 | kwargs['button'] = 'Import' |
|
1619 | kwargs['button'] = 'Import' | |
1616 | kwargs['menu_configurations'] = 'active' |
|
1620 | kwargs['menu_configurations'] = 'active' | |
1617 |
|
1621 | |||
1618 | kwargs.update(sidebar(conf=conf)) |
|
1622 | kwargs.update(sidebar(conf=conf)) | |
1619 |
|
1623 | |||
1620 | return render(request, 'dev_conf_import.html', kwargs) |
|
1624 | return render(request, 'dev_conf_import.html', kwargs) | |
1621 |
|
1625 | |||
1622 |
|
1626 | |||
1623 | @login_required |
|
1627 | @login_required | |
1624 | def dev_conf_export(request, id_conf): |
|
1628 | def dev_conf_export(request, id_conf): | |
1625 |
|
1629 | |||
1626 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1630 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1627 |
|
1631 | |||
1628 | if request.method == 'GET': |
|
1632 | if request.method == 'GET': | |
1629 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1633 | file_form = DownloadFileForm(conf.device.device_type.name) | |
1630 |
|
1634 | |||
1631 | if request.method == 'POST': |
|
1635 | if request.method == 'POST': | |
1632 | file_form = DownloadFileForm( |
|
1636 | file_form = DownloadFileForm( | |
1633 | conf.device.device_type.name, request.POST) |
|
1637 | conf.device.device_type.name, request.POST) | |
1634 |
|
1638 | |||
1635 | if file_form.is_valid(): |
|
1639 | if file_form.is_valid(): | |
1636 | fields = conf.export_to_file( |
|
1640 | fields = conf.export_to_file( | |
1637 | format=file_form.cleaned_data['format']) |
|
1641 | format=file_form.cleaned_data['format']) | |
1638 | if not fields['content']: |
|
1642 | if not fields['content']: | |
1639 | messages.error(request, conf.message) |
|
1643 | messages.error(request, conf.message) | |
1640 | return redirect(conf.get_absolute_url_export()) |
|
1644 | return redirect(conf.get_absolute_url_export()) | |
1641 | response = HttpResponse(content_type=fields['content_type']) |
|
1645 | response = HttpResponse(content_type=fields['content_type']) | |
1642 | response['Content-Disposition'] = 'attachment; filename="%s"' % fields['filename'] |
|
1646 | response['Content-Disposition'] = 'attachment; filename="%s"' % fields['filename'] | |
1643 | response.write(fields['content']) |
|
1647 | response.write(fields['content']) | |
1644 |
|
1648 | |||
1645 | return response |
|
1649 | return response | |
1646 |
|
1650 | |||
1647 | messages.error(request, "Could not export parameters") |
|
1651 | messages.error(request, "Could not export parameters") | |
1648 |
|
1652 | |||
1649 | kwargs = {} |
|
1653 | kwargs = {} | |
1650 | kwargs['id_dev'] = conf.id |
|
1654 | kwargs['id_dev'] = conf.id | |
1651 | kwargs['title'] = 'Device Configuration' |
|
1655 | kwargs['title'] = 'Device Configuration' | |
1652 | kwargs['form'] = file_form |
|
1656 | kwargs['form'] = file_form | |
1653 | kwargs['suptitle'] = 'Exporting file' |
|
1657 | kwargs['suptitle'] = 'Exporting file' | |
1654 | kwargs['button'] = 'Export' |
|
1658 | kwargs['button'] = 'Export' | |
1655 | kwargs['menu_configurations'] = 'active' |
|
1659 | kwargs['menu_configurations'] = 'active' | |
1656 |
|
1660 | |||
1657 | return render(request, 'dev_conf_export.html', kwargs) |
|
1661 | return render(request, 'dev_conf_export.html', kwargs) | |
1658 |
|
1662 | |||
1659 |
|
1663 | |||
1660 | @login_required |
|
1664 | @login_required | |
1661 | def dev_conf_delete(request, id_conf): |
|
1665 | def dev_conf_delete(request, id_conf): | |
1662 |
|
1666 | |||
1663 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1667 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1664 |
|
1668 | |||
1665 | if request.method == 'POST': |
|
1669 | if request.method == 'POST': | |
1666 | if is_developer(request.user): |
|
1670 | if is_developer(request.user): | |
1667 | conf.delete() |
|
1671 | conf.delete() | |
1668 | return redirect('url_dev_confs') |
|
1672 | return redirect('url_dev_confs') | |
1669 |
|
1673 | |||
1670 | messages.error(request, 'Not enough permission to delete this object') |
|
1674 | messages.error(request, 'Not enough permission to delete this object') | |
1671 | return redirect(conf.get_absolute_url()) |
|
1675 | return redirect(conf.get_absolute_url()) | |
1672 |
|
1676 | |||
1673 | kwargs = { |
|
1677 | kwargs = { | |
1674 | 'title': 'Delete', |
|
1678 | 'title': 'Delete', | |
1675 | 'suptitle': 'Configuration', |
|
1679 | 'suptitle': 'Configuration', | |
1676 | 'object': conf, |
|
1680 | 'object': conf, | |
1677 | 'delete': True |
|
1681 | 'delete': True | |
1678 | } |
|
1682 | } | |
1679 | kwargs['menu_configurations'] = 'active' |
|
1683 | kwargs['menu_configurations'] = 'active' | |
1680 |
|
1684 | |||
1681 | return render(request, 'confirm.html', kwargs) |
|
1685 | return render(request, 'confirm.html', kwargs) | |
1682 |
|
1686 | |||
1683 |
|
1687 | |||
1684 | def sidebar(**kwargs): |
|
1688 | def sidebar(**kwargs): | |
1685 |
|
1689 | |||
1686 | side_data = {} |
|
1690 | side_data = {} | |
1687 |
|
1691 | |||
1688 | conf = kwargs.get('conf', None) |
|
1692 | conf = kwargs.get('conf', None) | |
1689 | experiment = kwargs.get('experiment', None) |
|
1693 | experiment = kwargs.get('experiment', None) | |
1690 |
|
1694 | |||
1691 | if not experiment: |
|
1695 | if not experiment: | |
1692 | experiment = conf.experiment |
|
1696 | experiment = conf.experiment | |
1693 |
|
1697 | |||
1694 | if experiment: |
|
1698 | if experiment: | |
1695 | side_data['experiment'] = experiment |
|
1699 | side_data['experiment'] = experiment | |
1696 | campaign = experiment.campaign_set.all() |
|
1700 | campaign = experiment.campaign_set.all() | |
1697 | if campaign: |
|
1701 | if campaign: | |
1698 | side_data['campaign'] = campaign[0] |
|
1702 | side_data['campaign'] = campaign[0] | |
1699 | experiments = campaign[0].experiments.all().order_by('name') |
|
1703 | experiments = campaign[0].experiments.all().order_by('name') | |
1700 | else: |
|
1704 | else: | |
1701 | experiments = [experiment] |
|
1705 | experiments = [experiment] | |
1702 | configurations = experiment.configuration_set.filter(type=0) |
|
1706 | configurations = experiment.configuration_set.filter(type=0) | |
1703 | side_data['side_experiments'] = experiments |
|
1707 | side_data['side_experiments'] = experiments | |
1704 | side_data['side_configurations'] = configurations.order_by( |
|
1708 | side_data['side_configurations'] = configurations.order_by( | |
1705 | 'device__device_type__name') |
|
1709 | 'device__device_type__name') | |
1706 |
|
1710 | |||
1707 | return side_data |
|
1711 | return side_data | |
1708 |
|
1712 | |||
1709 | def get_paginator(model, page, order, filters={}, n=8): |
|
1713 | def get_paginator(model, page, order, filters={}, n=8): | |
1710 | kwargs = {} |
|
1714 | kwargs = {} | |
1711 | query = Q() |
|
1715 | query = Q() | |
1712 | if isinstance(filters, QueryDict): |
|
1716 | if isinstance(filters, QueryDict): | |
1713 | filters = filters.dict() |
|
1717 | filters = filters.dict() | |
1714 | copy_filters=filters.copy() |
|
1718 | copy_filters=filters.copy() | |
1715 | [filters.pop(key) for key in copy_filters.keys() if copy_filters[key] in (' ', ' ')] |
|
1719 | [filters.pop(key) for key in copy_filters.keys() if copy_filters[key] in (' ', ' ')] | |
1716 | filters.pop('page', None) |
|
1720 | filters.pop('page', None) | |
1717 |
|
1721 | |||
1718 | fields = [f.name for f in model._meta.get_fields()] |
|
1722 | fields = [f.name for f in model._meta.get_fields()] | |
1719 |
|
1723 | |||
1720 | if 'template' in copy_filters: |
|
1724 | if 'template' in copy_filters: | |
1721 | filters['template'] = True |
|
1725 | filters['template'] = True | |
1722 | if 'historical' in copy_filters: |
|
1726 | if 'historical' in copy_filters: | |
1723 | filters.pop('historical') |
|
1727 | filters.pop('historical') | |
1724 | filters['type'] = 1 |
|
1728 | filters['type'] = 1 | |
1725 | elif 'type' in fields: |
|
1729 | elif 'type' in fields: | |
1726 | filters['type'] = 0 |
|
1730 | filters['type'] = 0 | |
1727 | if 'start_date' in copy_filters: |
|
1731 | if 'start_date' in copy_filters: | |
1728 | filters['start_date__gte'] =filters.pop('start_date') |
|
1732 | filters['start_date__gte'] =filters.pop('start_date') | |
1729 | if 'end_date' in copy_filters: |
|
1733 | if 'end_date' in copy_filters: | |
1730 | filters['start_date__lte'] =filters.pop('end_date') |
|
1734 | filters['start_date__lte'] =filters.pop('end_date') | |
1731 | if 'tags' in copy_filters: |
|
1735 | if 'tags' in copy_filters: | |
1732 | tags =filters.pop('tags') |
|
1736 | tags =filters.pop('tags') | |
1733 | if 'tags' in fields: |
|
1737 | if 'tags' in fields: | |
1734 | query = query | Q(tags__icontains=tags) |
|
1738 | query = query | Q(tags__icontains=tags) | |
1735 | if 'label' in fields: |
|
1739 | if 'label' in fields: | |
1736 | query = query | Q(label__icontains=tags) |
|
1740 | query = query | Q(label__icontains=tags) | |
1737 | if 'location' in fields: |
|
1741 | if 'location' in fields: | |
1738 | query = query | Q(location__name__icontains=tags) |
|
1742 | query = query | Q(location__name__icontains=tags) | |
1739 | if 'device' in fields: |
|
1743 | if 'device' in fields: | |
1740 | query = query | Q(device__device_type__name__icontains=tags) |
|
1744 | query = query | Q(device__device_type__name__icontains=tags) | |
1741 | query = query | Q(device__location__name__icontains=tags) |
|
1745 | query = query | Q(device__location__name__icontains=tags) | |
1742 | if 'device_type' in fields: |
|
1746 | if 'device_type' in fields: | |
1743 | query = query | Q(device_type__name__icontains=tags) |
|
1747 | query = query | Q(device_type__name__icontains=tags) | |
1744 |
|
1748 | |||
1745 | if 'mine' in copy_filters: |
|
1749 | if 'mine' in copy_filters: | |
1746 | filters['author_id'] =filters['mine'] |
|
1750 | filters['author_id'] =filters['mine'] | |
1747 | filters.pop('mine') |
|
1751 | filters.pop('mine') | |
1748 | object_list = model.objects.filter(query, **filters).order_by(*order) |
|
1752 | object_list = model.objects.filter(query, **filters).order_by(*order) | |
1749 | paginator = Paginator(object_list, n) |
|
1753 | paginator = Paginator(object_list, n) | |
1750 |
|
1754 | |||
1751 | try: |
|
1755 | try: | |
1752 | objects = paginator.page(page) |
|
1756 | objects = paginator.page(page) | |
1753 | except PageNotAnInteger: |
|
1757 | except PageNotAnInteger: | |
1754 | objects = paginator.page(1) |
|
1758 | objects = paginator.page(1) | |
1755 | except EmptyPage: |
|
1759 | except EmptyPage: | |
1756 | objects = paginator.page(paginator.num_pages) |
|
1760 | objects = paginator.page(paginator.num_pages) | |
1757 |
|
1761 | |||
1758 | kwargs['objects'] = objects |
|
1762 | kwargs['objects'] = objects | |
1759 | kwargs['offset'] = (int(page)-1)*n if page else 0 |
|
1763 | kwargs['offset'] = (int(page)-1)*n if page else 0 | |
1760 |
|
1764 | |||
1761 | return kwargs |
|
1765 | return kwargs | |
1762 |
|
1766 | |||
1763 | # def get_paginator(model, page, order, filters={}, n=8): |
|
1767 | # def get_paginator(model, page, order, filters={}, n=8): | |
1764 | # kwargs = {} |
|
1768 | # kwargs = {} | |
1765 | # query = Q() |
|
1769 | # query = Q() | |
1766 | # if isinstance(filters, QueryDict): |
|
1770 | # if isinstance(filters, QueryDict): | |
1767 | # filters = filters.dict() |
|
1771 | # filters = filters.dict() | |
1768 | # [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] |
|
1772 | # [filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')] | |
1769 | # filters.pop('page', None) |
|
1773 | # filters.pop('page', None) | |
1770 |
|
1774 | |||
1771 | # fields = [f.name for f in model._meta.get_fields()] |
|
1775 | # fields = [f.name for f in model._meta.get_fields()] | |
1772 |
|
1776 | |||
1773 | # if 'template' in filters: |
|
1777 | # if 'template' in filters: | |
1774 | # filters['template'] = True |
|
1778 | # filters['template'] = True | |
1775 | # if 'historical' in filters: |
|
1779 | # if 'historical' in filters: | |
1776 | # filters.pop('historical') |
|
1780 | # filters.pop('historical') | |
1777 | # filters['type'] = 1 |
|
1781 | # filters['type'] = 1 | |
1778 | # elif 'type' in fields: |
|
1782 | # elif 'type' in fields: | |
1779 | # filters['type'] = 0 |
|
1783 | # filters['type'] = 0 | |
1780 | # if 'start_date' in filters: |
|
1784 | # if 'start_date' in filters: | |
1781 | # filters['start_date__gte'] = filters.pop('start_date') |
|
1785 | # filters['start_date__gte'] = filters.pop('start_date') | |
1782 | # if 'end_date' in filters: |
|
1786 | # if 'end_date' in filters: | |
1783 | # filters['start_date__lte'] = filters.pop('end_date') |
|
1787 | # filters['start_date__lte'] = filters.pop('end_date') | |
1784 | # if 'tags' in filters: |
|
1788 | # if 'tags' in filters: | |
1785 | # tags = filters.pop('tags') |
|
1789 | # tags = filters.pop('tags') | |
1786 | # if 'tags' in fields: |
|
1790 | # if 'tags' in fields: | |
1787 | # query = query | Q(tags__icontains=tags) |
|
1791 | # query = query | Q(tags__icontains=tags) | |
1788 | # if 'label' in fields: |
|
1792 | # if 'label' in fields: | |
1789 | # query = query | Q(label__icontains=tags) |
|
1793 | # query = query | Q(label__icontains=tags) | |
1790 | # if 'location' in fields: |
|
1794 | # if 'location' in fields: | |
1791 | # query = query | Q(location__name__icontains=tags) |
|
1795 | # query = query | Q(location__name__icontains=tags) | |
1792 | # if 'device' in fields: |
|
1796 | # if 'device' in fields: | |
1793 | # query = query | Q(device__device_type__name__icontains=tags) |
|
1797 | # query = query | Q(device__device_type__name__icontains=tags) | |
1794 | # query = query | Q(device__location__name__icontains=tags) |
|
1798 | # query = query | Q(device__location__name__icontains=tags) | |
1795 | # if 'device_type' in fields: |
|
1799 | # if 'device_type' in fields: | |
1796 | # query = query | Q(device_type__name__icontains=tags) |
|
1800 | # query = query | Q(device_type__name__icontains=tags) | |
1797 |
|
1801 | |||
1798 | # if 'mine' in filters: |
|
1802 | # if 'mine' in filters: | |
1799 | # filters['author_id'] = filters['mine'] |
|
1803 | # filters['author_id'] = filters['mine'] | |
1800 | # filters.pop('mine') |
|
1804 | # filters.pop('mine') | |
1801 | # object_list = model.objects.filter(query, **filters).order_by(*order) |
|
1805 | # object_list = model.objects.filter(query, **filters).order_by(*order) | |
1802 | # paginator = Paginator(object_list, n) |
|
1806 | # paginator = Paginator(object_list, n) | |
1803 |
|
1807 | |||
1804 | # try: |
|
1808 | # try: | |
1805 | # objects = paginator.page(page) |
|
1809 | # objects = paginator.page(page) | |
1806 | # except PageNotAnInteger: |
|
1810 | # except PageNotAnInteger: | |
1807 | # objects = paginator.page(1) |
|
1811 | # objects = paginator.page(1) | |
1808 | # except EmptyPage: |
|
1812 | # except EmptyPage: | |
1809 | # objects = paginator.page(paginator.num_pages) |
|
1813 | # objects = paginator.page(paginator.num_pages) | |
1810 |
|
1814 | |||
1811 | # kwargs['objects'] = objects |
|
1815 | # kwargs['objects'] = objects | |
1812 | # kwargs['offset'] = (int(page)-1)*n if page else 0 |
|
1816 | # kwargs['offset'] = (int(page)-1)*n if page else 0 | |
1813 |
|
1817 | |||
1814 | # return kwargs |
|
1818 | # return kwargs | |
1815 |
|
1819 | |||
1816 |
|
1820 | |||
1817 | def operation(request, id_camp=None): |
|
1821 | def operation(request, id_camp=None): | |
1818 |
|
1822 | |||
1819 | kwargs = {} |
|
1823 | kwargs = {} | |
1820 | kwargs['title'] = 'Radars Operation' |
|
1824 | kwargs['title'] = 'Radars Operation' | |
1821 | kwargs['no_sidebar'] = True |
|
1825 | kwargs['no_sidebar'] = True | |
1822 | kwargs['menu_operation'] = 'active' |
|
1826 | kwargs['menu_operation'] = 'active' | |
1823 | campaigns = Campaign.objects.filter(start_date__lte=datetime.now(), |
|
1827 | campaigns = Campaign.objects.filter(start_date__lte=datetime.now(), | |
1824 | end_date__gte=datetime.now()).order_by('-start_date') |
|
1828 | end_date__gte=datetime.now()).order_by('-start_date') | |
1825 |
|
1829 | |||
1826 | if id_camp: |
|
1830 | if id_camp: | |
1827 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
1831 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
1828 | form = OperationForm( |
|
1832 | form = OperationForm( | |
1829 | initial={'campaign': campaign.id}, campaigns=campaigns) |
|
1833 | initial={'campaign': campaign.id}, campaigns=campaigns) | |
1830 | kwargs['campaign'] = campaign |
|
1834 | kwargs['campaign'] = campaign | |
1831 | else: |
|
1835 | else: | |
1832 | # form = OperationForm(campaigns=campaigns) |
|
1836 | # form = OperationForm(campaigns=campaigns) | |
1833 | kwargs['campaigns'] = campaigns |
|
1837 | kwargs['campaigns'] = campaigns | |
1834 | return render(request, 'operation.html', kwargs) |
|
1838 | return render(request, 'operation.html', kwargs) | |
1835 |
|
1839 | |||
1836 | #---Experiment |
|
1840 | #---Experiment | |
1837 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1841 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1838 | kwargs['experiment_keys'] = keys[1:] |
|
1842 | kwargs['experiment_keys'] = keys[1:] | |
1839 | kwargs['experiments'] = experiments |
|
1843 | kwargs['experiments'] = experiments | |
1840 | #---Radar |
|
1844 | #---Radar | |
1841 | kwargs['locations'] = campaign.get_experiments_by_radar() |
|
1845 | kwargs['locations'] = campaign.get_experiments_by_radar() | |
1842 | kwargs['form'] = form |
|
1846 | kwargs['form'] = form | |
1843 |
|
1847 | |||
1844 | return render(request, 'operation.html', kwargs) |
|
1848 | return render(request, 'operation.html', kwargs) | |
1845 |
|
1849 | |||
1846 |
|
1850 | |||
1847 | @login_required |
|
1851 | @login_required | |
1848 | def radar_start(request, id_camp, id_radar): |
|
1852 | def radar_start(request, id_camp, id_radar): | |
1849 |
|
1853 | |||
1850 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
1854 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
1851 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1855 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] | |
1852 | now = datetime.now() |
|
1856 | now = datetime.now() | |
1853 |
|
1857 | |||
1854 | for exp in experiments: |
|
1858 | for exp in experiments: | |
1855 | #app.control.revoke(exp.task) |
|
1859 | #app.control.revoke(exp.task) | |
1856 | print("----------------------") |
|
1860 | print("----------------------") | |
1857 | print("status:->", exp.status) |
|
1861 | print("status:->", exp.status) | |
1858 | start = datetime.combine(datetime.now().date(), exp.start_time) |
|
1862 | start = datetime.combine(datetime.now().date(), exp.start_time) | |
1859 | end = datetime.combine(datetime.now().date(), exp.end_time) |
|
1863 | end = datetime.combine(datetime.now().date(), exp.end_time) | |
1860 | print("start exp: ",exp.start_time) |
|
1864 | print("start exp: ",exp.start_time) | |
1861 | print("end exp: ",exp.end_time) |
|
1865 | print("end exp: ",exp.end_time) | |
1862 |
|
1866 | |||
1863 | print("start comb: ",start) |
|
1867 | print("start comb: ",start) | |
1864 | print("end comb: ",end) |
|
1868 | print("end comb: ",end) | |
1865 | print(is_aware(start)) |
|
1869 | print(is_aware(start)) | |
1866 | print("start camp",campaign.start_date) |
|
1870 | print("start camp",campaign.start_date) | |
1867 | print("end camp",campaign.end_date) |
|
1871 | print("end camp",campaign.end_date) | |
1868 | print(is_aware(campaign.start_date)) |
|
1872 | print(is_aware(campaign.start_date)) | |
1869 | if end < start: |
|
1873 | if end < start: | |
1870 | end += timedelta(1) |
|
1874 | end += timedelta(1) | |
1871 |
|
1875 | |||
1872 | if exp.status == 2: |
|
1876 | if exp.status == 2: | |
1873 | messages.warning( |
|
1877 | messages.warning( | |
1874 | request, 'Experiment {} already running'.format(exp)) |
|
1878 | request, 'Experiment {} already running'.format(exp)) | |
1875 | #continue |
|
1879 | #continue | |
1876 |
|
1880 | |||
1877 | if exp.status == 3: |
|
1881 | if exp.status == 3: | |
1878 | messages.warning( |
|
1882 | messages.warning( | |
1879 | request, 'Experiment {} already programmed'.format(exp)) |
|
1883 | request, 'Experiment {} already programmed'.format(exp)) | |
1880 | #continue |
|
1884 | #continue | |
1881 |
|
1885 | |||
1882 | if exp.status == 1: |
|
1886 | if exp.status == 1: | |
1883 | messages.warning( |
|
1887 | messages.warning( | |
1884 | request, 'Experiment {} stopped'.format(exp)) |
|
1888 | request, 'Experiment {} stopped'.format(exp)) | |
1885 | #continue |
|
1889 | #continue | |
1886 |
|
1890 | |||
1887 | if start > campaign.end_date: |
|
1891 | if start > campaign.end_date: | |
1888 | messages.warning( |
|
1892 | messages.warning( | |
1889 | request, 'Experiment {} out of date'.format(exp)) |
|
1893 | request, 'Experiment {} out of date'.format(exp)) | |
1890 |
|
1894 | |||
1891 | #app.control.revoke(exp.task) |
|
1895 | #app.control.revoke(exp.task) | |
1892 | print("Llego luego del revoke") |
|
1896 | print("Llego luego del revoke") | |
1893 | if now >= start and now <= end: |
|
1897 | if now >= start and now <= end: | |
1894 |
|
1898 | |||
1895 | print("Caso now > start and < end -- (1)") |
|
1899 | print("Caso now > start and < end -- (1)") | |
1896 |
|
1900 | |||
1897 | # ------------------------------------------- |
|
1901 | # ------------------------------------------- | |
1898 |
|
1902 | |||
1899 | # task = task_start.delay(exp.id) |
|
1903 | # task = task_start.delay(exp.id) | |
1900 | # exp.task = task.id |
|
1904 | # exp.task = task.id | |
1901 | # exp.status = task.get() |
|
1905 | # exp.status = task.get() | |
1902 | # ------------------------------------------- |
|
1906 | # ------------------------------------------- | |
1903 |
|
1907 | |||
1904 | #exp.status = task.wait() |
|
1908 | #exp.status = task.wait() | |
1905 |
|
1909 | |||
1906 | if exp.status == 0: |
|
1910 | if exp.status == 0: | |
1907 | messages.error(request, 'Experiment {} not start'.format(exp)) |
|
1911 | messages.error(request, 'Experiment {} not start'.format(exp)) | |
1908 | if exp.status == 2: |
|
1912 | if exp.status == 2: | |
1909 | messages.success(request, 'Experiment {} started'.format(exp)) |
|
1913 | messages.success(request, 'Experiment {} started'.format(exp)) | |
1910 | elif now < start: |
|
1914 | elif now < start: | |
1911 | print("Caso now <= start -- (2)",exp.pk) |
|
1915 | print("Caso now <= start -- (2)",exp.pk) | |
1912 | #task = task_start.apply_async((exp.pk, ), eta=start)#start+timedelta(hours=5)) |
|
1916 | #task = task_start.apply_async((exp.pk, ), eta=start)#start+timedelta(hours=5)) | |
1913 | # task = task_start.apply_async((exp.pk, ), eta=start+timedelta(hours=5))#) |
|
1917 | # task = task_start.apply_async((exp.pk, ), eta=start+timedelta(hours=5))#) | |
1914 | # exp.task = task.id |
|
1918 | # exp.task = task.id | |
1915 | # exp.status = 3 |
|
1919 | # exp.status = 3 | |
1916 | messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start)) |
|
1920 | messages.success(request, 'Experiment {} programmed to start at {}'.format(exp, start)) | |
1917 | else: |
|
1921 | else: | |
1918 | print("Caso now > end -- (3)") |
|
1922 | print("Caso now > end -- (3)") | |
1919 | exp.status = 4 |
|
1923 | exp.status = 4 | |
1920 | messages.warning( |
|
1924 | messages.warning( | |
1921 | request, 'Experiment {} out of date'.format(exp)) |
|
1925 | request, 'Experiment {} out of date'.format(exp)) | |
1922 |
|
1926 | |||
1923 | exp.save() |
|
1927 | exp.save() | |
1924 |
|
1928 | |||
1925 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1929 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1926 |
|
1930 | |||
1927 |
|
1931 | |||
1928 | @login_required |
|
1932 | @login_required | |
1929 | def radar_stop(request, id_camp, id_radar): |
|
1933 | def radar_stop(request, id_camp, id_radar): | |
1930 |
|
1934 | |||
1931 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
1935 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
1932 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1936 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] | |
1933 | print("Ingreso en stop radar_stop") |
|
1937 | print("Ingreso en stop radar_stop") | |
1934 | #for exp in experiments: |
|
1938 | #for exp in experiments: | |
1935 |
|
1939 | |||
1936 | # if exp.task: |
|
1940 | # if exp.task: | |
1937 | # print("Ingreso antes de revoke stop") |
|
1941 | # print("Ingreso antes de revoke stop") | |
1938 | # app.control.revoke(exp.task) |
|
1942 | # app.control.revoke(exp.task) | |
1939 |
|
1943 | |||
1940 |
|
1944 | |||
1941 | # if exp.status == 2: #status 2 es started |
|
1945 | # if exp.status == 2: #status 2 es started | |
1942 | # print("llama a exp.stop") |
|
1946 | # print("llama a exp.stop") | |
1943 | # exp.stop() |
|
1947 | # exp.stop() | |
1944 | # messages.warning(request, 'Experiment {} stopped'.format(exp)) |
|
1948 | # messages.warning(request, 'Experiment {} stopped'.format(exp)) | |
1945 | # exp.status = 1 |
|
1949 | # exp.status = 1 | |
1946 | # exp.save() |
|
1950 | # exp.save() | |
1947 |
|
1951 | |||
1948 | #return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1952 | #return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1949 |
|
1953 | |||
1950 |
|
1954 | |||
1951 | @login_required |
|
1955 | @login_required | |
1952 | def radar_refresh(request, id_camp, id_radar): |
|
1956 | def radar_refresh(request, id_camp, id_radar): | |
1953 |
|
1957 | |||
1954 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
1958 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
1955 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1959 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] | |
1956 |
|
1960 | |||
1957 | i = app.control.inspect() |
|
1961 | i = app.control.inspect() | |
1958 | print("inspect",i) |
|
1962 | print("inspect",i) | |
1959 | print(i.scheduled()) |
|
1963 | print(i.scheduled()) | |
1960 | print(i.scheduled().values()) |
|
1964 | print(i.scheduled().values()) | |
1961 | scheduled = list(i.scheduled().values())[0] |
|
1965 | scheduled = list(i.scheduled().values())[0] | |
1962 | revoked = list(i.revoked().values())[0] |
|
1966 | revoked = list(i.revoked().values())[0] | |
1963 |
|
1967 | |||
1964 | # for exp in experiments: |
|
1968 | # for exp in experiments: | |
1965 | # if exp.task in revoked: |
|
1969 | # if exp.task in revoked: | |
1966 | # exp.status = 1 |
|
1970 | # exp.status = 1 | |
1967 | # elif exp.task in [t['request']['id'] for t in scheduled if 'task_stop' in t['request']['name']]: |
|
1971 | # elif exp.task in [t['request']['id'] for t in scheduled if 'task_stop' in t['request']['name']]: | |
1968 | # exp.status = 2 |
|
1972 | # exp.status = 2 | |
1969 | # elif exp.task in [t['request']['id'] for t in scheduled if 'task_start' in t['request']['name']]: |
|
1973 | # elif exp.task in [t['request']['id'] for t in scheduled if 'task_start' in t['request']['name']]: | |
1970 | # exp.status = 3 |
|
1974 | # exp.status = 3 | |
1971 | # else: |
|
1975 | # else: | |
1972 | # exp.status = 4 |
|
1976 | # exp.status = 4 | |
1973 | # exp.save() |
|
1977 | # exp.save() | |
1974 | # return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1978 | # return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1975 |
|
1979 | |||
1976 | #@login_required |
|
1980 | #@login_required | |
1977 | # def revoke_tasks(request, id_camp): |
|
1981 | # def revoke_tasks(request, id_camp): | |
1978 |
|
1982 | |||
1979 | # i = app.control.inspect() |
|
1983 | # i = app.control.inspect() | |
1980 | # scheduled = list(i.scheduled().values())[0] |
|
1984 | # scheduled = list(i.scheduled().values())[0] | |
1981 | # revoked = list(i.revoked().values())[0] |
|
1985 | # revoked = list(i.revoked().values())[0] | |
1982 |
|
1986 | |||
1983 | # for t in scheduled: |
|
1987 | # for t in scheduled: | |
1984 | # if t['request']['id'] in revoked: |
|
1988 | # if t['request']['id'] in revoked: | |
1985 | # continue |
|
1989 | # continue | |
1986 | # app.control.revoke(t['request']['id']) |
|
1990 | # app.control.revoke(t['request']['id']) | |
1987 | # exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0]) |
|
1991 | # exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0]) | |
1988 | # eta = t['eta'] |
|
1992 | # eta = t['eta'] | |
1989 | # #task = t['request']['name'].split('.')[-1] |
|
1993 | # #task = t['request']['name'].split('.')[-1] | |
1990 | # messages.warning(request, 'Scheduled {} at {} for experiment {} revoked'.format(task, eta, exp.name)) |
|
1994 | # messages.warning(request, 'Scheduled {} at {} for experiment {} revoked'.format(task, eta, exp.name)) | |
1991 |
|
1995 | |||
1992 | # return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1996 | # return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1993 |
|
1997 | |||
1994 | # @login_required |
|
1998 | # @login_required | |
1995 | # def show_tasks(request, id_camp): |
|
1999 | # def show_tasks(request, id_camp): | |
1996 |
|
2000 | |||
1997 | # i = app.control.inspect() |
|
2001 | # i = app.control.inspect() | |
1998 | # scheduled = list(i.scheduled().values())[0] |
|
2002 | # scheduled = list(i.scheduled().values())[0] | |
1999 | # revoked = list(i.revoked().values())[0] |
|
2003 | # revoked = list(i.revoked().values())[0] | |
2000 |
|
2004 | |||
2001 | # for t in scheduled: |
|
2005 | # for t in scheduled: | |
2002 | # if t['request']['id'] in revoked: |
|
2006 | # if t['request']['id'] in revoked: | |
2003 | # continue |
|
2007 | # continue | |
2004 | # exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0]) |
|
2008 | # exp = Experiment.objects.get(pk=eval(str(t['request']['args']))[0]) | |
2005 | # eta = t['eta'] |
|
2009 | # eta = t['eta'] | |
2006 | # #task = t['request']['name'].split('.')[-1] |
|
2010 | # #task = t['request']['name'].split('.')[-1] | |
2007 | # #messages.success(request, 'Task {} scheduled at {} for experiment {}'.format(task, eta, exp.name)) |
|
2011 | # #messages.success(request, 'Task {} scheduled at {} for experiment {}'.format(task, eta, exp.name)) | |
2008 |
|
2012 | |||
2009 | # return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
2013 | # return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
2010 |
|
2014 | |||
2011 | def real_time(request): |
|
2015 | def real_time(request): | |
2012 |
|
2016 | |||
2013 | graphic_path = "/home/fiorella/Pictures/catwbeanie.jpg" |
|
2017 | graphic_path = "/home/fiorella/Pictures/catwbeanie.jpg" | |
2014 |
|
2018 | |||
2015 | kwargs = {} |
|
2019 | kwargs = {} | |
2016 | kwargs['title'] = 'CLAIRE' |
|
2020 | kwargs['title'] = 'CLAIRE' | |
2017 | kwargs['suptitle'] = 'Real Time' |
|
2021 | kwargs['suptitle'] = 'Real Time' | |
2018 | kwargs['no_sidebar'] = True |
|
2022 | kwargs['no_sidebar'] = True | |
2019 | kwargs['graphic_path'] = graphic_path |
|
2023 | kwargs['graphic_path'] = graphic_path | |
2020 | kwargs['graphic1_path'] = 'http://www.bluemaize.net/im/girls-accessories/shark-beanie-11.jpg' |
|
2024 | kwargs['graphic1_path'] = 'http://www.bluemaize.net/im/girls-accessories/shark-beanie-11.jpg' | |
2021 |
|
2025 | |||
2022 | return render(request, 'real_time.html', kwargs) |
|
2026 | return render(request, 'real_time.html', kwargs) | |
2023 |
|
2027 | |||
2024 | def theme(request, theme): |
|
2028 | def theme(request, theme): | |
2025 |
|
2029 | |||
2026 | user = request.user |
|
2030 | user = request.user | |
2027 | user.profile.theme = theme |
|
2031 | user.profile.theme = theme | |
2028 | user.save() |
|
2032 | user.save() | |
2029 | return redirect('index') |
|
2033 | return redirect('index') |
@@ -1,70 +1,70 | |||||
1 | version: '3' |
|
1 | version: '3' | |
2 | services: |
|
2 | services: | |
3 | # Django app |
|
3 | # Django app | |
4 | radarsys: |
|
4 | radarsys: | |
5 | container_name: 'radarsys' |
|
5 | container_name: 'radarsys' | |
6 | build: . |
|
6 | build: . | |
7 | restart: always |
|
7 | restart: always | |
8 | image: radarsys |
|
8 | image: radarsys | |
9 | #command: gunicorn radarsys.wsgi:application -w 2 -b :8000 |
|
9 | #command: gunicorn radarsys.wsgi:application -w 2 -b :8000 | |
10 | #command: python manage.py runserver 0.0.0.0:8000 |
|
10 | #command: python manage.py runserver 0.0.0.0:8000 | |
11 | ports: |
|
11 | ports: | |
12 | - 8000:8000 |
|
12 | - 8000:8000 | |
13 | #ports: |
|
13 | #ports: | |
14 | # - 8030:8030 |
|
14 | # - 8030:8030 | |
15 | env_file: .env |
|
15 | env_file: .env | |
16 |
|
16 | |||
17 | links: |
|
17 | links: | |
18 | # - redis |
|
18 | # - redis | |
19 | - postgres |
|
19 | - postgres | |
20 | volumes: |
|
20 | volumes: | |
21 | - './:/radarsys' |
|
21 | - './:/radarsys' | |
22 | - '${DOCKER_DATA}/static:/radarsys/static' |
|
22 | - '${DOCKER_DATA}/static:/radarsys/static' | |
23 | depends_on: |
|
23 | depends_on: | |
24 | # - redis |
|
24 | # - redis | |
25 | - postgres |
|
25 | - postgres | |
26 |
|
26 | |||
27 | # redis: |
|
27 | # redis: | |
28 | # container_name: 'radarsys-redis' |
|
28 | # container_name: 'radarsys-redis' | |
29 | # image: 'redis:3.2-alpine' |
|
29 | # image: 'redis:3.2-alpine' | |
30 | # volumes: |
|
30 | # volumes: | |
31 | # - '${DOCKER_DATA}/redis:/data' |
|
31 | # - '${DOCKER_DATA}/redis:/data' | |
32 |
|
32 | |||
33 | # celery_worker: |
|
33 | # celery_worker: | |
34 | # container_name: 'radarsys-celery' |
|
34 | # container_name: 'radarsys-celery' | |
35 | # image: radarsys |
|
35 | # image: radarsys | |
36 | # env_file: .env |
|
36 | # env_file: .env | |
37 | # command: celery -A radarsys worker -l info |
|
37 | # command: celery -A radarsys worker -l info | |
38 | # volumes_from: |
|
38 | # volumes_from: | |
39 | # - web |
|
39 | # - web | |
40 | # depends_on: |
|
40 | # depends_on: | |
41 | # - web |
|
41 | # - web | |
42 |
|
42 | |||
43 | # PostgreSQL |
|
43 | # PostgreSQL | |
44 | postgres: |
|
44 | postgres: | |
45 | container_name: 'radarsys-postgres' |
|
45 | container_name: 'radarsys-postgres' | |
46 | build: ./postgres/ |
|
46 | build: ./postgres/ | |
47 | volumes: |
|
47 | volumes: | |
48 | - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d |
|
48 | - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d | |
49 | - pgdata:/var/lib/postgresql/data |
|
49 | - pgdata:/var/lib/postgresql/data | |
50 | ports: |
|
50 | ports: | |
51 | - 5432:5432 |
|
51 | - 5432:5432 | |
52 | env_file: .env |
|
52 | env_file: .env | |
53 |
|
53 | |||
54 | #Web Server |
|
54 | #Web Server | |
55 | nginx: |
|
55 | radarsys-nginx: | |
56 | container_name: 'radarsys-nginx' |
|
56 | container_name: 'radarsys-nginx' | |
57 | restart: always |
|
57 | restart: always | |
58 | build: ./nginx/ |
|
58 | build: ./nginx/ | |
59 | ports: |
|
59 | ports: | |
60 |
- ' |
|
60 | - '0.0.0.0:80:80' | |
61 | volumes_from: |
|
61 | volumes_from: | |
62 | - radarsys |
|
62 | - radarsys | |
63 | links: |
|
63 | links: | |
64 | - radarsys:radarsys |
|
64 | - radarsys:radarsys | |
65 | depends_on: |
|
65 | depends_on: | |
66 | - radarsys |
|
66 | - radarsys | |
67 |
|
67 | |||
68 | volumes: |
|
68 | volumes: | |
69 | pgdata: |
|
69 | pgdata: | |
70 | driver: local |
|
70 | driver: local |
@@ -1,12 +1,12 | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 | python3 manage.py makemigrations --no-input |
|
2 | python3 manage.py makemigrations --no-input | |
3 | python3 manage.py migrate --no-input |
|
3 | python3 manage.py migrate --no-input | |
4 | python3 manage.py loaddata apps/main/fixtures/main_initial_data.json |
|
4 | python3 manage.py loaddata apps/main/fixtures/main_initial_data.json | |
5 | python3 manage.py loaddata apps/rc/fixtures/rc_initial_data.json |
|
5 | python3 manage.py loaddata apps/rc/fixtures/rc_initial_data.json | |
6 | python3 manage.py loaddata apps/jars/fixtures/initial_filters_data.json |
|
6 | python3 manage.py loaddata apps/jars/fixtures/initial_filters_data.json | |
7 | python3 manage.py collectstatic --no-input |
|
7 | python3 manage.py collectstatic --no-input | |
8 |
|
8 | |||
9 | #DJANGO_SUPERUSER_PASSWORD=$SUPER_USER_PASSWORD python manage.py createsuperuser --username $SUPER_USER_NAME --email $SUPER_USER_EMAIL --noinput |
|
9 | #DJANGO_SUPERUSER_PASSWORD=$SUPER_USER_PASSWORD python manage.py createsuperuser --username $SUPER_USER_NAME --email $SUPER_USER_EMAIL --noinput | |
10 |
|
10 | |||
11 |
gunicorn radarsys.wsgi:application - |
|
11 | gunicorn -k eventlet radarsys.wsgi:application --bind 0.0.0.0:8000 | |
12 | No newline at end of file |
|
12 |
@@ -1,20 +1,28 | |||||
|
1 | upstream django { | |||
|
2 | server radarsys:8000; | |||
|
3 | } | |||
|
4 | ||||
1 | server { |
|
5 | server { | |
2 |
|
6 | |||
3 |
listen 80 |
|
7 | listen 80; | |
4 | server_name localhost; |
|
8 | server_name localhost; | |
5 |
|
9 | |||
6 | access_log /dev/stdout; |
|
10 | #access_log /dev/stdout; | |
7 | error_log /dev/stdout info; |
|
11 | #error_log /dev/stdout info; | |
8 |
|
12 | |||
9 | location /static { |
|
13 | location /static { | |
10 | alias /radarsys/static; |
|
14 | alias /radarsys/static; | |
11 | } |
|
15 | } | |
12 |
|
16 | |||
13 | location / { |
|
17 | location / { | |
14 | proxy_set_header Host "localhost"; |
|
18 | proxy_pass http://django; | |
15 | proxy_pass http://radarsys:8000; |
|
19 | proxy_set_header X-Real-IP $remote_addr; | |
16 | # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
20 | proxy_set_header Host $host; | |
17 |
|
21 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
|
22 | proxy_set_header X-Forwarded-Proto $scheme; | |||
|
23 | proxy_http_version 1.1; | |||
|
24 | proxy_set_header Upgrade $http_upgrade; | |||
|
25 | proxy_set_header Connection "upgrade"; | |||
18 | } |
|
26 | } | |
19 |
|
27 | |||
20 | } |
|
28 | } No newline at end of file |
@@ -1,170 +1,177 | |||||
1 | """ |
|
1 | """ | |
2 | Django settings for radarsys project. |
|
2 | Django settings for radarsys project. | |
3 |
|
3 | |||
4 | Generated by 'django-admin startproject' using Django 1.8.6. |
|
4 | Generated by 'django-admin startproject' using Django 1.8.6. | |
5 |
|
5 | |||
6 | For more information on this file, see |
|
6 | For more information on this file, see | |
7 | https://docs.djangoproject.com/en/1.8/topics/settings/ |
|
7 | https://docs.djangoproject.com/en/1.8/topics/settings/ | |
8 |
|
8 | |||
9 | For the full list of settings and their values, see |
|
9 | For the full list of settings and their values, see | |
10 | https://docs.djangoproject.com/en/1.8/ref/settings/ |
|
10 | https://docs.djangoproject.com/en/1.8/ref/settings/ | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
|
13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | |
14 | import os |
|
14 | import os | |
15 |
|
15 | |||
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
17 |
|
17 | |||
18 | # Quick-start development settings - unsuitable for production |
|
18 | # Quick-start development settings - unsuitable for production | |
19 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ |
|
19 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ | |
20 |
|
20 | |||
21 | # SECURITY WARNING: keep the secret key used in production secret! |
|
21 | # SECURITY WARNING: keep the secret key used in production secret! | |
22 | SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0' |
|
22 | SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0' | |
23 |
|
23 | |||
24 | # SECURITY WARNING: don't run with debug turned on in production! |
|
24 | # SECURITY WARNING: don't run with debug turned on in production! | |
25 | DEBUG = True |
|
25 | DEBUG = True | |
26 |
|
26 | |||
27 | ALLOWED_HOSTS = ['*'] |
|
27 | ALLOWED_HOSTS = ['*'] | |
28 |
|
28 | |||
29 | CSRF_TRUSTED_ORIGINS=[ |
|
29 | CSRF_TRUSTED_ORIGINS=[ | |
30 | "http://*.localhost:8030", |
|
30 | "http://*.localhost:8030", | |
31 | "http://localhost:8030", |
|
31 | "http://localhost:8030", | |
32 | "http://127.0.0.1:8030" |
|
32 | "http://127.0.0.1:8030" | |
33 | ] |
|
33 | ] | |
34 | #Si se requiere que la aplicación salga de este entorno, para otros usuarios es necesario hacer una API request https://fractalideas.com/blog/making-react-and-django-play-well-together-single-page-app-model/ |
|
34 | #Si se requiere que la aplicación salga de este entorno, para otros usuarios es necesario hacer una API request https://fractalideas.com/blog/making-react-and-django-play-well-together-single-page-app-model/ | |
35 |
|
35 | |||
36 | # Application definition |
|
36 | # Application definition | |
37 |
|
37 | |||
38 | INSTALLED_APPS = [ |
|
38 | INSTALLED_APPS = [ | |
39 | 'django.contrib.admin', |
|
39 | 'django.contrib.admin', | |
40 | 'django.contrib.auth', |
|
40 | 'django.contrib.auth', | |
41 | 'django.contrib.contenttypes', |
|
41 | 'django.contrib.contenttypes', | |
42 | 'django.contrib.sessions', |
|
42 | 'django.contrib.sessions', | |
43 | 'django.contrib.messages', |
|
43 | 'django.contrib.messages', | |
44 | 'django.contrib.staticfiles', |
|
44 | 'django.contrib.staticfiles', | |
45 | 'apps.accounts', |
|
45 | 'apps.accounts', | |
46 | 'apps.main', |
|
46 | 'apps.main', | |
47 | 'apps.misc', |
|
47 | 'apps.misc', | |
48 | 'apps.rc', |
|
48 | 'apps.rc', | |
49 | 'apps.dds', |
|
49 | 'apps.dds', | |
50 | 'apps.jars', |
|
50 | 'apps.jars', | |
51 | 'apps.usrp', |
|
51 | 'apps.usrp', | |
52 | 'apps.abs', |
|
52 | 'apps.abs', | |
53 | 'apps.cgs', |
|
53 | 'apps.cgs', | |
54 | 'apps.dds_rest', |
|
54 | 'apps.dds_rest', | |
|
55 | 'apps.atrad', | |||
55 | "django_bootstrap5", |
|
56 | "django_bootstrap5", | |
56 | 'polymorphic', |
|
57 | 'polymorphic', | |
57 |
' |
|
58 | 'radarsys', | |
58 | ] |
|
59 | ] | |
59 |
|
60 | |||
60 | MIDDLEWARE = [ |
|
61 | MIDDLEWARE = [ | |
61 | 'django.middleware.security.SecurityMiddleware', |
|
62 | 'django.middleware.security.SecurityMiddleware', | |
62 | 'django.contrib.sessions.middleware.SessionMiddleware', |
|
63 | 'django.contrib.sessions.middleware.SessionMiddleware', | |
63 | 'django.middleware.common.CommonMiddleware', |
|
64 | 'django.middleware.common.CommonMiddleware', | |
64 | 'django.middleware.csrf.CsrfViewMiddleware', |
|
65 | 'django.middleware.csrf.CsrfViewMiddleware', | |
65 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
66 | 'django.contrib.auth.middleware.AuthenticationMiddleware', | |
66 | 'django.contrib.messages.middleware.MessageMiddleware', |
|
67 | 'django.contrib.messages.middleware.MessageMiddleware', | |
67 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
|
68 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
68 |
|
69 | |||
69 | ] |
|
70 | ] | |
70 |
|
71 | |||
71 | ROOT_URLCONF = 'radarsys.urls' |
|
72 | ROOT_URLCONF = 'radarsys.urls' | |
72 |
|
73 | |||
73 | TEMPLATES = [ |
|
74 | TEMPLATES = [ | |
74 | { |
|
75 | { | |
75 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
|
76 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
76 | 'DIRS': [os.path.join(BASE_DIR, "templates")], |
|
77 | 'DIRS': [os.path.join(BASE_DIR, "templates")], | |
77 | 'APP_DIRS': True, |
|
78 | 'APP_DIRS': True, | |
78 | 'OPTIONS': { |
|
79 | 'OPTIONS': { | |
79 | 'context_processors': [ |
|
80 | 'context_processors': [ | |
80 | 'django.template.context_processors.debug', |
|
81 | 'django.template.context_processors.debug', | |
81 | 'django.template.context_processors.request', |
|
82 | 'django.template.context_processors.request', | |
82 | 'django.contrib.auth.context_processors.auth', |
|
83 | 'django.contrib.auth.context_processors.auth', | |
83 | 'django.contrib.messages.context_processors.messages', |
|
84 | 'django.contrib.messages.context_processors.messages', | |
84 | 'apps.main.processors.radarsys_globals', |
|
85 | 'apps.main.processors.radarsys_globals', | |
85 | ], |
|
86 | ], | |
86 | }, |
|
87 | }, | |
87 | }, |
|
88 | }, | |
88 | ] |
|
89 | ] | |
89 |
|
90 | |||
90 | WSGI_APPLICATION = 'radarsys.wsgi.application' |
|
91 | WSGI_APPLICATION = 'radarsys.wsgi.application' | |
91 | ASGI_APPLICATION = 'radarsys.asgi.application' |
|
92 | ASGI_APPLICATION = 'radarsys.asgi.application' | |
92 |
|
93 | |||
93 | # Database |
|
94 | # Database | |
94 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases |
|
95 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases | |
95 |
|
96 | |||
96 | DATABASES = { |
|
97 | DATABASES = { | |
97 | # 'default': { |
|
98 | # 'default': { | |
98 | # 'ENGINE': 'django.db.backends.sqlite3', |
|
99 | # 'ENGINE': 'django.db.backends.sqlite3', | |
99 | # 'NAME': 'radarsys.sqlite', |
|
100 | # 'NAME': 'radarsys.sqlite', | |
100 | # } |
|
101 | # } | |
101 | 'default': { |
|
102 | 'default': { | |
102 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', |
|
103 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', | |
103 | 'NAME': os.environ.get('DB_NAME', 'radarsys'), |
|
104 | 'NAME': os.environ.get('DB_NAME', 'radarsys'), | |
104 | 'USER': os.environ.get('DB_USER', 'docker'), |
|
105 | 'USER': os.environ.get('DB_USER', 'docker'), | |
105 | 'PASSWORD': os.environ.get('DB_PASSWORD', 'docker'), |
|
106 | 'PASSWORD': os.environ.get('DB_PASSWORD', 'docker'), | |
106 | 'HOST': os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', 'localhost'), |
|
107 | 'HOST': os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', 'localhost'), | |
107 | 'PORT': os.environ.get('POSTGRES_PORT_5432_TCP_PORT', '5432'), |
|
108 | 'PORT': os.environ.get('POSTGRES_PORT_5432_TCP_PORT', '5432'), | |
108 | } |
|
109 | } | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | # Internationalization |
|
112 | # Internationalization | |
112 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ |
|
113 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ | |
113 |
|
114 | |||
114 | LANGUAGE_CODE = 'en-us' |
|
115 | LANGUAGE_CODE = 'en-us' | |
115 |
|
116 | |||
116 | USE_TZ = False #True |
|
117 | USE_TZ = False #True | |
117 |
|
118 | |||
118 | TIME_ZONE = os.environ.get('TZ', 'America/Lima') |
|
119 | TIME_ZONE = os.environ.get('TZ', 'America/Lima') | |
119 |
|
120 | |||
120 | USE_I18N = True |
|
121 | USE_I18N = True | |
121 |
|
122 | |||
122 | USE_L10N = True |
|
123 | USE_L10N = True | |
123 |
|
124 | |||
124 | # Static files (CSS, JavaScript, Images) |
|
125 | # Static files (CSS, JavaScript, Images) | |
125 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ |
|
126 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ | |
126 |
|
127 | |||
127 | MEDIA_URL = '/media/' |
|
128 | MEDIA_URL = '/media/' | |
128 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') |
|
129 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') | |
129 |
|
130 | |||
130 | STATICFILES_DIRS = [ |
|
131 | STATICFILES_DIRS = [ | |
131 | os.path.join(BASE_DIR, 'radarsys/static/') |
|
132 | os.path.join(BASE_DIR, 'radarsys/static/') | |
132 | ] |
|
133 | ] | |
133 |
|
134 | |||
134 | STATIC_URL = '/static/' |
|
135 | STATIC_URL = '/static/' | |
135 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') |
|
136 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') | |
136 |
|
137 | |||
137 | LOGIN_URL = '/accounts/login' |
|
138 | LOGIN_URL = '/accounts/login' | |
138 | LOGOUT_URL = 'logout' |
|
139 | LOGOUT_URL = 'logout' | |
139 | LOGIN_REDIRECT_URL = '/admin' |
|
140 | LOGIN_REDIRECT_URL = '/admin' | |
140 | LOGOUT_REDIRECT_URL = '/' |
|
141 | LOGOUT_REDIRECT_URL = '/' | |
141 |
|
142 | |||
142 | STATICFILES_FINDERS = ( |
|
143 | STATICFILES_FINDERS = ( | |
143 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
|
144 | 'django.contrib.staticfiles.finders.FileSystemFinder', | |
144 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', |
|
145 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', | |
145 | ) |
|
146 | ) | |
146 |
|
147 | |||
147 | # # Celery stuff |
|
148 | # # Celery stuff | |
148 |
|
149 | |||
149 | # REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost') |
|
150 | # REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost') | |
150 | # #REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') |
|
151 | # #REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') | |
151 | # REDIS_PORT = os.environ.get('REDIS_PORT', 6379) |
|
152 | # REDIS_PORT = os.environ.get('REDIS_PORT', 6379) | |
152 |
|
153 | |||
153 | # BROKER_TRANSPORT = 'redis' |
|
154 | # BROKER_TRANSPORT = 'redis' | |
154 | # #BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) |
|
155 | # #BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) | |
155 | # BROKER_URL = 'redis://{}:{}'.format(REDIS_HOST, REDIS_PORT) |
|
156 | # BROKER_URL = 'redis://{}:{}'.format(REDIS_HOST, REDIS_PORT) | |
156 |
|
157 | |||
157 | # CELERY_RESULT_BACKEND = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) |
|
158 | # CELERY_RESULT_BACKEND = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) | |
158 | # CELERY_BROKER_TRANSPORT = BROKER_URL |
|
159 | # CELERY_BROKER_TRANSPORT = BROKER_URL | |
159 | # CELERY_ACCEPT_CONTENT = ['application/json'] |
|
160 | # CELERY_ACCEPT_CONTENT = ['application/json'] | |
160 | # CELERY_TASK_SERIALIZER = 'json' |
|
161 | # CELERY_TASK_SERIALIZER = 'json' | |
161 | # CELERY_RESULT_SERIALIZER = 'json' |
|
162 | # CELERY_RESULT_SERIALIZER = 'json' | |
162 | # CELERY_ENABLE_UTC = False |
|
163 | # CELERY_ENABLE_UTC = False | |
163 | # CELERY_TIMEZONE = 'America/Lima' |
|
164 | # CELERY_TIMEZONE = 'America/Lima' | |
164 |
|
165 | |||
165 | import django |
|
166 | import django | |
166 | from django.utils.encoding import force_str |
|
167 | from django.utils.encoding import force_str | |
167 | django.utils.encoding.force_text = force_str |
|
168 | django.utils.encoding.force_text = force_str | |
168 |
|
169 | |||
169 | # choose of auto-created primary keys |
|
170 | # choose of auto-created primary keys | |
170 | DEFAULT_AUTO_FIELD='django.db.models.AutoField' |
|
171 | DEFAULT_AUTO_FIELD='django.db.models.AutoField' | |
|
172 | ||||
|
173 | MQTT_SERVER = '10.10.10.99' | |||
|
174 | MQTT_PORT = 1883 | |||
|
175 | MQTT_KEEPALIVE = 60 | |||
|
176 | MQTT_USER = '' | |||
|
177 | MQTT_PASSWORD = '' No newline at end of file |
@@ -1,20 +1,20 | |||||
1 | from django.urls import include, path |
|
1 | from django.urls import include, path | |
2 | from django.contrib import admin |
|
2 | from django.contrib import admin | |
3 | #from django.contrib.staticfiles.urls import staticfiles_urlpatterns |
|
3 | #from django.contrib.staticfiles.urls import staticfiles_urlpatterns | |
4 |
|
4 | |||
5 | urlpatterns = [ |
|
5 | urlpatterns = [ | |
6 | path('admin/',admin.site.urls), |
|
6 | path('admin/',admin.site.urls), | |
7 | path('accounts/', include('apps.accounts.urls')), |
|
7 | path('accounts/', include('apps.accounts.urls')), | |
8 | path('', include('apps.main.urls')), |
|
8 | path('', include('apps.main.urls')), | |
9 | path('rc/', include('apps.rc.urls')), |
|
9 | path('rc/', include('apps.rc.urls')), | |
10 | path('dds/', include('apps.dds.urls')), |
|
10 | path('dds/', include('apps.dds.urls')), | |
11 | path('cgs/', include('apps.cgs.urls')), |
|
11 | path('cgs/', include('apps.cgs.urls')), | |
12 | path('jars/',include('apps.jars.urls')), |
|
12 | path('jars/',include('apps.jars.urls')), | |
13 | path('usrp/', include('apps.usrp.urls')), |
|
13 | path('usrp/', include('apps.usrp.urls')), | |
14 | path('abs/', include('apps.abs.urls')), |
|
14 | path('abs/', include('apps.abs.urls')), | |
15 | path('misc/',include('apps.misc.urls')), |
|
15 | path('misc/',include('apps.misc.urls')), | |
16 | path('dds_rest/', include('apps.dds_rest.urls')), |
|
16 | path('dds_rest/', include('apps.dds_rest.urls')), | |
17 |
|
17 | path('atrad/', include('apps.atrad.urls')), | ||
18 | ] |
|
18 | ] | |
19 |
|
19 | |||
20 | #urlpatterns += staticfiles_urlpatterns() |
|
20 | #urlpatterns += staticfiles_urlpatterns() |
@@ -1,16 +1,19 | |||||
1 | """ |
|
1 | """ | |
2 | WSGI config for radarsys project. |
|
2 | WSGI config for radarsys project. | |
3 |
|
3 | |||
4 | It exposes the WSGI callable as a module-level variable named ``application``. |
|
4 | It exposes the WSGI callable as a module-level variable named ``application``. | |
5 |
|
5 | |||
6 | For more information on this file, see |
|
6 | For more information on this file, see | |
7 | https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ |
|
7 | https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ | |
8 | """ |
|
8 | """ | |
9 |
|
9 | |||
10 | import os |
|
10 | import os | |
11 |
|
11 | |||
12 | from django.core.wsgi import get_wsgi_application |
|
12 | from django.core.wsgi import get_wsgi_application | |
|
13 | from .socketconfig import sio | |||
|
14 | import socketio | |||
13 |
|
15 | |||
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "radarsys.settings") |
|
16 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "radarsys.settings") | |
15 |
|
17 | |||
16 | application = get_wsgi_application() |
|
18 | application = get_wsgi_application() | |
|
19 | application = socketio.WSGIApp(sio, application) |
@@ -1,14 +1,18 | |||||
1 | Django==4.1.5 |
|
1 | Django==4.1.5 | |
2 | django-bootstrap5==22.2 |
|
2 | django-bootstrap5==22.2 | |
3 | psycopg2-binary==2.9.5 |
|
3 | psycopg2-binary==2.9.5 | |
4 | django-polymorphic==3.1 |
|
4 | django-polymorphic==3.1 | |
5 | bokeh==3.0.3 |
|
5 | bokeh==3.0.3 | |
6 | numpy==1.24.1 |
|
6 | numpy==1.24.1 | |
7 | matplotlib==3.6.3 |
|
7 | matplotlib==3.6.3 | |
8 | scipy==1.10.0 |
|
8 | scipy==1.10.0 | |
9 | celery==5.2.7 |
|
9 | celery==5.2.7 | |
10 | gunicorn==20.1.0 |
|
10 | gunicorn==20.1.0 | |
11 | requests==2.28.2 |
|
11 | requests==2.28.2 | |
12 | redis==4.4.2 |
|
12 | redis==4.4.2 | |
13 | channels==4.0.0 |
|
13 | ||
14 | daphne==4.0.0 No newline at end of file |
|
14 | paho-mqtt==1.6.1 | |
|
15 | ||||
|
16 | eventlet==0.30.2 | |||
|
17 | python-engineio | |||
|
18 | python-socketio No newline at end of file |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now