Newer
Older
Master_thesis / scratch / 3583789 / helperfunctions.py
@saslie saslie on 2 Apr 2019 589 bytes ...
# 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])