Newer
Older
Master_thesis / helperfunctions.py
@saslie saslie on 26 Mar 2019 589 bytes New, cleaner
# some helperfunctions

#Dislpay time (e.g. while generating points)

display_intervals = (
    ('w', 604800),  # 60 * 60 * 24 * 7
    ('d', 86400),    # 60 * 60 * 24
    ('h', 3600),    # 60 * 60
    ('min', 60),
    ('s', 1),
    )

def display_time(seconds, granularity=2):
    result = []

    for name, count in display_intervals:
        value = seconds // count
        if value:
            seconds -= value * count
            if value == 1:
                name = name.rstrip('s')
            result.append("{} {}".format(value, name))
    return ', '.join(result[:granularity])