Newer
Older
Master_thesis / helperfunctions.py
# some helperfunctions

import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt

#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])

def prepare_plot(title):
    plt.title(title)
    plt.grid()
    plt.legend(loc = 'best')