-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmappings.R
More file actions
111 lines (102 loc) · 2.22 KB
/
Copy pathmappings.R
File metadata and controls
111 lines (102 loc) · 2.22 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
flip <- function(a){
b <- c(names(a))
names(b) <- a
b
}
availableToHistoryPosition = c(
"DST"="Def"
)
historyToAvailablePosition <- flip(availableToHistoryPosition)
availableToHistoryTeam <- c(
"ARI"="ari",
"ATL"="atl",
"BAL"="bal",
"BUF"="buf",
"CAR"="car",
"CHI"="chi",
"CIN"="cin",
"CLE"="cle",
"DAL"="dal",
"DEN"="den",
"DET"="det",
"GB"="gnb",
"HOU"="hou",
"IND"="ind",
"JAX"="jac",
"KC"="kan",
"LAC"="lac",
"LAR"="lar",
"MIA"="mia",
"MIN"="min",
"NE"="ne",
"NO"="nor",
"NYJ"="nyj",
"NYG"="nyg",
"OAK"="oak",
"PIT"="pit",
"PHI"="phi",
"SEA"="sea",
"SF"="sfo",
"TB"="tam",
"TEN"="ten",
"WAS"="was"
)
historyToAvailableTeam <- flip(availableToHistoryTeam)
historyToAvailableName <- c(
"Arizona"="Cardinals",
"Atlanta"="Falcons",
"Baltimore"="Ravens",
"Buffalo"="Bills",
"Carolina"="Panthers",
"Chicago"="Bears",
"Cincinnati"="Bengals",
"Cleveland"="Cleveland",
"Dallas"="Cowboys",
"Denver"="Broncos",
"Detroit"="Lions",
"Green Bay"="Packers",
"Houston"="Texans",
"Indianapolis"="Colts",
"Jacksonville"="Jaguars",
"Kansas City"="Chiefs",
"LA Chargers"="Chargers",
"LA Rams"="Rams",
"Miami"="Dolphins",
"Minnesota"="Vikings",
"New England"="Patriots",
"New Orleans"="Saints",
"New York J"="Jets",
"New York G"="Giants",
"Oakland"="Raiders",
"Pittsburgh"="Steelers",
"Philadelphia"="Eagles",
"Seattle"="Seahawks",
"San Francisco"="49ers",
"Tampa Bay"="Tampa Bay",
"Tennessee"="Titans",
"Washington"="Redskins"
)
availableToHistoryName = flip(historyToAvailableName)
mapOrDefault <- function(x, mappings, default=NA) {
xMatch <- trimws(as.character(x))
if (xMatch %in% names(mappings)){
as.character(mappings[xMatch])
} else {
as.character(default)
}
}
softMatch <- function(x, possible){
if (!(x %in% possible)) {
matches <- c(" [I|V]+$", " $", " Jr\\.", " Sr\\.", "\\.")
replaces <- rep("", length(matches))
alt <- gsubs(matches, replaces, x)
if (alt %in% possible) {
return(alt)}
altPossible <- gsubs(matches, replaces, possible)
names(possible) <- unlist(altPossible)
if (x %in% names(possible)) {
return(as.character(possible[x]))
}
}
return(as.character(x))
}