An open API service indexing awesome lists of open source software.

https://github.com/centreon/warp10r

R client for interacting with a Warp 10™ instance
https://github.com/centreon/warp10r

Last synced: about 1 year ago
JSON representation

R client for interacting with a Warp 10™ instance

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# warp10r

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

R client for executing WarpScript on a Warp 10 instance.

## Fork

The original package [https://github.com/senx/warp10-r] has been forked to make the package more concilient with current developments of R packages :

- Package has been moved to the root of the git repository
- Dependancies have been added to the DESCRIPTION
- Construct a warp 10 script with helpers function and send them to Warp 10 database

## Installation

```r
remotes::install_github("centreon/warp10-r")
```

## First steps

### Hello World

```{r}
library(warp10r)

# Create a connection
con <- wrp_connect(endpoint = "https://warp.senx.io/api/v0/exec")
print(con)

# set_script store a script in the connection object.
set_script(con, "'Hello World'")
set_script(con, "NOW")
print(con)

# We can see the script
cat(get_script(con))

# Execute the script
wrp_exec(con)
```

### Example with Geo Time Series

```{r}
library(tibble)

df1 <- tibble(ds = 1:10, y = rnorm(10))
df2 <- tibble(ds = 2:11, y = rnorm(10))

con %>%
clear_script() %>%
wrp_new_gts() %>%
wrp_rename("randGTS") %>%
wrp_add_value_df(df1, tick = ds, value = y) %>%
wrp_new_gts() %>%
wrp_add_value_df(df2, tick = ds, value = y) %>%
wrp_rename("nogeoTS") %>%
wrp_exec()
```

## Outlier detection

Anomaly detection is already implemented in Warpscript.
Let's take twitter data as an example.

### Set up and show data

```{r}
library(AnomalyDetection)
library(dplyr)
library(ggplot2)
library(hrbrthemes)
library(lubridate)
library(purrr)

data("raw_data")

raw_data %>%
ggplot(aes(timestamp, count)) +
geom_line() +
theme_ipsum(base_family = "Verdana")
```

### Create a subset of the data

Default settings do not authorize more than 1,000 operations for a warpscript.
Therefore, let's take the previous data and concatenate them into 3 hours timespan.

```{r}
df <- raw_data %>%
group_by(date_hour = ceiling_date(timestamp, "3 hours")) %>%
summarise_at("count", sum)

df %>%
ggplot(aes(date_hour, count)) +
geom_line() +
theme_ipsum(base_family = "Verdana")
```

### Lets find some anomalies

```{r}
res <- con %>%
wrp_new_gts() %>%
wrp_rename("twitter data") %>%
wrp_add_value_df(df, tick = "date_hour", value = "count") %>%
wrp_bucketize(span = "3 h", bucketizer = "sum") %>%
wrp_hybridtest(period = 8, piece = 4, k = 4) %>%
wrp_exec()

print(res)

# Results is a list of abnormal dates in microseconds
res_dbl <- map_dbl(res[[1]], ~ .x / 1e6)

df %>%
ggplot(aes(date_hour, count)) +
geom_line() +
geom_vline(xintercept = res_dbl, linetype = 2, color = "red") +
theme_ipsum(base_family = "Verdana")
```