-
Notifications
You must be signed in to change notification settings - Fork 0
/
setPercentSetsGamesPointsWon.R
35 lines (28 loc) · 1.22 KB
/
setPercentSetsGamesPointsWon.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
rm(list = ls())
source("formulas.R")
calculatePercentGamesWonWinner <- function(row) {
winnerWonGames <- sum(c(row$W1, row$W2, row$W3, row$W4, row$W5), na.rm = T)
winnerLostGames <- sum(c(row$L1, row$L2, row$L3, row$L4, row$L5), na.rm = T)
winnerWonGames / (winnerWonGames + winnerLostGames)
}
calculatePercentPointsWonWinner <- function(row) {
pointsWon <- (row$w_1stWon + row$w_2ndWon) + (row$l_svpt - row$l_1stWon - row$l_2ndWon)
totalPoints <- row$w_svpt + row$l_svpt
pointsWon / totalPoints
}
allGames <- getAllGamesWithoutRating()
allGames <- allGames %>% mutate(Winner_percentsetswon = NA,
Winner_percentgameswon = NA,
Winner_percentpointswon = NA)
for(i in 1 : nrow(allGames)) {
if(calculateGames(allGames %>% slice(i)) <= 10) {
next()
}
allGames$Winner_percentsetswon[i] <- allGames$W1set[i] / (allGames$W1set[i] + allGames$L1set[i])
allGames$Winner_percentgameswon[i] <- calculatePercentGamesWonWinner(allGames %>% slice(i))
if(is.na(allGames$w_svpt[i]) | is.na(allGames$l_svpt[i])) {
next()
}
allGames$Winner_percentpointswon[i] <- calculatePercentPointsWonWinner(allGames %>% slice(i))
}
saveDatasetsWithoutRating(allGames)