4 TLDR

### Loads the required packages
require(tibble)
require(tidyr)
require(dplyr)
require(googlesheets4)

### Loads the required functions from SHL Github
source("https://raw.githubusercontent.com/canadice/shl/main/scripts/fhm6SaveParser.R")

##------------------------------------
##  These settings are user defined!
##

### Defines your paths to the save files and the base name for your saves.
##  Replace these strings with your folder path and save name.
##  Note that R needs / instead of \ for paths.
path <- 
  "C:/Users/Canadice/Documents/Out of the Park Developments/Franchise Hockey Manager 6/saved_games/"

baseName <- "SHL-S59-Casino-"

### Defines the number of tests run with the save name followed by a number
nSims <- 10

##------------------------------------


### Reads all the csv-files given the same base-name and a counting number at the end
testSims <- 
  ## Parallell data import with lapply()
  lapply(
    ## Defines the files to be read
    X = 
      ## Creates a vector with base-name and their numbers
      paste(
        baseName,
        1:nSims %>% as.character(),
        ".lg",
        sep = ""
      ),
    ## Specifies the function where the vector is used
    FUN = fhm6Parser,
    ## Specifies the path to the FHM6 save path
    saveFolder = path
  )

### Parses and combines all save game data for the teams into one single data frame
teamData <- 
  teamParserRaw(testSims)

#### For casino predictions this code creates the casino lines
### ID variable for each team
TeamId <- 
  c(18,7,0,8,1,9,2,13,4,10,20,5,14,21,12,19,6,15,3,11)

### Name variable for each team
Team <- 
  c(
    "Atlanta Inferno",
    "Baltimore Platoon",
    "Buffalo Stampede",
    "Calgary Dragons",
    "Chicago Syndicate",
    "Edmonton Blizzard",
    "Hamilton Steelhawks",
    "Los Angeles Panthers",
    "Manhattan Rage",
    "Minnesota Monarchs",
    "Montreal Patriotes",
    "New England Wolfpack",
    "New Orleans Specters",
    "Philadelphia Forge",
    "San Francisco Pride",
    "Seattle Argonauts",
    "Tampa Bay Barracuda",
    "Texas Renegades",
    "Toronto North Stars",
    "Winnipeg Aurora"
  )

### All lines are written in alphabetical order.
Casino <- 
  c(
    37.5,
    43.5,
    47.5,
    34.5,
    46.5,
    29.5,
    46.5,
    39.5,
    10.5,
    31.5,
    21.5,
    33.5,
    16.5,
    29.5,
    31.5,
    29.5,
    38.5,
    47.5,
    43.5,
    11.5
  )

### Creates a data.frame with all information
teamCasino <- 
  data.frame(
    TeamId,
    Team,
    Casino
  )

### Combines the casino lines and aggregates data from the teamData
casinoPredictions <- 
  casinoAggregator(
    teamRaw = teamData,
    teamCasino = teamCasino
  )


### Writes the data to a Google Sheet
rawDataWriter(
  data = teamData,
  file = "https://docs.google.com/spreadsheets/d/1kisvxMASJvX26djRXzDVDxMz1ODqbaaMfuwUXtVwpWw/edit#gid=1074258598",
  sheet = "Canadice's Raw Data"
)

casinoDataWriter(
  data = casinoPredictions,
  file = "https://docs.google.com/spreadsheets/d/1kisvxMASJvX26djRXzDVDxMz1ODqbaaMfuwUXtVwpWw/edit#gid=1074258598",
  sheet = "Canadice's Predictions"
)