##// END OF EJS Templates
clean abs code
clean abs code

File last commit:

r261:fa895af951ee
r315:b3c54f0853ae
Show More
models.py
184 lines | 5.5 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 from django.db import models
Juan C. Espinoza
Updating base models and views ...
r6 from apps.main.models import Configuration
Fiorella Quino
CGS files have been updated...
r261 from apps.main.utils import Params
Fiorella Quino
CGS model, form, view, url and html have been added....
r4 from django.core.validators import MinValueValidator, MaxValueValidator
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 from .files import read_json_file
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 import requests
Fiorella Quino
Task #95: Se agrego funcion "export" archivo .json para cgs. Se modifico modelo de cgs, de float a integer...
r43 # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)]
Fiorella Quino
CGS model, form, view, url and html have been added....
r4
Juan C. Espinoza
Updating base models and views ...
r6 class CGSConfiguration(Configuration):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
cgs status function updated...
r245 freq0 = models.PositiveIntegerField(verbose_name='Frequency 0 (Hz)',validators=[MaxValueValidator(450e6)], default = 60)
freq1 = models.PositiveIntegerField(verbose_name='Frequency 1 (Hz)',validators=[MaxValueValidator(450e6)], default = 60)
freq2 = models.PositiveIntegerField(verbose_name='Frequency 2 (Hz)',validators=[MaxValueValidator(450e6)], default = 60)
freq3 = models.PositiveIntegerField(verbose_name='Frequency 3 (Hz)',validators=[MaxValueValidator(450e6)], default = 60)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 def verify_frequencies(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 def status_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 ip=self.device.ip_address
port=self.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
status_device has been updated...
r248 route = "http://" + str(ip) + ":" + str(port) + "/status/"
Fiorella Quino
Task #95: Modulo CGS ...
r59 try:
Fiorella Quino
status_device has been updated...
r248 r = requests.get(route, timeout=0.7)
Fiorella Quino
CGSstatus function has been modificated...
r215 except Exception as e:
Fiorella Quino
Task #95: Modulo CGS ...
r59 self.device.status = 0
self.device.save()
Fiorella Quino
CGSstatus function has been modificated...
r215 self.message = 'Could not read CGS status: ' + str(e)
Fiorella Quino
standardize functions in cgs device, abs device does not have read_device function...
r207 return False
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
status_device has been updated...
r248 response = r.json()
self.device.status = response['status']
self.message = response['message']
self.device.save()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
status_device has been updated...
r248 if response['components_status']==0:
Fiorella Quino
cgs functions have been modificated...
r220 return False
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
standardize functions in cgs device, abs device does not have read_device function...
r207 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 def start_device(self):
ip=self.device.ip_address
port=self.device.port_address
Fiorella Quino
start_device has been updated...
r249 #---Device must be configured
if not self.device.status == 2:
self.message = 'CGS Device must be configured.'
return False
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 #---Frequencies from form
Fiorella Quino
start_device has been updated...
r249 post_data = self.parms_to_dict()
route = "http://" + str(ip) + ":" + str(port) + "/write/"
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208
try:
r = requests.post(route, post_data, timeout=0.7)
Fiorella Quino
start_device has been updated...
r249 except Exception as e:
self.message = "Could not start CGS device. "+str(e)
return False
response = r.json()
if response['status']==1:
self.device.status = 1
self.device.save()
self.message = response['message']
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 return False
Fiorella Quino
start_device has been updated...
r249 self.device.status = response['status']
self.device.save()
self.message = response['message']
return True
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208
def stop_device(self):
ip=self.device.ip_address
port=self.device.port_address
Fiorella Quino
status_device has been updated...
r248 if self.device.status == 2: #Configured
self.message = 'CGS device is already stopped.'
return False
post_data = {"freq0":0, "freq1":0, "freq2":0, "freq3":0}
route = "http://" + str(ip) + ":" + str(port) + "/write/"
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208
try:
r = requests.post(route, post_data, timeout=0.7)
Fiorella Quino
status_device has been updated...
r248 except Exception as e:
self.message = "Could not write CGS parameters. "+str(e)
self.device.status = 0
self.device.save()
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 return False
Fiorella Quino
status_device has been updated...
r248 response = r.json()
status = response['status']
if status == 1:
self.device.status = status
self.device.save()
self.message = 'Could not stop CGS device.'
return False
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208
Fiorella Quino
status_device has been updated...
r248 self.message = 'CGS device has been stopped successfully.'
self.device.status = 2
self.device.save()
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208
Fiorella Quino
status_device has been updated...
r248 return True
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208
Fiorella Quino
Task #95: Modulo CGS ...
r59 def read_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 ip=self.device.ip_address
port=self.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
read_device function updated...
r246 route = "http://" + str(ip) + ":" + str(port) + "/read/"
Fiorella Quino
Task #95: Modulo CGS ...
r59 try:
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 frequencies = requests.get(route,timeout=0.7)
Fiorella Quino
Task #95: Modulo CGS ...
r59 except:
self.message = "Could not read CGS parameters from this device"
return None
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 frequencies = frequencies.json()
Fiorella Quino
read_device function updated...
r246 if frequencies:
frequencies = frequencies.get("Frequencies")
freq0 = frequencies.get("freq0")
freq1 = frequencies.get("freq1")
freq2 = frequencies.get("freq2")
freq3 = frequencies.get("freq3")
parms = {'freq0': freq0,
'freq1': freq1,
'freq2': freq2,
'freq3': freq3}
self.message = "CGS parameters have been successfully read"
return parms
else:
self.message = "Error reading CGS parameters"
return None
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 def write_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 ip=self.device.ip_address
port=self.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 #---Frequencies from form
Fiorella Quino
CGS files have been updated...
r261 parms = self.parms_to_dict()['configurations']
for parm in parms['allIds']:
byid = parm
frequencies = parms['byId'][byid]
Fiorella Quino
write_function has been updated...
r247 post_data = {}
for data in frequencies:
if data in ['freq0','freq1','freq2','freq3']:
post_data[data] = frequencies[data]
route = "http://" + str(ip) + ":" + str(port) + "/write/"
Fiorella Quino
CGS files have been updated...
r261 print post_data
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 try:
Fiorella Quino
Standardize cgs functions. Start and Stop functions have been implemented...
r208 r = requests.post(route, post_data, timeout=0.7)
Fiorella Quino
Task #95: Modulo CGS ...
r59 except:
self.message = "Could not write CGS parameters"
Fiorella Quino
write_function has been updated...
r247 self.device.status = 0
self.device.save()
Fiorella Quino
standardize functions in cgs device, abs device does not have read_device function...
r207 return False
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
write_function has been updated...
r247 response = r.json()
self.message = response['message']
self.device.status = response['status']
self.device.save()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
write_function has been updated...
r247 if self.device.status==1:
return False
Fiorella Quino
status_device has been updated...
r248
Fiorella Quino
write_function has been updated...
r247 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59
Juan C. Espinoza
Updating base models and views ...
r6 class Meta:
db_table = 'cgs_configurations'