-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_functions.R
More file actions
63 lines (52 loc) · 1.98 KB
/
trigger_functions.R
File metadata and controls
63 lines (52 loc) · 1.98 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
source('validation.R')
graph_stats <- function() {
plot(autos_data$cars, type="l", col=plot_colors[1],
ylim=range(autos_data), axes=F, ann=T, xlab="Days",
ylab="Total", cex.lab=0.8, lwd=2)
lines(autos_data$trucks, type="l", lty=2, lwd=2,
col=plot_colors[2])
}
tabulate_stats <- function(target,rulefile,days=10) {
n_target <- normalize_and_group(target,days)
statdata <- expand_indexes(target,days)
statdata$numalarms <- 0
for(i in 1:nrow(statdata)) {
statdata$numalarms[i] <- numalarms(statdata$eventID[[i]], statdata$sequenceID[[i]], n_target)
}
return(statdata)
}
expand_indexes <- function(target, days = 1) {
sid <- as.factor(target$DVNI_INSTALLATIONCODE)
eid <- as.factor(target$DVNS_ERRORTIME)
eid <- strptime(eid, "%Y-%m-%d %H:%M:%S")
eid <- as.numeric(eid)
eid <- eid - min(eid)
eid <- as.numeric(eid) %/% (60*60*24*days) #Pasamos de segundos a dias.
maxday <- max(as.numeric(as.character(eid)))
days <- 0:maxday
seqs <- levels(factor(sid))
allindexes = expand.grid(days, seqs)
colnames(allindexes) <- c("eventID", "sequenceID")
return(allindexes)
}
normalize_and_group <- function(target,days = 10) {
prep <- data.frame(ERROR = target$ADDITIONAL_TEXT)
prep$ERROR <- as.factor(prep$ERROR)
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 <- prep[complete.cases(prep),]
prep$eventID <- prep$eventID - min(prep$eventID)
prep$eventID <- as.numeric(prep$eventID) %/% (60*60*24*days) #Pasamos de segundos a dias.
prep$eventID <- as.numeric(as.character(prep$eventID))
prep <- prep[order(prep$eventID, prep$sequenceID), ]
prep <- prep[!duplicated(prep),]
rownames(prep) <- NULL
return(prep)
}
numalarms <- function(eid, sid, n_target) {
sub <- n_target[n_target$eventID == eid & n_target$sequenceID == sid,]
num <- nrow(sub)
return(num)
}