Is there anything I can do to speed this script up?

Right now the way I'm pulling the data from the page using r is taking anywhere from 30-50 seconds for each game. Is there another way I could do this and shorten the wait time?? Pulling the data from the old xml based site I could pull the previous days games in roughly a couple minutes.

Any ideas/help is greatly appreciated!! Thanks!


url = "http://statsapi-prod-alt-968618993.us-east-1.elb.amazonaws.com/api/v1/game/565711/playByPlay"

#if(GET(url)$status_code==200) chk = chk + 1

#if (chk == 10) break()

if(GET(url)$status_code!=200) next

reposLoL <- fromJSON(url, simplifyDataFrame = FALSE)

repos <- as.Node(reposLoL)

if(length(repos$scoringPlays) == 39 && 
   length(repos$allPlays) == 39 &&
   length(repos$playsByInning) == 39) next

#convert this to a data.frame

pitchDetails <-  repos %>% ToDataFrameTable(
  #game_pk = '',  #substr(url, 84, 89),
  type = function(x) x$type,
  #isPitch = function(x) x$isPitch,
  atBatNum = function(x) x$about$atBatIndex,
  pitchNumber = function(x) x$pitchNumber,
  pitchCalled = function(x) x$details$call$code,
  pitchDesc = function(x) x$details$description,
  pitchType = function(x) x$details$type$code,
  pitchTypeDesc = function(x) x$details$type$description,
  countStrikes = function(x) x$count2$strikes,
  countBalls = function(x) x$count2$balls,
  countOuts = function(x) x$count2$outs,
  startSpeed = function(x) x$pitchData$startSpeed,
  endSpeed = function(x) x$pitchData$endSpeed,
  nastyFactor = function(x) x$pitchData$nastyFactor,
  strikeZoneTop = function(x) x$pitchData$strikeZoneTop,
  strikeZoneBottom = function(x) x$pitchData$strikeZoneBottom,
  zone = function(x) x$pitchData$zone,
  aX = function(x) x$pitchData$coordinates$aX,
  aY = function(x) x$pitchData$coordinates$aY,
  aZ = function(x) x$pitchData$coordinates$aZ,
  pfxX = function(x) x$pitchData$coordinates$pfxX,
  pfxZ = function(x) x$pitchData$coordinates$pfxZ,
  pX = function(x) x$pitchData$coordinates$pX,
  pZ = function(x) x$pitchData$coordinates$pZ,
  vX0 = function(x) x$pitchData$coordinates$vX0,
  vY0 = function(x) x$pitchData$coordinates$vY0,
  vZ0 = function(x) x$pitchData$coordinates$vZ0,
  X = function(x) x$pitchData$coordinates$x,
  Y = function(x) x$pitchData$coordinates$y,
  x0 = function(x) x$pitchData$coordinates$x0,
  y0 = function(x) x$pitchData$coordinates$y0,
  z0 = function(x) x$pitchData$coordinates$z0,
  breakAngle = function(x) x$pitchData$breaks$breakAngle,
  breakLength = function(x) x$pitchData$breaks$breakLength,
  breakY = function(x) x$pitchData$breaks$breakY,
  spinRate = function(x) x$pitchData$breaks$spinRate,
  spinDirection = function(x) x$pitchData$breaks$spinDirection,
  LaunchSpeed = function(x) x$hitData$launchSpeed,
  launchAngle = function(x) x$hitData$launchAngle,
  totalDistance = function(x) x$hitData$totalDistance,
  batter = function(x) x$matchup$batter$id,
  pitcher = function(x) x$matchup$pitcher$id,
  splitsBatter = function(x) x$matchup$splits$batter,
  splitsPitcher = function(x) x$matchup$splits$pitcher,
  splitsMenOnBase = function(x) x$matchup$splits$menOnBase,
  hasReview = function(x) x$details$hasReview

)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.