-
Notifications
You must be signed in to change notification settings - Fork 0
/
temporal_evaluation.R
43 lines (38 loc) · 1.53 KB
/
temporal_evaluation.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
target <- antequera
bfile = "baskets/antequera_baskets.txt"
#prep <- data.frame(ERROR = paste(antequera$ADDITIONAL_TEXT,gsub(" ","_",antequera$ADDITIONAL_INFOS),sep='#'))
prep <- data.frame(ERROR = target$ADDITIONAL_TEXT)
prep$ERROR <- as.factor(prep$ERROR)
prep$TYPE <- target$EVENT_TYPE
prep$sequenceID <- as.factor(target$DVNI_INSTALLATIONCODE)
prep$eventID <- as.factor(target$DVNS_ERRORTIME)
prep$eventID <- strptime(prep$eventID, "%Y-%m-%d %H:%M:%S")
prep$eventID <- as.numeric(prep$eventID)
prep$eventID <- prep$eventID - min(prep$eventID)
prep$eventID <- as.numeric(prep$eventID) %/% (60*60*24) #Pasamos de segundos a dias.
prep$eventID <- as.factor(prep$eventID)
get_triggers <- function(antecedent, testset) {
triggers <- testset[testset$event == antecedent[[1]], ]
triggers$event <- NULL
if (length(antecedent) == 1){
return(triggers)
}
#else, continue applying conditions to find triggers
for(i in 2:length(antecedent)){
triggersn <- testset[testset$event == antecedent[[i]], ]
triggersn$event <- NULL
triggers <- merge(triggers, triggersn, by=c("time","installation"))
}
return(triggers)
}
precision <- function(antecedent,consequent,testset,winmax,winmin=1) {
triggers <-get_triggers(antecedent,testset)
success = 0;
for(i in 1:nrow(triggers)){
ins <- triggers[i,]$installation
tim <- triggers[i,]$time
valid <- subset(testset, time >= tim+winmin & time <= tim+winmax & installation == ins & event == consequent[[1]])
success = success + (nrow(valid) >= 1)
}
return(success/nrow(triggers))
}