Newer
Older
Master_thesis / data / CLs / finished / f1d1 / bo5-+ / 2254891 / helperfunctions.py
@Sascha Liechti Sascha Liechti on 23 Sep 2019 773 bytes ...
# 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')
    plt.xlabel("q")