Selection Policy
The SelectionManager is the owner of SelectionPolicies and will use them to execute sql queries to the database.
The SelectionManager has a 1-1 relationship with the CalibrationStore, new configurable policies can be injected into the manager from the tango interface using UpdateSelectionPolicy
|
A SelectionManager. |
|
A SelectPreferred policy |
This subpackage implements calibration store functionality for MCCS.
- class SelectClosestInRange(logger: Logger, *args: Any, **kwargs: Any)[source]
A SelectClosestInRange policy
closest_in_range.The most recent solution within a defined frequency tolerance.
>>> "SELECT frequency_channel, " >>> "calibration_path, creation_time, station_id, preferred, " >>> "solution " >>> "FROM calibration_per_channel " >>> f"WHERE station_id = {station_id} " >>> f"AND frequency_channel >= {frequency_channel-self.frequency_tolerance} " >>> f"AND frequency_channel <= {frequency_channel+self.frequency_tolerance} " >>> "ORDER BY creation_time DESC " >>> "LIMIT 1"
- configure(frequency_tolerance: int = 0, **kwargs: Any) None[source]
Configure the SelectClosestInRange policy.
- Parameters:
frequency_tolerance – the absolute frequency tolerance.
kwargs – kwargs
- generate_sql(station_id: int, frequency_channel: int, **kwargs: Any) tuple[str, tuple][source]
Return an sql query with parameterized inputs.
- Parameters:
station_id – The id of the station we want a solution for.
frequency_channel – The current frequency channel.
kwargs – kwargs
- Returns:
a sql query.
- class SelectPreferred(logger: Logger, *args: Any, **kwargs: Any)[source]
A SelectPreferred policy
preferred.The most recent solution within a defined frequency tolerance with the field preferred == TRUE is chosen. If none defined as preferred, no solution is returned.
>>> "SELECT frequency_channel, " >>> "calibration_path, creation_time, station_id, preferred, " >>> "solution " >>> "FROM calibration_per_channel " >>> f"WHERE station_id = {station_id} " >>> f"AND frequency_channel >= {frequency_channel-self.frequency_tolerance} " >>> f"AND frequency_channel <= {frequency_channel+self.frequency_tolerance} " >>> "AND preferred = TRUE " >>> "ORDER BY creation_time DESC " >>> "LIMIT 1"
- configure(frequency_tolerance: int = 0, **kwargs: Any) None[source]
Configure the SelectPreferred policy.
- Parameters:
frequency_tolerance – the absolute frequency tolerance.
kwargs – kwargs
- generate_sql(station_id: int, frequency_channel: int, **kwargs: Any) tuple[str, tuple][source]
Return an sql query with parameterized inputs.
- Parameters:
station_id – The id of the station we want a solution for.
frequency_channel – The current frequency channel.
kwargs – kwargs
- Returns:
a sql query.
- class SelectionManager(logger: Logger)[source]
A SelectionManager.
- __init__(logger: Logger) None[source]
Initialise a new SelectionManager.
- Parameters:
logger – A logger for information purposes.
- check_calibration_id(connection: Any, cal_id: str) bool[source]
Check if the given cal id is in the database already.
- Parameters:
connection – the database connection.
cal_id – the cal ID to check.
- Returns:
True if the cal ID is already in the database
- get_calibration_ids(connection: Any) list[str][source]
Get all calibration_ids.
- Parameters:
connection – the database connection.
- Returns:
A list of all calibration_ids
- get_solution(connection: Any, **kwargs: Any) list[float][source]
Get a solution using the loaded SelectionPolicy.
This will return a solution from a query set by the loaded SelectionPolicy
- Parameters:
connection – the database connection.
kwargs – kwargs to feed the selection policy
- Returns:
the solution or an empty list.
- Raises:
ValueError – then there is no configured policy to use.
- get_solution_from_cal_id(connection: Any, channel_id: int, calibration_id: str) list[float][source]
Get a solution from the calibration and station ids.
- Parameters:
connection – the database connection.
channel_id – The channel id.
calibration_id – The calibration id.
- Returns:
the solution or an empty list.
- property policy_description: str
Return details about the policy description.
- Returns:
information about the selection policy.
- update_policy(policy: SelectPreferred | SelectClosestInRange) None[source]
Set a new policy.
- Parameters:
policy – the sql to use.