##// END OF EJS Templates
Add power monitor
Add power monitor

File last commit:

r390:2565c04022e1
r393:737695221ef9
Show More
models.py
245 lines | 7.7 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 import ast
Juan C. Espinoza
Updates to models, views & forms for CR...
r25 import json
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175 import requests
Primer commit radarsys_met
r345 import base64
Limpieza de código y funcionalidades usrp
r346 import struct
Juan C. Espinoza
Update RC model, RC api for testing...
r185 from struct import pack
Limpieza de código y funcionalidades usrp
r346 import time
from django.contrib import messages
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 from django.db import models
Nueva plantilla, prueba comunicacion y nuevos campos ddsrest
r335 from django.urls import reverse
Juan C. Espinoza
Add rc config mods...
r23 from django.core.validators import MinValueValidator, MaxValueValidator
Juan C. Espinoza
Updating base models and views ...
r6 from apps.main.models import Configuration
Juan C. Espinoza
- Update rc app...
r79
Experiment detail view update
r365 MODE_VALUE = (
Clean code and update Pedestal model
r368 ('position', 'Position'),
('speed', 'Speed'),
('table', 'Table')
Primer commit radarsys_met
r345 )
Juan C. Espinoza
Updating base models and views ...
r6
Limpieza de código y funcionalidades usrp
r346 class PedestalConfiguration(Configuration):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Experiment detail view update
r365 mode = models.CharField(
verbose_name='Mode',
New experiment views
r360 max_length=10,
Experiment detail view update
r365 choices=MODE_VALUE,
Primer commit radarsys_met
r345 null=False,
blank=False
)
Clean code and update Pedestal model
r368 axis = models.CharField(
verbose_name="Axis",
max_length=100,
default='az',
blank=False,
null=False,
help_text="Please separate the values with commas when using table mode"
)
speed = models.CharField(
Primer commit radarsys_met
r345 verbose_name='Speed',
Clean code and update Pedestal model
r368 max_length=100,
Primer commit radarsys_met
r345 blank=False,
Clean code and update Pedestal model
r368 null=False,
default=6
Primer commit radarsys_met
r345 )
Clean code and update Pedestal model
r368 angle = models.CharField(
verbose_name="Angle(s)",
Primer commit radarsys_met
r345 max_length=100,
Clean code and update Pedestal model
r368 default='0',
blank=False,
null=False,
help_text="Please separate the values with commas when using table mode"
)
min_value = models.FloatField(
verbose_name='Min angle',
validators=[MinValueValidator(-5), MaxValueValidator(185)],
blank=False,
null=False,
default=0
)
max_value = models.FloatField(
verbose_name='Max angle',
validators=[MinValueValidator(-5), MaxValueValidator(185)],
Primer commit radarsys_met
r345 blank=False,
Pedestal comma bug fixed, help text added and more
r352 null=False,
Clean code and update Pedestal model
r368 default=40
Primer commit radarsys_met
r345 )
Juan C. Espinoza
Updating base models and views ...
r6
class Meta:
Primer commit radarsys_met
r345 db_table = 'pedestal_configurations'
def __str__(self):
Clean code and update Pedestal model
r368 if self.mode=='position':
return u'Position: {}º {}'.format(self.angle, self.axis.upper())
if self.mode=='speed':
return u'Speed: {}º/s {}'.format(self.speed, self.axis.upper())
if self.mode=='table':
axis = [x.strip().upper() for x in self.axis.split(',')]
Update models.py Pedestal
r390 speeds = [float(x.strip()) for x in self.speed.split(',')]
table = [float(x.strip()) for x in self.angle.split(',')]
Clean code and update Pedestal model
r368 return u'Table: Axis {}, Speed {}º/s, Steps {}'.format(axis, speeds, table)
@property
def label(self):
return str(self)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
- Update rc app...
r79 def get_absolute_url_plot(self):
Primer commit radarsys_met
r345 return reverse('url_plot_pedestal_pulses', args=[str(self.id)])
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
RC files have been updated...
r264 def request(self, cmd, method='get', **kwargs):
req = getattr(requests, method)(self.device.url(cmd), **kwargs)
payload = req.json()
return payload
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175 def status_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC API methods...
r222 try:
Generator parameter type fixed, devices status & warning messages
r350 payload = requests.get(self.device.url())
Clean code and update Pedestal model
r368
Generator parameter type fixed, devices status & warning messages
r350 if payload:
self.device.status = 1
Fiorella Quino
RC files have been updated...
r264 elif payload['status']=='disable':
Juan C. Espinoza
Update RC API methods...
r222 self.device.status = 2
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
Fiorella Quino
import/export functions have been updated...
r243 self.device.status = 1
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal status: {}'.format(payload['status'])
Juan C. Espinoza
Update RC API methods...
r222 return False
Juan C. Espinoza
Update RC model, RC api for testing...
r185 except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal status: {}'.format(str(e))
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
self.device.save()
return True
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175
def reset_device(self):
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 try:
Update models.py Pedestal
r390 url = self.device.url() + "position?params="
Clean code and update Pedestal model
r368
payload_el = {'axis': 'elevation', 'position': 0}
Update models.py Pedestal
r390 json_data_el = json.dumps(payload_el)
base64_table_el = base64.standard_b64encode(json_data_el.encode('ascii'))
Clean code and update Pedestal model
r368
r = requests.get(url + base64_table_el.decode('ascii'))
payload_az = {'axis': 'azimuth', 'position': 0}
Update models.py Pedestal
r390 json_data_az = json.dumps(payload_az)
base64_table_az = base64.standard_b64encode(json_data_az.encode('ascii'))
Clean code and update Pedestal model
r368
r = requests.get(url + base64_table_az.decode('ascii'))
if r:
self.device.status = 3
Fiorella Quino
RC files have been updated...
r264 self.device.save()
Clean code and update Pedestal model
r368 self.message = 'Pedestal reset'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
Clean code and update Pedestal model
r368 return False
Juan C. Espinoza
Update RC model, RC api for testing...
r185 except Exception as e:
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal reset: {}'.format(str(e))
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175 def stop_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC model, RC api for testing...
r185 try:
Limpieza de código y funcionalidades usrp
r346 command = self.device.url() + "stop"
r = requests.get(command)
if r:
self.device.status = 4
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal stopped'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
self.device.status = 4
self.device.save()
return False
except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
else:
self.device.status = 0
Generator parameter type fixed, devices status & warning messages
r350 #self.message = 'Pedestal stop: {}'.format(str(e))
self.message = "Pedestal can't start, please check network/device connection or IP address/port configuration"
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Fiorella Quino
import/export functions have been updated...
r243 return False
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC app (add support for mix configurations, bug plotting window line, )...
r107 def start_device(self):
Generator parameter type fixed, devices status & warning messages
r350
Clean code and update Pedestal model
r368 AX = {'az':'azimuth', 'el':'elevation'}
axis = [AX[x.lower().strip()] for x in self.axis.split(',')]
if len(axis)==1:
axis = axis[0]
Limpieza de código y funcionalidades usrp
r346
Clean code and update Pedestal model
r368 try:
if self.mode == 'position':
Update models.py Pedestal
r390 url = self.device.url() + "position?params="
Clean code and update Pedestal model
r368 payload = {'axis': axis, 'position': float(self.angle)}
elif self.mode == 'speed':
Update models.py Pedestal
r390 url = self.device.url() + "speed?params="
Clean code and update Pedestal model
r368 payload = {'axis': axis, 'speed': float(self.speed)}
elif self.mode == 'table':
Update models.py Pedestal
r390 self.reset_device()
Clean code and update Pedestal model
r368 url = self.device.url() + "combinedtable?params="
list_of_floats = [float(x.strip()) for x in self.angle.split(",")]
byte_table = []
for x in list_of_floats:
temp = bytearray(struct.pack("f", x))
byte_table.append(temp[3])
byte_table.append(temp[2])
byte_table.append(temp[1])
byte_table.append(temp[0])
coded_table = base64.standard_b64encode(bytes(byte_table))
coded_table_ascii = coded_table.decode('ascii')
speed = [float(x.strip()) for x in self.speed.split(',')]
Update settings for postgres and pedestal start function
r374 payload = {
'arraylength': len(speed),
'axis': axis,
'speed': speed,
Update models.py Pedestal
r390 'bottom': self.min_value,
Update settings for postgres and pedestal start function
r374 'top': self.max_value,
Update models.py Pedestal
r390 'table': coded_table_ascii
Update settings for postgres and pedestal start function
r374 }
Update models.py Pedestal
r390 time.sleep(15)
Clean code and update Pedestal model
r368
json_data = json.dumps(payload)
print(json_data)
changed base64.urlsafe to base64.standard
r357 base64_table = base64.standard_b64encode(json_data.encode('ascii'))
Clean code and update Pedestal model
r368 url += base64_table.decode('ascii')
print(url)
r = requests.get(url)
Limpieza de código y funcionalidades usrp
r346
if r:
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.status = 3
self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal configured and started'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
return False
except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
else:
self.device.status = 0
Generator parameter type fixed, devices status & warning messages
r350 #self.message = 'Pedestal start: {}'.format(str(e))
self.message = "Pedestal can't start, please check network/device connection or IP address/port configuration"
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
RC files have been updated...
r264 def get_absolute_url_import(self):
Clean code and docker files
r349 return reverse('url_import_pedestal_conf', args=[str(self.id)])