diff --git a/data-raw/elo.R b/data-raw/elo.R index afbf609..b4d8726 100755 --- a/data-raw/elo.R +++ b/data-raw/elo.R @@ -14,15 +14,11 @@ # Test Package: 'Cmd + Shift + T' test <- function() { - library(oddsandsods) - library(speedway) - library(Rcpp) - source("~/R_GLOBALS/speedway_connect.R") - getConnection() + speedway:::getConnection() season <- 2016 competition <- "DMP" - teams <- customQuery( + teams <- DBI::dbGetQuery( { " SELECT @@ -72,10 +68,8 @@ testScript1 <- function() { library(rvest) library(magrittr) library(dplyr) - library(oddsandsods) library(reshape2) options(scipen = 999, digits = 5, sqldf.driver = "SQLite", gsubfn.engine = "R") - source("~/R_GLOBALS/speedway_connect.R") expandPairwise <- function(df, id, id2) { library(sqldf) grid <- sqldf(" @@ -96,8 +90,8 @@ testScript1 <- function() { return(grid) } - getConnection() - raw_heats <- customQuery({ + speedway:::getConnectionLocal() + raw_heats <- DBI::dbGetQuery({ " SELECT event_id, heat, field, rider_name, points, position @@ -107,14 +101,14 @@ testScript1 <- function() { rider_name != '' and points is not null" }) - raw_events <- customQuery({ + raw_events <- DBI::dbGetQuery({ " SELECT e.id event_id,e.date, e.competition, e.season, e.stage, e.place FROM events e " }) - dbDisconnect(con) + DBI::dbDisconnect(con) # wrangle events ----- events <- raw_events diff --git a/data-raw/update_sgp_data.R b/data-raw/update_sgp_data.R index b451054..bb9a8f8 100755 --- a/data-raw/update_sgp_data.R +++ b/data-raw/update_sgp_data.R @@ -1,54 +1,53 @@ update_sgp_data <- function() { - library(oddsandsods) library(magrittr) library(dplyr) library(RMySQL) library(runner) - con <- dbConnect( - drv = MySQL(), - username = "root", - dbname = "speedway", - password = "Elo#21ok", - encoding = "UTF-8" + con <- speedway:::getConnection() + DBI::dbGetQuery(con, "SET NAMES utf8") + gpsquads <- DBI::dbGetQuery( + statement = { + " + SELECT + e.id, + e.season, + e.date, + e.place, + e.round, + e.name, + s.rider_name rider, + s.points, + s.classification + FROM speedway.event_squads s + LEFT JOIN speedway.events e on e.id = s.event_id + WHERE competition = 'Grand-Prix' + ;" + }, + conn = con ) - dbGetQuery(con, "SET NAMES utf8") - gpsquads <- customQuery({ + gpheats <- DBI::dbGetQuery( + statement = { + " + SELECT + e.id, + e.season, + e.date, + e.round, + e.name, + h.heat, + h.field, + h.rider_name rider, + h.points, + h.position + FROM speedway.event_heats h + LEFT JOIN speedway.events e on e.id = h.event_id + WHERE + competition = 'Grand-Prix' " - SELECT - e.id, - e.season, - e.date, - e.place, - e.round, - e.name, - s.rider_name rider, - s.points, - s.classification - FROM speedway.event_squads s - LEFT JOIN speedway.events e on e.id = s.event_id - WHERE competition = 'Grand-Prix' - ;" - }) - gpheats <- customQuery({ - " - SELECT - e.id, - e.season, - e.date, - e.round, - e.name, - h.heat, - h.field, - h.rider_name rider, - h.points, - h.position - FROM speedway.event_heats h - LEFT JOIN speedway.events e on e.id = h.event_id - WHERE - competition = 'Grand-Prix' - " - }) - dbDisconnect(con) + }, + conn = con + ) + DBI::dbDisconnect(con) gpsquads$date <- as.POSIXct(strptime(gpsquads$date, "%Y-%m-%d %H:%M:%S")) gpheats$date <- as.POSIXct(strptime(gpheats$date, "%Y-%m-%d %H:%M:%S")) diff --git a/data/gpheats.rda b/data/gpheats.rda index 5d7c652..0bd3434 100755 Binary files a/data/gpheats.rda and b/data/gpheats.rda differ diff --git a/data/gpsquads.rda b/data/gpsquads.rda index d11abbd..a0c050f 100755 Binary files a/data/gpsquads.rda and b/data/gpsquads.rda differ