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)
#>     league_id franchise_id                 franchise_name season week
#>  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
#>  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
#>  1: 13.88,14.30,23.70, 6.40, 8.55, 6.05,...         0.7327635    138.77075
#>  2: 17.76,28.76,10.10, 8.30,12.85,13.95,...         0.8363729    151.23295
#>  3: 12.14,15.00,15.90,27.80,16.70,22.10,...         0.8141689    161.31942
#>  4:  9.58,20.46,11.30,26.80,24.70, 9.50,...         0.6693612    124.29367
#>  5: 29.60,24.02,21.10,15.10,22.50,23.60,...         0.7227733    159.61725
#>  6: 21.42,19.80,14.70,24.10,27.30,17.00,...         0.7951455    206.87301
#>  7: 10.94,15.15,13.90,22.50, 6.40, 9.40,...         0.7655543     97.37086
#>  8:  9.35, 4.50, 8.40,14.90, 2.45, 3.30,...         0.7852637     54.41877
#>  9: 21.70, 2.80,16.70, 2.70, 7.00, 1.85,...         0.7837519     76.49418
#> 10:  6.84,16.36, 3.20,13.80,12.70,12.75,...         0.8439527     90.13415
#> 11: 21.42,13.00,14.90,15.90, 5.55, 6.05,...         0.7691487    103.38897
#> 12: 13.32,17.50, 5.00,17.10, 8.20, 5.30,...         0.7795314    100.10742
#> 13: 27.54,26.74,11.80,12.20,28.10,15.10,...         0.8172760    152.89599
#> 14: 30.20,17.22,17.50, 6.70, 6.50, 8.40,...         0.8225947    111.31351
#> 15: 23.40, 8.70,10.40,11.30, 6.60, 6.35,...         0.7788129    100.23321
#> 16: 16.34,19.16,13.30, 9.50,12.30,14.90,...         0.8993706    111.56692
#> 17: 14.58,17.02,29.60,17.50, 4.70,13.10,...         0.8458776    139.73899
#> 18: 16.60,18.01,13.30,13.70,22.50,11.30,...         0.7830822    120.87657
#> 19: 29.90,17.30, 8.20,18.50, 7.15, 6.70,...         0.7085088    111.97981
#> 20: 23.12,28.48,27.10, 5.50,11.90, 7.60,...         0.7365348    120.71805
#> 21: 27.80,18.42,27.10, 6.80,21.10, 6.25,...         0.7421056    125.09674
#> 22: 39.00,29.96,22.70,13.20, 4.60, 9.30,...         0.7906176    118.71914
#> 23: 31.92,29.32, 7.00, 7.70,13.40,28.20,...         0.7563315    120.62732
#> 24: 18.32,30.00, 8.80,25.30, 7.85,10.75,...         0.7908511    118.48531
#> 25: 19.50,23.88,13.00, 6.70, 9.50,10.45,...         0.6961625     91.60802
#> 26: 17.52,33.84, 7.90,21.10, 9.50, 8.30,...         0.7220824    126.26334
#> 27: 21.46, 7.62, 4.60, 4.40,17.55, 6.90,...         0.8148997    118.10341
#> 28:       19.9,11.6,13.3, 9.7,15.8, 9.3,...         0.8643786    131.12623
#> 29: 12.94,22.20,18.20, 7.50,12.90,22.30,...         0.7853619    135.42781
#> 30: 18.79,25.40,15.10,16.20, 8.60,11.00,...         0.7270679    123.48521
#> 31:  4.32,17.36,31.70, 3.20, 9.50, 6.90,...         0.8076871     98.52167
#> 32: 26.34,15.74,15.20,11.20, 6.75, 8.80,...         0.7718601    112.86910
#> 33: 21.42,26.56, 4.70,13.10,10.35, 7.15,...         0.7536204    149.42785
#> 34: 11.32,13.58, 2.00, 0.90,19.00, 4.40,...         0.8648372     90.46198
#> 35: 19.26,10.52,18.50,15.30,31.40, 9.50,...         0.7390559    124.44224
#> 36: 10.94,22.38, 1.90, 3.20, 6.00, 3.30,...         0.7630138     67.77088
#> 37: 33.74,20.82,28.90, 5.50, 8.70, 9.75,...         0.8236902    144.48350
#> 38: 14.12,14.40,12.00, 1.65,10.30, 6.40,...         0.7581519     80.49299
#> 39: 33.74,22.90,11.80, 7.80,12.30, 5.00,...         0.7969538    119.89372
#> 40: 16.88,23.12,19.20,13.60, 8.60,15.70,...         0.8240103    130.72924
#> 41: 13.32,29.54,18.40,11.40,19.20,18.20,...         0.7348220    128.85838
#> 42: 22.50,21.44, 9.40,22.30, 7.90, 5.80,...         0.7607897    124.57170
#> 43: 24.38,22.06, 7.30,13.60, 7.10,16.10,...         0.8240914    157.80526
#> 44: 32.66,25.04, 7.70, 9.80,41.10,11.70,...         0.7660142    132.75026
#> 45: 18.03,14.10,22.90,28.00,12.40, 9.20,...         0.7584985    142.69632
#> 46: 12.30,19.44,17.50, 9.00,11.80, 9.50,...         0.8083326    127.99138
#> 47: 23.46,16.34, 8.40,15.10,15.70, 8.65,...         0.8576411    131.56214
#> 48: 19.37,31.35,39.80,15.00,12.20, 9.40,...         0.6826599    136.21796
#> 49: 21.28,36.14, 8.30, 8.00,17.55,37.20,...         0.7592354    166.78124
#> 50: 30.88,14.58, 9.00,11.60,18.30, 7.80,...         0.8224425    134.43645
#> 51: 25.42,18.32, 0.00,32.60,11.75,22.25,...         0.7888784    149.12956
#> 52: 27.96,13.12,14.80, 0.60, 6.85,10.90,...         0.8047182     96.99269
#> 53: 23.83,37.50, 5.90,42.40,12.90,10.50,...         0.7896160    139.62779
#> 54: 23.44,15.68,24.50,15.90,13.50,11.90,...         0.7405271    134.53155
#> 55: 10.40,19.22, 4.30, 0.80, 8.95,31.30,...         0.7716186    127.52540
#> 56: 21.42,42.00, 0.00,10.20, 1.65, 3.40,...         0.7547728     79.07754
#> 57: 10.40,28.08, 4.20,12.20, 7.15, 7.70,...         0.7540638     93.22490
#> 58: 39.64, 9.70,32.40, 0.00,12.60,12.00,...         0.7698273    128.28402
#> 59: 10.98, 3.96, 4.30,15.10, 6.90,12.50,...         0.7952570     83.61332
#> 60: 14.88,42.00, 3.40,10.30, 0.00,23.20,...         0.7733515    134.47035
#> 61: 25.04,24.44, 4.40,14.70,10.05, 6.50,...         0.8177603    122.27970
#> 62: 22.44,22.62,11.80, 8.60,13.40, 9.00,...         0.7753617    127.28337
#> 63: 38.86, 6.70,13.60,26.30, 7.20, 9.20,...         0.7935260    175.25816
#> 64: 25.60,21.12,12.70,17.70,26.40,15.45,...         0.7629821    180.68943
#> 65: 32.88,24.44,20.90, 8.40,12.45,12.35,...         0.7844028    136.50177
#> 66: 31.92,21.60, 7.60, 7.70, 7.90,14.45,...         0.8292177    126.84543
#> 67: 39.61,17.60, 9.70,20.20,22.80,25.30,...         0.7337124    150.49176
#> 68: 29.86,27.51,12.20,19.00, 8.20, 8.40,...         0.8422993    146.07154
#> 69: 19.22,27.96,14.80,23.00,11.70,15.50,...         0.8437127    161.00570
#> 70: 12.94,27.51,17.80,26.80,19.10,18.75,...         0.7957401    155.63085
#> 71: 17.96,39.00,13.30,15.90,11.90,12.75,...         0.7211928    124.34085
#> 72: 14.56,21.64,10.40,19.20,20.50,14.20,...         0.7592408    123.49052
#>                        optimal_player_score lineup_efficiency actual_score
# }