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 clash data.
This class defines the interface for clash data serialization and deserialization.
Any serializer must fully implement this abstract class.
Constructor#
- __init__()
Initializes a new instance of the AbstractClashDataSerializer class.
Methods#
- open(file_path_name: str) None
Creates a file or opens an existing.
- Parameters:
file_path_name (str) – The path to the file to open or create.
- Returns:
None
- get_file_path() str #
Returns the serializer file path.
- Returns:
The file path as a string.
- get_file_size() int #
Returns the serializer file size in bytes.
- Returns:
The file size in bytes.
- data_structures_compatible() bool #
Checks if the serializer has no compatibility issues with data structures or tables.
- Returns:
True if compatible, False otherwise.
- deferred_file_creation_until_first_write_op() bool #
Determines if file creation is postponed until the first write operation.
- Returns:
True if file creation is deferred, False otherwise.
- set_deferred_file_creation_until_first_write_op(value: bool)#
Sets whether file creation should be postponed until the first write operation.
- Parameters:
value (bool) – True to enable deferred file creation, False otherwise.
- Returns:
None
- set_on_modified_fnc(on_modified_fnc: Callable[[str], None])#
Sets the function to be called when the file is modified.
- Parameters:
on_modified_fnc (Callable[[str], None]) – The function to call on modification.
- Returns:
None
- on_modified_fnc#
Gets the function that is called when the file is modified.
- Returns:
The function as a callable.
- is_open() bool
Checks if the serializer is ready for operations.
- Returns:
True if the serializer is open, False otherwise.
- save() bool
Saves data to the target file.
- Returns:
True if the data was successfully saved, False otherwise.
- close() None
Closes the opened file.
- Returns:
None
- commit() None
Writes any unwritten data to the file. Committing bigger batches is advised.
- Returns:
None
- insert_overlap(
- clash_info: ClashInfo,
- insert_also_frame_info: bool,
- update_identifier: bool,
- commit: bool,
Inserts clash data. If already present, insertion is skipped. Returns the ID of the new record.
- Parameters:
clash_info – The clash information to insert.
insert_also_frame_info – Whether to also insert frame information.
update_identifier – Whether to update the identifier.
commit – Whether to commit the operation.
- Returns:
The ID of the new record as an integer.
- update_overlap(
- clash_info: ClashInfo,
- update_also_frame_info: bool,
- commit: bool,
Updates clash data if present in the database. Returns the number of affected records.
- Parameters:
clash_info – The clash information to update.
update_also_frame_info – Whether to also update frame information.
commit – Whether to commit the operation.
- Returns:
The number of affected records as an integer.
- 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,
Returns all clash data associated with a query ID. If not present, returns an empty dictionary.
- Parameters:
clash_query_id – The query ID to search for.
fetch_also_frame_info – Whether to also fetch frame information.
num_frames_to_load – The maximum number of frames to load when fetching frame information. Defaults to -1, which means all available frames are loaded.
first_frame_offset – The offset for the first frame to load when fetching frame information. Defaults to 0.
- Returns:
A dictionary of clash data.
- 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,
Returns clash data associated with single or multiple overlap IDs. If not present, returns an empty dictionary.
- Parameters:
overlap_id – The overlap IDs to search for.
fetch_also_frame_info – Whether to also fetch frame information.
num_frames_to_load – The maximum number of frames to load when fetching frame information. Defaults to -1, which means all available frames are loaded.
first_frame_offset – The offset for the first frame to load when fetching frame information. Defaults to 0.
- Returns:
A dictionary of clash data.
- remove_all_overlaps_by_query_id(
- clash_query_id: int,
- commit: bool,
Deletes specified clash data related to a query ID. If not present, nothing happens. Returns the number of deleted rows.
- Parameters:
clash_query_id – The query ID whose data is to be deleted.
commit – Whether to commit the operation.
- Returns:
The number of deleted rows as an integer.
- remove_overlap_by_id(overlap_id: int, commit: bool) int #
Deletes specified clash data by ID. If not present, nothing happens. Returns the number of deleted rows.
- Parameters:
overlap_id – The ID of the overlap to delete.
commit – Whether to commit the operation.
- Returns:
The number of deleted rows as an integer.
- fetch_clash_frame_info_by_clash_info_id(
- clash_info_id: int,
- num_frames_to_load: int = -1,
- first_frame_offset: int = 0,
Returns all clash frame info items associated with a clash_info_id. If not present, returns empty list.
- Parameters:
clash_info_id – The clash info ID to search for.
num_frames_to_load – The maximum number of frames to load when fetching frame information. Defaults to -1, which means all available frames are loaded.
first_frame_offset – The offset for the first frame to load when fetching frame information. Defaults to 0.
- Returns:
A sequence of clash frame info items or empty list.
- insert_clash_frame_info_from_clash_info(
- clash_info: ClashInfo,
- commit: bool,
Inserts clash frame info from clash info. If already present, insertion is skipped. Returns the number of affected records.
- Parameters:
clash_info – The clash information based on which to insert frame info.
commit – Whether to commit the operation.
- Returns:
The number of affected records as an integer.
- insert_clash_frame_info(
- clash_frame_info: ClashFrameInfo,
- clash_info_id: int,
- commit: bool,
Inserts clash frame info. If already present, insertion is skipped. Returns the ID of the new record.
- Parameters:
clash_frame_info – The clash frame information to insert.
clash_info_id – The clash info ID to associate with.
commit – Whether to commit the operation.
- Returns:
The ID of the new record as an integer.
- remove_clash_frame_info_by_clash_info_id(
- clash_info_id: int,
- commit: bool,
Deletes specified clash frame info data. If not present, nothing happens. Returns the number of deleted rows.
- Parameters:
clash_info_id – The clash info ID whose frame info is to be deleted.
commit – Whether to commit the operation.
- Returns:
The number of deleted rows as an integer.
- fetch_all_queries() Dict[int, ClashQuery] #
Returns all clash queries. If not present, returns an empty dictionary.
- Returns:
A dictionary of all clash queries.
- insert_query(
- clash_query: ClashQuery,
- update_identifier: bool,
- commit: bool,
Inserts a clash query. If already present, insertion is skipped. Returns the ID of the new record.
- Parameters:
clash_query – The clash query to insert.
update_identifier – Whether to update the identifier.
commit – Whether to commit the operation.
- Returns:
The ID of the new record as an integer.
- find_query(clash_query_id: int) Optional[ClashQuery]: #
Returns the specified clash query. If not present, returns None.
- Parameters:
clash_query_id – The ID of the clash query to find.
- Returns:
The specified clash query or None.
- update_query(clash_query: ClashQuery, commit: bool) int #
Updates a clash query if present in the database. Returns the number of affected records.
- Parameters:
clash_query – The clash query to update.
commit – Whether to commit the operation.
- Returns:
The number of affected records as an integer.
- remove_query_by_id(query_id: int, commit: bool) int #
Deletes specified clash data. If not present, nothing happens. Returns the number of deleted rows.
- Parameters:
query_id – The ID of the query to delete.
commit – Whether to commit the operation.
- Returns:
The number of deleted rows as an integer.
ClashDataSerializerSqlite Class#
- class ClashDataSerializerSqlite#
ClashDataSerializerSqlite class which implements ‘AbstractClashDataSerializer’ to serialize and deserialize clash data to SQLite database.