Skip to contents

In this vignette, I’ll walk through how to get started with a basic dynasty value analysis on Fleaflicker.

We’ll start by loading the packages:

In Fleaflicker, you can find the league ID by looking in the URL - it’s the number immediately after /league/ in this example URL: https://www.fleaflicker.com/nfl/leagues/312861.

Let’s set up a connection to this league:

aaa <- fleaflicker_connect(season = 2020, league_id = 312861)

aaa
#> <Fleaflicker connection 2020_312861>
#> List of 4
#>  $ platform  : chr "Fleaflicker"
#>  $ season    : chr "2020"
#>  $ user_email: NULL
#>  $ league_id : chr "312861"
#>  - attr(*, "class")= chr "flea_conn"

I’ve done this with the fleaflicker_connect() function, although you can also do this from the ff_connect() call - they are equivalent. Most if not all of the remaining functions after this point are prefixed with “ff_”.

Cool! Let’s have a quick look at what this league is like.


aaa_summary <- ff_league(aaa)
#> Using request.R from "ffscrapr"

str(aaa_summary)
#> tibble [1 × 15] (S3: tbl_df/tbl/data.frame)
#>  $ league_id      : chr "312861"
#>  $ league_name    : chr "Avid Auctioneers Alliance"
#>  $ season         : int 2020
#>  $ league_type    : chr "dynasty"
#>  $ franchise_count: num 12
#>  $ qb_type        : chr "2QB/SF"
#>  $ idp            : logi FALSE
#>  $ scoring_flags  : chr "0.5_ppr, PP1D"
#>  $ best_ball      : logi FALSE
#>  $ salary_cap     : logi FALSE
#>  $ player_copies  : num 1
#>  $ qb_count       : chr "1-2"
#>  $ roster_size    : int 28
#>  $ league_depth   : num 336
#>  $ keeper_count   : int 31

Okay, so it’s the Avid Auctioneers Alliance, it’s a 2QB league with 12 teams, half ppr scoring, and rosters about 340 players.

Let’s grab the rosters now.

aaa_rosters <- ff_rosters(aaa)

head(aaa_rosters)
#> # A tibble: 6 × 7
#>   franchise_id franchise_name player_id player_name    pos   team  sportradar_id
#>          <int> <chr>              <int> <chr>          <chr> <chr> <chr>        
#> 1      1578553 Running Bear       12159 Dak Prescott   QB    DAL   86197778-8d4…
#> 2      1578553 Running Bear       16259 Trey Lance     QB    DAL   676a508c-c65…
#> 3      1578553 Running Bear       14736 Devin Singlet… RB    HOU   a961b0d4-5d7…
#> 4      1578553 Running Bear       13772 Rashaad Penny  RB    PHI   2b119688-83b…
#> 5      1578553 Running Bear       12017 Laquon Treadw… WR    BAL   2e0badcd-b78…
#> 6      1578553 Running Bear       15531 Brandon Aiyuk  WR    SF    c90471cc-fa6…

Values

Cool! Let’s pull in some additional context by adding DynastyProcess player values.

player_values <- dp_values("values-players.csv")

# The values are stored by fantasypros ID since that's where the data comes from. 
# To join it to our rosters, we'll need playerID mappings.

player_ids <- dp_playerids() %>% 
  select(sportradar_id,fantasypros_id) %>% 
  filter(!is.na(sportradar_id),!is.na(fantasypros_id))

# We'll be joining it onto rosters, so we can trim down the values dataframe
# to just IDs, age, and values

player_values <- player_values %>% 
  left_join(player_ids, by = c("fp_id" = "fantasypros_id")) %>% 
  select(sportradar_id,age,ecr_2qb,ecr_pos,value_2qb)

# ff_rosters() will return the sportradar_id, which we can then match to our player values!

aaa_values <- aaa_rosters %>% 
  left_join(player_values, by = c("sportradar_id"="sportradar_id")) %>% 
  arrange(franchise_id,desc(value_2qb))

head(aaa_values)
#> # A tibble: 6 × 11
#>   franchise_id franchise_name player_id player_name    pos   team  sportradar_id
#>          <int> <chr>              <int> <chr>          <chr> <chr> <chr>        
#> 1      1578553 Running Bear       16250 Ja'Marr Chase  WR    CIN   fa99e984-d63…
#> 2      1578553 Running Bear       12159 Dak Prescott   QB    DAL   86197778-8d4…
#> 3      1578553 Running Bear       15531 Brandon Aiyuk  WR    SF    c90471cc-fa6…
#> 4      1578553 Running Bear       12926 Chris Godwin   WR    TB    baa61bb5-f8d…
#> 5      1578553 Running Bear       16552 Khalil Herbert RB    CHI   02af99e0-3c8…
#> 6      1578553 Running Bear       14736 Devin Singlet… RB    HOU   a961b0d4-5d7…
#> # ℹ 4 more variables: age <dbl>, ecr_2qb <dbl>, ecr_pos <dbl>, value_2qb <int>

Let’s do some team summaries now!

value_summary <- aaa_values %>% 
  group_by(franchise_id,franchise_name,pos) %>% 
  summarise(total_value = sum(value_2qb,na.rm = TRUE)) %>%
  ungroup() %>% 
  group_by(franchise_id,franchise_name) %>% 
  mutate(team_value = sum(total_value)) %>% 
  ungroup() %>% 
  pivot_wider(names_from = pos, values_from = total_value) %>% 
  arrange(desc(team_value)) %>% 
  select(franchise_id,franchise_name,team_value,QB,RB,WR,TE)

