-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadFromExcel.R
58 lines (47 loc) · 1.78 KB
/
readFromExcel.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
rm(list=ls())
#####add new data from excel
library(rdrop2)
setwd('C:/Users/AGIRIBET/Desktop/shinyApp')
drop_auth(rdstoken = "droptoken.rds")
loadDropbox<-source('functions/loaddropbox.R',local=T)$value
saveDropbox<-source('functions/savedropbox.R',local=T)$value
fuzzyLogic<-source('functions/fuzzylogic.R',local=T)$value
dataDropbox<-loadDropbox()
fuzzyMatches<-dataDropbox[[1]]
fuzzyData<-dataDropbox[[2]]
Results<-dataDropbox[[4]]
rm(dataDropbox,loadDropbox)
#players
newstats<-read.delim('clipboard',header=F) #h2h is last, confidence before this. dots as decimals
plays<-as.vector(t(read.delim('clipboard',header=F))) #players
matchId<-rep(paste('Ind', (nrow(fuzzyData)/2)+1:(nrow(newstats)/2),sep=''),each=2)
newstats<-data.frame(matchId,plays,newstats)
colnames(newstats)<-colnames(fuzzyData)
fuzzyData<-rbind(fuzzyData,newstats)
#matches
matchId<-paste('Ind', (nrow(fuzzyMatches)+1):((nrow(fuzzyMatches))+length(plays)/2),sep='')
tourn<-rep(fuzzyMatches$Tournament[1],length(matchId))
date<-rep(fuzzyMatches$Date[nrow(fuzzyMatches)]+lubridate::days(1),length(matchId))
p1<-plays[seq(1,length(plays),2)]
p2<-plays[seq(2,length(plays),2)]
m<-data.frame(matchId, tourn, date, p1, p2)
colnames(m)<-colnames(fuzzyMatches)
fuzzyMatches<-rbind(fuzzyMatches,m)
#probs
fuzzyProbs<-fuzzyLogic(fuzzyData)
#Results
res<-read.delim('clipboard',header=F) #copiar col1 nom, col2 nsets, col3 difjocs
res<-cbind(matchId,res)
won<-rep(0,nrow(res))
if(sum(as.character(res$V1) == as.character(m$Player1))>0){
won[which(as.character(res$V1) == as.character(m$Player1))]<-1
}
res$V1<-won
if(sum(res$V1!=1)>0){
res$V3[which(res$V1!=1)]<-res$V3[which(res$V1!=1)]*(-1)
}
res$V4<-'Finished'
colnames(res)<-colnames(Results)
Results<-rbind(Results,res)
#save on dropbox
saveDropbox(fuzzyMatches, fuzzyData, fuzzyProbs, Results)