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