rm(list=ls())

library(rapportools)

setwd("~/Dropbox/Congressi/sis2014/libro-abstracts/boa/allpapers/")
rs=read.table(file="../../../gestione-submissions/subrep/report.csv",header=TRUE,sep=",",quote="\"")
ids=rs$Title%in%c("","--","federico.rotolo@gustaveroussy.fr")
rs=rs[!ids,]
# Remove Archived
rs=rs[rs$Status!="Archived",]
rs$Title=as.character(rs$Title)

res=NULL
for(i in 1:nrow(rs)){
  tt=agrep(pattern=rs$Title[i],x=rs$Title,ignore.case=TRUE)
  if(length(tt)>1) res=rbind(res,tt)
}

res=res[order(res[,1]),]
res=res[seq(1,nrow(res),by=2),]
rs=rs[-res[,1],]

idnecessarie=rs$Submission.ID
n=nrow(rs)
esistente=rep(FALSE,n)
for(f in dir()){
  nome=unlist(strsplit(f,".",fixed=TRUE))
  nome[1]=substr(nome[1],1,4)
  esistente[idnecessarie==nome[1]]=TRUE
  nome=paste(nome,collapse=".")
  file.rename(f,nome)
}

idnecessarie[!esistente]

file.presenti=as.numeric(substr(dir(),1,4))
file.presenti=file.presenti[!is.na(file.presenti)]
file.presenti[which(!(file.presenti%in%idnecessarie))]

tab=table(file.presenti)
tab[tab>1]

