annotate BilanEnrichiRP.R @ 0:0e3db3a308c0 draft default tip

Uploaded
author mnhn65mo
date Mon, 06 Aug 2018 09:13:29 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
1 library(data.table)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
2 library(DT)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
3 library(htmlwidgets)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
4
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
5 args <- commandArgs(trailingOnly = TRUE)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
6 #print(args)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
7 EchelleErreur=c("","POSSIBLE","PROBABLE","SUR")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
8 EchelleNumErreur=c(99,50,10,1)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
9
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
10 #for test
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
11 #inputest=list.files("C:/Users/Yves Bas/Documents/GitHub/65MO_Galaxy-E/raw_scripts/Vigie-Chiro/output_IdValid_input_BilanEnrichi/",pattern="IdC2.csv",full.names=T)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
12 #for (i in 1:length(inputest))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
13 #{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
14 # args=c(inputest[i],"refRPSeuil50.csv","SpeciesList.csv")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
15
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
16 IdC2=fread(args[1])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
17 refRP=fread(args[2])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
18 GroupList=fread(args[3])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
19
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
20
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
21 if(substr(IdC2$`nom du fichier`[1],2,2)!="i")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
22 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
23 print("Protocole non conforme, ce script doit etre lance pour un protocole Routier ou Pedestre")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
24 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
25
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
26 Routier=grepl("-",substr(IdC2$`nom du fichier`[1],4,7))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
27 #compute error risk by species (minimum error among files)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
28 #to be replaced by glm outputs if I'll have time
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
29 RisqueErreurT=aggregate(IdC2$IdProb,by=list(IdC2$IdExtrap),FUN=function(x) ceiling((1-max(x-0.0001))*100))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
30 barplot(RisqueErreurT$x,names.arg=RisqueErreurT$Group.1,las=2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
31 #compute error risk accoring to observer/validator (a little dirty because it relies on alphabetical order of confidence classes: POSSIBLE < PROBABLE < SUR)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
32 RisqueErreurOV0=match(IdC2$ConfV,EchelleErreur)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
33 RisqueErreurOV=aggregate(RisqueErreurOV0,by=list(IdC2$IdExtrap)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
34 ,FUN=max)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
35 RisqueErreurOV2=EchelleNumErreur[RisqueErreurOV$x]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
36 #compute minimum error risk between man and machine
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
37 RisqueErreur=pmin(RisqueErreurT$x,RisqueErreurOV2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
38
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
39 #compute number of files validated per species
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
40 FichValid=aggregate(IdC2$IdV,by=list(IdC2$IdExtrap,IdC2$'nom du fichier')
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
41 ,FUN=function(x) sum(x!=""))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
42 NbValid2=aggregate(FichValid$x,by=list(FichValid$Group.1),FUN=function(x) sum(x>0))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
43
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
44 DiffC50=vector() # to store the median of confidence difference between unvalidated records and validated ones
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
45 DiffT50=vector() # to store the median of time difference between unvalidated records and validated ones
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
46 for (j in 1:nlevels(as.factor(IdC2$IdExtrap)))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
47 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
48 IdSp=subset(IdC2
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
49 ,IdC2$IdExtrap==levels(as.factor(IdC2$IdExtrap))[j])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
50 IdSp$IdProb[is.na(IdSp$IdProb)]=0
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
51 IdSp=IdSp[order(IdSp$IdProb),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
52 IdSpV=subset(IdSp,IdSp$IdV!="")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
53 if(nrow(IdSpV)>0)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
54 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
55 cuts <- c(-Inf, IdSpV$IdProb[-1]-diff(IdSpV$IdProb)/2, Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
56 CorrC=findInterval(IdSp$IdProb, cuts)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
57 CorrC2=IdSpV$IdProb[CorrC]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
58 DiffC=abs(IdSp$IdProb-CorrC2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
59 DiffC50=c(DiffC50,median(DiffC))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
60
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
61 IdSp=IdSp[order(IdSp$TimeNum),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
62 IdSpV=subset(IdSp,IdSp$IdV!="")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
63 cuts <- c(-Inf, IdSpV$TimeNum[-1]-diff(IdSpV$TimeNum)/2, Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
64 CorrT=findInterval(IdSp$TimeNum, cuts)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
65 CorrT2=IdSpV$TimeNum[CorrT]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
66 DiffT=abs(IdSp$TimeNum-CorrT2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
67 DiffT50=c(DiffT50,median(DiffT))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
68 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
69 DiffC50=c(DiffC50,Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
70 DiffT50=c(DiffT50,Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
71 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
72 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
73 #compute an index of validation effort per species
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
74 EffortV=1/DiffC50/DiffT50
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
75 EffortClass=(EffortV>0.0005)+(EffortV>0.005)+RisqueErreurOV$x
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
76 #cbind(RisqueErreurOV,EffortV,DiffC50,DiffT50)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
77 barplot(EffortClass-1,names.arg=NbValid2$Group.1,las=2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
78 ClassEffortV=c("-","FAIBLE","SUFFISANT","SUFFISANT","FORT","FORT")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
79 EffortClassMot=ClassEffortV[EffortClass]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
80
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
81
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
82 #compare activity / reference frame
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
83 FileInfo=as.data.table(tstrsplit(IdC2$`nom du fichier`,"-"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
84 IdC2$Tron=FileInfo$V4
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
85
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
86 MicTempsInfo=as.data.table(tstrsplit(as.data.frame(FileInfo)[,(ncol(FileInfo))],"_"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
87 MicDroit=(as.data.frame(MicTempsInfo)[,(ncol(MicTempsInfo)-2)]=="1")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
88 IdC2$MicDroit=MicDroit
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
89
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
90 testTempsFin=aggregate(IdC2$temps_fin,by=list(MicDroit),FUN=max)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
91 testTempsFin$Direct=(testTempsFin$x>0.5)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
92 testTF2=sum((testTempsFin$x>0.5))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
93 if(testTF2>1){stop("Probleme stereo : les 2 canaux semblent etre en enregistrement direct")}
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
94 IdC2M=merge(IdC2,testTempsFin,by.x="MicDroit",by.y="Group.1")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
95
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
96 ActMoy=aggregate(IdC2$`nom du fichier`
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
97 ,by=list(IdC2M$IdExtrap,IdC2M$Direct),FUN=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
98 ListSpref=match(levels(as.factor(ActMoy$Group.1)),refRP$Espece)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
99 Subref=refRP[ListSpref]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
100 if(Routier)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
101 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
102 Subref=Subref[,c(1:17)]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
103 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
104 Subref=Subref[,c(1,18:33)]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
105 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
106 QualifActE=vector()
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
107 QualifActD=vector()
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
108
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
109 for (k in 1:nlevels(as.factor(ActMoy$Group.1)))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
110 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
111 Actsub=subset(ActMoy,ActMoy$Group.1==levels(as.factor(ActMoy$Group.1))[k])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
112 if(is.na(Subref[k,2]))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
113 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
114 QualifActE=c(QualifActE,NA)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
115 QualifActD=c(QualifActD,NA)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
116 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
117 ActE=subset(Actsub,Actsub$Group.2==F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
118 if(nrow(ActE)==0)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
119 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
120 QualifActE=c(QualifActE,NA)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
121
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
122 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
123 cuts=cbind(-Inf,as.numeric(Subref[k,6]),as.numeric(Subref[k,7])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
124 ,as.numeric(Subref[k,8]),Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
125 QualifActE=c(QualifActE,findInterval(ActE$x,cuts,left.open=T))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
126 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
127 ActD=subset(Actsub,Actsub$Group.2==T)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
128 if(nrow(ActD)==0)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
129 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
130 QualifActD=c(QualifActD,NA)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
131
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
132 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
133 cuts=cbind(-Inf,as.numeric(Subref[k,14]),as.numeric(Subref[k,15])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
134 ,as.numeric(Subref[k,16]),Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
135 QualifActD=c(QualifActD,findInterval(ActD$x,cuts,left.open=T))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
136 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
137
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
138 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
139 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
140 ClassAct=c("FAIBLE","MODEREE","FORTE","TRES FORTE")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
141 QualifActMotE=ClassAct[QualifActE]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
142 QualifActMotD=ClassAct[QualifActD]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
143
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
144 #compute activity by nights (to be completed)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
145 #ActNuit=aggregate(IdC2M$`nom du fichier`,by=list(IdC2M$DateNuit,IdC2M$IdExtrap),FUN=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
146 ActED=dcast(data=ActMoy,formula=Group.1~Group.2,value=x)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
147 ActED[is.na(ActED)]=0
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
148 #organize the csv summary
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
149 SummPart0=cbind(Esp=levels(as.factor(IdC2M$IdExtrap))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
150 ,RisqueErreur,NbValid=NbValid2$x,EffortValid=EffortClassMot)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
151
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
152 test=match("FALSE",colnames(ActED))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
153 if(is.na(test)==F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
154 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
155 SummPart0=cbind(SummPart0,Contacts_Expansion=ActED$'FALSE'
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
156 ,Niveau_Activite_Expansion=QualifActMotE)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
157 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
158 SummPart0=cbind(SummPart0,Contacts_Expansion=""
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
159 ,Niveau_Activite_Expansion="")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
160 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
161 test=match("TRUE",colnames(ActED))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
162 if(is.na(test)==F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
163 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
164
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
165 SummPart0=cbind(SummPart0,Contacts_Direct=ActED$'TRUE'
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
166 ,Niveau_Activite_Direct=QualifActMotD)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
167 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
168 SummPart0=cbind(SummPart0,Contacts_Direct=""
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
169 ,Niveau_Activite_Direct="")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
170 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
171
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
172 InfoSp=c("GroupFR","NomFR","Scientific name","Esp")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
173 GroupShort=GroupList[,..InfoSp]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
174 SummPart=merge(GroupShort,SummPart0,by="Esp")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
175 IndexGroupe=c("Autre","Sauterelle","Chauve-souris")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
176 SummPart$IndexSumm=match(SummPart$GroupFR,IndexGroupe)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
177 SummPart=SummPart[with(SummPart
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
178 ,order(IndexSumm,as.numeric(Contacts_Direct),as.numeric(Contacts_Expansion),decreasing=T)),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
179 colnames(SummPart)=c("Code","Groupe","Nom francais","Nom scientifique"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
180 ,"Risque d'erreur (%)","Nb Validations"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
181 ,"Effort de validation","Nb de Contacts en expansion"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
182 ,"Niveau d'Activite en expansion"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
183 ,"Nb de Contacts en direct"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
184 ,"Niveau d'Activite en direct","TriGroupe")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
185
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
186 #to do: extend colors to other columns to improve readability
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
187 SummHTML=datatable(SummPart, rownames = FALSE) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
188 formatStyle(columns = c("Code","Groupe","Nom francais","Nom scientifique","Risque d'erreur (%)"),valueColumns="Risque d'erreur (%)",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
189 background = styleInterval(c(1, 10, 50), c("white", "khaki", "orange", "orangered"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
190 formatStyle(columns = "Effort de validation",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
191 background = styleEqual(c("-","FAIBLE","SUFFISANT","FORT"), c("white", "cyan", "royalblue", "darkblue"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
192 formatStyle(columns = c("Nb de Contacts en expansion","Niveau d'Activite en expansion"),valueColumns="Niveau d'Activite en expansion",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
193 background = styleEqual(c("FAIBLE","MODEREE","FORTE","TRES FORTE"), c("palegoldenrod", "greenyellow", "limegreen", "darkgreen"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
194 formatStyle(columns = c("Nb de Contacts en direct","Niveau d'Activite en direct"),valueColumns="Niveau d'Activite en direct",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
195 background = styleEqual(c("FAIBLE","MODEREE","FORTE","TRES FORTE"), c("palegoldenrod", "greenyellow", "limegreen", "darkgreen")))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
196
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
197
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
198 saveWidget(SummHTML,"output-summaryRP.html")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
199 write.table(SummPart,"output-summaryRP.tabular",row.names=F,sep="\t")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
200
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
201 #summary for each point/transect
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
202
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
203 #compute number of files validated per species
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
204 IdC2M$Canal=sapply(IdC2M$Direct,FUN=function(x) if(x){"Direct"}else{"Expansion"})
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
205
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
206 ActMoyTA=aggregate(IdC2M$`nom du fichier`,by=list(IdC2M$IdExtrap,IdC2M$Canal,IdC2M$Session),FUN=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
207 ActMoyT=dcast(data=IdC2M,formula=IdExtrap+Canal~Session
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
208 ,fun.aggregate=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
209 SummPartshort=cbind(SummPart[,c(1:5)],TriGroupe=SummPart[,TriGroupe])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
210 SummPartTron=merge(SummPartshort,ActMoyT,by.x="Code",by.y="IdExtrap")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
211 SummPartTron=SummPartTron[order(TriGroupe,decreasing=T),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
212
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
213 ListSession=levels(as.factor(IdC2M$Session))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
214 brks <- quantile(ActMoyTA$x, probs = seq(.05, .95, .05), na.rm = TRUE)-1
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
215 clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
216 {paste0("rgb(255,", ., ",", ., ")")}
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
217
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
218
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
219 #to do: extend colors to other columns to improve readability
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
220 SummHTMLT=datatable(SummPartTron, rownames = FALSE) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
221 formatStyle(columns = c("Code","Groupe","Nom francais","Nom scientifique","Risque d'erreur (%)"),valueColumns="Risque d'erreur (%)",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
222 background = styleInterval(c(1, 10, 50), c("white", "khaki", "orange", "orangered"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
223 formatStyle(columns=ListSession, backgroundColor = styleInterval(brks, clrs))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
224
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
225 saveWidget(SummHTMLT,"output-detailRP.html")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
226 write.table(SummPartTron,"output-detailRP.tabular",row.names=F,sep="\t")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
227
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
228 #saveWidget(SummHTML,paste0(substr(args[1],1,nchar(args[1])-9),"-summary.html"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
229 #write.table(SummPart,paste0(substr(args[1],1,nchar(args[1])-9),"-summary.csv"),row.names=F,sep="\t")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
230 #saveWidget(SummHTMLT,paste0(substr(args[1],1,nchar(args[1])-9),"-detail.html"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
231 #write.table(SummPartTron,paste0(substr(args[1],1,nchar(args[1])-9),"-detail.csv"),row.names=F,sep="\t")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
232
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
233
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
234
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
235 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
236
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
237
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
238