value_summary
#> # A tibble: 12 × 7
#>    franchise_id franchise_name        team_value    QB    RB    WR    TE
#>           <int> <chr>                      <int> <int> <int> <int> <int>
#>  1      1581722 syd12nyjets's Team         44863 19449  3083 22260    71
#>  2      1581719 Jmuthers's Team            37355  9881 10151 11267  6056
#>  3      1581803 ZachFarni's Team           30026  7048  5096 17718   164
#>  4      1581721 Mjenkyns2004's Team        28058 12496  5628  9508   426
#>  5      1581988 The DK Crew                26267 13954  7683  4496   134
#>  6      1581720 brosene's Team             23041 11281  5516  1599  4645
#>  7      1578553 Running Bear               21771  5998   698 15002    73
#>  8      1582416 Ray Jay Team               16853   903  1130 10890  3930
#>  9      1581718 Officially Rebuilding      13491  2362   858  8757  1514
#> 10      1581726 SCJaguars's Team           13039 11225   789  1017     8
#> 11      1582423 The Verblanders            12439  6890  2178  3350    21
#> 12      1581753 fede_mndz's Team           11846   164  4596  6356   730

So with that, we’ve got a team summary of values! I like applying some context, so let’s turn these into percentages - this helps normalise it to your league environment.

value_summary_pct <- value_summary %>% 
  mutate_at(c("team_value","QB","RB","WR","TE"),~.x/sum(.x)) %>% 
  mutate_at(c("team_value","QB","RB","WR","TE"),round, 3)

value_summary_pct
#> # A tibble: 12 × 7
#>    franchise_id franchise_name        team_value    QB    RB    WR    TE
#>           <int> <chr>                      <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1      1581722 syd12nyjets's Team         0.161 0.191 0.065 0.198 0.004
#>  2      1581719 Jmuthers's Team            0.134 0.097 0.214 0.1   0.341
#>  3      1581803 ZachFarni's Team           0.108 0.069 0.107 0.158 0.009
#>  4      1581721 Mjenkyns2004's Team        0.101 0.123 0.119 0.085 0.024
#>  5      1581988 The DK Crew                0.094 0.137 0.162 0.04  0.008
#>  6      1581720 brosene's Team             0.083 0.111 0.116 0.014 0.261
#>  7      1578553 Running Bear               0.078 0.059 0.015 0.134 0.004
#>  8      1582416 Ray Jay Team               0.06  0.009 0.024 0.097 0.221
#>  9      1581718 Officially Rebuilding      0.048 0.023 0.018 0.078 0.085
#> 10      1581726 SCJaguars's Team           0.047 0.11  0.017 0.009 0    
#> 11      1582423 The Verblanders            0.045 0.068 0.046 0.03  0.001
#> 12      1581753 fede_mndz's Team           0.042 0.002 0.097 0.057 0.041

Armed with a value summary like this, we can see team strengths and weaknesses pretty quickly, and figure out who might be interested in your positional surpluses and who might have a surplus at a position you want to look at.

Age

Another question you might ask: what is the average age of any given team?

I like looking at average age by position, but weighted by dynasty value. This helps give a better idea of age for each team - including who might be looking to offload an older veteran!

age_summary <- aaa_values %>% 
  filter(pos %in% c("QB","RB","WR","TE")) %>% 
  group_by(franchise_id,pos) %>% 
  mutate(position_value = sum(value_2qb,na.rm=TRUE)) %>% 
  ungroup() %>% 
  mutate(weighted_age = age*value_2qb/position_value,
         weighted_age = round(weighted_age, 1)) %>% 
  group_by(franchise_id,franchise_name,pos) %>% 
  summarise(count = n(),
            age = sum(weighted_age,na.rm = TRUE)) %>% 
  pivot_wider(names_from = pos,
              values_from = c(age,count))

age_summary
#> # A tibble: 12 × 10
#> # Groups:   franchise_id, franchise_name [12]
#>    franchise_id franchise_name     age_QB age_RB age_TE age_WR count_QB count_RB
#>           <int> <chr>               <dbl>  <dbl>  <dbl>  <dbl>    <int>    <int>
#>  1      1578553 Running Bear         30.2   25.9   27.9   24.7        5        6
#>  2      1581718 Officially Rebuil…   34.1   30.5   23.3   26.3        4       13
#>  3      1581719 Jmuthers's Team      27.5   27.3   27.1   25.7        5        7
#>  4      1581720 brosene's Team       27.3   26.7   27.7   27.7        6       17
#>  5      1581721 Mjenkyns2004's Te…   28.1   24.9   27.4   29.3        6        8
#>  6      1581722 syd12nyjets's Team   25.9   27.5   31     24.7        5        8
#>  7      1581726 SCJaguars's Team     24.5   25.2   29.5   25          5        6
#>  8      1581753 fede_mndz's Team     25.2   26.5   24.9   28.3        5       12
#>  9      1581803 ZachFarni's Team     25.9   24.8   28.4   25.8        4        8
#> 10      1581988 The DK Crew          26.6   25     27.3   27.1        4        8
#> 11      1582416 Ray Jay Team         33.3   29.9   32.8   28.5        5        5
#> 12      1582423 The Verblanders      26.8   28.6   25.6   29.9        3        8
#> # ℹ 2 more variables: count_TE <int>, count_WR <int>

Next steps

In this vignette, I’ve used only a few functions: ff_connect, ff_league, ff_rosters, and dp_values. Now that you’ve gotten this far, why not check out some of the other possibilities?