Skip to content
Snippets Groups Projects
Commit 4323f17b authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-1030: improve code

parent 2c225b80
Branches
No related tags found
1 merge request!468Resolve L2SS-1030 "Create configuration device"
...@@ -26,26 +26,25 @@ def get_db_data(db, tangodb_timeout:int = 10000): ...@@ -26,26 +26,25 @@ def get_db_data(db, tangodb_timeout:int = 10000):
# Create empty dictionaries to be populated # Create empty dictionaries to be populated
devices_dict = {} devices_dict = {}
server_dict = {} server_dict = {}
# Query TangoDb with built-in function for devices data
_, raw_result = dbproxy.command_inout("DbMySqlSelect", DEVICE_PROPERTIES_QUERY)
# Remodel the query result
device_property_result = query_to_tuples(raw_result, 3)
# Populate devices dictionary from query data # Populate devices dictionary from query data
device_property_result = query_tangodb(dbproxy, DEVICE_PROPERTIES_QUERY, 3)
devices_dict = add_to_devices_dict(devices_dict, device_property_result) devices_dict = add_to_devices_dict(devices_dict, device_property_result)
# Query TangoDb with built-in function for attributes data
_, raw_result = dbproxy.command_inout("DbMySqlSelect", ATTRS_PROPERTIES_QUERY)
# Remodel the query result
attrs_property_result = query_to_tuples(raw_result, 4)
# Populate devices dictionary from query data # Populate devices dictionary from query data
attrs_property_result = query_tangodb(dbproxy, ATTRS_PROPERTIES_QUERY, 4)
devices_dict = add_to_attrs_dict(devices_dict, attrs_property_result) devices_dict = add_to_attrs_dict(devices_dict, attrs_property_result)
# Query TangoDb with built-in function for server data
_, raw_result = dbproxy.command_inout("DbMySqlSelect", SERVER_QUERY)
# Remodel the query result
server_result = query_to_tuples(raw_result, 3)
# Populate server dictionary from query data and merge it with devices dict # Populate server dictionary from query data and merge it with devices dict
server_result = query_tangodb(dbproxy, SERVER_QUERY, 3)
server_dict = add_to_server_dict(server_dict, devices_dict, server_result) server_dict = add_to_server_dict(server_dict, devices_dict, server_result)
return {"servers" : server_dict} return {"servers" : server_dict}
def query_tangodb(dbproxy: DeviceProxy, sql_query: str, num_cols: int):
""" Query TangoDb with a built-in function and return data as tuples """
_, raw_result = dbproxy.command_inout("DbMySqlSelect", sql_query)
return query_to_tuples(raw_result, num_cols)
def add_to_devices_dict(devices_dict:dict, result:list): def add_to_devices_dict(devices_dict:dict, result:list):
""" Populate a devices dictionary with the following structure: """ Populate a devices dictionary with the following structure:
'device_name': { 'properties' : { 'property_name': ['property_value'] } } 'device_name': { 'properties' : { 'property_name': ['property_value'] } }
......
...@@ -240,6 +240,7 @@ class Boot(lofar_device): ...@@ -240,6 +240,7 @@ class Boot(lofar_device):
dtype='DevVarStringArray', dtype='DevVarStringArray',
mandatory=False, mandatory=False,
default_value=["STAT/Docker/1", # Docker controls the device containers, so it goes before anything else default_value=["STAT/Docker/1", # Docker controls the device containers, so it goes before anything else
"STAT/Configuration/1", # Configuration device loads and update station configuration
"STAT/PSOC/1", # PSOC boot early to detect power delivery failure as fast as possible "STAT/PSOC/1", # PSOC boot early to detect power delivery failure as fast as possible
"STAT/PCON/1", # PCON boot early because it is responsible for power delivery. "STAT/PCON/1", # PCON boot early because it is responsible for power delivery.
"STAT/APSPU/1", # APS Power Units control other hardware we want to initialise "STAT/APSPU/1", # APS Power Units control other hardware we want to initialise
...@@ -256,7 +257,6 @@ class Boot(lofar_device): ...@@ -256,7 +257,6 @@ class Boot(lofar_device):
"STAT/TileBeam/1", # Accesses AntennaField "STAT/TileBeam/1", # Accesses AntennaField
"STAT/DigitalBeam/1", # Accessed SDP and Beamlet "STAT/DigitalBeam/1", # Accessed SDP and Beamlet
"STAT/TemperatureManager/1", "STAT/TemperatureManager/1",
"STAT/Configuration/1",
], ],
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment