-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep_narr_diar.R
executable file
·51 lines (47 loc) · 1.63 KB
/
prep_narr_diar.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
###########################Script for preparing narration for Diarrhée ##############
cat("calculate percentile rank for diarrhée...")
dist= percentile_diar_alerte[name==k & is.na(occurence)==F,get("occurence")]
myranks_diar=array()
p=1-1
while ( (pos_j+p)<=length(mycode) & p!=11-1 )
{
myranks_diar[p+1]=perc_rank( dist,
percentile_diar_alerte[code==mycode[pos_j+p] & name==k,get("occurence")] )
p=p+1
}
#Handle alerts duration > 10 weeks for diarrhée
myranks_diar_additionnal=array(); myindex=1
alpha=11-1
if ( (pos_j+alpha)<length(mycode) )
{
tmp= perc_rank(dist, percentile_diar_alerte[code==mycode[pos_j+alpha] & name==k,get("occurence")])
tmp= ifelse (is.na(tmp)== T || length(tmp)==0,0,tmp)
while ( tmp>=90 & (pos_j+alpha)<length(mycode) )
{
cat(k,'has reached the threshold at',alpha,'th week','with a rank:',tmp,'\n')
myranks_diar_additionnal[myindex]=tmp
myindex = myindex + 1
alpha = alpha+1
tmp= perc_rank(dist, percentile_diar_alerte[code==mycode[pos_j+alpha] & name==k,get("occurence")])
tmp= ifelse (is.na(tmp)== T || length(tmp)==0,0,tmp)
}
}
#append if non vide:
if ( length(myranks_diar_additionnal)>1)
{
myranks_diar=c(myranks_diar,myranks_diar_additionnal)
}
#
tmp=myranks_diar
tmp[is.na(tmp)==T]=0
mylength_diar=length(myranks_diar)
while( all(tmp>=90) == F & length(tmp)!=3 )
{
#remove last value of myranks
tmp=tmp[-length(tmp)]
mylength_diar=mylength_diar-1
}
cat('DONE\n')
# Effective Duration of the alert:
mylength_diar=1-1+length(percentile_diar_alerte[alert_status=="alert" & name==k & code %in% mycode[(pos_j):(pos_j+mylength_diar-1)],alert_status])
#