knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", dpi = 300 )
trendminer is an R client for accessing selected endpoints of the TrendMiner API that is documented at http://developer.trendminer.com. TrendMiner is an industrial self-service analytics platform for analyzing, monitoring and predicting time-series based process and asset data.
``` {r install, eval=FALSE}
remotes::install_github("TrendMiner/trendminer")
## Usage Below are some things you can do after installing the package. Check out the [introduction vignette](https://trendminer.github.io/trendminer/articles/trendminer.html) and [the docs](https://trendminer.github.io/trendminer/reference/index.html) for further details. Start with fetching an access token which you'll need for any subsequent API call: ```r library(trendminer) token <- tm_token()
Browse and explore the site/plant structures starting on top with the available root structures:
library(dplyr) # Get root structures tm_af_root_structures(token) %>% select(structureId, name) # Get child structures of Site Grenoble tm_af_child_structures(token, "ca12dc39-516d-4217-b7cc-a8d220a32858") %>% select(structureId, name, parentName) # Get entire subtree structure underneath Line 1 tm_af_descendant_structures(token, "2cd8f0c6-4bfc-49f9-9c0d-5c878d05eae6") %>% select(name, parentName, type, tagName)
Search for specific assets/tags or retrieve all tags at once
# Retrieve all assets and tags that have "Reactor" in their name tm_af_search_assets(token, 'name=="*Reactor*"') %>% select(nodeId, name, type) %>% head() # Fetch all available tags tm_af_tags(token) %>% select(name, tagName) %>% head()
Fetch time series data of a tag:
library(lubridate) start <- ymd_hms("2019-09-15T03:10:14Z") end <- ymd_hms("2019-09-15T08:42:15Z") tag_data <- tm_ts_interpolated_data(token, "BA:CONC.1", start, end, 2) head(tag_data$timeSeries)
Visualize fetched time series data:
library(ggplot2) tag_data$timeSeries %>% ggplot(aes(index, value)) + geom_line(color = "#09557f") + ggtitle(tag_data$tag$tagName) + theme_minimal()
All requests to the TrendMiner API require authentication using a valid Bearer access token that is sent as part of the request headers.
Request tokens are obtained via OAuth2.0 using a resource owner password credentials flow. Any client which likes to interact with the API needs to collect the credentials from the user (username and password) and passes them together with its own client credentials (client ID and client secret) to the TrendMiner server using the tm_token()
function. The server responds with an access token which the user needs to use for any subsequent API requests.
User credentials, client credentials and the TrendMiner base URL can be passed as arguments to tm_token()
for quick testing in interactive mode. However, it is recommended to call tm_token()
without arguments. In this case tm_token()
will fetch the credentials and the TrendMiner base URL from the environment variables below which you need to store in .Renviron
. You can easily edit .Renviron
using usethis::edit_r_environ()
.
TM_client_ID = YOUR_CLIENT_ID_HERE TM_client_secret = YOUR_CLIENT_SECRET_HERE TM_usr = YOUR_USER_NAME_HERE TM_pwd = YOUR_USER_PASSWORD_HERE TM_base_url = YOUR_TM_BASE_URL_HERE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.