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
- Host: GitHub
- URL: https://github.com/centreon/warp10r
- Owner: centreon
- License: other
- Created: 2019-10-02T14:59:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-17T10:04:43.000Z (about 1 year ago)
- Last Synced: 2025-04-18T00:46:09.123Z (about 1 year ago)
- Language: R
- Homepage:
- Size: 691 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
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
[](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")
```