Skip to content

Commit

Permalink
data update
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Dec 25, 2023
1 parent 6cba5dc commit 8d04653
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 56 deletions.
18 changes: 6 additions & 12 deletions data-raw/elo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Check warning on line 72 in data-raw/elo.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/elo.R,line=72,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 81 characters.
source("~/R_GLOBALS/speedway_connect.R")
expandPairwise <- function(df, id, id2) {

Check warning on line 73 in data-raw/elo.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/elo.R,line=73,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
library(sqldf)
grid <- sqldf("

Check warning on line 75 in data-raw/elo.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/elo.R,line=75,col=13,[object_usage_linter] no visible global function definition for 'sqldf'
Expand All @@ -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
Expand All @@ -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
Expand Down
87 changes: 43 additions & 44 deletions data-raw/update_sgp_data.R
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
Binary file modified data/gpheats.rda
Binary file not shown.
Binary file modified data/gpsquads.rda
Binary file not shown.

0 comments on commit 8d04653

Please sign in to comment.