dfs-with-r / coach

Lineup optimization for daily fantasy sports
https://dfs-with-r.github.io/coach/
GNU General Public License v3.0
47 stars 13 forks source link

The write_lineups isn't working for nhl/draftkings. I took a look at the issue #6 you had recently but this is for draftkings. #8

Closed tdemmer18 closed 5 years ago

tdemmer18 commented 5 years ago

Here is the error:

Error in split.default(lineups, lineups[["lineup"]]) : group length is 0 but data length > 0

Here is the code I ran. The draftkings file is for today 2019-02-26, full game slate.

devtools::install_github("dfs-with-r/coach") library(coach)

data <- read_dk("~/Downloads/DKSalaries.csv")

set.seed(100) n <- nrow(data) data$fpts_proj <- rnorm(n, data$fpts_avg) data

model <- model_dk_nhl(data)

lineups <- optimize_generic(data, model) lineups

write_lineups(lineups, "mylineups.csv", site = "draftkings", sport = "nhl")

zamorarr commented 5 years ago

Hmm.. This looks like the exact same issue as #6. I'll take a look

zamorarr commented 5 years ago

This is working fine for me. When I run write_lineups() I get back:

C C W W W D D G UTIL
12146192 12146242 12146678 12146550 12146558 12147206 12147110 12147657 12146658
12146192 12146242 12146498 12146550 12146558 12147202 12147206 12147657 12146658
12146192 12146242 12146498 12146550 12146558 12147206 12147204 12147657 12146658

Can you verify your version of coach? When you type devtools::session_info() what does the line for coach return? It should be:

coach           * 0.0.1   2019-02-20 [1] Github (dfs-with-r/coach@4904527)
tdemmer18 commented 5 years ago

coach * 0.0.1 2019-02-15 [1] Github (zamorarr/ coach@78c5a2a)

**without the space after zamorarr/

zamorarr commented 5 years ago

That looks to have a different commit hash than mine (4904527 vs 78c5a2a) . Can you try re-installing with devtools::install_github("dfs-with-r/coach") again?

If you look at the commit history you'll see that your version of the code is much older. The write_lineups() fix should be in the most recent version.

tdemmer18 commented 5 years ago

Okay, I was able to get it to update, but now when I run it, I get the error below. coach * 0.0.1 2019-02-26 [1] Github (dfs-with-r/ coach@4904527)

Error in split.default(lineups, lineups[["lineup"]]) : group length is 0 but data length > 0

zamorarr commented 5 years ago

Ok it looks like you are up to date. That error is very strange since that line split(lineups, lineups[["lineup"]])) should no longer exist in the code.

if you type write_lineups in your R console (without any parenthesis) it should print out the source code for the function. It should look like this:

function (lineups, path = NULL, site = c("draftkings", "fanduel", 
    "fantasydraft"), sport = c("nfl", "mlb", "nba", "nhl", "nascar"), 
    ...) 
{
    converted_lineups <- lapply(lineups, convert_lineup, site, 
        sport, ...)
    df <- do.call(rbind, converted_lineups)
    if (!is.null(path)) {
        utils::write.csv(df, file = path, row.names = FALSE, 
            quote = FALSE)
    }
    df
}

If it starts with a line that looks like split(lineups, ... then somehow it is still loading the old version of the library.

tdemmer18 commented 5 years ago

Okay it worked. I restarted rstudio and re-ran everything and it worked. Thanks for the help and great job with the package. I'm still relatively new to R so I appreciate the help.

zamorarr commented 5 years ago

no problem @tdemmer18. Thanks for using the package. Feel free to post any other questions in the future!