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 |
|
A SelectClosestInRange policy |
This subpackage implements calibration store functionality for MCCS.
- class SelectClosestInRange(logger: Logger, *args: Any, **kwargs: Any)[source]
A SelectClosestInRange policy
closest_in_range.A solution is selected from a set of tolerances. The most recent solution within these tolerances is chosen. If more than one solutions tie we yield the one with the smallest absolute summed difference.
>>> "SELECT frequency_channel, outside_temperature, " >>> "calibration_path, creation_time, station_id, preferred " >>> "FROM tab_mccs_calib " >>> 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 outside_temperature >= " >>> f"{outside_temperature-self.temperature_tolerance} " >>> "AND outside_temperature <= " >>> f"{outside_temperature+self.temperature_tolerance} " >>> "ORDER BY preferred DESC, " >>> "creation_time DESC, " >>> f"ABS(ABS(frequency_channel-{frequency_channel}) " >>> f"+ ABS(outside_temperature-{outside_temperature})) DESC"
- configure(temperature_tolerance: float = 0.0, frequency_tolerance: int = 0) None[source]
Configure the SelectClosestInRange policy.
- Parameters:
temperature_tolerance – the absolute temperature tolerance.
frequency_tolerance – the absolute frequency tolerance.
- generate_sql(outside_temperature: float, frequency_channel: int, station_id: int, **kwargs: Any) str[source]
Return an sql query.
- Parameters:
outside_temperature – The current outside temperature.
frequency_channel – The current frequency channel.
station_id – The id of the station we want a solution for.
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, outside_temperature, " >>> "calibration_path, creation_time, station_id, preferred " >>> "FROM tab_mccs_calib " >>> 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"
- class SelectionManager(logger: Logger)[source]
A SelectionManager.
- __init__(logger: Logger) None[source]
Initialise a new SelectionManager.
- Parameters:
logger – A logger for information purposes.
- 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.
- property policy: str
Return 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.