@@ -1,213 +1,284 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | from apps.main.utils import Params |
|
4 | 4 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | 5 | |
|
6 | 6 | from .files import read_json_file |
|
7 | 7 | import requests |
|
8 | 8 | |
|
9 | 9 | class ATRADData(models.Model): |
|
10 | 10 | datetime = models.DateTimeField() |
|
11 | 11 | |
|
12 | 12 | nstx = models.SmallIntegerField() |
|
13 | status = models.SmallIntegerField() | |
|
14 | temp_cll = models.SmallIntegerField() | |
|
15 | nboards = models.SmallIntegerField() | |
|
16 | 13 | |
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
14 | status_1 = models.SmallIntegerField() | |
|
15 | temp_cll_1 = models.SmallIntegerField() | |
|
16 | nboards_1 = models.SmallIntegerField() | |
|
17 | tempdvr_1 = models.SmallIntegerField() | |
|
18 | potincdvr_1 = models.SmallIntegerField() | |
|
19 | potretdvr_1 = models.SmallIntegerField() | |
|
20 | 20 | |
|
21 | temp1 = models.SmallIntegerField() | |
|
22 | potinc1 = models.SmallIntegerField() | |
|
23 | potret1 = models.SmallIntegerField() | |
|
24 | temp2 = models.SmallIntegerField() | |
|
25 | potinc2 = models.SmallIntegerField() | |
|
26 | potret2 = models.SmallIntegerField() | |
|
27 | temp3 = models.SmallIntegerField() | |
|
28 | potinc3 = models.SmallIntegerField() | |
|
29 | potret3 = models.SmallIntegerField() | |
|
30 | temp4 = models.SmallIntegerField() | |
|
31 | potinc4 = models.SmallIntegerField() | |
|
32 | potret4 = models.SmallIntegerField() | |
|
33 | temp5 = models.SmallIntegerField() | |
|
34 | potinc5 = models.SmallIntegerField() | |
|
35 | potret5 = models.SmallIntegerField() | |
|
36 | temp6 = models.SmallIntegerField() | |
|
37 | potinc6 = models.SmallIntegerField() | |
|
38 | potret6 = models.SmallIntegerField() | |
|
39 | ||
|
40 | ||
|
21 | temp1_1 = models.SmallIntegerField() | |
|
22 | potinc1_1 = models.SmallIntegerField() | |
|
23 | potret1_1 = models.SmallIntegerField() | |
|
24 | temp2_1 = models.SmallIntegerField() | |
|
25 | potinc2_1 = models.SmallIntegerField() | |
|
26 | potret2_1 = models.SmallIntegerField() | |
|
27 | temp3_1 = models.SmallIntegerField() | |
|
28 | potinc3_1 = models.SmallIntegerField() | |
|
29 | potret3_1 = models.SmallIntegerField() | |
|
30 | temp4_1 = models.SmallIntegerField() | |
|
31 | potinc4_1 = models.SmallIntegerField() | |
|
32 | potret4_1 = models.SmallIntegerField() | |
|
33 | temp5_1 = models.SmallIntegerField() | |
|
34 | potinc5_1 = models.SmallIntegerField() | |
|
35 | potret5_1 = models.SmallIntegerField() | |
|
36 | temp6_1 = models.SmallIntegerField() | |
|
37 | potinc6_1 = models.SmallIntegerField() | |
|
38 | potret6_1 = models.SmallIntegerField() | |
|
39 | ||
|
40 | status_2 = models.SmallIntegerField() | |
|
41 | temp_cll_2 = models.SmallIntegerField() | |
|
42 | nboards_2 = models.SmallIntegerField() | |
|
43 | tempdvr_2 = models.SmallIntegerField() | |
|
44 | potincdvr_2 = models.SmallIntegerField() | |
|
45 | potretdvr_2 = models.SmallIntegerField() | |
|
46 | ||
|
47 | temp1_2 = models.SmallIntegerField() | |
|
48 | potinc1_2 = models.SmallIntegerField() | |
|
49 | potret1_2 = models.SmallIntegerField() | |
|
50 | temp2_2 = models.SmallIntegerField() | |
|
51 | potinc2_2 = models.SmallIntegerField() | |
|
52 | potret2_2 = models.SmallIntegerField() | |
|
53 | temp3_2 = models.SmallIntegerField() | |
|
54 | potinc3_2 = models.SmallIntegerField() | |
|
55 | potret3_2 = models.SmallIntegerField() | |
|
56 | temp4_2 = models.SmallIntegerField() | |
|
57 | potinc4_2 = models.SmallIntegerField() | |
|
58 | potret4_2 = models.SmallIntegerField() | |
|
59 | temp5_2 = models.SmallIntegerField() | |
|
60 | potinc5_2 = models.SmallIntegerField() | |
|
61 | potret5_2 = models.SmallIntegerField() | |
|
62 | temp6_2 = models.SmallIntegerField() | |
|
63 | potinc6_2 = models.SmallIntegerField() | |
|
64 | potret6_2 = models.SmallIntegerField() | |
|
65 | ||
|
66 | status_3 = models.SmallIntegerField() | |
|
67 | temp_cll_3 = models.SmallIntegerField() | |
|
68 | nboards_3 = models.SmallIntegerField() | |
|
69 | tempdvr_3 = models.SmallIntegerField() | |
|
70 | potincdvr_3 = models.SmallIntegerField() | |
|
71 | potretdvr_3 = models.SmallIntegerField() | |
|
72 | ||
|
73 | temp1_3 = models.SmallIntegerField() | |
|
74 | potinc1_3 = models.SmallIntegerField() | |
|
75 | potret1_3 = models.SmallIntegerField() | |
|
76 | temp2_3 = models.SmallIntegerField() | |
|
77 | potinc2_3 = models.SmallIntegerField() | |
|
78 | potret2_3 = models.SmallIntegerField() | |
|
79 | temp3_3 = models.SmallIntegerField() | |
|
80 | potinc3_3 = models.SmallIntegerField() | |
|
81 | potret3_3 = models.SmallIntegerField() | |
|
82 | temp4_3 = models.SmallIntegerField() | |
|
83 | potinc4_3 = models.SmallIntegerField() | |
|
84 | potret4_3 = models.SmallIntegerField() | |
|
85 | temp5_3 = models.SmallIntegerField() | |
|
86 | potinc5_3 = models.SmallIntegerField() | |
|
87 | potret5_3 = models.SmallIntegerField() | |
|
88 | temp6_3 = models.SmallIntegerField() | |
|
89 | potinc6_3 = models.SmallIntegerField() | |
|
90 | potret6_3 = models.SmallIntegerField() | |
|
91 | ||
|
92 | status_4 = models.SmallIntegerField() | |
|
93 | temp_cll_4 = models.SmallIntegerField() | |
|
94 | nboards_4 = models.SmallIntegerField() | |
|
95 | tempdvr_4 = models.SmallIntegerField() | |
|
96 | potincdvr_4 = models.SmallIntegerField() | |
|
97 | potretdvr_4 = models.SmallIntegerField() | |
|
98 | ||
|
99 | temp1_4 = models.SmallIntegerField() | |
|
100 | potinc1_4 = models.SmallIntegerField() | |
|
101 | potret1_4 = models.SmallIntegerField() | |
|
102 | temp2_4 = models.SmallIntegerField() | |
|
103 | potinc2_4 = models.SmallIntegerField() | |
|
104 | potret2_4 = models.SmallIntegerField() | |
|
105 | temp3_4 = models.SmallIntegerField() | |
|
106 | potinc3_4 = models.SmallIntegerField() | |
|
107 | potret3_4 = models.SmallIntegerField() | |
|
108 | temp4_4 = models.SmallIntegerField() | |
|
109 | potinc4_4 = models.SmallIntegerField() | |
|
110 | potret4_4 = models.SmallIntegerField() | |
|
111 | temp5_4 = models.SmallIntegerField() | |
|
112 | potinc5_4 = models.SmallIntegerField() | |
|
113 | potret5_4 = models.SmallIntegerField() | |
|
114 | temp6_4 = models.SmallIntegerField() | |
|
115 | potinc6_4 = models.SmallIntegerField() | |
|
116 | potret6_4 = models.SmallIntegerField() | |
|
41 | 117 | |
|
42 | 118 | class Meta: |
|
43 | 119 | db_table = 'atrad_datas' |
|
44 | 120 | |
|
45 | 121 | def __unicode__(self): |
|
46 | 122 | return u'%s' % (self.name) |
|
47 | 123 | |
|
48 | 124 | class ATRADConfiguration(Configuration): |
|
49 | 125 | |
|
50 | 126 | topic = models.PositiveIntegerField(verbose_name='Topic',validators=[MaxValueValidator(10)], default = 0) |
|
51 | 127 | |
|
52 | 128 | def status_device(self): |
|
53 | 129 | |
|
54 | 130 | ip=self.device.ip_address |
|
55 | 131 | port=self.device.port_address |
|
56 | 132 | |
|
57 | 133 | route = "http://" + str(ip) + ":" + str(port) + "/status/" |
|
58 | 134 | try: |
|
59 | 135 | r = requests.get(route, timeout=0.7) |
|
60 | 136 | except Exception as e: |
|
61 | 137 | self.device.status = 0 |
|
62 | 138 | self.device.save() |
|
63 | 139 | self.message = 'Could not read TX status: ' + str(e) |
|
64 | 140 | return False |
|
65 | 141 | |
|
66 | 142 | response = r.json() |
|
67 | 143 | self.device.status = response['status'] |
|
68 | 144 | self.message = response['message'] |
|
69 | 145 | self.device.save() |
|
70 | 146 | |
|
71 | 147 | if response['components_status']==0: |
|
72 | 148 | return False |
|
73 | 149 | |
|
74 | 150 | return True |
|
75 | 151 | |
|
76 | 152 | |
|
77 | 153 | def start_device(self): |
|
78 | 154 | |
|
79 | 155 | ip=self.device.ip_address |
|
80 | 156 | port=self.device.port_address |
|
81 | 157 | |
|
82 | 158 | #---Device must be configured |
|
83 | 159 | if not self.device.status == 2: |
|
84 | 160 | self.message = 'TX Device must be configured.' |
|
85 | 161 | return False |
|
86 | 162 | #---Frequencies from form |
|
87 | 163 | post_data = self.parms_to_dict() |
|
88 | 164 | route = "http://" + str(ip) + ":" + str(port) + "/write/" |
|
89 | 165 | |
|
90 | 166 | try: |
|
91 | 167 | r = requests.post(route, post_data, timeout=0.7) |
|
92 | 168 | except Exception as e: |
|
93 | 169 | self.message = "Could not start TX device. "+str(e) |
|
94 | 170 | return False |
|
95 | 171 | |
|
96 | 172 | response = r.json() |
|
97 | 173 | if response['status']==1: |
|
98 | 174 | self.device.status = 1 |
|
99 | 175 | self.device.save() |
|
100 | 176 | self.message = response['message'] |
|
101 | 177 | return False |
|
102 | 178 | |
|
103 | 179 | self.device.status = response['status'] |
|
104 | 180 | self.device.save() |
|
105 | 181 | self.message = response['message'] |
|
106 | 182 | |
|
107 | 183 | return True |
|
108 | 184 | |
|
109 | 185 | |
|
110 | 186 | def stop_device(self): |
|
111 | 187 | |
|
112 | 188 | ip=self.device.ip_address |
|
113 | 189 | port=self.device.port_address |
|
114 | 190 | |
|
115 | 191 | if self.device.status == 2: #Configured |
|
116 | 192 | self.message = 'TX device is already stopped.' |
|
117 | 193 | return False |
|
118 | ||
|
119 | # Se crea el modo ocupado para una vez inicia el STOP | |
|
120 | self.device.status = 5 | |
|
121 | self.device.save() | |
|
122 | # Por si se demora deteniendo, que su estado sea busy | |
|
123 | 194 | |
|
124 | 195 | post_data = {"topic":0} |
|
125 | 196 | route = "http://" + str(ip) + ":" + str(port) + "/write/" |
|
126 | 197 | |
|
127 | 198 | try: |
|
128 | 199 | r = requests.post(route, post_data, timeout=0.7) |
|
129 | 200 | except Exception as e: |
|
130 | 201 | self.message = "Could not write TX parameters. "+str(e) |
|
131 | 202 | self.device.status = 0 |
|
132 | 203 | self.device.save() |
|
133 | 204 | return False |
|
134 | 205 | |
|
135 | 206 | response = r.json() |
|
136 | 207 | status = response['status'] |
|
137 | 208 | if status == 1: |
|
138 | 209 | self.device.status = status |
|
139 | 210 | self.device.save() |
|
140 | 211 | self.message = 'Could not stop TX device.' |
|
141 | 212 | return False |
|
142 | 213 | |
|
143 | 214 | self.message = 'TX device has been stopped successfully.' |
|
144 | 215 | self.device.status = 2 |
|
145 | 216 | self.device.save() |
|
146 | 217 | |
|
147 | 218 | return True |
|
148 | 219 | |
|
149 | 220 | |
|
150 | 221 | def read_device(self): |
|
151 | 222 | |
|
152 | 223 | ip=self.device.ip_address |
|
153 | 224 | port=self.device.port_address |
|
154 | 225 | |
|
155 | 226 | route = "http://" + str(ip) + ":" + str(port) + "/read/" |
|
156 | 227 | try: |
|
157 | 228 | frequencies = requests.get(route,timeout=0.7) |
|
158 | 229 | except: |
|
159 | 230 | self.message = "Could not read TX parameters from this device" |
|
160 | 231 | return None |
|
161 | 232 | |
|
162 | 233 | frequencies = frequencies.json() |
|
163 | 234 | if frequencies: |
|
164 | 235 | frequencies = frequencies.get("Frequencies") |
|
165 | 236 | topic = frequencies.get("topic") |
|
166 | 237 | |
|
167 | 238 | parms = {'topic': topic} |
|
168 | 239 | |
|
169 | 240 | self.message = "TX parameters have been successfully read" |
|
170 | 241 | return parms |
|
171 | 242 | else: |
|
172 | 243 | self.message = "Error reading TX parameters" |
|
173 | 244 | return None |
|
174 | 245 | |
|
175 | 246 | |
|
176 | 247 | def write_device(self): |
|
177 | 248 | |
|
178 | 249 | ip=self.device.ip_address |
|
179 | 250 | port=self.device.port_address |
|
180 | 251 | |
|
181 | 252 | #---Frequencies from form |
|
182 | 253 | parms = self.parms_to_dict()['configurations'] |
|
183 | 254 | for parm in parms['allIds']: |
|
184 | 255 | byid = parm |
|
185 | 256 | frequencies = parms['byId'][byid] |
|
186 | 257 | post_data = {} |
|
187 | 258 | for data in frequencies: |
|
188 | 259 | if data in ['topic']: |
|
189 | 260 | post_data[data] = frequencies[data] |
|
190 | 261 | |
|
191 | 262 | route = "http://" + str(ip) + ":" + str(port) + "/write/" |
|
192 | 263 | print (post_data) |
|
193 | 264 | try: |
|
194 | 265 | r = requests.post(route, post_data, timeout=0.7) |
|
195 | 266 | except: |
|
196 | 267 | self.message = "Could not write TX parameters" |
|
197 | 268 | self.device.status = 0 |
|
198 | 269 | self.device.save() |
|
199 | 270 | return False |
|
200 | 271 | |
|
201 | 272 | response = r.json() |
|
202 | 273 | self.message = response['message'] |
|
203 | 274 | self.device.status = response['status'] |
|
204 | 275 | self.device.save() |
|
205 | 276 | |
|
206 | 277 | if self.device.status==1: |
|
207 | 278 | return False |
|
208 | 279 | |
|
209 | 280 | return True |
|
210 | 281 | |
|
211 | 282 | |
|
212 | 283 | class Meta: |
|
213 | 284 | db_table = 'atrad_configurations' No newline at end of file |
@@ -1,104 +1,127 | |||
|
1 | 1 | import paho.mqtt.client as mqtt |
|
2 | 2 | from radarsys import settings |
|
3 | 3 | from radarsys.socketconfig import sio as sio |
|
4 | 4 | import numpy as np |
|
5 | 5 | import psycopg2 |
|
6 | 6 | import os |
|
7 | 7 | |
|
8 | 8 | def insert(time,data): |
|
9 | 9 | sql = """INSERT INTO atrad_datas( |
|
10 | datetime,nstx,status,temp_cll,nboards,tempdvr,potincdvr,potretdvr, | |
|
11 | temp1,potinc1,potret1,temp2,potinc2,potret2,temp3,potinc3,potret3, | |
|
12 |
temp4,potinc4,potret4,temp5,potinc5,potret5,temp6,potinc6,potret6 |
|
|
10 | datetime,nstx,status_1,temp_cll_1,nboards_1,tempdvr_1,potincdvr_1,potretdvr_1, | |
|
11 | temp1_1,potinc1_1,potret1_1,temp2_1,potinc2_1,potret2_1,temp3_1,potinc3_1,potret3_1, | |
|
12 | temp4_1,potinc4_1,potret4_1,temp5_1,potinc5_1,potret5_1,temp6_1,potinc6_1,potret6_1, | |
|
13 | status_2,temp_cll_2,nboards_2,tempdvr_2,potincdvr_2,potretdvr_2, | |
|
14 | temp1_2,potinc1_2,potret1_2,temp2_2,potinc2_2,potret2_2,temp3_2,potinc3_2,potret3_2, | |
|
15 | temp4_2,potinc4_2,potret4_2,temp5_2,potinc5_2,potret5_2,temp6_2,potinc6_2,potret6_2, | |
|
16 | status_3,temp_cll_3,nboards_3,tempdvr_3,potincdvr_3,potretdvr_3, | |
|
17 | temp1_3,potinc1_3,potret1_3,temp2_3,potinc2_3,potret2_3,temp3_3,potinc3_3,potret3_3, | |
|
18 | temp4_3,potinc4_3,potret4_3,temp5_3,potinc5_3,potret5_3,temp6_3,potinc6_3,potret6_3, | |
|
19 | status_4,temp_cll_4,nboards_4,tempdvr_4,potincdvr_4,potretdvr_4, | |
|
20 | temp1_4,potinc1_4,potret1_4,temp2_4,potinc2_4,potret2_4,temp3_4,potinc3_4,potret3_4, | |
|
21 | temp4_4,potinc4_4,potret4_4,temp5_4,potinc5_4,potret5_4,temp6_4,potinc6_4,potret6_4) | |
|
13 | 22 | VALUES(%s,%s,%s,%s,%s,%s,%s,%s, |
|
14 | 23 | %s,%s,%s,%s,%s,%s,%s,%s,%s, |
|
24 | %s,%s,%s,%s,%s,%s,%s,%s,%s, | |
|
25 | %s,%s,%s,%s,%s,%s, | |
|
26 | %s,%s,%s,%s,%s,%s,%s,%s,%s, | |
|
27 | %s,%s,%s,%s,%s,%s,%s,%s,%s, | |
|
28 | %s,%s,%s,%s,%s,%s, | |
|
29 | %s,%s,%s,%s,%s,%s,%s,%s,%s, | |
|
30 | %s,%s,%s,%s,%s,%s,%s,%s,%s, | |
|
31 | %s,%s,%s,%s,%s,%s, | |
|
32 | %s,%s,%s,%s,%s,%s,%s,%s,%s, | |
|
15 | 33 | %s,%s,%s,%s,%s,%s,%s,%s,%s);""" |
|
16 | 34 | try: |
|
17 | 35 | # connect to the PostgreSQL database |
|
18 | 36 | conn = psycopg2.connect(database="radarsys", user='docker', password='docker', host='radarsys-postgres', port= '5432') |
|
19 | 37 | # create a new cursor |
|
20 | 38 | cur = conn.cursor() |
|
21 | 39 | # execute the INSERT statement |
|
22 | 40 | #data_tuple = [tuple(i[:]) for i in a] |
|
23 | values = (time,) + tuple(data[0][:25]) | |
|
41 | values = (time,) + tuple(data[0][:25])+tuple(data[1][1:25])+tuple(data[2][1:25])+tuple(data[3][1:25]) | |
|
24 | 42 | cur.execute(sql, values) |
|
25 | 43 | |
|
26 | 44 | # get the generated id back |
|
27 | 45 | #vendor_id = cur.fetchone()[0] |
|
28 | 46 | |
|
29 | 47 | # commit the changes to the database |
|
30 | 48 | conn.commit() |
|
31 | 49 | # close communication with the database |
|
32 | 50 | cur.close() |
|
33 | 51 | except (Exception, psycopg2.DatabaseError) as error: |
|
34 | 52 | print(error) |
|
35 | 53 | finally: |
|
36 | 54 | if conn is not None: |
|
37 | 55 | conn.close() |
|
38 | 56 | |
|
39 | 57 | def maxTemperature(trs): |
|
40 | 58 | temps = GetTemperatures(trs) |
|
41 | 59 | maxT_STX = [max(i) for i in temps] |
|
42 | 60 | maxT = max(maxT_STX) |
|
43 | 61 | STXnum = maxT_STX.index(maxT) |
|
44 | 62 | STXloc = temps[STXnum].index(maxT) |
|
45 | 63 | maxT_loc = 'Amp ' + str(STXnum+1) |
|
46 | 64 | |
|
47 | 65 | if STXloc == 0: |
|
48 | 66 | maxT_loc = maxT_loc + " Controller" |
|
49 |
elif STXloc |
|
|
50 |
maxT_loc = maxT_loc + " |
|
|
67 | elif STXloc == 1: | |
|
68 | maxT_loc = maxT_loc + " Driver" | |
|
69 | elif STXloc<8: | |
|
70 | maxT_loc = maxT_loc + " PA " + str(STXloc-1) | |
|
51 | 71 | else: |
|
52 | 72 | maxT_loc = maxT_loc + " Combiners" |
|
53 | 73 | |
|
54 | 74 | return maxT,maxT_loc,temps |
|
55 | 75 | |
|
56 | 76 | def dataConvert(msg): |
|
57 | 77 | msgStr = str(msg.payload) |
|
58 | 78 | msgClean = [i for i in msgStr[21:-1].split("*")] |
|
59 | 79 | dataSTX = [[],[],[],[]] |
|
60 | 80 | for trs,i in zip(msgClean,[0,1,2,3]) : |
|
61 | 81 | dataSTX[i]= [int(i) for i in trs[1:-1].split(",")] |
|
62 | 82 | # Data to database |
|
63 | 83 | insert(msgStr[2:21],dataSTX) |
|
64 | 84 | # Data to send by socket |
|
65 | 85 | id_STX = dataSTX[0][0] // 4 |
|
66 | 86 | status = ''.join([msgClean[i][3] for i in [0,1,2,3]]) |
|
67 | powers = [dataSTX[0][34],dataSTX[0][36],dataSTX[2][32],dataSTX[2][34]] | |
|
87 | powers = [dataSTX[0][34],dataSTX[0][36],dataSTX[2][32],dataSTX[2][34],0,0,0,0] | |
|
88 | # alerta | |
|
89 | for i in range(4): | |
|
90 | if powers[i] < 10000 and status == '1111': | |
|
91 | power[4+i] = 1 | |
|
92 | ||
|
68 | 93 | tmax,index,tempData = maxTemperature(dataSTX) |
|
69 | 94 | #Json to send |
|
70 | 95 | data = {'time':msgStr[2:21],'num':id_STX,'pow':powers,'tmax':[str(tmax),index],'status':status} |
|
71 | 96 | data_temp = {'time':msgStr[2:21],'temp':tempData} |
|
72 | 97 | return data, data_temp |
|
73 | 98 | |
|
74 | 99 | def GetTemperatures(data): |
|
75 | 100 | np_data = [np.array(i) for i in data] |
|
76 | 101 | temps = [i[i<40] for i in np_data] |
|
77 | 102 | return [i[i>15].tolist() for i in temps] |
|
78 | 103 | |
|
79 | 104 | def on_connect(mqtt_client, userdata, flags, rc): |
|
80 | 105 | if rc == 0: |
|
81 |
|
|
|
106 | print('Connected successfullyasdss') | |
|
82 | 107 | mqtt_client.subscribe("atrad/test4") |
|
108 | print("Exito") | |
|
83 | 109 | else: |
|
84 | 110 | print('Bad connection. Code:', rc) |
|
85 | 111 | |
|
86 | 112 | def on_message(mqtt_client, userdata, msg): |
|
87 | 113 | print('Received message on topic: {} with payload: {}'.format(msg.topic,msg.payload), flush=True) |
|
88 | 114 | mainData, tempData = dataConvert(msg) |
|
89 | # print("Recibi : {}".format(msg.payload),flush=True) | |
|
90 | #socket fot general data | |
|
91 | 115 | sio.emit('test',data = mainData) |
|
92 | print(mainData) | |
|
93 | 116 | #socket for temperature details |
|
94 | 117 | sio.emit('temptx'+str(mainData['num'] + 1),data = tempData) |
|
95 | 118 | |
|
96 | 119 | client = mqtt.Client() |
|
97 | 120 | client.on_connect = on_connect |
|
98 | 121 | client.on_message = on_message |
|
99 | 122 | client.username_pw_set( '','') |
|
100 | 123 | client.connect( |
|
101 | 124 | host=os.environ.get('MQTT_SERVER', '10.10.10.200'), |
|
102 | 125 | port=int(settings.os.environ.get('MQTT_PORT', 1883)), |
|
103 | 126 | keepalive=int(os.environ.get('MQTT_KEEPALIVE', 60)) |
|
104 | 127 | ) No newline at end of file |
@@ -1,270 +1,283 | |||
|
1 | 1 | {% extends "dev_conf.html" %} |
|
2 | 2 | {% load static %} |
|
3 | 3 | {% block extra-head %} |
|
4 | 4 | <style> |
|
5 | 5 | .dot { |
|
6 | 6 | height: 25px; |
|
7 | 7 | width: 25px; |
|
8 | 8 | background-color: #b0b3af; |
|
9 | 9 | border-radius: 50%; |
|
10 | 10 | display: inline-block; |
|
11 | 11 | } |
|
12 | 12 | .row{ |
|
13 | 13 | margin-top: 3px; |
|
14 | 14 | margin-bottom: 3px; |
|
15 | 15 | } |
|
16 | 16 | .th { |
|
17 | 17 | vertical-align: middle; |
|
18 | 18 | } |
|
19 | 19 | </style> |
|
20 | 20 | <link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet"> |
|
21 | 21 | {% endblock %} |
|
22 | 22 | |
|
23 | 23 | {% block content-graph %} |
|
24 | 24 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> |
|
25 | 25 | <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script> |
|
26 | 26 | |
|
27 | 27 | <div class="container-fluid"> |
|
28 | 28 | <h1 class="py-4 text-center" >ATRAD Monitoring</h1> |
|
29 | 29 | |
|
30 | 30 | <!-- First row : Control--> |
|
31 | 31 | <div class="row"> |
|
32 | 32 | <div class="card border-light"> |
|
33 | 33 | <div class="card-body"> |
|
34 | 34 | <h3 class="card-title">Control</h3> |
|
35 | 35 | <table class="table table-borderless"> |
|
36 | 36 | <tbody> |
|
37 | 37 | <tr> |
|
38 | 38 | <th class="align-middle">Tx1</th> |
|
39 | 39 | <td> |
|
40 | 40 | <button type="button" class="btn btn-outline-success" id="ONBtn1"> ON </button> |
|
41 | 41 | <button type="button" class="btn btn-outline-danger" id="OFFBtn1"> OFF </button> |
|
42 | 42 | </td> |
|
43 | 43 | </tr> |
|
44 | 44 | <tr> |
|
45 | 45 | <th class="align-middle">Tx2</th> |
|
46 | 46 | <td> |
|
47 | 47 | <button type="button" class="btn btn-outline-success" id="ONBtn2"> ON </button> |
|
48 | 48 | <button type="button" class="btn btn-outline-danger" id="OFFBtn2"> OFF </button> |
|
49 | 49 | </td> |
|
50 | 50 | </tr> |
|
51 | 51 | </tbody> |
|
52 | 52 | </table> |
|
53 | 53 | </div> |
|
54 | 54 | </div> |
|
55 | 55 | </div> |
|
56 | 56 | |
|
57 | 57 | <!-- Second row : Status and alerts --> |
|
58 | 58 | <div class="row"> |
|
59 | <div class="card-deck"> | |
|
59 | <div class="card-deck" style="width: 90%;"> | |
|
60 | 60 | <div class="card border-light"> |
|
61 | 61 | <div class="card-body"> |
|
62 | 62 | <h4 class="card-title">Status</h4> |
|
63 | 63 | <table class="table table-borderless"> |
|
64 | 64 | <tbody> |
|
65 | 65 | <tr> |
|
66 | 66 | <th scope="row">Tx1</th> |
|
67 | 67 | <td><span id="status1" class="dot"></span></td> |
|
68 | 68 | <td><p id="status-text1" class="font-weight-bold">No data</p></td> |
|
69 | 69 | </tr> |
|
70 | 70 | <tr> |
|
71 | 71 | <th scope="row">Tx2</th> |
|
72 | 72 | <td><span id="status2" class="dot"></span></td> |
|
73 | 73 | <td><p id="status-text2" class="font-weight-bold">No data</p></td> |
|
74 | 74 | </tr> |
|
75 | 75 | </tbody> |
|
76 | 76 | </table> |
|
77 | 77 | </div> |
|
78 | 78 | </div> |
|
79 | 79 | <div class="card border-light"> |
|
80 | 80 | <div class="card-body"> |
|
81 | 81 | <h4 class="card-title">High Temperature Alerts</h4> |
|
82 | 82 | <table class="table table-borderless"> |
|
83 | 83 | <tbody> |
|
84 | 84 | <tr> |
|
85 | <th scope="row"><p id="alert-time1" class="font-weight-bold"></p></th> | |
|
86 |
<td><p id="alert |
|
|
87 | <td><p id="alert-loc1" class="font-weight-bold"></p></td> | |
|
85 | <th scope="row"><p id="alerttemp-time1" class="font-weight-bold"></p></th> | |
|
86 | <td><p id="alerttemp-1" class="font-weight-bold"></p></td> | |
|
87 | <td><p id="alerttemp-loc1" class="font-weight-bold"></p></td> | |
|
88 | 88 | </tr> |
|
89 | 89 | <tr> |
|
90 | <th scope="row"><p id="alert-time2" class="font-weight-bold"></p></th> | |
|
91 |
<td><p id="alert |
|
|
92 | <td><p id="alert-loc2" class="font-weight-bold"></p></td> | |
|
90 | <th scope="row"><p id="alerttemp-time2" class="font-weight-bold"></p></th> | |
|
91 | <td><p id="alerttemp-2" class="font-weight-bold"></p></td> | |
|
92 | <td><p id="alerttemp-loc2" class="font-weight-bold"></p></td> | |
|
93 | 93 | </tr> |
|
94 | 94 | </tbody> |
|
95 | 95 | </table> |
|
96 | 96 | </div> |
|
97 | 97 | </div> |
|
98 | 98 | <div class="card border-light"> |
|
99 | 99 | <div class="card-body"> |
|
100 | 100 | <h4 class="card-title">Power Alerts</h4> |
|
101 | Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempora quisquam cupiditate sunt eaque distinctio explicabo aliquam blanditiis illo eligendi eveniet culpa, vel laboriosam! Facilis dolores assumenda autem. Maiores, quibusdam eum. | |
|
101 | <table class="table table-borderless"> | |
|
102 | <tbody> | |
|
103 | <tr> | |
|
104 | <th scope="row"><p id="alertpot-time1" class="font-weight-bold"></p></th> | |
|
105 | <td><p id="alertpot-1" class="font-weight-bold"></p></td> | |
|
106 | <td><p id="alertpot-loc1" class="font-weight-bold"></p></td> | |
|
107 | </tr> | |
|
108 | <tr> | |
|
109 | <th scope="row"><p id="alertpot-time2" class="font-weight-bold"></p></th> | |
|
110 | <td><p id="alertpot-2" class="font-weight-bold"></p></td> | |
|
111 | <td><p id="alertpot-loc2" class="font-weight-bold"></p></td> | |
|
112 | </tr> | |
|
113 | </tbody> | |
|
114 | </table> | |
|
102 | 115 | </div> |
|
103 | 116 | </div> |
|
104 | 117 | </div> |
|
105 | 118 | </div> |
|
106 | 119 | |
|
107 | 120 | <!-- Third row : power graph--> |
|
108 | 121 | <div class="row "> |
|
109 | 122 | <div class="card border-light"> |
|
110 | 123 | <div class="card-body"> |
|
111 | 124 | <h3 class="card-title">Power graph</h3> |
|
112 | 125 | <div class="row justify-content-md-center"> |
|
113 | 126 | <div class="col-md-9"> |
|
114 | 127 | <div id="plot-pot"></div> |
|
115 | 128 | </div> |
|
116 | 129 | <div class="col-md-3 text-end"> |
|
117 | 130 | <div class="card-body"> |
|
118 | 131 | <table class="table" style="max-width:170px;"> |
|
119 | 132 | <tbody> |
|
120 | 133 | <tr> |
|
121 | 134 | <th scope="col"># Tx</th> |
|
122 | 135 | <th scope="col">Power (kW)</th> |
|
123 | 136 | </tr> |
|
124 | 137 | <tr> |
|
125 | 138 | <th scope="row">1</th> |
|
126 | 139 | <td><p id="pot1"></p></td> |
|
127 | 140 | </tr> |
|
128 | 141 | <tr> |
|
129 | 142 | <th scope="row">2</th> |
|
130 | 143 | <td><p id="pot2"></p></td> |
|
131 | 144 | </tr> |
|
132 | 145 | </tbody> |
|
133 | 146 | </table> |
|
134 | 147 | </div> |
|
135 | 148 | <div class="card-body"> |
|
136 | 149 | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Pot-1">T1</button> |
|
137 | 150 | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Pot-2">T2</button> |
|
138 | 151 | </div> |
|
139 | 152 | </div> |
|
140 | 153 | </div> |
|
141 | 154 | </div> |
|
142 | 155 | </div> |
|
143 | 156 | </div> |
|
144 | 157 | <!--Temperature Graph--> |
|
145 | 158 | <div class="row "> |
|
146 | 159 | <div class="card border-light"> |
|
147 | 160 | <div class="card-body"> |
|
148 | 161 | <h3 class="card-title">Temperature graph</h3> |
|
149 | 162 | <div class="row justify-content-md-center"> |
|
150 | 163 | <div class="col-md-9"> |
|
151 | 164 | <div id="plot-temp"></div> |
|
152 | 165 | </div> |
|
153 | 166 | <div class="col-md-3 text-end"> |
|
154 | 167 | <div class="card-body"> |
|
155 | 168 | <table class="table table-hover" style="max-width:170px;"> |
|
156 | 169 | <tbody> |
|
157 | 170 | <tr> |
|
158 | 171 | <th scope="col"># Tx</th> |
|
159 | 172 | <th scope="col">Temperature (Β°C)</th> |
|
160 | 173 | </tr> |
|
161 | 174 | <tr class="clickable-row" data-href="{% url 'url_tx_atrad' dev_conf.id 'tx1' %}"> |
|
162 | 175 | <th scope="row">1</th> |
|
163 | 176 | <td><p id="temp1"></p></td> |
|
164 | 177 | </tr> |
|
165 | 178 | <tr class="clickable-row" data-href="{% url 'url_tx_atrad' dev_conf.id 'tx2' %}"> |
|
166 | 179 | <th scope="row">2</th> |
|
167 | 180 | <td><p id="temp2"></p></td> |
|
168 | 181 | </tr> |
|
169 | 182 | </tbody> |
|
170 | 183 | </table> |
|
171 | 184 | </div> |
|
172 | 185 | </div> |
|
173 | 186 | </div> |
|
174 | 187 | </div> |
|
175 | 188 | </div> |
|
176 | 189 | </div> |
|
177 | 190 | </div> |
|
178 | 191 | |
|
179 | 192 | <!--Modales--> |
|
180 | 193 | <div class="modal fade" id="Pot-1" role="dialog"> |
|
181 | 194 | <div class="modal-dialog modal-lg" style="max-width:50%;min-width:750px"> |
|
182 | 195 | <div class="modal-content"> |
|
183 | 196 | <div class="modal-header"> |
|
184 | 197 | <h4 class="modal-title">Potencia incidente - Transmisor 1</h4> |
|
185 | 198 | <button type="button" class="close" data-dismiss="modal">×</button> |
|
186 | 199 | </div> |
|
187 | 200 | <div class="modal-body"> |
|
188 | 201 | <div class="row"> |
|
189 | 202 | <div class="col"> |
|
190 | 203 | <div id="plot-pot-t1"></div> |
|
191 | 204 | </div> |
|
192 | 205 | <div class="col"> |
|
193 | 206 | <table class="table" style="max-width: 150px;"> |
|
194 | 207 | <tbody> |
|
195 | 208 | <tr> |
|
196 | 209 | <th scope="col"># Amp</th> |
|
197 | 210 | <th scope="col">Potencia (kW)</th> |
|
198 | 211 | </tr> |
|
199 | 212 | <tr> |
|
200 | 213 | <th scope="row">P1</th> |
|
201 | 214 | <td><p id="pot1-1"></p></td> |
|
202 | 215 | </tr> |
|
203 | 216 | <tr> |
|
204 | 217 | <th scope="row">P2</th> |
|
205 | 218 | <td><p id="pot1-2"></p></td> |
|
206 | 219 | </tr> |
|
207 | 220 | <tr> |
|
208 | 221 | <th scope="row">P3</th> |
|
209 | 222 | <td><p id="pot1-3"></p></td> |
|
210 | 223 | </tr> |
|
211 | 224 | <tr> |
|
212 | 225 | <th scope="row">P4</th> |
|
213 | 226 | <td><p id="pot1-4"></p></td> |
|
214 | 227 | </tr> |
|
215 | 228 | </tbody> |
|
216 | 229 | </table> |
|
217 | 230 | </div> |
|
218 | 231 | </div> |
|
219 | 232 | </div> |
|
220 | 233 | </div> |
|
221 | 234 | </div> |
|
222 | 235 | </div> |
|
223 | 236 | |
|
224 | 237 | <div class="modal fade" id="Pot-2" role="dialog"> |
|
225 | 238 | <div class="modal-dialog modal-lg" style="max-width:50%;min-width:750px"> |
|
226 | 239 | <div class="modal-content"> |
|
227 | 240 | <div class="modal-header"> |
|
228 | 241 | <h4 class="modal-title">Potencia incidente - Transmisor 2</h4> |
|
229 | 242 | <button type="button" class="close" data-dismiss="modal">×</button> |
|
230 | 243 | </div> |
|
231 | 244 | <div class="modal-body"> |
|
232 | 245 | <div class="row"> |
|
233 | 246 | <div class="col"> |
|
234 | 247 | <div id="plot-pot-t2"></div> |
|
235 | 248 | </div> |
|
236 | 249 | <div class="col"> |
|
237 | 250 | <table class="table" style="max-width: 150px;"> |
|
238 | 251 | <tbody> |
|
239 | 252 | <tr> |
|
240 | 253 | <th scope="col"># Amp</th> |
|
241 | 254 | <th scope="col">Potencia (kW)</th> |
|
242 | 255 | </tr> |
|
243 | 256 | <tr> |
|
244 | 257 | <th scope="row">P1</th> |
|
245 | 258 | <td><p id="pot2-1"></p></td> |
|
246 | 259 | </tr> |
|
247 | 260 | <tr> |
|
248 | 261 | <th scope="row">P2</th> |
|
249 | 262 | <td><p id="pot2-2"></p></td> |
|
250 | 263 | </tr> |
|
251 | 264 | <tr> |
|
252 | 265 | <th scope="row">P3</th> |
|
253 | 266 | <td><p id="pot2-3"></p></td> |
|
254 | 267 | </tr> |
|
255 | 268 | <tr> |
|
256 | 269 | <th scope="row">P4</th> |
|
257 | 270 | <td><p id="pot2-4"></p></td> |
|
258 | 271 | </tr> |
|
259 | 272 | </tbody> |
|
260 | 273 | </table> |
|
261 | 274 | </div> |
|
262 | 275 | </div> |
|
263 | 276 | </div> |
|
264 | 277 | </div> |
|
265 | 278 | </div> |
|
266 | 279 | </div> |
|
267 | 280 | |
|
268 | 281 | <script src="{% static 'js/atrad-conf.js' %}"></script> |
|
269 | 282 | |
|
270 | 283 | {% endblock %} No newline at end of file |
@@ -1,136 +1,168 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load static %} |
|
3 | 3 | {% block title %}ATRAD Tx{{id_tx}} Temperatures{% endblock %} |
|
4 | 4 | {% block content-title %}{{title}}{% endblock %} |
|
5 | 5 | {% block content-suptitle %}Tx {{id_tx}}{% endblock %} |
|
6 | 6 | |
|
7 | 7 | {% block extra-head %} |
|
8 | 8 | <style> |
|
9 | 9 | .panel-body { |
|
10 | 10 | background:#ffffff;} |
|
11 | 11 | .panel-footer { |
|
12 | 12 | background:#ffffff;} |
|
13 | 13 | .card-body { |
|
14 | 14 | padding-top: 1px; |
|
15 | 15 | padding-bottom: 1px; |
|
16 | 16 | } |
|
17 | 17 | </style> |
|
18 | 18 | {% endblock %} |
|
19 | 19 | |
|
20 | 20 | {% block content-graph %} |
|
21 | 21 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> |
|
22 | 22 | <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script> |
|
23 | 23 | |
|
24 | 24 | <div class="container-fluid"> |
|
25 | 25 | <!-- Temperatura generales --> |
|
26 | 26 | <div class="row "> |
|
27 | 27 | <div class="panel panel-default"> |
|
28 | 28 | <div class="panel-heading"> |
|
29 | 29 | <h3 class="panel-title">Amplifiers</h3> |
|
30 | 30 | </div> |
|
31 | 31 | <div class="panel-body"> |
|
32 | 32 | <div class="card border-0"> |
|
33 | 33 | <div class="row"> |
|
34 | 34 | <div class="card-body"> |
|
35 | 35 | <h5 class="card-title">Amplifier 1</h5> |
|
36 | 36 | <div id="plot-temp-1"></div> |
|
37 | 37 | </div> |
|
38 | 38 | <div class="card-body"> |
|
39 | 39 | <h5 class="card-title">Amplifier 2</h5> |
|
40 | 40 | <div id="plot-temp-2"></div> |
|
41 | 41 | </div> |
|
42 | 42 | <div class="card-body"> |
|
43 | 43 | <h5 class="card-title">Amplifier 3</h5> |
|
44 | 44 | <div id="plot-temp-3"></div> |
|
45 | 45 | </div> |
|
46 | 46 | <div class="card-body"> |
|
47 | 47 | <h5 class="card-title">Amplifier 4</h5> |
|
48 | 48 | <div id="plot-temp-4"></div> |
|
49 | 49 | </div> |
|
50 | 50 | </div> |
|
51 | 51 | </div> |
|
52 | 52 | </div> |
|
53 | 53 | </div> |
|
54 | 54 | </div> |
|
55 | 55 | <div class="row"> |
|
56 | 56 | <div class="panel panel-default"> |
|
57 | 57 | <div class="panel-heading"> |
|
58 | 58 | <h3 class="panel-title">Controllers and combiners</h3> |
|
59 | 59 | </div> |
|
60 | 60 | <div class="panel-body"> |
|
61 | 61 | <div id="plot-temp-0"></div> |
|
62 | 62 | </div> |
|
63 | 63 | </div> |
|
64 | 64 | </div> |
|
65 | 65 | </div> |
|
66 | 66 | |
|
67 | 67 | <script> |
|
68 | 68 | $(document).ready(function() { |
|
69 | 69 | var socket = io.connect('http://' + document.domain + ':' + location.port); |
|
70 | 70 | socket.on('connect', function(data) { |
|
71 | 71 | console.log('Connecting... OK'); |
|
72 |
var data = '{{data|safe}}' |
|
|
73 | console.log(data); | |
|
74 | makePlot("plot-temp-0",4,["PC1","PC2","PC3","PC4"],[0,40]); | |
|
75 | makePlot("plot-temp-1",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) | |
|
76 | makePlot("plot-temp-2",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) | |
|
77 | makePlot("plot-temp-3",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) | |
|
78 | makePlot("plot-temp-4",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) | |
|
79 | }) | |
|
72 | var basedata = JSON.parse('{{data|safe}}') | |
|
73 | console.log(basedata); | |
|
74 | makePlot("plot-temp-0",4,["PC1","PC2","PC3","PC4"],[10,40]); | |
|
75 | makePlot2("plot-temp-1",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) | |
|
76 | makePlot2("plot-temp-2",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) | |
|
77 | makePlot2("plot-temp-3",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) | |
|
78 | makePlot2("plot-temp-4",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) | |
|
79 | }) | |
|
80 | 80 | socket.on("temptx"+"{{id_tx}}", function(data) { |
|
81 | 81 | var controllers = [data.temp[0][1],data.temp[1][1],data.temp[2][1],data.temp[3][1]] |
|
82 | 82 | streamPlot2("plot-temp-0",data.time,controllers,4); |
|
83 |
streamPlot2("plot-temp-1",data.time,data.temp[0].slice( |
|
|
84 |
streamPlot2("plot-temp-2",data.time,data.temp[1].slice( |
|
|
85 |
streamPlot2("plot-temp-3",data.time,data.temp[2].slice( |
|
|
86 |
streamPlot2("plot-temp-4",data.time,data.temp[3].slice( |
|
|
83 | streamPlot2("plot-temp-1",data.time,data.temp[0].slice(2,8),6); | |
|
84 | streamPlot2("plot-temp-2",data.time,data.temp[1].slice(2,8),6); | |
|
85 | streamPlot2("plot-temp-3",data.time,data.temp[2].slice(2,8),6); | |
|
86 | streamPlot2("plot-temp-4",data.time,data.temp[3].slice(2,8),6); | |
|
87 | 87 | }) |
|
88 | 88 | }); |
|
89 | 89 | |
|
90 | 90 | function makePlot(div, n=1, names=["", ""],ranges){ |
|
91 | 91 | var plotDiv = document.getElementById(div); |
|
92 | 92 | var traces = []; |
|
93 | 93 | for (let i = 0; i < n; i++) { |
|
94 | 94 | traces.push({x: [], y: [],mode: 'lines', name: names[i]}); |
|
95 | 95 | } |
|
96 | 96 | traces.push({x: [], y: [],mode: 'lines',line: {color:'rgb(219, 64, 82)',dash: 'dot',width: 2},name:"nominal",showlegend: false}); |
|
97 | 97 | var yrange = ranges; |
|
98 | 98 | var layout = { |
|
99 | 99 | width: 505, |
|
100 | height: 300, | |
|
101 | font: {size: 12}, | |
|
102 | margin: { t: 10, b:50, r:15 ,l:15}, | |
|
103 | xaxis: { | |
|
104 | type: 'date' | |
|
105 | }, | |
|
106 | yaxis: { | |
|
107 | range: yrange, | |
|
108 | }, | |
|
109 | legend: {"orientation": "h"}, | |
|
110 | }; | |
|
111 | var config = {responsive: true} | |
|
112 | Plotly.newPlot(plotDiv, traces, layout,config); | |
|
113 | }; | |
|
114 | ||
|
115 | function makePlot2(div, n=1, names=["", ""],ranges,data){ | |
|
116 | var plotDiv = document.getElementById(div); | |
|
117 | var traces = []; | |
|
118 | var keys = ['temp1','temp2','temp3','temp4','temp5','temp6'] | |
|
119 | ||
|
120 | for (let i = 0; i < n; i++) { | |
|
121 | var x = []; | |
|
122 | var y = []; | |
|
123 | for(let j = 0;j < data.length; j++){ | |
|
124 | x[j] = data[j].datetime; | |
|
125 | y[j] = data[j][keys[i]+'_'+div.charAt(10)]; | |
|
126 | } | |
|
127 | traces.push({x:x, y:y,mode: 'lines', name: names[i]}); | |
|
128 | } | |
|
129 | var yrange = ranges; | |
|
130 | var layout = { | |
|
131 | width: 505, | |
|
100 | 132 | height: 400, |
|
101 | 133 | font: {size: 12}, |
|
102 | 134 | margin: { t: 10, b:50, r:15 ,l:15}, |
|
103 | 135 | xaxis: { |
|
104 | 136 | type: 'date' |
|
105 | 137 | }, |
|
106 | 138 | yaxis: { |
|
107 | 139 | range: yrange, |
|
108 | 140 | }, |
|
109 | 141 | legend: {"orientation": "h"}, |
|
110 | 142 | }; |
|
111 | 143 | var config = {responsive: true} |
|
112 | 144 | Plotly.newPlot(plotDiv, traces, layout,config); |
|
113 | 145 | }; |
|
114 | 146 | |
|
115 | 147 | function streamPlot2(div,x,y,cant){ |
|
116 | 148 | var plotDiv = document.getElementById(div); |
|
117 | 149 | if (plotDiv.data[0].x.length > 8){ |
|
118 | 150 | for(let i=0;i<cant;i++){ |
|
119 | 151 | plotDiv.data[i].x = plotDiv.data[i].x.slice(-11) |
|
120 | 152 | plotDiv.data[i].y = plotDiv.data[i].y.slice(-11) |
|
121 | 153 | } |
|
122 | 154 | } |
|
123 | 155 | var tm = []; |
|
124 | 156 | var values = []; |
|
125 | 157 | var index = [] |
|
126 | 158 | for(let i=0;i<cant;i++){ |
|
127 | 159 | values[i]=[y[i]]; |
|
128 | 160 | tm[i] = [x]; |
|
129 | 161 | index[i] = i; |
|
130 | 162 | } |
|
131 | 163 | var data_update = {x: tm, y: values} |
|
132 | 164 | Plotly.extendTraces(plotDiv, data_update,index) |
|
133 | 165 | }; |
|
134 | 166 | |
|
135 | 167 | </script> |
|
136 | 168 | {% endblock %} No newline at end of file |
@@ -1,121 +1,125 | |||
|
1 | 1 | from django.shortcuts import redirect, render, get_object_or_404 |
|
2 | 2 | from django.contrib import messages |
|
3 | 3 | from django.http import HttpResponse |
|
4 | 4 | from django.template.loader import get_template |
|
5 | 5 | |
|
6 | 6 | from apps.main.models import Experiment |
|
7 | 7 | from .models import ATRADConfiguration, ATRADData |
|
8 | 8 | |
|
9 | 9 | from .forms import ATRADConfigurationForm, UploadFileForm |
|
10 | 10 | from apps.main.views import sidebar |
|
11 | 11 | |
|
12 | 12 | import requests |
|
13 | 13 | import json |
|
14 | 14 | |
|
15 | 15 | import os |
|
16 | 16 | from django.http import JsonResponse |
|
17 | 17 | from .mqtt import client as mqtt_client |
|
18 | 18 | from radarsys.socketconfig import sio as sio |
|
19 | 19 | from datetime import timedelta |
|
20 | 20 | |
|
21 | 21 | def atrad_conf(request, id_conf): |
|
22 | 22 | |
|
23 | 23 | conf = get_object_or_404(ATRADConfiguration, pk=id_conf) |
|
24 | 24 | |
|
25 | 25 | ip=conf.device.ip_address |
|
26 | 26 | port=conf.device.port_address |
|
27 | 27 | |
|
28 | 28 | kwargs = {} |
|
29 | 29 | |
|
30 | 30 | kwargs['status'] = conf.device.get_status_display() |
|
31 | 31 | |
|
32 | 32 | kwargs['dev_conf'] = conf |
|
33 | 33 | kwargs['dev_conf_keys'] = ['label', |
|
34 | 34 | 'topic'] |
|
35 | 35 | |
|
36 | 36 | kwargs['title'] = 'ATRAD Configuration' |
|
37 | 37 | kwargs['suptitle'] = 'Details' |
|
38 | 38 | |
|
39 | 39 | kwargs['button'] = 'Edit Configuration' |
|
40 | 40 | |
|
41 | 41 | #kwargs['no_play'] = True |
|
42 | 42 | ###### SIDEBAR ###### |
|
43 | 43 | kwargs.update(sidebar(conf=conf)) |
|
44 | 44 | |
|
45 | 45 | return render(request, 'atrad_conf.html', kwargs) |
|
46 | 46 | |
|
47 | 47 | def atrad_tx(request, id_conf, id_tx): |
|
48 | 48 | kwargs = {} |
|
49 | 49 | kwargs['id_tx'] = id_tx[-1] |
|
50 | kwargs['keys'] = ['id','temp1','temp2','temp3','temp4','temp5','temp6'] | |
|
51 | 50 | kwargs['title'] = 'Temperature Details' |
|
52 | 51 | kwargs['button'] = 'Edit Configuration' |
|
53 | 52 | time = ATRADData.objects.last().datetime |
|
54 | mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(minutes=20)),nstx=1).values_list('datetime','temp1','temp2','temp3','temp4','temp5','temp6') | |
|
55 | kwargs['data'] = QuerytoStr(mydata) | |
|
53 | id_stx = (int(id_tx[-1])-1)*4+1 | |
|
54 | mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(hours=1)),nstx = id_stx).values('datetime','temp1_1','temp2_1','temp3_1','temp4_1','temp5_1','temp6_1', | |
|
55 | 'temp1_2','temp2_2','temp3_2','temp4_2','temp5_2','temp6_2','temp1_3','temp2_3','temp3_3','temp4_3','temp5_3','temp6_3', | |
|
56 | 'temp1_4','temp2_4','temp3_4','temp4_4','temp5_4','temp6_4') | |
|
57 | kwargs['data'] = json.dumps(list(mydata),default=str) | |
|
56 | 58 | return render(request, 'atrad_tx.html', kwargs) |
|
57 | 59 | |
|
58 | 60 | def QuerytoStr(data): |
|
59 | 61 | time = data[0] |
|
60 | 62 | strdata = str(time) |
|
61 | 63 | return strdata |
|
62 | 64 | |
|
63 | 65 | def atrad_conf_edit(request, id_conf): |
|
64 | 66 | |
|
65 | 67 | conf = get_object_or_404(ATRADConfiguration, pk=id_conf) |
|
66 | 68 | |
|
67 | 69 | if request.method=='GET': |
|
68 | 70 | form = ATRADConfigurationForm(instance=conf) |
|
69 | 71 | |
|
70 | 72 | if request.method=='POST': |
|
71 | 73 | form = ATRADConfigurationForm(request.POST, instance=conf) |
|
72 | 74 | |
|
73 | 75 | if form.is_valid(): |
|
74 | 76 | if conf.topic == None: conf.topic = 0 |
|
75 | 77 | |
|
76 | 78 | conf = form.save(commit=False) |
|
77 | 79 | |
|
78 | 80 | if conf.verify_frequencies(): |
|
79 | 81 | conf.save() |
|
80 | 82 | return redirect('url_atrad_conf', id_conf=conf.id) |
|
81 | 83 | |
|
82 | 84 | kwargs = {} |
|
83 | 85 | kwargs['id_dev'] = conf.id |
|
84 | 86 | kwargs['form'] = form |
|
85 | 87 | kwargs['title'] = 'Device Configuration' |
|
86 | 88 | kwargs['suptitle'] = 'Edit' |
|
87 | 89 | kwargs['button'] = 'Save' |
|
88 | 90 | |
|
89 | 91 | return render(request, 'atrad_conf_edit.html', kwargs) |
|
90 | 92 | |
|
91 | 93 | def publish_message(request): |
|
92 | 94 | rc, mid = mqtt_client.publish('test/data2',1) |
|
93 | 95 | return JsonResponse({'code1': 'HIKA', 'code2': 'LUCAS'}) |
|
94 | 96 | |
|
95 | 97 | def monitor(request): |
|
96 | 98 | kwargs = {'no_sidebar': True} |
|
97 | 99 | return render(request, 'monitor.html', kwargs) |
|
98 | 100 | |
|
99 | 101 | def atrad_prueba(request): |
|
100 | 102 | keys = ['id','temp1','temp2','temp3','temp4','temp5','temp6'] |
|
101 | 103 | time = ATRADData.objects.last().datetime |
|
102 |
mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(hours=1))).values('id','temp1','temp2','temp3','temp4','temp5','temp6' |
|
|
104 | mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(hours=1))).values('id','temp1_1','temp2_1','temp3_1','temp4_1','temp5_1','temp6_1', | |
|
105 | 'temp1_2','temp2_2','temp3_2','temp4_2','temp5_2','temp6_2','temp1_3','temp2_3','temp3_3','temp4_3','temp5_3','temp6_3', | |
|
106 | 'temp1_4','temp2_4','temp3_4','temp4_4','temp5_4','temp6_4') | |
|
103 | 107 | template = get_template('prueba.html') |
|
104 | 108 | context = { |
|
105 | 109 | 'last' : time, |
|
106 | 110 | 'temps': mydata, |
|
107 | 111 | 'keys' : keys, |
|
108 | 112 | } |
|
109 | 113 | return HttpResponse(template.render(context, request)) |
|
110 | 114 | |
|
111 | 115 | @sio.on('connection-bind') |
|
112 | 116 | def atrad_connection_bind(sid, data): |
|
113 | 117 | print("sid:",sid,"data",data) |
|
114 | 118 | |
|
115 | 119 | @sio.on('disconnect') |
|
116 | 120 | def atrad_disconnect(sid): |
|
117 | 121 | print("Disconnected") |
|
118 | 122 | |
|
119 | 123 | @sio.event |
|
120 | 124 | def atrad_control_event(sid,message): |
|
121 |
mqtt_client.publish('test/data2', json.dumps(message)) |
|
|
125 | mqtt_client.publish('test/data2', json.dumps(message)) No newline at end of file |
@@ -1,74 +1,74 | |||
|
1 | 1 | version: '3' |
|
2 | 2 | services: |
|
3 | 3 | # Django app |
|
4 | 4 | radarsys: |
|
5 | 5 | container_name: 'radarsys' |
|
6 | 6 | build: . |
|
7 | 7 | restart: always |
|
8 | 8 | image: radarsys |
|
9 | 9 | ports: |
|
10 | 10 | - 8000:8000 |
|
11 | 11 | env_file: .env |
|
12 | 12 | links: |
|
13 | 13 | - radarsys-postgres |
|
14 | 14 | volumes: |
|
15 | 15 | - './:/radarsys' |
|
16 | 16 | - '${DOCKER_DATA}/static:/radarsys/static' |
|
17 | 17 | labels: |
|
18 | 18 | ofelia.enabled: "true" |
|
19 | 19 | # ofelia.job-exec.restart-reception.schedule: "0 1/5 * * * *" |
|
20 | 20 | ofelia.job-exec.test.schedule: "@every 5s" |
|
21 | 21 | ofelia.job-exec.test.command: "python manage.py hello" |
|
22 | 22 | # ofelia.job-exec.restart-pedestal.schedule: "0 2/10 * * * *" |
|
23 | 23 | # ofelia.job-exec.restart-pedestal.command: "python manage.py restart_pedestal" |
|
24 | 24 | # ofelia.job-exec.restart-experiment.schedule: "@midnight" |
|
25 | 25 | # ofelia.job-exec.restart-experiment.command: "python manage.py restart_experiment" |
|
26 | 26 | depends_on: |
|
27 | 27 | - radarsys-postgres |
|
28 | 28 | |
|
29 | 29 | # PostgreSQL |
|
30 | 30 | radarsys-postgres: |
|
31 | 31 | container_name: 'radarsys-postgres' |
|
32 | 32 | build: ./postgres/ |
|
33 | 33 | volumes: |
|
34 | 34 | - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d |
|
35 | 35 | - pgdata:/var/lib/postgresql/data |
|
36 | 36 | ports: |
|
37 | 37 | - 5432:5432 |
|
38 | 38 | expose: |
|
39 | 39 | - 5432 |
|
40 | 40 | env_file: .env |
|
41 | 41 | |
|
42 | 42 | #Web Server |
|
43 | 43 | radarsys-nginx: |
|
44 | 44 | container_name: 'radarsys-nginx' |
|
45 | 45 | restart: always |
|
46 | 46 | build: ./nginx/ |
|
47 | 47 | ports: |
|
48 | - '0.0.0.0:80:80' | |
|
48 | - '0.0.0.0:8086:80' | |
|
49 | 49 | volumes_from: |
|
50 | 50 | - radarsys |
|
51 | 51 | links: |
|
52 | 52 | - radarsys:radarsys |
|
53 | 53 | depends_on: |
|
54 | 54 | - radarsys |
|
55 | 55 | |
|
56 | 56 | #Ofelia Scheduler |
|
57 | 57 | radarsys-job: |
|
58 | 58 | container_name: 'radarsys-job' |
|
59 | 59 | image: mcuadros/ofelia:v0.3.6 |
|
60 | 60 | depends_on: |
|
61 | 61 | - radarsys |
|
62 | 62 | # networks: |
|
63 | 63 | # - backend_sirm |
|
64 | 64 | command: daemon --docker |
|
65 | 65 | volumes: |
|
66 | 66 | - /var/run/docker.sock:/var/run/docker.sock:ro |
|
67 | 67 | logging: |
|
68 | 68 | driver: "json-file" |
|
69 | 69 | options: |
|
70 | 70 | max-size: "12m" |
|
71 | 71 | |
|
72 | 72 | volumes: |
|
73 | 73 | pgdata: |
|
74 | 74 | driver: local |
@@ -1,127 +1,134 | |||
|
1 | 1 | $(document).ready(function() { |
|
2 | 2 | var socket = io.connect('http://' + document.domain + ':' + location.port); |
|
3 | 3 | |
|
4 | 4 | socket.on('connect', function(data) { |
|
5 | 5 | console.log('Connecting OK'); |
|
6 | 6 | makePlot("plot-temp",2,["Tx1","Tx2"],[14, 45]) |
|
7 | 7 | makePlot("plot-pot",2,["Tx1","Tx2"],[70,100]) |
|
8 | 8 | makePlot("plot-pot-t1",4,["P1","P2","P3","P4"],[0,25]) |
|
9 | 9 | makePlot("plot-pot-t2",4,["P1","P2","P3","P4"],[0,25]) |
|
10 | 10 | }) |
|
11 | 11 | |
|
12 | 12 | socket.on('test', function(data) { |
|
13 | 13 | UpdateData(data.num,data); |
|
14 | 14 | }) |
|
15 | 15 | $('#ONBtn1').click(function() { |
|
16 | 16 | console.log("holaa") |
|
17 | 17 | socket.emit('atrad_control_event', '11'); |
|
18 | 18 | }); |
|
19 | 19 | $('#ONBtn2').click(function(){ |
|
20 | 20 | console.log("holaa2") |
|
21 | 21 | socket.emit('atrad_control_event', '21'); |
|
22 | 22 | }); |
|
23 | 23 | $('#OFFBtn1').click(function() { |
|
24 | 24 | socket.emit('atrad_control_event','10'); |
|
25 | 25 | }); |
|
26 | 26 | $('#OFFBtn2').click(function(){ |
|
27 | 27 | socket.emit('atrad_control_event', '20'); |
|
28 | 28 | }); |
|
29 | 29 | }); |
|
30 | 30 | |
|
31 | 31 | function UpdateData(id,data){ |
|
32 | 32 | let total = data.pow.reduce((a, b) => a + b, 0)/1000.0; |
|
33 | 33 | streamPlot("plot-pot",data.time,total,id,81); |
|
34 | 34 | streamPlot("plot-temp",data.time,data.tmax[0],id,40); |
|
35 | 35 | streamPlot2("plot-pot-t"+(id+1),data.time,data.pow); |
|
36 | 36 | ligthStatus(id,data.status); |
|
37 | PotenciaAmplificador(id,data.pow,total); | |
|
37 | PotenciaAmplificador(id,data.pow,total,data.time); | |
|
38 | 38 | $('#temp'+(id+1)).text(data.tmax[0]); |
|
39 | 39 | if(eval(data.tmax[0])>20){ |
|
40 | $('#alert-time'+(id+1)).text(data.time.slice(-8,)); | |
|
41 |
$('#alert |
|
|
42 | $('#alert-loc'+(id+1)).text('Tx'+(id+1)+' '+data.tmax[1]); | |
|
40 | $('#alerttemp-time'+(id+1)).text(data.time.slice(-8,)); | |
|
41 | $('#alerttemp-'+(id+1)).text(data.tmax[0]); | |
|
42 | $('#alerttemp-loc'+(id+1)).text('Tx'+(id+1)+' '+data.tmax[1]); | |
|
43 | 43 | } |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | function makePlot(div, n=1, names=["", ""],ranges){ |
|
47 | 47 | var plotDiv = document.getElementById(div); |
|
48 | 48 | var traces = []; |
|
49 | 49 | for (let i = 0; i < n; i++) { |
|
50 | 50 | traces.push({x: [], y: [],mode: 'lines', name: names[i]}); |
|
51 | 51 | } |
|
52 | 52 | traces.push({x: [], y: [],mode: 'lines',line: {color:'rgb(219, 64, 82)',dash: 'dot',width: 2},name:"nominal",showlegend: false}); |
|
53 | 53 | var yrange = ranges; |
|
54 | 54 | var layout = { |
|
55 | 55 | width: 700, |
|
56 | 56 | height: 350, |
|
57 | 57 | font: {size: 12}, |
|
58 | 58 | margin: { t: 10, b:40,}, |
|
59 | 59 | xaxis: { |
|
60 | 60 | type: 'date' |
|
61 | 61 | }, |
|
62 | 62 | yaxis: { |
|
63 | 63 | range: yrange, |
|
64 | 64 | }, |
|
65 | 65 | }; |
|
66 | 66 | var config = {responsive: true} |
|
67 | 67 | Plotly.newPlot(plotDiv, traces, layout,config); |
|
68 | 68 | }; |
|
69 | 69 | |
|
70 | 70 | function streamPlot(div,x,y,ind,val){ |
|
71 | 71 | var plotDiv = document.getElementById(div); |
|
72 | 72 | if (plotDiv.data[ind].x.length > 8){ |
|
73 | 73 | plotDiv.data[2].x = plotDiv.data[2].x.slice(-23) |
|
74 | 74 | plotDiv.data[2].y = plotDiv.data[2].y.slice(-23) |
|
75 | 75 | plotDiv.data[ind].x = plotDiv.data[ind].x.slice(-11) |
|
76 | 76 | plotDiv.data[ind].y = plotDiv.data[ind].y.slice(-11) |
|
77 | 77 | } |
|
78 | 78 | var tm = [x]; |
|
79 | 79 | var values = [y]; |
|
80 | 80 | var data_update = {x: [tm,tm], y: [values,[val]]} |
|
81 | 81 | Plotly.extendTraces(plotDiv, data_update,[ind,2]) |
|
82 | 82 | }; |
|
83 | 83 | function streamPlot2(div,x,y){ |
|
84 | 84 | var plotDiv = document.getElementById(div); |
|
85 | 85 | if (plotDiv.data[0].x.length > 8){ |
|
86 | 86 | for(let i=0;i<4;i++){ |
|
87 | 87 | plotDiv.data[i].x = plotDiv.data[i].x.slice(-11) |
|
88 | 88 | plotDiv.data[i].y = plotDiv.data[i].y.slice(-11) |
|
89 | 89 | } |
|
90 | 90 | } |
|
91 | 91 | var tm = [x]; |
|
92 | 92 | var values = []; |
|
93 | 93 | for(let i=0;i<4;i++){ |
|
94 | 94 | values[i]=[y[i]/1000.0]; |
|
95 | 95 | } |
|
96 | 96 | var data_update = {x: [tm,tm,tm,tm], y: values} |
|
97 | 97 | Plotly.extendTraces(plotDiv, data_update,[0,1,2,3]) |
|
98 | 98 | }; |
|
99 | 99 | |
|
100 | 100 | function ligthStatus(id,status){ |
|
101 | 101 | let div1 = 'status'+(id+1); |
|
102 | 102 | let div2 = 'status-text'+(id+1); |
|
103 | 103 | |
|
104 | 104 | if(status==='0000'){ |
|
105 | 105 | document.getElementById(div1).style.backgroundColor = "red"; |
|
106 | 106 | document.getElementById(div2).innerHTML = "Disable"; |
|
107 | 107 | } |
|
108 | 108 | else if(status==='1111'){ |
|
109 | 109 | document.getElementById(div1).style.backgroundColor = "green"; |
|
110 | 110 | document.getElementById(div2).innerHTML = "Fully enable"; |
|
111 | 111 | } |
|
112 | 112 | else{ |
|
113 | 113 | document.getElementById(div1).style.backgroundColor = "yellow"; |
|
114 | 114 | document.getElementById(div2).innerHTML = "Not fully enable"; |
|
115 | 115 | } |
|
116 | 116 | }; |
|
117 | 117 | |
|
118 | function PotenciaAmplificador(id,data1,data2){ | |
|
119 |
|
|
|
118 | function PotenciaAmplificador(id,data1,data2,time){ | |
|
119 | id_tx = (id+1) | |
|
120 | let div = '#pot'+id_tx; | |
|
120 | 121 | for(let i=1; i<5; i++){ |
|
121 |
|
|
|
122 | } | |
|
123 | $(div).text(data2); | |
|
122 | var pot = (data1[i-1]/1000.0).toFixed(1) | |
|
123 | $(div+'-'+i).text(pot); | |
|
124 | if (data1[i-1]<23000){ | |
|
125 | $("#alertpot-time"+id_tx).text(time.slice(-8,)); | |
|
126 | $("#alertpot-"+id_tx).text(pot); | |
|
127 | $("#alertpot-loc"+id_tx).text('Tx'+ id_tx+ ' Amp '+i); | |
|
128 | } | |
|
124 | 129 | } |
|
125 | $(".clickable-row").click(function() { | |
|
130 | $(div).text(data2.toFixed(1)); | |
|
131 | } | |
|
132 | $(".clickable-row").click(function() { | |
|
126 | 133 | window.open($(this).data("href"),); |
|
127 | 134 | }); No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now