annotate BilanEnrichiPF.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 f2p <- function(x) #get date-time data from recording file names
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
6 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
7 if (is.data.frame((x)[1])) {pretemps <- vector(length = nrow(x))}
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
8 op <- options(digits.secs = 3)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
9 pretemps <- paste(substr(x, nchar(x) - 18, nchar(x)-4), ".", substr(x, nchar(x) - 2, nchar(x)), sep = "")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
10 strptime(pretemps, "%Y%m%d_%H%M%OS",tz="UTC")-7200
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
11 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
12
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
13 args <- commandArgs(trailingOnly = TRUE)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
14 #print(args)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
15 EchelleErreur=c("","POSSIBLE","PROBABLE","SUR")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
16 EchelleNumErreur=c(99,50,10,1)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
17
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
18 #for test
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
19 #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
20 #for (i in 1:length(inputest))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
21 #{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
22 # args=c(inputest[i],"refPF.csv","SpeciesList.csv")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
23
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
24
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
25 IdC2=fread(args[1])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
26 refPF=fread(args[2])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
27 GroupList=fread(args[3])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
28
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
29 if(substr(IdC2$`nom du fichier`[1],2,2)!="a")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
30 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
31 print("Protocole non conforme, ce script doit etre lance pour un protocole Point Fixe")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
32 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
33
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
34
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
35 #compute error risk by species (minimum error among files)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
36 #to be replaced by glm outputs if I'll have time
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
37 RisqueErreurT=aggregate(IdC2$IdProb,by=list(IdC2$IdExtrap),FUN=function(x) ceiling((1-max(x-0.0001))*100))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
38 barplot(RisqueErreurT$x,names.arg=RisqueErreurT$Group.1,las=2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
39 #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
40 RisqueErreurOV0=match(IdC2$ConfV,EchelleErreur)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
41 RisqueErreurOV=aggregate(RisqueErreurOV0,by=list(IdC2$IdExtrap)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
42 ,FUN=max)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
43 RisqueErreurOV2=EchelleNumErreur[RisqueErreurOV$x]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
44 #compute minimum error risk between man and machine
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
45 RisqueErreur=pmin(RisqueErreurT$x,RisqueErreurOV2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
46
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
47 #compute number of files validated per species
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
48 FichValid=aggregate(IdC2$IdV,by=list(IdC2$IdExtrap,IdC2$'nom du fichier')
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
49 ,FUN=function(x) sum(x!=""))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
50 NbValid2=aggregate(FichValid$x,by=list(FichValid$Group.1),FUN=function(x) sum(x>0))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
51
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
52 DiffC50=vector() # to store the median of confidence difference between unvalidated records and validated ones
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
53 DiffT50=vector() # to store the median of time difference between unvalidated records and validated ones
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
54 for (j in 1:nlevels(as.factor(IdC2$IdExtrap)))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
55 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
56 IdSp=subset(IdC2
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
57 ,IdC2$IdExtrap==levels(as.factor(IdC2$IdExtrap))[j])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
58 IdSp=IdSp[order(IdSp$IdProb),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
59 IdSpV=subset(IdSp,IdSp$IdV!="")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
60 if(nrow(IdSpV)>0)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
61 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
62 cuts <- c(-Inf, IdSpV$IdProb[-1]-diff(IdSpV$IdProb)/2, Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
63 CorrC=findInterval(IdSp$IdProb, cuts)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
64 CorrC2=IdSpV$IdProb[CorrC]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
65 DiffC=abs(IdSp$IdProb-CorrC2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
66 DiffC50=c(DiffC50,median(DiffC))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
67
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
68 IdSp=IdSp[order(IdSp$TimeNum),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
69 IdSpV=subset(IdSp,IdSp$IdV!="")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
70 cuts <- c(-Inf, IdSpV$TimeNum[-1]-diff(IdSpV$TimeNum)/2, Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
71 CorrT=findInterval(IdSp$TimeNum, cuts)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
72 CorrT2=IdSpV$TimeNum[CorrT]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
73 DiffT=abs(IdSp$TimeNum-CorrT2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
74 DiffT50=c(DiffT50,median(DiffT))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
75 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
76 DiffC50=c(DiffC50,Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
77 DiffT50=c(DiffT50,Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
78 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
79 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
80 #compute an index of validation effort per species
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
81 EffortV=1/DiffC50/DiffT50
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
82 EffortClass=(EffortV>0.0005)+(EffortV>0.005)+RisqueErreurOV$x
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
83 cbind(RisqueErreurOV,EffortV,DiffC50,DiffT50)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
84 barplot(EffortClass-1,names.arg=NbValid2$Group.1,las=2)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
85 ClassEffortV=c("-","FAIBLE","SUFFISANT","SUFFISANT","FORT","FORT")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
86 EffortClassMot=ClassEffortV[EffortClass]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
87
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
88
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
89 #get date-night
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
90 pourDateNuit=IdC2$TimeNum-12*3600 #bricolage-decalage de 12 heures pour ramener a la date du debut de nuit
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
91 DateNuit=as.Date.POSIXct(pourDateNuit) # date of the beginning of the night
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
92 DateJour=as.Date.POSIXct(IdC2$TimeNum) # date (UTC+0)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
93 IdC2$DateNuit=DateNuit
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
94 IdC2$DateJour=DateJour
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
95 NbNuit=as.numeric(max(IdC2$DateNuit)-min(IdC2$DateNuit))+1
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
96
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
97 #compare activity / reference frame
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
98 ActMoy=aggregate(IdC2$`nom du fichier`
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
99 ,by=list(IdC2$IdExtrap),FUN=function(x) length(x)/NbNuit)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
100 ListSpref=match(ActMoy$Group.1,refPF$Espece)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
101 Subref=refPF[ListSpref]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
102 QualifAct=vector()
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
103 for (k in 1:nrow(ActMoy))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
104 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
105 if(is.na(Subref$Q25[k]))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
106 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
107 QualifAct=c(QualifAct,NA)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
108 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
109 cuts=cbind(-Inf,as.numeric(Subref$Q25[k]),as.numeric(Subref$Q75[k])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
110 ,as.numeric(Subref$Q98[k]),Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
111
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
112 QualifAct=c(QualifAct,findInterval(ActMoy$x[k],cuts,left.open=T))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
113 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
114 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
115 ClassAct=c("FAIBLE","MODEREE","FORTE","TRES FORTE")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
116 QualifActMot=ClassAct[QualifAct]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
117
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
118 #compute activity by nights (to be completed)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
119 #ActNuit=aggregate(IdC2$`nom du fichier`,by=list(IdC2$DateNuit,IdC2$IdExtrap),FUN=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
120
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
121 #organize the csv summary
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
122 SummPart0=cbind(Esp=levels(as.factor(IdC2$IdExtrap))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
123 ,RisqueErreur,NbValid=NbValid2$x,EffortValid=EffortClassMot
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
124 ,Contacts_Nuit=round(ActMoy$x),Niveau_Activite=QualifActMot)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
125
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
126
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
127 InfoSp=c("GroupFR","NomFR","Scientific name","Esp")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
128 GroupShort=GroupList[,InfoSp,with=FALSE]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
129 #GroupShort=GroupList[,..InfoSp]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
130 SummPart=merge(GroupShort,SummPart0,by="Esp")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
131 IndexGroupe=c("Autre","Sauterelle","Chauve-souris")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
132 SummPart$IndexSumm=match(SummPart$GroupFR,IndexGroupe)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
133 SummPart=SummPart[with(SummPart
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
134 ,order(IndexSumm,as.numeric(Contacts_Nuit),decreasing=T)),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
135 colnames(SummPart)=c("Code","Groupe","Nom francais","Nom scientifique"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
136 ,"Risque d'erreur (%)","Nb Validations"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
137 ,"Effort de validation","Nb de Contacts par Nuit"
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
138 ,"Niveau d'Activite","TriGroupe")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
139
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
140 #to do: extend colors to other columns to improve readability
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
141 SummHTML=datatable(SummPart, rownames = FALSE) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
142 formatStyle(columns = c("Code","Groupe","Nom francais","Nom scientifique","Risque d'erreur (%)"),valueColumns="Risque d'erreur (%)",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
143 background = styleInterval(c(1, 10, 50), c("white", "khaki", "orange", "orangered"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
144 formatStyle(columns = "Effort de validation",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
145 background = styleEqual(c("-","FAIBLE","SUFFISANT","FORT"), c("white", "cyan", "royalblue", "darkblue"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
146 formatStyle(columns = c("Nb de Contacts par Nuit","Niveau d'Activite"),valueColumns="Niveau d'Activite",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
147 background = styleEqual(c("FAIBLE","MODEREE","FORTE","TRES FORTE"), c("palegoldenrod", "greenyellow", "limegreen", "darkgreen")))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
148
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
149 saveWidget(SummHTML,"output-summary.html")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
150 write.table(SummPart,"output-summary.tabular",sep="\t",row.names=F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
151
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
152 #compute number of files validated per night/hour
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
153 IdC2$Heure=sapply(IdC2$`nom du fichier`,FUN=function(x) substr(x,nchar(x)-9,nchar(x)-8))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
154
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
155 ActNuit=aggregate(IdC2$`nom du fichier`,by=list(IdC2$IdExtrap,IdC2$Session),FUN=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
156 ListSpref=match(ActNuit$Group.1,refPF$Espece)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
157 Subref=refPF[ListSpref]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
158
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
159
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
160 QualifActN=vector()
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
161 for (k in 1:nrow(ActNuit))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
162 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
163 if(is.na(Subref$Q25[k]))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
164 {
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
165 QualifActN=c(QualifActN,NA)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
166 }else{
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
167 cuts=cbind(-Inf,as.numeric(Subref$Q25[k]),as.numeric(Subref$Q75[k])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
168 ,as.numeric(Subref$Q98[k]),Inf)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
169
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
170 QualifActN=c(QualifActN,findInterval(ActNuit$x[k],cuts,left.open=T))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
171 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
172 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
173 ActNuit$QualifActN=QualifActN
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
174
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
175 ActNuitT=dcast(data=ActNuit,formula=Group.1~Group.2
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
176 ,value.var="x")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
177 ActNuitT[is.na(ActNuitT)]=0
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
178 RefNuitT=dcast(data=ActNuit,formula=Group.1~Group.2
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
179 ,value.var="QualifActN")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
180 ARNuit=merge(ActNuitT,RefNuitT,by="Group.1")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
181
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
182 SummPartshort=cbind(SummPart[,c(1:5)],TriGroupe=SummPart[,TriGroupe])
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
183 SummPartN=merge(SummPartshort,ARNuit,by.x="Code",by.y="Group.1")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
184 SummPartN=SummPartN[order(TriGroupe,decreasing=T),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
185
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
186 test=grepl(".x",colnames(SummPartN))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
187 colnames(SummPartN)=mapply(FUN=function(x,y) if(y){substr(x,1,2)}else{x}
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
188 ,colnames(SummPartN),test)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
189 ListNuit=subset(colnames(SummPartN),test)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
190 ListRef=subset(colnames(SummPartN),grepl(".y",colnames(SummPartN)))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
191 testHide=match(ListRef,colnames(SummPartN))-1
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
192 #to do: extend colors to other columns to improve readability
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
193 SummHTMLN=datatable(SummPartN, rownames = FALSE,options = list(
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
194 columnDefs = list(list(targets = testHide,visible = FALSE)))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
195 formatStyle(columns = c("Code","Groupe","Nom francais","Nom scientifique","Risque d'erreur (%)"),valueColumns="Risque d'erreur (%)",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
196 background = styleInterval(c(1, 10, 50), c("white", "khaki", "orange", "orangered"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
197 formatStyle(columns = ListNuit,valueColumns=ListRef,
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
198 background = styleEqual(c(1,2,3,4), c("palegoldenrod", "greenyellow", "limegreen", "darkgreen")))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
199
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
200 saveWidget(SummHTMLN,"output-nightly.html")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
201 write.table(SummPartN,"output-nightly.tabular",sep="\t",row.names=F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
202
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
203
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
204 #summary by hour
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
205 ActMoyH=dcast(data=IdC2,formula=IdExtrap~Heure
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
206 ,fun.aggregate=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
207 ActMoyHA=aggregate(IdC2$`nom du fichier`
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
208 ,by=list(IdC2$IdExtrap,IdC2$Heure)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
209 ,FUN=length)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
210
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
211 test=(as.numeric(colnames(ActMoyH))>12)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
212 ColDebut=subset(colnames(ActMoyH),test)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
213 ColFin=subset(colnames(ActMoyH),test==F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
214 ListH=c(ColDebut,ColFin)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
215 neworder=c("IdExtrap",ColDebut,ColFin)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
216 ActMoyH=ActMoyH[,..neworder]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
217
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
218 SummPartH=merge(SummPartshort,ActMoyH,by.x="Code",by.y="IdExtrap")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
219 SummPartH=SummPartH[order(TriGroupe,decreasing=T),]
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
220
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
221
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
222 brks <- quantile(ActMoyHA$x, probs = seq(.05, .95, .05), na.rm = TRUE)-1
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
223 clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
224 {paste0("rgb(255,", ., ",", ., ")")}
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
225
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
226
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
227 SummHTMLH=datatable(SummPartH, rownames = FALSE) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
228 formatStyle(columns = c("Code","Groupe","Nom francais","Nom scientifique","Risque d'erreur (%)"),valueColumns="Risque d'erreur (%)",
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
229 background = styleInterval(c(1, 10, 50), c("white", "khaki", "orange", "orangered"))) %>%
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
230 formatStyle(columns=ListH, backgroundColor = styleInterval(brks, clrs))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
231
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
232 saveWidget(SummHTMLH,"output-hourly.html")
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
233 write.table(SummPartH,"output-hourly.tabular",sep="\t",row.names=F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
234
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
235
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
236 #saveWidget(SummHTML,paste0(substr(args[1],1,nchar(args[1])-9),"-summary.html"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
237 #write.table(SummPart,paste0(substr(args[1],1,nchar(args[1])-9),"-summary.csv"),sep="\t",row.names=F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
238 #saveWidget(SummHTMLN,paste0(substr(args[1],1,nchar(args[1])-9),"-nightly.html"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
239 #write.table(SummPartN,paste0(substr(args[1],1,nchar(args[1])-9),"-nightly.csv"),sep="\t",row.names=F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
240 #saveWidget(SummHTMLH,paste0(substr(args[1],1,nchar(args[1])-9),"-hourly.html"))
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
241 #write.table(SummPartH,paste0(substr(args[1],1,nchar(args[1])-9),"-hourly.csv"),sep="\t",row.names=F)
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
242
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
243
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
244 }
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
245
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
246
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
247
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
248
0e3db3a308c0 Uploaded
mnhn65mo
parents:
diff changeset
249