🔍 Code Extractor

function print_status

Maturity: 42

Prints a formatted status report for SharePoint to FileCloud synchronization operations, displaying sync statistics, timing information, and health indicators.

File:
/tf/active/vicechatdev/SPFCsync/monitor.py
Lines:
112 - 155
Complexity:
simple

Purpose

This function generates a comprehensive console output report for monitoring SharePoint to FileCloud sync operations. It displays sync activity metrics (cycles, uploads, updates, skips), timing information (last sync time, average cycle duration), log statistics (errors, warnings), and an overall health status indicator using emoji symbols. The function is designed for operational monitoring and troubleshooting of sync processes.

Source Code

def print_status(stats):
    """Print formatted status information."""
    print("SharePoint to FileCloud Sync - Status Report")
    print("=" * 50)
    print(f"Report time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    print()
    
    if not stats:
        print("No statistics available")
        return
    
    print("Sync Activity (last 24 hours):")
    print(f"  Sync cycles completed: {stats['sync_cycles']}")
    print(f"  New files uploaded: {stats['new_uploads']}")
    print(f"  Files updated: {stats['updated_files']}")
    print(f"  Files skipped: {stats['skipped_files']}")
    print()
    
    if stats['last_sync']:
        time_since_last = datetime.now() - stats['last_sync']
        print(f"Last sync: {stats['last_sync'].strftime('%Y-%m-%d %H:%M:%S')}")
        print(f"Time since last sync: {time_since_last}")
    else:
        print("No completed sync cycles found")
    
    print()
    
    if stats['avg_cycle_time'] > 0:
        print(f"Average cycle time: {stats['avg_cycle_time']:.1f} seconds")
    
    print("Log Summary:")
    print(f"  Total log entries: {stats['total_lines']}")
    print(f"  Errors: {stats['errors']}")
    print(f"  Warnings: {stats['warnings']}")
    
    print()
    
    # Status indicator
    if stats['errors'] > 0:
        print("🔴 Status: ERRORS DETECTED")
    elif stats['last_sync'] and (datetime.now() - stats['last_sync']).total_seconds() > 3600:
        print("🟡 Status: NO RECENT SYNC")
    else:
        print("🟢 Status: HEALTHY")

Parameters

Name Type Default Kind
stats - - positional_or_keyword

Parameter Details

stats: A dictionary containing synchronization statistics and metrics. Expected keys include: 'sync_cycles' (int: number of completed sync cycles), 'new_uploads' (int: count of newly uploaded files), 'updated_files' (int: count of updated files), 'skipped_files' (int: count of skipped files), 'last_sync' (datetime object or None: timestamp of last sync), 'avg_cycle_time' (float: average time per cycle in seconds), 'total_lines' (int: total log entries), 'errors' (int: error count), 'warnings' (int: warning count). If None or empty, displays 'No statistics available'.

Return Value

This function returns None. It produces side effects by printing formatted output directly to stdout using the print() function.

Required Imports

from datetime import datetime

Usage Example

from datetime import datetime

# Example statistics dictionary
stats = {
    'sync_cycles': 5,
    'new_uploads': 12,
    'updated_files': 3,
    'skipped_files': 8,
    'last_sync': datetime(2024, 1, 15, 14, 30, 0),
    'avg_cycle_time': 45.7,
    'total_lines': 150,
    'errors': 0,
    'warnings': 2
}

# Print the status report
print_status(stats)

# Example with no statistics
print_status(None)

# Example with empty statistics
print_status({})

Best Practices

  • Ensure the stats dictionary contains all expected keys before calling to avoid KeyError exceptions
  • The function expects 'last_sync' to be a datetime object or None; passing other types may cause errors
  • Status indicators use emoji characters that require UTF-8 console support; consider fallback text for environments without emoji support
  • The 'NO RECENT SYNC' warning triggers if more than 1 hour (3600 seconds) has passed since last sync; adjust this threshold based on your sync frequency requirements
  • This function is designed for human-readable console output, not for logging or machine-parseable formats
  • Consider wrapping calls in try-except blocks if stats dictionary structure is uncertain

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function analyze_logs 66.4% similar

    Parses and analyzes log files to extract synchronization statistics, error counts, and performance metrics for a specified time period.

    From: /tf/active/vicechatdev/SPFCsync/monitor.py
  • function main_v16 64.5% similar

    Executes a diagnostic analysis for file synchronization issues, analyzes missing files, and saves the results to a JSON file.

    From: /tf/active/vicechatdev/SPFCsync/deep_diagnostics.py
  • class SyncDiagnostics 64.2% similar

    A diagnostic class that analyzes and reports on synchronization issues between SharePoint and FileCloud, identifying missing files and root causes of sync failures.

    From: /tf/active/vicechatdev/SPFCsync/deep_diagnostics.py
  • function main_v32 63.8% similar

    Command-line interface entry point for monitoring SharePoint to FileCloud synchronization logs, providing status analysis, log tailing, and real-time watching capabilities.

    From: /tf/active/vicechatdev/SPFCsync/monitor.py
  • function main_v17 63.5% similar

    Orchestrates and executes a comprehensive test suite for SharePoint to FileCloud synchronization service, running configuration, connection, and operation tests.

    From: /tf/active/vicechatdev/SPFCsync/test_connections.py
← Back to Browse