diff --git a/apps/atrad/models.py b/apps/atrad/models.py index d90dde2..67b65c5 100644 --- a/apps/atrad/models.py +++ b/apps/atrad/models.py @@ -10,34 +10,110 @@ class ATRADData(models.Model): datetime = models.DateTimeField() nstx = models.SmallIntegerField() - status = models.SmallIntegerField() - temp_cll = models.SmallIntegerField() - nboards = models.SmallIntegerField() - tempdvr = models.SmallIntegerField() - potincdvr = models.SmallIntegerField() - potretdvr = models.SmallIntegerField() + status_1 = models.SmallIntegerField() + temp_cll_1 = models.SmallIntegerField() + nboards_1 = models.SmallIntegerField() + tempdvr_1 = models.SmallIntegerField() + potincdvr_1 = models.SmallIntegerField() + potretdvr_1 = models.SmallIntegerField() - temp1 = models.SmallIntegerField() - potinc1 = models.SmallIntegerField() - potret1 = models.SmallIntegerField() - temp2 = models.SmallIntegerField() - potinc2 = models.SmallIntegerField() - potret2 = models.SmallIntegerField() - temp3 = models.SmallIntegerField() - potinc3 = models.SmallIntegerField() - potret3 = models.SmallIntegerField() - temp4 = models.SmallIntegerField() - potinc4 = models.SmallIntegerField() - potret4 = models.SmallIntegerField() - temp5 = models.SmallIntegerField() - potinc5 = models.SmallIntegerField() - potret5 = models.SmallIntegerField() - temp6 = models.SmallIntegerField() - potinc6 = models.SmallIntegerField() - potret6 = models.SmallIntegerField() - - + temp1_1 = models.SmallIntegerField() + potinc1_1 = models.SmallIntegerField() + potret1_1 = models.SmallIntegerField() + temp2_1 = models.SmallIntegerField() + potinc2_1 = models.SmallIntegerField() + potret2_1 = models.SmallIntegerField() + temp3_1 = models.SmallIntegerField() + potinc3_1 = models.SmallIntegerField() + potret3_1 = models.SmallIntegerField() + temp4_1 = models.SmallIntegerField() + potinc4_1 = models.SmallIntegerField() + potret4_1 = models.SmallIntegerField() + temp5_1 = models.SmallIntegerField() + potinc5_1 = models.SmallIntegerField() + potret5_1 = models.SmallIntegerField() + temp6_1 = models.SmallIntegerField() + potinc6_1 = models.SmallIntegerField() + potret6_1 = models.SmallIntegerField() + + status_2 = models.SmallIntegerField() + temp_cll_2 = models.SmallIntegerField() + nboards_2 = models.SmallIntegerField() + tempdvr_2 = models.SmallIntegerField() + potincdvr_2 = models.SmallIntegerField() + potretdvr_2 = models.SmallIntegerField() + + temp1_2 = models.SmallIntegerField() + potinc1_2 = models.SmallIntegerField() + potret1_2 = models.SmallIntegerField() + temp2_2 = models.SmallIntegerField() + potinc2_2 = models.SmallIntegerField() + potret2_2 = models.SmallIntegerField() + temp3_2 = models.SmallIntegerField() + potinc3_2 = models.SmallIntegerField() + potret3_2 = models.SmallIntegerField() + temp4_2 = models.SmallIntegerField() + potinc4_2 = models.SmallIntegerField() + potret4_2 = models.SmallIntegerField() + temp5_2 = models.SmallIntegerField() + potinc5_2 = models.SmallIntegerField() + potret5_2 = models.SmallIntegerField() + temp6_2 = models.SmallIntegerField() + potinc6_2 = models.SmallIntegerField() + potret6_2 = models.SmallIntegerField() + + status_3 = models.SmallIntegerField() + temp_cll_3 = models.SmallIntegerField() + nboards_3 = models.SmallIntegerField() + tempdvr_3 = models.SmallIntegerField() + potincdvr_3 = models.SmallIntegerField() + potretdvr_3 = models.SmallIntegerField() + + temp1_3 = models.SmallIntegerField() + potinc1_3 = models.SmallIntegerField() + potret1_3 = models.SmallIntegerField() + temp2_3 = models.SmallIntegerField() + potinc2_3 = models.SmallIntegerField() + potret2_3 = models.SmallIntegerField() + temp3_3 = models.SmallIntegerField() + potinc3_3 = models.SmallIntegerField() + potret3_3 = models.SmallIntegerField() + temp4_3 = models.SmallIntegerField() + potinc4_3 = models.SmallIntegerField() + potret4_3 = models.SmallIntegerField() + temp5_3 = models.SmallIntegerField() + potinc5_3 = models.SmallIntegerField() + potret5_3 = models.SmallIntegerField() + temp6_3 = models.SmallIntegerField() + potinc6_3 = models.SmallIntegerField() + potret6_3 = models.SmallIntegerField() + + status_4 = models.SmallIntegerField() + temp_cll_4 = models.SmallIntegerField() + nboards_4 = models.SmallIntegerField() + tempdvr_4 = models.SmallIntegerField() + potincdvr_4 = models.SmallIntegerField() + potretdvr_4 = models.SmallIntegerField() + + temp1_4 = models.SmallIntegerField() + potinc1_4 = models.SmallIntegerField() + potret1_4 = models.SmallIntegerField() + temp2_4 = models.SmallIntegerField() + potinc2_4 = models.SmallIntegerField() + potret2_4 = models.SmallIntegerField() + temp3_4 = models.SmallIntegerField() + potinc3_4 = models.SmallIntegerField() + potret3_4 = models.SmallIntegerField() + temp4_4 = models.SmallIntegerField() + potinc4_4 = models.SmallIntegerField() + potret4_4 = models.SmallIntegerField() + temp5_4 = models.SmallIntegerField() + potinc5_4 = models.SmallIntegerField() + potret5_4 = models.SmallIntegerField() + temp6_4 = models.SmallIntegerField() + potinc6_4 = models.SmallIntegerField() + potret6_4 = models.SmallIntegerField() class Meta: db_table = 'atrad_datas' @@ -115,11 +191,6 @@ class ATRADConfiguration(Configuration): if self.device.status == 2: #Configured self.message = 'TX device is already stopped.' return False - - # Se crea el modo ocupado para una vez inicia el STOP - self.device.status = 5 - self.device.save() - # Por si se demora deteniendo, que su estado sea busy post_data = {"topic":0} route = "http://" + str(ip) + ":" + str(port) + "/write/" diff --git a/apps/atrad/mqtt.py b/apps/atrad/mqtt.py index e567014..ec95c96 100644 --- a/apps/atrad/mqtt.py +++ b/apps/atrad/mqtt.py @@ -7,11 +7,29 @@ import os def insert(time,data): sql = """INSERT INTO atrad_datas( - datetime,nstx,status,temp_cll,nboards,tempdvr,potincdvr,potretdvr, - temp1,potinc1,potret1,temp2,potinc2,potret2,temp3,potinc3,potret3, - temp4,potinc4,potret4,temp5,potinc5,potret5,temp6,potinc6,potret6) + datetime,nstx,status_1,temp_cll_1,nboards_1,tempdvr_1,potincdvr_1,potretdvr_1, + temp1_1,potinc1_1,potret1_1,temp2_1,potinc2_1,potret2_1,temp3_1,potinc3_1,potret3_1, + temp4_1,potinc4_1,potret4_1,temp5_1,potinc5_1,potret5_1,temp6_1,potinc6_1,potret6_1, + status_2,temp_cll_2,nboards_2,tempdvr_2,potincdvr_2,potretdvr_2, + temp1_2,potinc1_2,potret1_2,temp2_2,potinc2_2,potret2_2,temp3_2,potinc3_2,potret3_2, + temp4_2,potinc4_2,potret4_2,temp5_2,potinc5_2,potret5_2,temp6_2,potinc6_2,potret6_2, + status_3,temp_cll_3,nboards_3,tempdvr_3,potincdvr_3,potretdvr_3, + temp1_3,potinc1_3,potret1_3,temp2_3,potinc2_3,potret2_3,temp3_3,potinc3_3,potret3_3, + temp4_3,potinc4_3,potret4_3,temp5_3,potinc5_3,potret5_3,temp6_3,potinc6_3,potret6_3, + status_4,temp_cll_4,nboards_4,tempdvr_4,potincdvr_4,potretdvr_4, + temp1_4,potinc1_4,potret1_4,temp2_4,potinc2_4,potret2_4,temp3_4,potinc3_4,potret3_4, + temp4_4,potinc4_4,potret4_4,temp5_4,potinc5_4,potret5_4,temp6_4,potinc6_4,potret6_4) VALUES(%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s, + %s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s,%s,%s);""" try: # connect to the PostgreSQL database @@ -20,7 +38,7 @@ def insert(time,data): cur = conn.cursor() # execute the INSERT statement #data_tuple = [tuple(i[:]) for i in a] - values = (time,) + tuple(data[0][:25]) + values = (time,) + tuple(data[0][:25])+tuple(data[1][1:25])+tuple(data[2][1:25])+tuple(data[3][1:25]) cur.execute(sql, values) # get the generated id back @@ -46,8 +64,10 @@ def maxTemperature(trs): if STXloc == 0: maxT_loc = maxT_loc + " Controller" - elif STXloc<7: - maxT_loc = maxT_loc + " PA " + str(STXloc+1) + elif STXloc == 1: + maxT_loc = maxT_loc + " Driver" + elif STXloc<8: + maxT_loc = maxT_loc + " PA " + str(STXloc-1) else: maxT_loc = maxT_loc + " Combiners" @@ -64,7 +84,12 @@ def dataConvert(msg): # Data to send by socket id_STX = dataSTX[0][0] // 4 status = ''.join([msgClean[i][3] for i in [0,1,2,3]]) - powers = [dataSTX[0][34],dataSTX[0][36],dataSTX[2][32],dataSTX[2][34]] + powers = [dataSTX[0][34],dataSTX[0][36],dataSTX[2][32],dataSTX[2][34],0,0,0,0] + # alerta + for i in range(4): + if powers[i] < 10000 and status == '1111': + power[4+i] = 1 + tmax,index,tempData = maxTemperature(dataSTX) #Json to send data = {'time':msgStr[2:21],'num':id_STX,'pow':powers,'tmax':[str(tmax),index],'status':status} @@ -78,18 +103,16 @@ def GetTemperatures(data): def on_connect(mqtt_client, userdata, flags, rc): if rc == 0: - # print('Connected successfullyasdss') + print('Connected successfullyasdss') mqtt_client.subscribe("atrad/test4") + print("Exito") else: print('Bad connection. Code:', rc) def on_message(mqtt_client, userdata, msg): print('Received message on topic: {} with payload: {}'.format(msg.topic,msg.payload), flush=True) mainData, tempData = dataConvert(msg) - # print("Recibi : {}".format(msg.payload),flush=True) - #socket fot general data sio.emit('test',data = mainData) - print(mainData) #socket for temperature details sio.emit('temptx'+str(mainData['num'] + 1),data = tempData) diff --git a/apps/atrad/templates/atrad_conf.html b/apps/atrad/templates/atrad_conf.html index 5811149..40f89d9 100644 --- a/apps/atrad/templates/atrad_conf.html +++ b/apps/atrad/templates/atrad_conf.html @@ -56,7 +56,7 @@
-
+

