Table Of Contents

  1. Redis Data Structures
  2. Competition Information
  3. Match Information
  4. Team Information
  5. Player Information
  6. League Table
  7. Results

Redis Data Structures {#datastructures}

Below is a list of data structures that are available through the redis DB

library(footballstats)
library(rredis)
library(magrittr)
blank <- utils::capture.output(footballstats::redis_con())
first_four <- function(z) {
  z <- lapply(1:4, function(x) z[[x]])
  return(c(z, '...'))
}
f_json <- function(y) {
  return(y %>% jsonlite::toJSON(auto_unbox = TRUE) %>% jsonlite::prettify())
}

Competition Information {#competitioninfo}

competition:set

#competition.set <- "competition:set" %>% 
#  rredis::redisSMembers() %>%
competition.set <- list(
  "1005",
  "1007",
  "1093",
  "1102",
  "..."
) %>% f_json()
print(competition.set)

Match Information {#matchinfo}

csm:{comp_id}:{season}:{match_id}

#match.info <- "csm:1204:2017:2213059" %>% 
#  rredis::redisHGetAll() %>%
match.info <- list(
  id =  "2213059",
  comp_id = "1204",
  formatted_date = "09.12.2017",
  season = "2017/2018",
  week = "16",
  venue = "The John Smith's Stadium (Huddersfield, West Yorkshire)",
  venue_id = "15188",
  venue_city = "Huddersfield, West Yorkshire",
  status = "FT",
  timer = "",
  time = "15:00",
  localteam_id = "9220",
  localteam_name = "Huddersfield Town",
  localteam_score = "2",
  visitorteam_id = "9065",
  visitorteam_name = "Brighton & Hove Albion",
  visitorteam_score = "0",
  ht_score = "[2-0]",
  ft_score = "[2-0]",
  et_score = NA,
  penalty_local = NA,
  penalty_visitor = NA
) %>% f_json()
print(match.info)

c:1204:ready.

print(list("2213173", "2213174", "2213175", "2213176", "...") %>% f_json())

Check to see if the match belongs to the set

#match.in.set <- "c_matchSetInfo:1204" %>% 
#  rredis::redisSMembers() %>%
match.in.set <- list(
  "2212907",
  "2212908",
  "2212909",
  "2212910",
  "..."
) %>% f_json()
print(match.in.set)

Team Information {#teaminformation}

This list is constantly pushed to and lifted from with no replace. It looks like the following when we issue lrange analyseTeams 0 -1.

print(list("9221", "9074", "9348", "9021", "...") %>% f_json())

hgetall ct_basic:1204:9065

basic.info <- list(
  team_id = "9065",
  is_national = "False",
  name = "Brighton & Hove Albion",
  country = "England",
  founded = "1901",
  leagues = "1204,1198,1199",
  venue_name = "The American Express Community Stadium",
  venue_id = "86109",
  venue_surface = "grass",
  venue_address = "Village Way",
  venue_city = "Falmer, East Sussex",
  venue_capacity = "30750",
  coach_name = "C. Hughton",
  coach_id = "136328"
) %>% f_json()
print(basic.info)

Player Information {#playerinformation}

Everytime a match is analysed and the team information stored, all the player IDs involved in the update are pushed to a new list, and are accessible through lrange analysePlayers 0 -1. Through another approach, and another CRON job, the players are analysed one by one.

print(list("453145", "49530", "376371", "15512", "...") %>% f_json())

Player statistics are then accessible through the following key names and all have a similar data structure.

player.info <- list(
  name = "West Bromwich Albion",
  id = "9426",
  league = "Premier League",
  league_id = "1204",
  season = "2017/2018",
  minutes = "180",
  appearances = "2",
  lineups = "2",
  substitute_in = "0",
  substitute_out = "0",
  substitute_on_bench = "0",
  goals = "0",
  yellowcards = "0",
  yellowred = "0",
  redcards = "0"
) 
print(player.info %>% f_json())

League Table {#leaguetable}

Lets have a look at the key structure first

#team.info.keys <- "cwt_l:1204:2017*" %>% 
#  rredis::redisKeys() %>% 
team.info.keys <- list(
  "cwt_l:1204:2017:12:9423",
  "cwt_l:1204:2017:15:9158",
  "cwt_l:1204:2017:16:9053",
  "cwt_l:1204:2017:20:9426",
  "..."
) %>% f_json()
print(team.info.keys)

Then looking at a particular key we can see the structure each one has.

team.week.info <- list(
  TEAM = "Newcastle United",
  PTS = "23",
  GF = "21",
  GD = "-10"
) %>% f_json()
print(team.week.info)

Once a key is analysed it is pushed to here;

league.updated <- list(
  "2243999:17002", 
  "2243932:17072", 
  "2239831:14378", 
  "2224810:10307",
  "..."
) %>% f_json()
print(league.updated)

All these individual hash maps containing a single teams accumulative points for each week means we can build a league table for any of the weeks up until the current date, and is accessible through the following;

positions <- list(
  `9259` = "1",
  `9260` = "2",
  `9249` = "3",
  `9092` = "4",
  `...` = "..."
) %>% f_json()
print(positions)

Results {#results}

Below is a list of the results obtained so far...



ntyndall/footballstats documentation built on Aug. 13, 2019, 1:36 p.m.