Your IP : 216.73.217.13


Current Path : /home/deltalab/PMS/recommendations/user_profiling/_library/
Upload File :
Current File : //home/deltalab/PMS/recommendations/user_profiling/_library/visual_utils.py

from collections import defaultdict

def visualize_user_profile(user_id, user_profile):
    print("\n" + "-" * 140 +  "\n" + "-" * 64, f'USER ID: {user_id}', "-" * 63 + "\n" + "-" * 140, "\n")
    chart_divider = ' | '
    
    for attribute_name, attribute_values in user_profile.items(): 
               
        # CASE A: list/set
        if isinstance(attribute_values, set) or isinstance(attribute_values, list):
            print(attribute_name.upper(), f"({len(attribute_values)}):", chart_divider.join(sorted(map(str, attribute_values))))
        
        # CASE B: dictionary of lists
        elif isinstance(attribute_values, defaultdict):
            print(attribute_name.upper(), f"({len(attribute_values)}):\n\t",
                  '\n\t '.join([f't{key} ({len(values)} items) --> ' +  chart_divider.join(sorted(values)) for key, values in attribute_values.items()]))
        
        # GENERAL CASE
        else: 
            print(str(attribute_name).upper() + ":", attribute_values)
        print("-" * 80)
    return user_profile

def visualize_message(message, width = 90):
    padding = (width - len(message) - 2) // 2
    print('-' * width)
    print('-' * padding,  message, '-' *padding)
    print('-' * width, "\n")
    
def visualize_recommendations(recommendations):
    print('-' * 60)
    for recom in recommendations:
        print(f"--> [{recom['item_type']}] {recom['product_name'].upper()} by '{recom['item_vendor']}'")
    print('-' * 60)

# def visualize_spark_settings(sc,width = 90):
#     padding = (width - len("SPARK SETTINGS") - 2) // 2
#     print('-' * padding,  "SPARK SETTINGS", '-' *padding)
#     print(f"SPARK CONTEXT VERSION : {sc.version}")
#     print(f"PYTHON VERSION: {sc.pythonVer}")
#     print(f"MASTER URL: {sc.master}")
#     print(f"SPARK INSTALLATION PATH ON WORKER NODES: {sc.sparkHome}")
#     print(f"NAME OF SPARK USER RUNNING SPARKCONTEXT: {sc.sparkUser()}")
#     print(f"APPLICATION NAME: {sc.appName}")
#     print(f"APPLICATION ID: {sc.applicationId}")
#     print(f"DEFAULT LEVEL OF PARALLELISM: {sc.defaultParallelism}")
#     print(f"DEFAULT MINIMUM PARTITIONS: {sc.defaultMinPartitions}")
#     print('-' * width, "\n")