Skip to contents

Calculates optimal lineups for all franchises in the dataframe based on a table of lineup constraints.

Usage

ffs_optimise_lineups(
  roster_scores,
  lineup_constraints,
  lineup_efficiency_mean = 0.775,
  lineup_efficiency_sd = 0.05,
  best_ball = FALSE,
  pos_filter = c("QB", "RB", "WR", "TE")
)

ffs_optimize_lineups(
  roster_scores,
  lineup_constraints,
  lineup_efficiency_mean = 0.775,
  lineup_efficiency_sd = 0.05,
  best_ball = FALSE,
  pos_filter = c("QB", "RB", "WR", "TE")
)

Arguments

roster_scores

a dataframe as generated by ffs_score_rosters() - should contain columns like: projected_score, pos, and player_id

lineup_constraints

a dataframe as generated by ffscrapr::ff_starter_positions() - should contain columns pos, min, max, and offense_starters

lineup_efficiency_mean

the average lineup efficiency to use, defaults to 0.775

lineup_efficiency_sd

the standard deviation of lineup efficiency, defaults to 0.05

best_ball

a logical: FALSE will apply a lineup efficiency factor and TRUE uses optimal scores as actual scores, default = FALSE

pos_filter

a character vector specifying which positions are eligible - defaults to c("QB","RB","WR","TE)

Value

a dataframe of what each team scored for each week

Details

Lineup efficiency is the percentage of optimal/best-ball score that is used as the actual score - by default, the lineup efficiency for a team in non-best-ball settings is normally distributed around a mean of 77.5% and a standard deviation of 5%.

See also

vignette("custom") for example usage

Examples

# \donttest{
# cached examples
roster_scores <- .ffs_cache("roster_scores.rds")
lineup_constraints <- .ffs_cache("mfl_lineup_constraints.rds")

ffs_optimise_lineups(roster_scores, lineup_constraints)
#> Key: <league_id, franchise_id, franchise_name, season, week>
#>     league_id franchise_id                 franchise_name season  week
#>        <char>       <char>                         <char>  <int> <int>
#>  1:     22627         0001        Mexico City Space Force      1     1
#>  2:     22627         0001        Mexico City Space Force      1     2
#>  3:     22627         0001        Mexico City Space Force      1     3
#>  4:     22627         0001        Mexico City Space Force      2     1
#>  5:     22627         0001        Mexico City Space Force      2     2
#>  6:     22627         0001        Mexico City Space Force      2     3
#>  7:     22627         0002                    Dirty Dgens      1     1
#>  8:     22627         0002                    Dirty Dgens      1     2
#>  9:     22627         0002                    Dirty Dgens      1     3
#> 10:     22627         0002                    Dirty Dgens      2     1
#> 11:     22627         0002                    Dirty Dgens      2     2
#> 12:     22627         0002                    Dirty Dgens      2     3
#> 13:     22627         0003             Alberta Armadillos      1     1
#> 14:     22627         0003             Alberta Armadillos      1     2
#> 15:     22627         0003             Alberta Armadillos      1     3
#> 16:     22627         0003             Alberta Armadillos      2     1
#> 17:     22627         0003             Alberta Armadillos      2     2
#> 18:     22627         0003             Alberta Armadillos      2     3
#> 19:     22627         0004               Electric Woodies      1     1
#> 20:     22627         0004               Electric Woodies      1     2
#> 21:     22627         0004               Electric Woodies      1     3
#> 22:     22627         0004               Electric Woodies      2     1
#> 23:     22627         0004               Electric Woodies      2     2
#> 24:     22627         0004               Electric Woodies      2     3
#> 25:     22627         0005               Motor City Mutts      1     1
#> 26:     22627         0005               Motor City Mutts      1     2
#> 27:     22627         0005               Motor City Mutts      1     3
#> 28:     22627         0005               Motor City Mutts      2     1
#> 29:     22627         0005               Motor City Mutts      2     2
#> 30:     22627         0005               Motor City Mutts      2     3
#> 31:     22627         0006            Hoth City Tauntauns      1     1
#> 32:     22627         0006            Hoth City Tauntauns      1     2
#> 33:     22627         0006            Hoth City Tauntauns      1     3
#> 34:     22627         0006            Hoth City Tauntauns      2     1
#> 35:     22627         0006            Hoth City Tauntauns      2     2
#> 36:     22627         0006            Hoth City Tauntauns      2     3
#> 37:     22627         0007                     Paw Patrol      1     1
#> 38:     22627         0007                     Paw Patrol      1     2
#> 39:     22627         0007                     Paw Patrol      1     3
#> 40:     22627         0007                     Paw Patrol      2     1
#> 41:     22627         0007                     Paw Patrol      2     2
#> 42:     22627         0007                     Paw Patrol      2     3
#> 43:     22627         0008             Domination Station      1     1
#> 44:     22627         0008             Domination Station      1     2
#> 45:     22627         0008             Domination Station      1     3
#> 46:     22627         0008             Domination Station      2     1
#> 47:     22627         0008             Domination Station      2     2
#> 48:     22627         0008             Domination Station      2     3
#> 49:     22627         0009 Kill Devil Hills Carpetbaggers      1     1
#> 50:     22627         0009 Kill Devil Hills Carpetbaggers      1     2
#> 51:     22627         0009 Kill Devil Hills Carpetbaggers      1     3
#> 52:     22627         0009 Kill Devil Hills Carpetbaggers      2     1
#> 53:     22627         0009 Kill Devil Hills Carpetbaggers      2     2
#> 54:     22627         0009 Kill Devil Hills Carpetbaggers      2     3
#> 55:     22627         0010                     [Redacted]      1     1
#> 56:     22627         0010                     [Redacted]      1     2
#> 57:     22627         0010                     [Redacted]      1     3
#> 58:     22627         0010                     [Redacted]      2     1
#> 59:     22627         0010                     [Redacted]      2     2
#> 60:     22627         0010                     [Redacted]      2     3
#> 61:     22627         0011                           TB12      1     1
#> 62:     22627         0011                           TB12      1     2
#> 63:     22627         0011                           TB12      1     3
#> 64:     22627         0011                           TB12      2     1
#> 65:     22627         0011                           TB12      2     2
#> 66:     22627         0011                           TB12      2     3
#> 67:     22627         0012           Indigo Plateau Elite      1     1
#> 68:     22627         0012           Indigo Plateau Elite      1     2
#> 69:     22627         0012           Indigo Plateau Elite      1     3
#> 70:     22627         0012           Indigo Plateau Elite      2     1
#> 71:     22627         0012           Indigo Plateau Elite      2     2
#> 72:     22627         0012           Indigo Plateau Elite      2     3
#>     league_id franchise_id                 franchise_name season  week
#>     optimal_score                       optimal_player_id
#>             <num>                                  <list>
#>  1:        189.38 14777,15241,12447,14079,13722,14137,...
#>  2:        180.82 13592,14777,14079,15260,13672,14138,...
#>  3:        198.14 13592,14777,12447,14797,13722,12175,...
#>  4:        185.69 13592,14777,14081,14073,14079,14797,...
#>  5:        220.84 13592,15241,14073,15260,14143,11674,...
#>  6:        260.17 13592,14777,12447,14073,14797,14805,...
#>  7:        127.19 12610,15238,11747,14803,12212,12263,...
#>  8:         69.30 15238,11747,13138,14803,12212,15330,...
#>  9:         97.60 15238,11390,11747,14815,15268,12212,...
#> 10:        106.80 12141,15238,13138,14803,15268,12263,...
#> 11:        134.42 12610,15238,11747,13138,12212,12263,...
#> 12:        128.42 12610,14780,11747,14803,14815,12263,...
#> 13:        187.08 10700,11644,13610,14085,14802,14806,...
#> 14:        135.32 11644,13424,13610,14075,14087,14802,...
#> 15:        128.70 11644,13113,13610,14087,14085,11695,...
#> 16:        124.05 10700,11644,12386,13610,14087,14802,...
#> 17:        165.20 10700,11644,13610,14075,14085,14802,...
#> 18:        154.36 10700,13424,12386,13610,14802,15256,...
#> 19:        158.05 10703,14778,13319,13364,13880,10973,...
#> 20:        163.90 10703,13589,13139,13378,14813,13236,...
#> 21:        168.57 10703,14778,13139,13319,13364,13880,...
#> 22:        150.16 10703,13115,13319,13378,14801,13236,...
#> 23:        159.49 13589,14778,13139,13146,13319,14813,...
#> 24:        149.82 13589,14778,13319,13364,13236,13880,...
#> 25:        131.59   13593,9431,12171,13234,12677,9474,...
#> 26:        174.86  13593,9431,13404,14080,12677,14867,...
#> 27:        144.93  13593,9431,13135,13620,13919,14867,...
#> 28:        151.70  13593,13135,13404,15258,12677,9474,...
#> 29:        172.44  13593,9431,13234,14095,14072,13919,...
#> 30:        169.84  13593,9431,13135,13404,15258,12677,...
#> 31:        121.98  13590,15237,14804,14808,14870,9925,...
#> 32:        146.23 13590,15237,11886,15414,11247,12656,...
#> 33:        198.28 11640,15237,11886,13726,11247,14875,...
#> 34:        104.60  13590,15237,13726,14804,9925,12176,...
#> 35:        168.38 13590,14057,13789,14808,15414,14870,...
#> 36:         88.82 11640,13590,13789,14808,15337,12176,...
#> 37:        175.41 12611,12620,13128,15257,14807,13679,...
#> 38:        106.17 12620,11761,15255,13679,13153,13164,...
#> 39:        150.44 12611,12620,12152,13128,15255,13679,...
#> 40:        158.65 10413,12620,11761,13128,15257,10276,...
#> 41:        175.36 12620,15252,12152,13128,14811,15255,...
#> 42:        163.74 12611,12620,12151,13128,15257,11516,...
#> 43:        191.49  15240,9099,13290,13604,13607,13299,...
#> 44:        173.30  15240,9099,12164,13290,13604,14798,...
#> 45:        188.13 11760,12164,13604,13607,14798,13299,...
#> 46:        158.34  14067,9099,12164,12629,13604,13188,...
#> 47:        153.40  15246,9099,12164,13604,14798,13188,...
#> 48:        199.54  15240,9099,13604,13608,14798,15272,...
#> 49:        219.67  10697,7836,11657,13132,13427,12187,...
#> 50:        163.46  14059,7836,11657,12625,13132,13133,...
#> 51:        189.04  10697,7836,11657,13132,12678,13427,...
#> 52:        120.53 10697,14059,12625,13108,13753,11222,...
#> 53:        176.83  13846,7836,11657,12625,13108,13132,...
#> 54:        181.67  14059,7836,12625,13108,13132,12678,...
#> 55:        165.27 12140,13116,13622,14827,12676,11671,...
#> 56:        104.77 12140,13116,13136,14223,13680,11671,...
#> 57:        123.63 12140,13116,14223,15254,12676,13680,...
#> 58:        166.64 13116,14223,15254,12676,11671,13163,...
#> 59:        105.14 12140,13116,13622,15254,12676,11671,...
#> 60:        173.88 12623,13116,13136,14223,12676,11671,...
#> 61:        149.53  14782,5848,13131,13850,15329,10729,...
#> 62:        164.16  15239,5848,13131,13614,13850,14828,...
#> 63:        220.86 14783,12630,13131,13850,15262,13192,...
#> 64:        236.82  15239,5848,13131,13614,14017,13192,...
#> 65:        174.02  14783,5848,13131,13850,13192,13674,...
#> 66:        152.97 14783,15239,12630,13129,15262,13674,...
#> 67:        205.11  14056,7401,11193,12626,13130,14071,...
#> 68:        173.42  14056,8062,11193,13130,14071,14852,...
#> 69:        190.83 14056,14779,12626,13130,13606,14071,...
#> 70:        195.58  14056,7401,12626,13130,14852,11244,...
#> 71:        172.41 14056,14779,11193,12626,14071,11647,...
#> 72:        162.65   7401,8062,12626,13130,13606,11244,...
#>     optimal_score                       optimal_player_id
#>                        optimal_player_score lineup_efficiency actual_score
#>                                      <list>             <num>        <num>
#>  1: 13.88,14.30,23.70, 6.40, 8.55, 6.05,...         0.7606412    144.05023
#>  2: 17.76,28.76,10.10, 8.30,12.85,13.95,...         0.8147328    147.31998
#>  3: 12.14,15.00,15.90,27.80,16.70,22.10,...         0.6876548    136.25193
#>  4:  9.58,20.46,11.30,26.80,24.70, 9.50,...         0.7130349    132.40346
#>  5: 29.60,24.02,21.10,15.10,22.50,23.60,...         0.7952551    175.62413
#>  6: 21.42,19.80,14.70,24.10,27.30,17.00,...         0.7360405    191.49565
#>  7: 10.94,15.15,13.90,22.50, 6.40, 9.40,...         0.7624619     96.97753
#>  8:  9.35, 4.50, 8.40,14.90, 2.45, 3.30,...         0.8882800     61.55781
#>  9: 21.70, 2.80,16.70, 2.70, 7.00, 1.85,...         0.8050372     78.57163
#> 10:  6.84,16.36, 3.20,13.80,12.70,12.75,...         0.7012182     74.89010
#> 11: 21.42,13.00,14.90,15.90, 5.55, 6.05,...         0.7589778    102.02180
#> 12: 13.32,17.50, 5.00,17.10, 8.20, 5.30,...         0.7467030     95.89160
#> 13: 27.54,26.74,11.80,12.20,28.10,15.10,...         0.8087065    151.29282
#> 14: 30.20,17.22,17.50, 6.70, 6.50, 8.40,...         0.7901321    106.92068
#> 15: 23.40, 8.70,10.40,11.30, 6.60, 6.35,...         0.6926458     89.14351
#> 16: 16.34,19.16,13.30, 9.50,12.30,14.90,...         0.6971187     86.47758
#> 17: 14.58,17.02,29.60,17.50, 4.70,13.10,...         0.7746345    127.96962
#> 18: 16.60,18.01,13.30,13.70,22.50,11.30,...         0.7813897    120.61531
#> 19: 29.90,17.30, 8.20,18.50, 7.15, 6.70,...         0.7370296    116.48754
#> 20: 23.12,28.48,27.10, 5.50,11.90, 7.60,...         0.7919922    129.80751
#> 21: 27.80,18.42,27.10, 6.80,21.10, 6.25,...         0.7285890    122.81826
#> 22: 39.00,29.96,22.70,13.20, 4.60, 9.30,...         0.8242317    123.76662
#> 23: 31.92,29.32, 7.00, 7.70,13.40,28.20,...         0.7691403    122.67018
#> 24: 18.32,30.00, 8.80,25.30, 7.85,10.75,...         0.8148716    122.08406
#> 25: 19.50,23.88,13.00, 6.70, 9.50,10.45,...         0.7279799     95.79487
#> 26: 17.52,33.84, 7.90,21.10, 9.50, 8.30,...         0.8267139    144.55919
#> 27: 21.46, 7.62, 4.60, 4.40,17.55, 6.90,...         0.7750179    112.32334
#> 28:       19.9,11.6,13.3, 9.7,15.8, 9.3,...         0.8193501    124.29540
#> 29: 12.94,22.20,18.20, 7.50,12.90,22.30,...         0.8343206    143.87025
#> 30: 18.79,25.40,15.10,16.20, 8.60,11.00,...         0.7973450    135.42107
#> 31:  4.32,17.36,31.70, 3.20, 9.50, 6.90,...         0.7675822     93.62968
#> 32: 26.34,15.74,15.20,11.20, 6.75, 8.80,...         0.7589735    110.98469
#> 33: 21.42,26.56, 4.70,13.10,10.35, 7.15,...         0.7746839    153.60433
#> 34: 11.32,13.58, 2.00, 0.90,19.00, 4.40,...         0.7747222     81.03594
#> 35: 19.26,10.52,18.50,15.30,31.40, 9.50,...         0.7288883    122.73022
#> 36: 10.94,22.38, 1.90, 3.20, 6.00, 3.30,...         0.8274584     73.49485
#> 37: 33.74,20.82,28.90, 5.50, 8.70, 9.75,...         0.8154684    143.04132
#> 38: 14.12,14.40,12.00, 1.65,10.30, 6.40,...         0.7344336     77.97482
#> 39: 33.74,22.90,11.80, 7.80,12.30, 5.00,...         0.7055793    106.14735
#> 40: 16.88,23.12,19.20,13.60, 8.60,15.70,...         0.7530493    119.47127
#> 41: 13.32,29.54,18.40,11.40,19.20,18.20,...         0.7957641    139.54520
#> 42: 22.50,21.44, 9.40,22.30, 7.90, 5.80,...         0.8428589    138.00971
#> 43: 24.38,22.06, 7.30,13.60, 7.10,16.10,...         0.7860703    150.52460
#> 44: 32.66,25.04, 7.70, 9.80,41.10,11.70,...         0.7944333    137.67530
#> 45: 18.03,14.10,22.90,28.00,12.40, 9.20,...         0.7379543    138.83133
#> 46: 12.30,19.44,17.50, 9.00,11.80, 9.50,...         0.8151813    129.07581
#> 47: 23.46,16.34, 8.40,15.10,15.70, 8.65,...         0.8099764    124.25038
#> 48: 19.37,31.35,39.80,15.00,12.20, 9.40,...         0.7201561    143.69995
#> 49: 21.28,36.14, 8.30, 8.00,17.55,37.20,...         0.7357569    161.62371
#> 50: 30.88,14.58, 9.00,11.60,18.30, 7.80,...         0.7712530    126.06902
#> 51: 25.42,18.32, 0.00,32.60,11.75,22.25,...         0.8448512    159.71068
#> 52: 27.96,13.12,14.80, 0.60, 6.85,10.90,...         0.6971505     84.02755
#> 53: 23.83,37.50, 5.90,42.40,12.90,10.50,...         0.6837984    120.91607
#> 54: 23.44,15.68,24.50,15.90,13.50,11.90,...         0.7691501    139.73150
#> 55: 10.40,19.22, 4.30, 0.80, 8.95,31.30,...         0.8092774    133.74927
#> 56: 21.42,42.00, 0.00,10.20, 1.65, 3.40,...         0.7802863     81.75060
#> 57: 10.40,28.08, 4.20,12.20, 7.15, 7.70,...         0.9001750    111.28863
#> 58: 39.64, 9.70,32.40, 0.00,12.60,12.00,...         0.7388058    123.11459
#> 59: 10.98, 3.96, 4.30,15.10, 6.90,12.50,...         0.8241903     86.65537
#> 60: 14.88,42.00, 3.40,10.30, 0.00,23.20,...         0.7694052    133.78418
#> 61: 25.04,24.44, 4.40,14.70,10.05, 6.50,...         0.7045498    105.35134
#> 62: 22.44,22.62,11.80, 8.60,13.40, 9.00,...         0.7983085    131.05032
#> 63: 38.86, 6.70,13.60,26.30, 7.20, 9.20,...         0.8606213    190.07682
#> 64: 25.60,21.12,12.70,17.70,26.40,15.45,...         0.6856525    162.37622
#> 65: 32.88,24.44,20.90, 8.40,12.45,12.35,...         0.7503205    130.57077
#> 66: 31.92,21.60, 7.60, 7.70, 7.90,14.45,...         0.8745661    133.78237
#> 67: 39.61,17.60, 9.70,20.20,22.80,25.30,...         0.7084497    145.31012
#> 68: 29.86,27.51,12.20,19.00, 8.20, 8.40,...         0.8205370    142.29752
#> 69: 19.22,27.96,14.80,23.00,11.70,15.50,...         0.7146817    136.38271
#> 70: 12.94,27.51,17.80,26.80,19.10,18.75,...         0.7987662    156.22270
#> 71: 17.96,39.00,13.30,15.90,11.90,12.75,...         0.8494843    146.45959
#> 72: 14.56,21.64,10.40,19.20,20.50,14.20,...         0.7720057    125.56672
#>                        optimal_player_score lineup_efficiency actual_score
# }