##// END OF EJS Templates
ATRAD actualizado
Renato Huallpa -
r396:bcff7b1b68a2
parent child
Show More
@@ -10,34 +10,110 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 tempdvr = models.SmallIntegerField()
18 potincdvr = models.SmallIntegerField()
19 potretdvr = models.SmallIntegerField()
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'
@@ -115,11 +191,6 class ATRADConfiguration(Configuration):
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/"
@@ -7,11 +7,29 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
@@ -20,7 +38,7 def insert(time,data):
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
@@ -46,8 +64,10 def maxTemperature(trs):
46 64
47 65 if STXloc == 0:
48 66 maxT_loc = maxT_loc + " Controller"
49 elif STXloc<7:
50 maxT_loc = maxT_loc + " PA " + str(STXloc+1)
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
@@ -64,7 +84,12 def dataConvert(msg):
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}
@@ -78,18 +103,16 def GetTemperatures(data):
78 103
79 104 def on_connect(mqtt_client, userdata, flags, rc):
80 105 if rc == 0:
81 # print('Connected successfullyasdss')
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
@@ -56,7 +56,7
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>
@@ -82,14 +82,14
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-temp1" class="font-weight-bold"></p></td>
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-temp2" class="font-weight-bold"></p></td>
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>
@@ -98,7 +98,20
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>
@@ -69,21 +69,21
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}}'.split(',')
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(1,7),6);
84 streamPlot2("plot-temp-2",data.time,data.temp[1].slice(1,7),6);
85 streamPlot2("plot-temp-3",data.time,data.temp[2].slice(1,7),6);
86 streamPlot2("plot-temp-4",data.time,data.temp[3].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(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
@@ -97,6 +97,38
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},
@@ -47,12 +47,14 def atrad_conf(request, id_conf):
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):
@@ -99,7 +101,9 def monitor(request):
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,
@@ -118,4 +122,4 def atrad_disconnect(sid):
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
@@ -45,7 +45,7 services:
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:
@@ -34,12 +34,12 function UpdateData(id,data){
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-temp'+(id+1)).text(data.tmax[0]);
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
@@ -115,13 +115,20 function ligthStatus(id,status){
115 115 }
116 116 };
117 117
118 function PotenciaAmplificador(id,data1,data2){
119 let div = '#pot'+(id+1);
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 $(div+'-'+i).text(data1[i-1]/1000.0);
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