Clash Data Serializer#
Overview#
File Name: clash_data_serializer.py
This file contains an abstract base class for serializing clash data AbstractClashDataSerializer.
AbstractClashDataSerializer Class#
- class AbstractClashDataSerializer#
An abstract base class for serializing and managing clash data.
This abstract class defines the necessary methods for handling clash data serialization, including opening and closing files, managing data compatibility, and performing CRUD operations on clash data and related information. Implementations of this class should provide concrete definitions for the abstract methods.
Constructor#
- __init__()
Initializes the AbstractClashDataSerializer class.
Methods#
- open(file_path_name: str) None
Creates a file or opens an existing.
- Parameters:
file_path_name (str) – Path of the file to open.
- get_file_path() str #
Returns the serializer file path.
- Returns:
The file path of the serializer.
- Return type:
str
- get_file_size() int #
Returns the serializer file size in bytes.
- Returns:
The file size in bytes.
- Return type:
int
- data_structures_compatible() bool #
Returns True if the serializer has no compatibility issues (data structures, tables).
- Returns:
True if compatible, False otherwise.
- Return type:
bool
- deferred_file_creation_until_first_write_op() bool #
Returns True if the serializer will postpone file creation until first write op is requested.
- Returns:
True if deferred creation is enabled, False otherwise.
- Return type:
bool
- set_deferred_file_creation_until_first_write_op(value: bool)#
Sets if the serializer must postpone file creation until first write op is requested.
- Parameters:
value (bool) – Whether to defer file creation.
- set_on_modified_fnc(on_modified_fnc: Callable[[str], None] | None)#
Sets on_modified_fnc - a function to be called when the file is modified.
- Parameters:
on_modified_fnc (Optional[Callable[[str], None]]) – The function to call when modified.
- on_modified_fnc#
Gets on_modified_fnc.
- Returns:
The on_modified function.
- Return type:
Optional[Callable[[str], None]]
- is_open() bool
Returns if the serializer is ready.
- Returns:
True if open, False otherwise.
- Return type:
bool
- save() bool
Saves data to the target file.
- Returns:
True if save was successful, False otherwise.
- Return type:
bool
- close() None
Closes the opened file.
- commit() None
Writes any unwritten data to the file. Committing bigger batches is advised.
- insert_overlap(
- clash_info: ClashInfo,
- insert_also_frame_info: bool,
- update_identifier: bool,
- commit: bool,
Inserts clash data. If already present, insertion is skipped.
- Parameters:
clash_info (ClashInfo) – Clash information to insert.
insert_also_frame_info (bool) – Whether to insert frame info.
update_identifier (bool) – Whether to update the identifier.
commit (bool) – Whether to commit the operation.
- Returns:
ID of the new record.
- Return type:
int
- update_overlap(
- clash_info: ClashInfo,
- update_also_frame_info: bool,
- commit: bool,
Updates clash data if present in the DB.
- Parameters:
clash_info (ClashInfo) – Clash information to update.
update_also_frame_info (bool) – Whether to update frame info.
commit (bool) – Whether to commit the operation.
- Returns:
Number of affected records.
- Return type:
int
- find_all_overlaps_by_query_id(
- clash_query_id: int,
- fetch_also_frame_info: bool,
- num_frames_to_load: int = -1,
- first_frame_offset: int = 0,
Finds all overlaps associated with a specific query ID.
This method retrieves all ClashInfo objects corresponding to the given clash_query_id from the database and optionally fetches additional frame information for each clash.
- Parameters:
clash_query_id (int) – The ID of the query to search for overlaps.
fetch_also_frame_info (bool) – If True, fetches frame information associated with each ClashInfo object.
num_frames_to_load (int) – The maximum number of frames to load when fetching frame information. Defaults to -1, which means all available frames are loaded.
first_frame_offset (int) – The offset for the first frame to load when fetching frame information. Defaults to 0.
- Returns:
A dictionary where the keys are overlap IDs (as strings) and the values are the corresponding ClashInfo objects. If no results are found, an empty dictionary is returned.
- Return type:
Dict[str, ClashInfo]
- find_all_overlaps_by_overlap_id(
- overlap_id: Sequence[int],
- fetch_also_frame_info: bool,
- num_frames_to_load: int = -1,
- first_frame_offset: int = 0,
Finds all overlaps by their overlap IDs.
This method retrieves all ClashInfo objects associated with the given overlap IDs and optionally fetches additional frame information for each clash.
- Parameters:
overlap_id (Sequence[int]) – A sequence of overlap IDs to search for.
fetch_also_frame_info (bool) – If True, fetches frame information associated with each ClashInfo object.
num_frames_to_load (int) – The maximum number of frames to load when fetching frame information. Defaults to -1, which means all available frames are loaded.
first_frame_offset (int) – The offset for the first frame to load when fetching frame information. Defaults to 0.
- Returns:
A dictionary where the keys are overlap IDs (as strings) and the values are the corresponding ClashInfo objects. If no results are found, an empty dictionary is returned.
- Return type:
Dict[str, ClashInfo]
- remove_all_overlaps_by_query_id(
- clash_query_id: int,
- commit: bool,
Deletes specified clash data related to query_id. If not present, nothing happens.
- Parameters:
clash_query_id (int) – The query ID to remove.
commit (bool) – Whether to commit the operation.
- Returns:
Number of deleted rows.
- Return type:
int
- remove_overlap_by_id(overlap_id: int, commit: bool) int #
Deletes specified clash data. If not present, nothing happens.
- Parameters:
overlap_id (int) – The overlap ID to remove.
commit (bool) – Whether to commit the operation.
- Returns:
Number of deleted rows.
- Return type:
int
- fetch_clash_frame_info_by_clash_info_id(
- clash_info_id: int,
- num_frames_to_load: int = -1,
- first_frame_offset: int = 0,
Fetches frame information associated with a specific clash.
This method retrieves ClashFrameInfo records from the database for a given clash_info_id, ordered by timecode. It supports limiting the number of frames fetched and applying an offset to the starting frame.
- Parameters:
clash_info_id (int) – The ID of the clash for which frame information is to be fetched.
num_frames_to_load (int) – The maximum number of frames to load. Defaults to -1, which means all available frames are loaded.
first_frame_offset (int) – The offset for the first frame to load. Defaults to 0.
- Returns:
A list of ClashFrameInfo objects representing the fetched frame information. Returns an empty list if no results are found.
- Return type:
Sequence[ClashFrameInfo]
- insert_clash_frame_info_from_clash_info(
- clash_info: ClashInfo,
- commit: bool,
Inserts clash_frame_info from ClashInfo.
- Parameters:
clash_info (ClashInfo) – The ClashInfo object to extract frame info from.
commit (bool) – Whether to commit the change.
- Returns:
Number of affected records.
- Return type:
int
- insert_clash_frame_info(
- clash_frame_info: ClashFrameInfo,
- clash_info_id: int,
- commit: bool,
Inserts clash_frame_info.
- Parameters:
clash_frame_info (ClashFrameInfo) – The ClashFrameInfo object to insert.
clash_info_id (int) – The ID of the associated ClashInfo.
commit (bool) – Whether to commit the change.
- Returns:
ID of the new record.
- Return type:
int
- remove_clash_frame_info_by_clash_info_id(
- clash_info_id: int,
- commit: bool,
Deletes specified clash_frame_info data.
- Parameters:
clash_info_id (int) – The ID of the associated ClashInfo.
commit (bool) – Whether to commit the change.
- Returns:
Number of deleted rows.
- Return type:
int
- fetch_all_queries() Dict[int, ClashQuery] #
Returns all clash queries.
- Returns:
Dictionary of all clash queries.
- Return type:
Dict[int, ClashQuery]
- insert_query(
- clash_query: ClashQuery,
- update_identifier: bool,
- commit: bool,
Inserts clash query.
- Parameters:
clash_query (ClashQuery) – The ClashQuery object to insert.
update_identifier (bool) – Whether to update the identifier.
commit (bool) – Whether to commit the change.
- Returns:
ID of the new record.
- Return type:
int
- find_query(clash_query_id: int) ClashQuery | None #
Returns specified clash query.
- Parameters:
clash_query_id (int) – The ID of the ClashQuery to find.
- Returns:
The found ClashQuery or None.
- Return type:
Optional[ClashQuery]
- update_query(clash_query: ClashQuery, commit: bool) int #
Updates clash query if present in the DB.
- Parameters:
clash_query (ClashQuery) – The ClashQuery object to update.
commit (bool) – Whether to commit the change.
- Returns:
Number of affected records.
- Return type:
int
- remove_query_by_id(query_id: int, commit: bool) int #
Deletes specified clash data.
- Parameters:
query_id (int) – The ID of the query to remove.
commit (bool) – Whether to commit the change.
- Returns:
Number of deleted rows.
- Return type:
int
ClashDataSerializerSqlite Class#
- class ClashDataSerializerSqlite#
ClashDataSerializerSqlite class which implements ‘AbstractClashDataSerializer’ to serialize and deserialize clash data to SQLite database.