datafest competition 2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.9 KiB

  1. # Look at data
  2. library(tidyverse)
  3. library(DBI)
  4. library(RSQLite)
  5. gpsData <- read.csv("data/gps.csv")
  6. gpsDataTibble <- as_tibble(gpsData)
  7. #workingTibble <- head(gpsDataTibble, 500000)
  8. workingTibble <- gpsDataTibble
  9. playerIds <-unique(workingTibble$PlayerID)
  10. cat("Number of Players: ", length(playerIds), sep="")
  11. gameIds <- unique(workingTibble$GameID)
  12. cat("Number of Games: ", length(gameIds), sep="")
  13. playerIDMetrics <- c()
  14. gameIDMetrics <- c()
  15. averageSpeed <- c()
  16. accelDistance <- c()
  17. for(playerID in playerIds)
  18. {
  19. for(gameID in gameIds)
  20. {
  21. cat(playerID, gameID , '\n', sep=" ")
  22. speedTibble <- subset(workingTibble, GameID == gameID & PlayerID == playerID)
  23. # crunch average speed
  24. averageSpeed <- c(averageSpeed, mean(speedTibble$Speed, na.rm = 0))
  25. # average for accel value
  26. accelDistance <- c(accelDistance, mean(sqrt(speedTibble$AccelX^2 + speedTibble$AccelY^2 + speedTibble$AccelZ^ 2), na.rm = 0))
  27. # game and player id to vector
  28. playerIDMetrics <- c(playerIDMetrics, playerID)
  29. gameIDMetrics <- c(gameIDMetrics, gameID)
  30. }
  31. }
  32. plot(accelDistance, averageSpeed)
  33. compressedMetrics <- tibble(gameID = gameIDMetrics, playerID = playerIDMetrics, averageSpeed = averageSpeed, accelerationVector = accelDistance)
  34. length(compressedMetrics$averageSpeed)
  35. length(compressedMetrics$accelerationVector)
  36. write.csv(compressedMetrics, "data/speedData.csv")
  37. #putSQLiteHere <- "gpsData.sqlite" # could also be ":memory:"
  38. #mySQLiteDB <- dbConnect(RSQLite::SQLite(),putSQLiteHere)
  39. #dbWriteTable(mySQLiteDB, "gpsData", compressedMetrics, overwrite=TRUE)
  40. #dbDisconnect(mySQLiteDB)
  41. rpeData <- read.csv("./data/rpe.csv")
  42. rpeDataTibble <- as_tibble(rpeData)
  43. gameData <- read.csv("./data/game.csv")
  44. gameDataTibble <- as_tibble(gameData)
  45. wellnessData <- read.csv("./data/wellness.csv")
  46. wellnessDataTibble <- as_tibble(wellnessData)
  47. head(gpsData)