# Path: philharmonic/logger.py
# LOG_PATH, LOG_FILENAME = '.', 'philharmonic.log'
# LOG_LEVEL = logging.DEBUG
# def log(message):


from philharmonic.logger import info, debug

Functions for printing and visualising model data

'''


get_locations = lambda cloud : list(set([s.loc for s in cloud.servers]))
servers_at_location = lambda cloud, loc : [s for s in cloud.servers if s.loc == loc]

def create_usage_str(usage, bins=8):
    sum_ = 0
    filled = 0
    while usage > sum_:
        sum_ += 1. / bins
        filled += 1
    if filled > bins:
        filled = bins
    return filled * '#' + (bins - filled) * '_'

def server_usage_repr(server_free, server_cap):
    server_usage_str = ''
    for res, res_free in server_free.iteritems():
        res_usage = 1 - res_free / float(server_cap[res])
        res_usage_str = create_usage_str(res_usage)
        server_usage_str += '{}:|{}| '.format(res, res_usage_str)
    return server_usage_str

def show_unallocated_vms(cloud, state):
    unallocated_vms = state.unallocated_vms()
    if len(unallocated_vms) > 0:

# Path: philharmonic/logger.py
# LOG_PATH, LOG_FILENAME = '.', 'philharmonic.log'
# LOG_LEVEL = logging.DEBUG
# def log(message):


# Path: philharmonic/cloud/visualiser.py
from philharmonic.logger import info, debug


Functions for printing and visualising model data

'''


get_locations = lambda cloud : list(set([s.loc for s in cloud.servers]))
servers_at_location = lambda cloud, loc : [s for s in cloud.servers if s.loc == loc]

def create_usage_str(usage, bins=8):
    sum_ = 0
    filled = 0
    while usage > sum_:
        sum_ += 1. / bins
        filled += 1
    if filled > bins:
        filled = bins
    return filled * '#' + (bins - filled) * '_'

def server_usage_repr(server_free, server_cap):
    server_usage_str = ''
    for res, res_free in server_free.iteritems():
        res_usage = 1 - res_free / float(server_cap[res])
        res_usage_str = create_usage_str(res_usage)
        server_usage_str += '{}:|{}| '.format(res, res_usage_str)
    return server_usage_str

def show_unallocated_vms(cloud, state):
    unallocated_vms = state.unallocated_vms()
    if len(unallocated_vms) > 0:

        info('Unallocated VMs\n---------------')