streamQ: streamQ

Description Usage Arguments Examples

View source: R/streamQ.R

Description

The function receives a numerical data stream and computes its outliers. The Quality of such stream is defined as Q = 1 - percentage of outliers.

Usage

1
streamQ(datastream)

Arguments

datastream

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (datastream)
{
    df <- jsonlite::stream_in(url(datastream))
    dfjson <- jsonlite::fromJSON(jsonlite::toJSON(df))
    mydata <- dfjson$nameValuePairs
    columnnames <- colnames(mydata)
    x <- data.frame(mydata$inDateTime$nameValuePairs)
    tempout_index <- grep(columnnames[grepl("temperature_indoor",
        columnnames)], colnames(mydata))
    xy <- data.frame(x, mydata[tempout_index])
    xy <- na.omit(xy)
    colnames(xy) <- c("time", "tempout")
    summary(xy)
    xy = xy[1:3, ]
    dat.ts <- ts(xy$tempout, frequency = 1)
    data.ts.outliers <- tso(dat.ts, types = c("AO", "LS", "TC",
        "IO", "SLS"))
    Q = 1 - nrow(data.ts.outliers$outliers)/nrow(xy)
    return(Q)
  }

auroragonzalez/streamQ documentation built on Nov. 3, 2019, 2:01 p.m.