šŸ” Code Extractor

function print_database_analysis

Maturity: 42

Prints a comprehensive, formatted analysis of a reMarkable tablet replica database, including statistics, hierarchy information, file types, and a content tree visualization.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_replica.py
Lines:
171 - 236
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v66 72.5% similar

    Main entry point function that analyzes a reMarkable tablet replica directory by loading its database, printing analysis results, and displaying sync information.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_replica.py
  • function test_root_finding 66.2% similar

    A test function that analyzes a reMarkable tablet replica database JSON file to identify and list all root-level entries (folders and documents without parent nodes).

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/debug_root.py
  • function analyze_file_types 65.7% similar

    Analyzes file types within a replica database structure, counting different file categories and tracking file extensions.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_replica.py
  • function main_v113 64.7% similar

    Analyzes and compares .content files for PDF documents stored in reMarkable cloud storage, identifying differences between working and non-working documents.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_content_files.py
  • function analyze_pylontech_document 62.7% similar

    Performs deep forensic analysis of a specific Pylontech document stored in reMarkable Cloud, examining all document components (content, metadata, pagedata, PDF) to identify patterns and differences between app-uploaded and API-uploaded documents.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_pylontech_details.py
← Back to Browse