Skip to content

Instantly share code, notes, and snippets.

@durtal
durtal / betfair.R
Last active October 25, 2015 19:32
bf <- betfair(usr = Sys.getenv("BETFAIR_USR"),
pwd = Sys.getenv("BETFAIR_PWD"),
key = Sys.getenv("BETFAIR_KEY"))
outlist <- vector("list", 120)
for(i in 1:120) {
# sleep for 60seconds
Sys.sleep(60)
# collect marketCatalogue data, contains team names
tmp <- bf$marketCatalogue(filter = marketFilter(marketIds = "1.121198987"),
@durtal
durtal / gulfstream_race.R
Created May 21, 2015 10:43
Helper funs to get data from Gulfstream app (durtal.github.io/gulfstream) into R
gulf_races_helper <- function(race) {
runners <- ldply(race$runners, data.frame, stringsAsFactors = FALSE)
details <- data.frame(race$details, stringsAsFactors = FALSE)
conditions <- data.frame(race$conditions, stringsAsFactors = FALSE)
date_race <- data.frame(date = race$date,
date_race = race$date_race,
race = race$race,
stringsAsFactors = FALSE)
@durtal
durtal / gulfstream_data.R
Last active August 29, 2015 14:15
Gulfstream App Data
gulf_ratings <- function(ratings, .progress = "none") {
ratings <- ldply(ratings, .fun = gulf_ratings_helper, .progress = .progress)
id <- sapply(1:ncol(ratings), FUN = function(x) is.factor(ratings[, x]))
ratings[, id] <- lapply(ratings[, id], as.character)
return(ratings)
}
@durtal
durtal / turftrax.R
Last active August 29, 2015 14:04
Helper function to convert Turftrax PDF times to neat dataframe
# SHORT SCRIPT TO GET TURFTRAX TIMES FROM PDF INTO R
# example PDF http://www.turftrax.co.uk/tracking/Glorious2014/GWD290714R1_1M2F.pdf
# highlight horses names and times in the table in Turftrax PDF using mouse
# (don't highlight the table headers)
# copy to clipboard using "Ctrl-C"
# in R (once PDF table is copied to clipboard)
df <- read.delim("clipboard", h=F, stringsAsFactors=F)
library(ggplot2)
#Load Data
#Make sure months stay ordered - first time I ever wanted a factor!
#Label x-axis with every fifth label
visits_visitors <- read.csv("visits_visitors.csv")
visits_visitors$Month <- factor(visits_visitors$Month, levels = visits_visitors$Month, ordered = TRUE)
visits_visitors$Month_ <- ifelse(as.numeric(row.names(visits_visitors)) %% 5 == 0, as.character(visits_visitors$Month), "")
#Build plot as a series of elements