################################## Auswählen der Suchparameter #############################################
# Das Skript kann für nicht-kommerzielle Zwecke weitergegeben und verändert werden.
# Dateipfad (Anführungszeichen bitte beibehalten):
pfad1 <- "C:/Users/x/Desktop/"
# Name der fertigen Tabelle:
Tabelle.komplett <- "meine_fifa_spieler.csv"
# Gesamtbewertung:
gesamtbewertung.min <- 83
gesamtbewertung.max <- 99
# Potential:
potential.min <- 75
# Vertragsende:
vertragsende.min <- 2019
vertragsende.max <- 2022
################################################## ################################################## ###
setwd(pfad1)
links <- read.table("teamplayerlinks.txt", fileEncoding="UCS-2LE", header=TRUE)
player <- read.table("players.txt", fileEncoding="UCS-2LE", header=TRUE)
linkcol <- c("teamid", "playerid")
linkcol
links
links <- links[, linkcol]
colnames(links) <- c("teamid", "playerid_team")
head(links)
player <- player[player$birthdate<999999999 & player$overallrating > gesamtbewertung.min & player$overallrating < gesamtbewertung.max & player$potential > potential.min & player$contractvaliduntil > vertragsende.min & player$contractvaliduntil < vertragsende.max,]
index <- c(1:nrow(player))
player$index <- index
playercol <- c("index", "lastnameid", "playerid", "birthdate", "height", "weight", "overallrating", "potential", "skillmoves", "contractvaliduntil", "preferredposition1", "preferredposition2", "preferredposition3", "preferredposition4", "preferredfoot", "acceleration", "sprintspeed", "agility", "strength","stamina", "jumping", "balance", "reactions", "aggression", "positioning", "vision", "dribbling", "ballcontrol","shortpassing", "longpassing", "crossing", "shotpower", "longshots", "finishing", "headingaccuracy", "freekickaccuracy", "penalties", "volleys", "standingtackle", "marking", "slidingtackle", "gkdiving", "gkpositioning", "gkreflexes", "gkkicking", "gkhandling")
player <- player[, playercol]
player
head(player)
teamids <- read.table("teams_edit.txt", fileEncoding="UCS-2LE", header=FALSE)
teamids
teamnames <- scan("teamnames.txt", sep="\t", what=list("character"))
as.vector(teamnames)
teamnames
head(teamnames)
team.data <- cbind(teamids, teamnames)
colnames(team.data) <- c("teamid", "budget", "teamname")
head(links)
head(player)
head(team.data)
aim <- player$playerid
length(aim)
f1 <- function(x){
count <- 1
tac <- cbind(player[1, ], links[1, ])
as.data.frame(tac)
# tac$"teamid" <- "xxx"
for (i in 1:length(x)){
target.player <- player[count, ]
target.teams <- links[links$playerid_team==x[count], ]
rows.teams <- nrow(target.teams)
if (rows.teams > 1){
multi.target.player <- target.player
for (i in 2:rows.teams){
multi.target.player <- rbind(multi.target.player, target.player)
}
tab <- cbind(links[links$playerid_team==x[count], ], multi.target.player)
tac <- rbind(tac, tab)
count <- count+1
tabelle <<- tac
}
else if (rows.teams < 1){
count <- count+1
}
else{
tab <- cbind(target.teams, target.player)
tac <- rbind(tac, tab)
count <- count+1
tabelle <<- tac
}
}
tabelle <<- tabelle[-1,]
tabelle <<- tabelle[, c("index", "teamid", "playerid_team", "lastnameid", "playerid", "birthdate", "height", "weight", "overallrating", "potential", "skillmoves", "contractvaliduntil", "preferredposition1", "preferredposition2", "preferredposition3", "preferredposition4", "preferredfoot", "acceleration", "sprintspeed", "agility", "strength","stamina", "jumping", "balance", "reactions", "aggression", "positioning", "vision", "dribbling", "ballcontrol","shortpassing", "longpassing", "crossing", "shotpower", "longshots", "finishing", "headingaccuracy", "freekickaccuracy", "penalties", "volleys", "standingtackle", "marking", "slidingtackle", "gkdiving", "gkpositioning", "gkreflexes", "gkkicking", "gkhandling")]
print(tabelle)
}
f1(aim)
aim2 <- tabelle$teamid
aim2
f2 <- function(x){
count2 <- 1
tac <- cbind(tabelle[1, ], team.data[1, ])
as.data.frame(tac)
tac$"teamid" <- "xxx"
failed.ids <<- c()
for (i in 1:length(x)){
teamid <- x[count2]
team.ids.data <- team.data[team.data$teamid==teamid,]
if (nrow(team.ids.data) < 1){
count2 <- count2+1
failed.ids <<- c(failed.ids, tabelle[count2, "playerid"])
print(tabelle[count2, "playerid"])
}
else{
spalte.neu <- cbind(tabelle[count2,], team.data[team.data$teamid==teamid,])
tac <- rbind(tac, spalte.neu)
count2 <- count2+1
tabelle1 <<- tac
}
}
tabelle1 <<- tabelle1[-1,]
tabelle1 <<- tabelle1[, c("index", "teamname", "budget", "teamid", "playerid_team", "lastnameid", "playerid", "birthdate", "height", "weight", "overallrating", "potential", "skillmoves", "contractvaliduntil", "preferredposition1", "preferredposition2", "preferredposition3", "preferredposition4", "preferredfoot", "acceleration", "sprintspeed", "agility", "strength","stamina", "jumping", "balance", "reactions", "aggression", "positioning", "vision", "dribbling", "ballcontrol","shortpassing", "longpassing", "crossing", "shotpower", "longshots", "finishing", "headingaccuracy", "freekickaccuracy", "penalties", "volleys", "standingtackle", "marking", "slidingtackle", "gkdiving", "gkpositioning", "gkreflexes", "gkkicking", "gkhandling")]
print(tabelle1)
}
f2(aim2)
tabelle.fertig <- tabelle1[tabelle1$budget > 2 | tabelle1$teamid == 111592 | tabelle1$teamid == 130011,]
tabelle.fertig
tabelle.fertig2 <- tabelle.fertig[, c("index", "teamname", "lastnameid", "birthdate", "height", "weight", "overallrating", "potential", "skillmoves", "contractvaliduntil", "preferredposition1", "preferredposition2", "preferredfoot", "acceleration", "sprintspeed", "agility", "strength","stamina", "jumping", "balance", "reactions", "aggression", "positioning", "vision", "dribbling", "ballcontrol","shortpassing", "longpassing", "crossing", "shotpower", "longshots", "finishing", "headingaccuracy", "freekickaccuracy", "penalties", "volleys", "standingtackle", "marking", "slidingtackle", "gkdiving", "gkpositioning", "gkreflexes", "gkkicking", "gkhandling")]
tabelle.fertig2
colnames(tabelle.fertig2) <- c("Index", "Team", "Lastname", "Year", "Height", "Weight", "Rating", "Potential", "Skill", "Contractend", "Pos1", "Pos2", "Foot", "Acc", "Speed", "Agility", "Strength","Stamina", "Jumping", "Balance", "Reactions", "Aggression", "Positioning", "Vision", "Dribbling", "Ballcontrol","Shortpassing", "Longpassing", "Crossing", "Shotpower", "Longshots", "Finishing", "Headingaccuracy", "Freekickaccuracy", "Penalties", "Volleys", "Standingtackle", "Marking", "Slidingtackle", "Gkdiving", "Gkpositioning", "Gkreflexes", "Gkkicking", "Gkhandling")
tabelle.fertig2
year <- tabelle.fertig2$Year
f3 <- function(x){
count3 <- 1
Year.of.Birth <- c()
for (i in 1:length(x)){
new.year <- floor(x[count3]/365+1582)
Year.of.Birth <- c(Year.of.Birth, new.year)
count3 <- count3+1
target.year <<- Year.of.Birth
}
print(target.year)
}
f3(year)
tabelle.fertig2$NewYear <- target.year
all.pos1 <- tabelle.fertig2$Pos1
all.pos2 <- tabelle.fertig2$Pos2
f4 <- function(x){
count4 <- 1
pos1 <- c()
for (i in 1:length(x)){
pos.item <- x[count4]
if (identical(pos.item, "0")){
pos1 <<- c(pos1, "TW")
count4 <- count4+1
}
else if (pos.item == 1){
pos1 <- c(pos1, "LIB")
count4 <- count4+1
}
else if (pos.item == 2){
pos1 <- c(pos1, "RAV")
count4 <- count4+1
}
else if (pos.item == 3){
pos1 <- c(pos1, "RV")
count4 <- count4+1
}
else if (pos.item == 4){
pos1 <- c(pos1, "RIV")
count4 <- count4+1
}
else if (pos.item == 5){
pos1 <- c(pos1, "IV")
count4 <- count4+1
}
else if (pos.item == 6){
pos1 <- c(pos1, "LIV")
count4 <- count4+1
}
else if (pos.item == 7){
pos1 <- c(pos1, "LV")
count4 <- count4+1
}
else if (pos.item == 8){
pos1 <- c(pos1, "LAV")
count4 <- count4+1
}
else if (pos.item == 9){
pos1 <- c(pos1, "RDM")
count4 <- count4+1
}
else if (pos.item == 10){
pos1 <- c(pos1, "ZDM")
count4 <- count4+1
}
else if (pos.item == 11){
pos1 <- c(pos1, "LDM")
count4 <- count4+1
}
else if (pos.item == 12){
pos1 <- c(pos1, "RM")
count4 <- count4+1
}
else if (pos.item == 13){
pos1 <- c(pos1, "RZM")
count4 <- count4+1
}
else if (pos.item == 14){
pos1 <- c(pos1, "ZM")
count4 <- count4+1
}
else if (pos.item == 15){
pos1 <- c(pos1, "LZM")
count4 <- count4+1
}
else if (pos.item == 16){
pos1 <- c(pos1, "LM")
count4 <- count4+1
}
else if (pos.item == 17){
pos1 <- c(pos1, "ROM")
count4 <- count4+1
}
else if (pos.item == 18){
pos1 <- c(pos1, "ZOM")
count4 <- count4+1
}
else if (pos.item == 19){
pos1 <- c(pos1, "LOM")
count4 <- count4+1
}
else if (pos.item == 20){
pos1 <- c(pos1, "RMS")
count4 <- count4+1
}
else if (pos.item == 21){
pos1 <- c(pos1, "MS")
count4 <- count4+1
}
else if (pos.item == 22){
pos1 <- c(pos1, "LMS")
count4 <- count4+1
}
else if (pos.item == 23){
pos1 <- c(pos1, "RF")
count4 <- count4+1
}
else if (pos.item == 24){
pos1 <- c(pos1, "RS")
count4 <- count4+1
}
else if (pos.item == 25){
pos1 <- c(pos1, "ST")
count4 <- count4+1
}
else if (pos.item == 26){
pos1 <- c(pos1, "LS")
count4 <- count4+1
}
else if (pos.item == 27){
pos1 <- c(pos1, "LF")
count4 <- count4+1
}
else if (pos.item == 28){
pos1 <- c(pos1, "Bank")
count4 <- count4+1
}
else if (pos.item == 29){
pos1 <- c(pos1, "Tribuene")
count4 <- count4+1
}
else if (pos.item == -1){
pos1 <- c(pos1, "xxx")
count4 <- count4+1
}
else{
pos1 <- c(pos1, "TW")
count4 <- count4+1
}
}
Pos.final <<-pos1
print(Pos.final)
}
f4(all.pos1)
tabelle.fertig2$Posi1 <- Pos.final
f4(all.pos2)
tabelle.fertig2$Posi2 <- Pos.final
tabelle.fertig2 <- tabelle.fertig2[, c("Index", "Posi1", "Posi2", "Team", "Lastname", "NewYear", "Height", "Weight", "Rating", "Potential", "Skill", "Contractend", "Foot", "Acc", "Speed", "Agility", "Strength","Stamina", "Jumping", "Balance", "Reactions", "Aggression", "Positioning", "Vision", "Dribbling", "Ballcontrol","Shortpassing", "Longpassing", "Crossing", "Shotpower", "Longshots", "Finishing", "Headingaccuracy", "Freekickaccuracy", "Penalties", "Volleys", "Standingtackle", "Marking", "Slidingtackle", "Gkdiving", "Gkpositioning", "Gkreflexes", "Gkkicking", "Gkhandling")]
colnames(tabelle.fertig2) <- c("Index", "Pos1", "Pos2", "Team", "Lastname", "Year", "Height", "Weight", "Rating", "Potential", "Skill", "Contractend", "Foot", "Acc", "Speed", "Agility", "Strength","Stamina", "Jumping", "Balance", "Reactions", "Aggression", "Positioning", "Vision", "Dribbling", "Ballcontrol","Shortpassing", "Longpassing", "Crossing", "Shotpower", "Longshots", "Finishing", "Headingaccuracy", "Freekickaccuracy", "Penalties", "Volleys", "Standingtackle", "Marking", "Slidingtackle", "Gkdiving", "Gkpositioning", "Gkreflexes", "Gkkicking", "Gkhandling")
write.table(tabelle.fertig2, Tabelle.komplett, sep="\t", fileEncoding="UTF-8", row.names = FALSE)