core¶
Shared utilities used across the dashboard: configuration, graph layout, colour schemes, database abstraction, and data processing.
- exception fstg_toolkit.app.core.config.NotConfiguredError(name: str)[source]¶
Bases:
ExceptionRaised when a required configuration attribute has not been set.
- class fstg_toolkit.app.core.geometry.Arc(begin: float, end: float)[source]¶
Bases:
objectAn arc on the unit circle defined by start and end angles (in radians).
- static from_proportions(proportions: list[float], begin: float = 0, length: float = 6.283185307179586, gap_size: float = 0.005) list[Arc][source]¶
Create a list of arcs from proportional sizes with uniform gaps.
- Parameters:
proportions (list[float]) – Relative sizes of each arc. Need not sum to 1.
begin (float, optional) – Starting angle in radians (default 0).
length (float, optional) – Total angular length to distribute (default
2π).gap_size (float, optional) – Gap between arcs as a fraction of the full circle (default 0.005).
- Returns:
One
Arcper proportion, laid out consecutively with gaps.- Return type:
- class fstg_toolkit.app.core.geometry.ArcShape(arc: Arc, thickness: float, radius: float)[source]¶
Bases:
ShapeA filled arc shape with a given radius and thickness.
- Parameters:
- class fstg_toolkit.app.core.geometry.Line(length: float, orientation: float, origin: tuple[float, float] = (0, 0))[source]¶
Bases:
objectA straight line segment defined by a length, orientation, and origin.
- Parameters:
- static from_proportions(proportions: list[float], total_length: float, orientation: float, origin: tuple[float, float] = (0, 0), gap_length: float = 0.25) list[Line][source]¶
Create proportionally-sized line segments laid end-to-end with gaps.
- Parameters:
total_length (float) – Total available length (gaps included).
orientation (float) – Shared orientation angle in radians.
origin (tuple[float, float], optional) – Starting point for the first segment (default
(0, 0)).gap_length (float, optional) – Fixed gap length between consecutive segments (default 0.25).
- Returns:
One
Lineper proportion, laid out consecutively with gaps.- Return type:
- class fstg_toolkit.app.core.geometry.LineShape(line: Line, thickness: float)[source]¶
Bases:
ShapeA filled rectangular shape centred on a line segment.
- Parameters:
- class fstg_toolkit.app.core.geometry.Path(points: list[tuple[float, float]] = <factory>)[source]¶
Bases:
objectA closed polygonal path defined by a sequence of 2-D points.
- Parameters:
points (list[tuple[float, float]], optional) – Ordered list of
(x, y)vertices (default empty list).
- class fstg_toolkit.app.core.geometry.Ribbon(begin: float, end: float)[source]¶
Bases:
objectA curved ribbon connecting two angular positions on the unit circle via a quadratic Bezier.
- Parameters:
- sample(radius: float = 1.0, origin: tuple[float, float] = (0, 0), strength: float = 0.3, nb_points: int = 50) ndarray[source]¶
Sample points along the ribbon curve.
- Parameters:
radius (float, optional) – Circle radius at which the ribbon endpoints sit (default 1.0).
origin (tuple[float, float], optional) – Centre of the circle (default
(0, 0)).strength (float, optional) – Pull strength of the Bezier control point towards the origin (default 0.3).
nb_points (int, optional) – Number of sample points along the curve (default 50).
- Returns:
Array of shape
(2, nb_points)with x- and y-coordinates.- Return type:
- class fstg_toolkit.app.core.geometry.RibbonShape(left_ribbon: Ribbon, right_ribbon: Ribbon, radius: float, strength: float)[source]¶
Bases:
ShapeA filled ribbon bounded by two Bézier curves and two arc caps.
- Parameters:
left_ribbon (Ribbon) – The left boundary ribbon (connects
arc_source.begintoarc_target.begin).right_ribbon (Ribbon) – The right boundary ribbon (connects
arc_source.endtoarc_target.end).radius (float) – Circle radius for the ribbon endpoints.
strength (float) – Bezier control-point strength for both ribbons.
- class fstg_toolkit.app.core.geometry.Shape[source]¶
Bases:
ABCAbstract base class for geometric shapes that can be converted to a
Path.
- class fstg_toolkit.app.core.color.ColorsInterpolator[source]¶
Bases:
ABCAbstract base class for color interpolators that generate a palette of
ncolors.
- class fstg_toolkit.app.core.color.HueInterpolator(saturation: float = 0.7, value: float = 0.9)[source]¶
Bases:
ColorsInterpolatorColor interpolator that steps evenly through the HSV hue wheel.
- Parameters:
- exception fstg_toolkit.app.core.datafilesdb.AbstractClassNotMeantToBeUsedDirectly[source]¶
Bases:
NotImplementedError
- class fstg_toolkit.app.core.datafilesdb.DataFilesDB(token_nb_bytes: int = 3, debug: bool = False)[source]¶
Bases:
ABCAbstract base class for managing a database of data files, each associated with a unique token.
- Parameters:
token_nb_bytes (int, optional) – Number of bytes to use when generating unique tokens for data files (default is 3).
- get(token: str) pathlib.Path | None[source]¶
Retrieves the file path associated with the given token.
- list() Generator[tuple[str, pathlib.Path], None, None][source]¶
Lists all token-file path pairs in the database.
- class fstg_toolkit.app.core.datafilesdb.MemoryDataFilesDB(*args, **kwargs)[source]¶
Bases:
DataFilesDBIn-memory implementation of the DataFilesDB abstract base class.
This class manages a database of data files using a Python dictionary, mapping unique tokens to file paths. It is suitable for use cases where persistence is not required and the number of files is relatively small.
- Parameters:
token_nb_bytes (int, optional) – Number of bytes to use when generating unique tokens for data files (default is 3).
- list() Generator[tuple[str, Path], None, None][source]¶
Lists all token-file path pairs in the database.
- class fstg_toolkit.app.core.datafilesdb.SQLiteDataFilesDB(db_path: Path, *args, **kwargs)[source]¶
Bases:
DataFilesDB,SQLiteConnectedSQLite-backed implementation of the DataFilesDB.
Stores token -> file path mappings in a SQLite database. Pass a Path or string via the db_path parameter to persist to disk.
- Parameters:
db_path (pathlib.Path | str) – Path to the sqlite database file.
token_nb_bytes (Other keyword args are forwarded to the parent DataFilesDB (e.g.)
:param : :param debug).:
- fstg_toolkit.app.core.datafilesdb.get_data_file_db(requested_type: Type[DataFilesDB] | None = None, **kwargs) DataFilesDB[source]¶
Returns the singleton instance of the data files database.
If the singleton instance does not exist, it is created using the specified type or defaults to SQLiteDataFilesDB.
- Parameters:
requested_type (type[DataFilesDB] or None, optional) – The class type of the data files database to instantiate. If None, defaults to SQLiteDataFilesDB for database creation.
- Returns:
The singleton instance of the data files database.
- Return type:
- Raises:
RuntimeError – If a database instance already exists with a different type than requested_type.
- class fstg_toolkit.app.core.processing.DatasetProcessingManager(db_path: Path)[source]¶
Bases:
SQLiteConnected- list(limit: int = 30) list[DatasetResult][source]¶
- submit(dataset: SubmittedDataset)[source]¶
- class fstg_toolkit.app.core.processing.DatasetResult(dataset: fstg_toolkit.app.core.processing.SubmittedDataset, job_status: fstg_toolkit.app.core.processing.ProcessingJobStatus, submitted_at: datetime.datetime, result: str, error: str | None)[source]¶
Bases:
object- dataset: SubmittedDataset¶
- job_status: ProcessingJobStatus¶
- exception fstg_toolkit.app.core.processing.InvalidSubmittedDataset(message: str)[source]¶
Bases:
Exception
- class fstg_toolkit.app.core.processing.JobStatusMonitor(db_path: Path)[source]¶
Bases:
SQLiteConnected,ProcessingQueueListener- on_job_completed(job_id: str, result: T | None)[source]¶
Called when a job finishes successfully.
- Parameters:
job_id (str) – The unique identifier of the completed job.
result (any or None) – The return value of the job function.
- on_job_failed(job_id: str, error: Exception)[source]¶
Called when a job raises an unhandled exception.
- class fstg_toolkit.app.core.processing.ProcessingJobStatus(*values)[source]¶
Bases:
Enum- COMPLETED = 'Completed'¶
- FAILED = 'Failed'¶
- PENDING = 'Pending'¶
- RUNNING = 'Running'¶
- static from_value(name: str) ProcessingJobStatus | None[source]¶
- class fstg_toolkit.app.core.processing.ProcessingQueue(max_workers: int = 1, listener: ProcessingQueueListener | None = None)[source]¶
Bases:
objectA thread-pool-backed job queue with optional lifecycle event notifications.
Each submitted callable receives a unique job ID as its first argument. An optional
ProcessingQueueListeneris notified at each stage of a job’s lifecycle (submitted, started, completed, failed).- __init__(max_workers: int = 1, listener: ProcessingQueueListener | None = None)[source]¶
Initialise the processing queue.
- Parameters:
max_workers (int, optional) – Maximum number of concurrent worker threads (default 1).
listener (ProcessingQueueListener or None, optional) – Observer to notify on job lifecycle events.
- submit(func: Callable[[str, ...], T], *args, **kwargs) str[source]¶
Submit a callable for asynchronous execution.
- Parameters:
func (Callable) – The function to execute. It will receive a unique job ID string as its first positional argument, followed by
*argsand**kwargs.*args – Additional arguments forwarded to
func.**kwargs – Additional arguments forwarded to
func.
- Returns:
The UUID string identifying the submitted job.
- Return type:
- class fstg_toolkit.app.core.processing.ProcessingQueueListener[source]¶
Bases:
ABCAbstract observer interface for
ProcessingQueuelifecycle events.Implement this interface to receive notifications when jobs are submitted, started, completed, or failed.
- abstractmethod on_job_completed(job_id: str, result: T | None)[source]¶
Called when a job finishes successfully.
- Parameters:
job_id (str) – The unique identifier of the completed job.
result (any or None) – The return value of the job function.
- abstractmethod on_job_failed(job_id: str, error: Exception)[source]¶
Called when a job raises an unhandled exception.
- class fstg_toolkit.app.core.processing.SubmittedDataset(name: str, include_raw: bool, compute_metrics: bool, compute_frequent: bool, areas_file: pathlib.Path, matrices_files: list[pathlib.Path])[source]¶
Bases:
object
- fstg_toolkit.app.core.processing.get_dataset_processing_manager() DatasetProcessingManager[source]¶
- fstg_toolkit.app.core.processing.get_processing_queue() ProcessingQueue[source]¶
- class fstg_toolkit.app.core.utils.SQLiteConnected(db_path: Path | None, timeout: float = 30.0)[source]¶
Bases:
objectA class that brings a connection to an SQLite database as a feature.
- fstg_toolkit.app.core.utils.join(l: list[Any], sep: Any) list[Any][source]¶
Interleave a separator between elements of a list.
- Parameters:
l (list) – Sequence of elements to be joined. If empty, an empty list is returned.
sep (Any) – Separator value to insert between consecutive elements of
l.
- Returns:
A new list with
sepinserted between each pair of elements froml. Iflis empty, returns[]. Iflcontains a single element, a shallow copy oflis returned.- Return type:
Examples
>>> join([1, 2, 3], 0) [1, 0, 2, 0, 3] >>> join(['a'], '-') ['a'] >>> join([], None) []