需要帮助来加速脚本,可以更快地完成吗?

时间:2019-05-02 11:23:30

标签: r json jsonlite

现在,他们使用r从页面提取数据的方式每个游戏大约需要30-50秒。还有另一种方法可以缩短等待时间吗?从旧的基于xml的站点中提取数据,我可以在大约几分钟后提取以前的游戏。

任何想法/帮助都将不胜感激!!谢谢!

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

)

0 个答案:

没有答案