Exemple #1
0
def delete_cache(key):
    cache = shelve.open(_get_fullpath('cache'))
    try:
        del cache[key]
    except KeyError:
        pass
    cache.close()
Exemple #2
0
def compute_fitness_fatigue_form(
        date=datetime.datetime.today().date(), planed=None):
    # Define the window.
    end = datetime.datetime(date.year, date.month,
                            date.day) + datetime.timedelta(days=1)
    start = end - datetime.timedelta(days=42)
    act_in_window = api.get_activities(per_page=100,
                                       before=end.timestamp(),
                                       after=start.timestamp())
    ids_in_window = [a.get('id') for a in act_in_window]

    # Compute and store daily TSS values.
    cache = shelve.open(_get_fullpath('cache'))
    tss_list = []
    for act_id in ids_in_window:
        id_str = str(act_id)
        if id_str in cache:
            tss_entry = cache[id_str]
            tss_list.append(tss_entry)
        else:
            tss_entry = get_tss_entry(act_id)
            cache[id_str] = tss_entry
            tss_list.append(tss_entry)
    cache.close()
    daily_tss = compute_daily_tss(tss_list)

    # Add planed TSS to daily values.
    if planed:
        daily_tss.update(planed)

    # Compute values.
    delta = end - start
    tss_table = pd.DataFrame(columns=('date', 'tss'))
    for i in range(delta.days + 1):
        day = start + datetime.timedelta(days=i)
        st_day = day.strftime('%Y-%m-%d')
        if st_day in daily_tss.keys():
            tss_entry = daily_tss[st_day]
        else:
            tss_entry = 0
        tss_table = tss_table.append({
            'date': st_day,
            'tss': tss_entry
        },
                                     ignore_index=True)

    CTL = compute_CTL(tss_table[(len(tss_table) - 42):(len(tss_table) - 1)])
    ATL = compute_ATL(tss_table[(len(tss_table) - 7):(len(tss_table) - 1)])
    TSB = CTL - ATL

    return CTL, ATL, TSB
Exemple #3
0
def clean_cache():
    cache = shelve.open(_get_fullpath('cache'))
    keys = list(cache.keys())
    for key in keys:
        del cache[key]
    cache.close()
Exemple #4
0
def list_cache():
    cache = shelve.open(_get_fullpath('cache'))
    keys = list(cache.keys())
    cache.close()
    return keys
Exemple #5
0
def read_cache(key):
    cache = shelve.open(_get_fullpath('cache'))
    if key in cache:
        value = cache[key]
    cache.close()
    return value
Exemple #6
0
def write_cache(key, value):
    cache = shelve.open(_get_fullpath('cache'))
    cache[key] = value
    cache.close()