metrics_moving_avg: Gives a PMax, Wbal and mFTP estimations from a given period...

Description Usage Arguments Value Author(s) Examples

View source: R/metrics_moving_avg.R

Description

From a mean maximum power file, containing the best power marks during a certain period for every training sessions, this function is able to calculate the Pmax, WBal and mFTP estimations for a season.

Usage

1
metrics_moving_avg(updt, mmp_alldata, dates_list, period = 90, wpk = F, weight, pmax_all = NULL, wbal_all = NULL, mftp_all = NULL, ...)

Arguments

updt

A boolean indicating wheter it's to update with newer training sessions (updt=T), or to create from scratch (updt=F).

mmp_alldata

The mean maximum power from each training session. It's the result of mmp_alldata function inside this package.

period

The period of days to calculate the moving average. The default is 90 days.

wpk

A boolean to indicate wheter the power information are in watts (wpk=F) or watts per kilo (wpk=T).

weight

The weight of the athlete in kilos.

dates_list

A vector containing all dates and times from every training session. It's good to use with get_power_data() within Golden Cheetah.

pmax_all

If updt=T, then this is the older vector of PMax estimations.

wbal_all

If updt=T, then this is the older vector of WBal estimations.

mftp_all

If updt=T, then this is the older vector of mFTP estimations.

Value

pmax

The maximum power estimation for each 90-day period, in watts.

wbal

The anaerobic capacity estimations for each 90-day period, in Joules.

mftp

The modeled functional threshold power estimation for each 90-day period, in watts.

Author(s)

Natan Freitas Leite.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## The function is currently defined as
function (updt, mmp_alldata, dates_list, period = 90, wpk = F,
    weight, pmax_all = NULL, wbal_all = NULL, mftp_all = NULL)
{
    require(zoo)
    require(changepoint)
    require(lubridate)
    options(warn = -1)
    len = c()
    l_ma = length(mmp_alldata)
    for (i in 1:l_ma) {
        len[i] = length(mmp_alldata[[i]])
    }
    mmp_all_df = data.frame(1:max(len))
    for (i in 1:l_ma) {
        if (length(mmp_alldata[[i]] < max(len))) {
            mmp_all_df[, i] = c(mmp_alldata[[i]], rep(0, max(len) -
                length(mmp_alldata[[i]])))
        }
        else {
            mmp_all_df[, i] = mmp_alldata[[i]]
        }
    }
    if (!wpk) {
        mmp_all_df = mmp_all_df/weight
    }
    dates_list_2 = lubridate::date(dates_list)
    dates = dates_list_2[1]:tail(dates_list_2, 1)
    dates = as.Date(dates, origin = "1970-01-01")
    if (!updt) {
        pmax_all = c()
        mftp_all = c()
        wbal_all = c()
        condition = as.numeric(tail(dates_list_2, 1) - dates_list_2[1]) -
            period + 1
        for (i in 1:condition) {
            if (length(which(dates_list_2 %in% (dates[i] - period):dates[i])) ==
                1) {
                max_mmp = mmp_all_df[, which(dates_list_2 %in%
                  (dates[i] - period):dates[i])]
                metrics = metrics_model(max_mmp, T, weight)
                pmax_all[i] = metrics[1]
                mftp_all[i] = metrics[2]
                wbal_all[i] = metrics[3]
                print(i)
            }
            else {
                max_mmp = apply(mmp_all_df[, which(dates_list_2 %in%
                  dates[i]:(dates[i] + period))], 1, max)
                metrics = metrics_model(max_mmp, T, weight)
                pmax_all[i] = metrics[1]
                mftp_all[i] = metrics[2]
                wbal_all[i] = metrics[3]
                print(i)
            }
        }
    }
    else {
        condition1 = length(pmax_all) + 1
        condition2 = as.numeric(tail(dates_list_2, 1) - dates_list_2[1]) -
            period + 1
        for (i in condition1:condition2) {
            max_mmp = apply(mmp_all_df[, which(dates_list_2 %in%
                dates[i]:(dates[i] + period))], 1, max)
            metrics = metrics_model(max_mmp, T, weight)
            pmax_all[i] = metrics[1]
            mftp_all[i] = metrics[2]
            wbal_all[i] = metrics[3]
            print(i)
        }
    }
    options(warn = 0)
    return(list(pmax_all, mftp_all, wbal_all))
  }

  data(mmp_alldata_dataset)
  data(dates_list_updt)

  metrics=metrics_moving_avg(F,mmp_alldata_dataset,dates_list_updt,weight=65)

Bolshom/optimumtt documentation built on May 24, 2019, 8:56 a.m.