Status

@@ -82,14 +82,14 @@ - - - + + + - - - + + +

@@ -98,7 +98,20 @@

Power Alerts

- 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. + + + + + + + + + + + + + +

diff --git a/apps/atrad/templates/atrad_tx.html b/apps/atrad/templates/atrad_tx.html index 4b6fa99..d303cd8 100644 --- a/apps/atrad/templates/atrad_tx.html +++ b/apps/atrad/templates/atrad_tx.html @@ -69,21 +69,21 @@ var socket = io.connect('http://' + document.domain + ':' + location.port); socket.on('connect', function(data) { console.log('Connecting... OK'); - var data = '{{data|safe}}'.split(',') - console.log(data); - makePlot("plot-temp-0",4,["PC1","PC2","PC3","PC4"],[0,40]); - makePlot("plot-temp-1",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) - makePlot("plot-temp-2",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) - makePlot("plot-temp-3",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) - makePlot("plot-temp-4",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[0,40]) - }) + var basedata = JSON.parse('{{data|safe}}') + console.log(basedata); + makePlot("plot-temp-0",4,["PC1","PC2","PC3","PC4"],[10,40]); + makePlot2("plot-temp-1",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) + makePlot2("plot-temp-2",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) + makePlot2("plot-temp-3",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) + makePlot2("plot-temp-4",6,["PA1","PA2","PA3","PA4","PA5","PA6"],[10,40],basedata) + }) socket.on("temptx"+"{{id_tx}}", function(data) { var controllers = [data.temp[0][1],data.temp[1][1],data.temp[2][1],data.temp[3][1]] streamPlot2("plot-temp-0",data.time,controllers,4); - streamPlot2("plot-temp-1",data.time,data.temp[0].slice(1,7),6); - streamPlot2("plot-temp-2",data.time,data.temp[1].slice(1,7),6); - streamPlot2("plot-temp-3",data.time,data.temp[2].slice(1,7),6); - streamPlot2("plot-temp-4",data.time,data.temp[3].slice(1,7),6); + streamPlot2("plot-temp-1",data.time,data.temp[0].slice(2,8),6); + streamPlot2("plot-temp-2",data.time,data.temp[1].slice(2,8),6); + streamPlot2("plot-temp-3",data.time,data.temp[2].slice(2,8),6); + streamPlot2("plot-temp-4",data.time,data.temp[3].slice(2,8),6); }) }); @@ -97,6 +97,38 @@ var yrange = ranges; var layout = { width: 505, + height: 300, + font: {size: 12}, + margin: { t: 10, b:50, r:15 ,l:15}, + xaxis: { + type: 'date' + }, + yaxis: { + range: yrange, + }, + legend: {"orientation": "h"}, + }; + var config = {responsive: true} + Plotly.newPlot(plotDiv, traces, layout,config); + }; + + function makePlot2(div, n=1, names=["", ""],ranges,data){ + var plotDiv = document.getElementById(div); + var traces = []; + var keys = ['temp1','temp2','temp3','temp4','temp5','temp6'] + + for (let i = 0; i < n; i++) { + var x = []; + var y = []; + for(let j = 0;j < data.length; j++){ + x[j] = data[j].datetime; + y[j] = data[j][keys[i]+'_'+div.charAt(10)]; + } + traces.push({x:x, y:y,mode: 'lines', name: names[i]}); + } + var yrange = ranges; + var layout = { + width: 505, height: 400, font: {size: 12}, margin: { t: 10, b:50, r:15 ,l:15}, diff --git a/apps/atrad/views.py b/apps/atrad/views.py index a65da20..6d8d238 100644 --- a/apps/atrad/views.py +++ b/apps/atrad/views.py @@ -47,12 +47,14 @@ def atrad_conf(request, id_conf): def atrad_tx(request, id_conf, id_tx): kwargs = {} kwargs['id_tx'] = id_tx[-1] - kwargs['keys'] = ['id','temp1','temp2','temp3','temp4','temp5','temp6'] kwargs['title'] = 'Temperature Details' kwargs['button'] = 'Edit Configuration' time = ATRADData.objects.last().datetime - mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(minutes=20)),nstx=1).values_list('datetime','temp1','temp2','temp3','temp4','temp5','temp6') - kwargs['data'] = QuerytoStr(mydata) + id_stx = (int(id_tx[-1])-1)*4+1 + 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', + 'temp1_2','temp2_2','temp3_2','temp4_2','temp5_2','temp6_2','temp1_3','temp2_3','temp3_3','temp4_3','temp5_3','temp6_3', + 'temp1_4','temp2_4','temp3_4','temp4_4','temp5_4','temp6_4') + kwargs['data'] = json.dumps(list(mydata),default=str) return render(request, 'atrad_tx.html', kwargs) def QuerytoStr(data): @@ -99,7 +101,9 @@ def monitor(request): def atrad_prueba(request): keys = ['id','temp1','temp2','temp3','temp4','temp5','temp6'] time = ATRADData.objects.last().datetime - mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(hours=1))).values('id','temp1','temp2','temp3','temp4','temp5','temp6') + mydata = ATRADData.objects.filter(datetime__gte = (time-timedelta(hours=1))).values('id','temp1_1','temp2_1','temp3_1','temp4_1','temp5_1','temp6_1', + 'temp1_2','temp2_2','temp3_2','temp4_2','temp5_2','temp6_2','temp1_3','temp2_3','temp3_3','temp4_3','temp5_3','temp6_3', + 'temp1_4','temp2_4','temp3_4','temp4_4','temp5_4','temp6_4') template = get_template('prueba.html') context = { 'last' : time, @@ -118,4 +122,4 @@ def atrad_disconnect(sid): @sio.event def atrad_control_event(sid,message): - mqtt_client.publish('test/data2', json.dumps(message)) + mqtt_client.publish('test/data2', json.dumps(message)) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d27c93e..e6e64b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,7 +45,7 @@ services: restart: always build: ./nginx/ ports: - - '0.0.0.0:80:80' + - '0.0.0.0:8086:80' volumes_from: - radarsys links: diff --git a/radarsys/static/js/atrad-conf.js b/radarsys/static/js/atrad-conf.js index 9547168..7a99c73 100644 --- a/radarsys/static/js/atrad-conf.js +++ b/radarsys/static/js/atrad-conf.js @@ -34,12 +34,12 @@ function UpdateData(id,data){ streamPlot("plot-temp",data.time,data.tmax[0],id,40); streamPlot2("plot-pot-t"+(id+1),data.time,data.pow); ligthStatus(id,data.status); - PotenciaAmplificador(id,data.pow,total); + PotenciaAmplificador(id,data.pow,total,data.time); $('#temp'+(id+1)).text(data.tmax[0]); if(eval(data.tmax[0])>20){ - $('#alert-time'+(id+1)).text(data.time.slice(-8,)); - $('#alert-temp'+(id+1)).text(data.tmax[0]); - $('#alert-loc'+(id+1)).text('Tx'+(id+1)+' '+data.tmax[1]); + $('#alerttemp-time'+(id+1)).text(data.time.slice(-8,)); + $('#alerttemp-'+(id+1)).text(data.tmax[0]); + $('#alerttemp-loc'+(id+1)).text('Tx'+(id+1)+' '+data.tmax[1]); } } @@ -115,13 +115,20 @@ function ligthStatus(id,status){ } }; -function PotenciaAmplificador(id,data1,data2){ - let div = '#pot'+(id+1); +function PotenciaAmplificador(id,data1,data2,time){ + id_tx = (id+1) + let div = '#pot'+id_tx; for(let i=1; i<5; i++){ - $(div+'-'+i).text(data1[i-1]/1000.0); - } - $(div).text(data2); + var pot = (data1[i-1]/1000.0).toFixed(1) + $(div+'-'+i).text(pot); + if (data1[i-1]<23000){ + $("#alertpot-time"+id_tx).text(time.slice(-8,)); + $("#alertpot-"+id_tx).text(pot); + $("#alertpot-loc"+id_tx).text('Tx'+ id_tx+ ' Amp '+i); + } } - $(".clickable-row").click(function() { + $(div).text(data2.toFixed(1)); +} +$(".clickable-row").click(function() { window.open($(this).data("href"),); }); \ No newline at end of file