Add min, max, std, and mode to calls metrics

replace/04c233103a0395372f7e3fa085d6005dd8633bc4
JulioV 2019-11-11 15:15:20 -05:00
parent b16702561c
commit 1d242abbe1
2 changed files with 11 additions and 2 deletions

View File

@ -37,8 +37,8 @@ CALLS:
TYPES: [missed, incoming, outgoing]
METRICS:
missed: [count, distinctcontacts]
incoming: [count, distinctcontacts, meanduration, sumduration, hubermduration, varqnduration, entropyduration]
outgoing: [count, distinctcontacts, meanduration, sumduration, hubermduration, varqnduration, entropyduration]
incoming: [count, distinctcontacts, meanduration, sumduration, minduration, maxduration, stdduration, modeduration, hubermduration, varqnduration, entropyduration]
outgoing: [count, distinctcontacts, meanduration, sumduration, minduration, maxduration, stdduration, modeduration, hubermduration, varqnduration, entropyduration]
DAY_SEGMENTS: *day_segments
PHONE_VALID_SENSED_DAYS:

View File

@ -11,6 +11,11 @@ filter_by_day_segment <- function(data, day_segment) {
return(data %>% group_by(local_date))
}
Mode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
compute_call_feature <- function(calls, metric, day_segment){
calls <- calls %>% filter_by_day_segment(day_segment)
feature <- switch(metric,
@ -18,6 +23,10 @@ compute_call_feature <- function(calls, metric, day_segment){
"distinctcontacts" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := n_distinct(trace)),
"meanduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := mean(call_duration)),
"sumduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := sum(call_duration)),
"minduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := min(call_duration)),
"maxduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := max(call_duration)),
"stdduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := sd(call_duration)),
"modeduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := Mode(call_duration)),
"hubermduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := huberM(call_duration)$mu),
"varqnduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := Qn(call_duration)),
"entropyduration" = calls %>% summarise(!!paste("call", type, day_segment, metric, sep = "_") := entropy.MillerMadow(call_duration)))