function print_database_analysis
Prints a comprehensive, formatted analysis of a reMarkable tablet replica database, including statistics, hierarchy information, file types, and a content tree visualization.
/tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_replica.py
171 - 236
moderate
Purpose
This function provides a detailed console output report for analyzing the structure and contents of a reMarkable tablet database replica. It displays metadata about the replica creation, node counts, file statistics, hierarchy depth analysis, file type distributions, and a visual tree representation of the content structure. This is useful for debugging, auditing, or understanding the organization of a reMarkable tablet's content after it has been replicated to a local database format.
Source Code
def print_database_analysis(database: Dict[str, Any]):
"""Print comprehensive database analysis"""
replica_info = database.get('replica_info', {})
nodes = database.get('nodes', {})
print("š REMARKABLE REPLICA DATABASE ANALYSIS")
print("=" * 60)
# Basic info
print(f"š
Created: {replica_info.get('created', 'unknown')}")
print(f"š Replica directory: {replica_info.get('replica_dir', 'unknown')}")
print(f"š Total nodes: {len(nodes)}")
# Statistics
stats = replica_info.get('statistics', {})
if stats:
print(f"\nš BUILD STATISTICS:")
print(f" š Folders: {stats.get('folders', 0)}")
print(f" š Documents: {stats.get('documents', 0)}")
print(f" š Notebooks: {stats.get('notebooks', 0)}")
print(f" š PDFs extracted: {stats.get('pdfs_extracted', 0)}")
print(f" š Notebooks extracted: {stats.get('notebooks_extracted', 0)}")
print(f" š Total files: {stats.get('total_files', 0)}")
# Hierarchy analysis
hierarchy_info = analyze_hierarchy(database)
print(f"\nš³ HIERARCHY ANALYSIS:")
print(f" š Root nodes: {len(hierarchy_info['root_nodes'])}")
print(f" š Maximum depth: {hierarchy_info['max_depth']}")
print(f" š„ Parent-child relationships: {hierarchy_info['total_parent_relationships']}")
# Node type distribution
print(f" š Node type distribution:")
for node_type, count in hierarchy_info['type_counts'].items():
print(f" ⢠{node_type}: {count}")
# Depth distribution
print(f" š Depth distribution:")
for depth in sorted(hierarchy_info['depth_counts'].keys()):
count = hierarchy_info['depth_counts'][depth]
print(f" ⢠Depth {depth}: {count} nodes")
# File type analysis
file_stats = analyze_file_types(database)
print(f"\nš FILE TYPE ANALYSIS:")
print(f" š PDF files: {file_stats['pdf_files']}")
print(f" š Notebook components: {file_stats['notebook_files']}")
print(f" šļø reMarkable (.rm) files: {file_stats['rm_files']}")
print(f" š Content files: {file_stats['content_files']}")
print(f" š Total extracted files: {file_stats['total_extracted_files']}")
if file_stats['file_extensions']:
print(f" š File extensions:")
for ext, count in sorted(file_stats['file_extensions'].items(), key=lambda x: x[1], reverse=True):
print(f" ⢠{ext}: {count}")
# Tree view of content
print(f"\nš³ CONTENT TREE:")
hierarchy = database.get('hierarchy', {})
for root_uuid in hierarchy_info['root_nodes'][:3]: # Show first 3 root nodes
print_node_tree(nodes, hierarchy, root_uuid, max_depth=3)
print()
if len(hierarchy_info['root_nodes']) > 3:
print(f" ... ({len(hierarchy_info['root_nodes']) - 3} more root nodes)")
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
database |
Dict[str, Any] | - | positional_or_keyword |
Parameter Details
database: A dictionary containing the complete reMarkable replica database structure. Expected keys include: 'replica_info' (dict with 'created', 'replica_dir', 'statistics' subdicts), 'nodes' (dict mapping UUIDs to node objects), and 'hierarchy' (dict representing parent-child relationships). The 'statistics' subdict should contain counts like 'folders', 'documents', 'notebooks', 'pdfs_extracted', 'notebooks_extracted', and 'total_files'.
Return Value
This function returns None. It produces side effects by printing formatted analysis output directly to stdout using print() statements. The output includes emoji-decorated sections for replica info, build statistics, hierarchy analysis, file type analysis, and a content tree visualization.
Required Imports
from typing import Dict, Any
Usage Example
# Assuming you have a database dict from a reMarkable replica
# and the required helper functions are available
database = {
'replica_info': {
'created': '2024-01-15T10:30:00',
'replica_dir': '/path/to/replica',
'statistics': {
'folders': 10,
'documents': 25,
'notebooks': 15,
'pdfs_extracted': 20,
'notebooks_extracted': 15,
'total_files': 50
}
},
'nodes': {
'uuid-1': {'type': 'CollectionType', 'name': 'My Folder'},
'uuid-2': {'type': 'DocumentType', 'name': 'My Document'}
},
'hierarchy': {
'uuid-1': ['uuid-2']
}
}
# Print comprehensive analysis
print_database_analysis(database)
Best Practices
- Ensure the database dictionary is properly structured with all expected keys before calling this function to avoid KeyError exceptions
- The function depends on three helper functions (analyze_hierarchy, analyze_file_types, print_node_tree) that must be available in scope
- This function is designed for console output and debugging; for programmatic access to analysis data, consider using the helper functions directly
- The content tree display is limited to the first 3 root nodes with max depth of 3 to prevent overwhelming output; adjust these limits if needed
- Consider redirecting stdout if you need to capture the output for logging or further processing
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v66 72.5% similar
-
function test_root_finding 66.2% similar
-
function analyze_file_types 65.7% similar
-
function main_v113 64.7% similar
-
function analyze_pylontech_document 62.7% similar