Documentation for the casman.assembly package.
Assembly management functionality for CAsMan.
This module provides functionality for recording and retrieving assembly connections, building connection chains, and interactive assembly scanning.
Assembly chain building and analysis functionality.
This module handles building connection chains from assembly data and provides analysis functions for understanding assembly relationships.
Functions:
build_connection_chains() - Build a dictionary mapping each part to its connected partsprint_assembly_chains() - Print all assembly chains in a readable formatAssembly connection recording functionality.
This module handles the recording of assembly connections between parts in the assembled database.
Functions:
record_assembly_connection() - Record an assembly connection or disconnection in the database with explicit timestampsrecord_assembly_disconnection() - Record an assembly disconnection in the databaseInteractive assembly operations for CAsMan.
This module provides interactive command-line interfaces for scanning and assembling parts.
Functions:
validate_connection_rules() - Validate that the connection follows the defined chain rulesvalidate_chain_directionality() - Validate that parts follow proper chain directionality rulescheck_existing_connections() - Check if a part already has existing connections to prevent duplicates/branchescheck_target_connections() - Check if the target part can accept a new connectionvalidate_part_in_database() - Validate if a part exists in the parts database or SNAP mappingvalidate_snap_part() - Validate a SNAP part format (SNAPscan_and_assemble_interactive() - Interactive scanning and assembly functionscan_and_disassemble_interactive() - Interactive scanning and disassembly functionmain() - Main entry point for assembly scanning CLIAssembly data retrieval and statistics functionality.
This module handles querying assembly connection data and generating statistics from the assembled database.
Functions:
get_assembly_connections() - Get all assembly connections from the databaseThis module provides functionality for recording and retrieving assembly connections, building connection chains, and interactive assembly scanning.
Signature: main()
Legacy entry point for assembly scanning (deprecated). Use casman scan connect for interactive assembly management.
This module handles building connection chains from assembly data and provides analysis functions for understanding assembly relationships.
Signature: build_connection_chains(db_dir: Optional[str]) -> Dict[str, List[str]]
Build a dictionary mapping each part to its connected parts.
Returns:
Dict[str, List[str]] Dictionary where keys are part numbers and values are lists of connected part numbers.
Examples:
>>> chains = build_connection_chains()
>>> print(chains.get('ANT00001P1', []))
['LNA00001P1']
Signature: print_assembly_chains(db_dir: Optional[str]) -> None
Print all assembly chains in a readable format.
Parameters:
db_dir : str, optional Custom database directory. If not provided, uses the project root’s database directory. This function builds connection chains and prints them in a tree-like structure showing how parts are connected to each other.
Examples:
>>> print_assembly_chains()
Assembly Chains:
================
ANT00001P1 ---> LNA00001P1 ---> CXS00001P1
ANT00002P1 ---> LNA00002P1
This module handles the recording of assembly connections between parts in the assembled database.
Signature: record_assembly_connection(part_number: str, part_type: str, polarization: str, scan_time: str, connected_to: str, connected_to_type: str, connected_polarization: str, connected_scan_time: str, db_dir: Optional[str], connection_status: str) -> bool
Record an assembly connection or disconnection in the database with explicit timestamps.
Parameters:
part_number : str The part number being scanned. part_type : str The type of the part being scanned. polarization : str The polarization of the part being scanned. scan_time : str The timestamp when the part was scanned (YYYY-MM-DD HH:MM:SS). connected_to : str The part number this part is connected to. connected_to_type : str The type of the connected part. connected_polarization : str The polarization of the connected part. connected_scan_time : str The timestamp when the connection was made (YYYY-MM-DD HH:MM:SS). db_dir : Optional[str] Custom database directory. If not provided, uses the project root’s database directory. connection_status : str, optional Status of the connection: ‘connected’ or ‘disconnected’. Defaults to ‘connected’.
Returns:
bool True if the connection was recorded successfully, False otherwise.
Examples:
>>> success = record_assembly_connection(
... "ANT00001P1", "ANTENNA", "P1", "2024-01-01 10:00:00",
... "LNA00001P1", "LNA", "P1", "2024-01-01 10:05:00"
... )
>>> print(success)
True
>>> success = record_assembly_connection(
... "ANT00001P1", "ANTENNA", "P1", "2024-01-01 10:00:00",
... "LNA00001P1", "LNA", "P1", "2024-01-01 10:10:00",
... connection_status="disconnected"
... )
Signature: record_assembly_disconnection(part_number: str, part_type: str, polarization: str, scan_time: str, connected_to: str, connected_to_type: str, connected_polarization: str, connected_scan_time: str, db_dir: Optional[str]) -> bool
Record an assembly disconnection in the database. This is a convenience wrapper around record_assembly_connection that sets the connection_status to ‘disconnected’.
Parameters:
part_number : str The part number being disconnected. part_type : str The type of the part being disconnected. polarization : str The polarization of the part being disconnected. scan_time : str The timestamp when the part was scanned (YYYY-MM-DD HH:MM:SS). connected_to : str The part number this part was connected to. connected_to_type : str The type of the connected part. connected_polarization : str The polarization of the connected part. connected_scan_time : str The timestamp when the disconnection was made (YYYY-MM-DD HH:MM:SS). db_dir : Optional[str] Custom database directory. If not provided, uses the project root’s database directory.
Returns:
bool True if the disconnection was recorded successfully, False otherwise.
Examples:
>>> success = record_assembly_disconnection(
... "ANT00001P1", "ANTENNA", "P1", "2024-01-01 10:00:00",
... "LNA00001P1", "LNA", "P1", "2024-01-01 10:10:00"
... )
>>> print(success)
True
This module provides interactive command-line interfaces for scanning and assembling parts.
Signature: validate_connection_rules(first_part: str, first_type: str, connected_part: str, connected_type: str) -> Tuple[bool, str]
Validate that the connection follows the defined chain rules.
Returns:
tuple[bool, str]: (is_valid, error_message)
Signature: validate_chain_directionality(part_type: str, connection_direction: str) -> Tuple[bool, str]
Validate that parts follow proper chain directionality rules.
Returns:
tuple[bool, str]: (is_valid, error_message)
Signature: check_existing_connections(part_number: str) -> Tuple[bool, str, List]
Check if a part already has existing connections to prevent duplicates/branches.
Returns:
tuple[bool, str, list]: (can_connect, error_message, existing_connections)
Signature: check_target_connections(connected_part: str) -> Tuple[bool, str]
Check if the target part can accept a new connection.
Returns:
tuple[bool, str]: (can_accept, error_message)
Signature: validate_part_in_database(part_number: str) -> Tuple[bool, str, str]
Validate if a part exists in the parts database or SNAP mapping.
Returns:
tuple[bool, str, str]: (is_valid, part_type, polarization)
Signature: validate_snap_part(part_number: str) -> Tuple[bool, str, str]
Validate a SNAP part format (SNAP
Returns:
tuple[bool, str, str]: (is_valid, part_type, polarization)
Signature: scan_and_assemble_interactive() -> None
Interactive scanning and assembly function. Provides a command-line interface for scanning parts and recording their connections. Continues until the user types ‘quit’.
Returns:
None
Examples:
>>> scan_and_assemble_interactive() # doctest: +SKIP
Interactive Assembly Scanner
============================
Type 'quit' to exit.
Scan first part: ANTP1-00001
Scan connected part: LNA-P1-00001
Connection recorded: ANTP1-00001 -> LNA-P1-00001
Scan first part: quit
Goodbye!
Signature: scan_and_disassemble_interactive() -> None
Interactive scanning and disassembly function. Provides a command-line interface for scanning parts and recording their disconnections. Continues until the user types ‘quit’.
Returns:
None
Examples:
>>> scan_and_disassemble_interactive() # doctest: +SKIP
Interactive Disassembly Scanner
===============================
Type 'quit' to exit.
Scan first part: ANTP1-00001
Scan disconnected part: LNA-P1-00001
Disconnection recorded: ANTP1-00001 -X-> LNA-P1-00001
Scan first part: quit
Goodbye!
Signature: main() -> None
Main entry point for assembly scanning CLI. Provides interactive interface for assembly management operations.
This module handles querying assembly connection data and generating statistics from the assembled database.
Signature: get_assembly_connections(db_dir: Optional[str]) -> List[Tuple[str, Optional[str], str, Optional[str], Optional[str]]]
Get all assembly connections from the database. Only returns connections where the most recent status between any two parts (checking both directions) is ‘connected’. This ensures disconnected pairs are properly filtered out even if only one direction was recorded.
Parameters:
db_dir : str, optional Custom database directory. If not provided, uses the project root’s database directory.
Returns:
List[Tuple[str, Optional[str], str, Optional[str], Optional[str]]] List of (part_number, connected_to, scan_time, part_type, polarization) tuples.
Examples:
>>> connections = get_assembly_connections()
>>> for part, connected, time, ptype, pol in connections:
... print(f"{part} -> {connected} at {time}")
ANTP1-00001 -> LNA-P1-00001 at 2024-01-01 10:00:00