Commit 517a01c5 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

add get_new_element from old one

parent df85478b
#' get_short_new_element
#' get_short_new_element
#' @param frostObj frostObj
#' @param old_element old_element
#' @keywords frostr
#' @export
get_short_new_element <- function(frostObj,old_element=NULL){
if (is.null(old_element)) stop("try 'TA', 'TAM', 'TAMRR', 'RR', 'RR_1', 'FF', 'PR', 'PO', 'DG', 'DD', 'FG', 'TAN', 'TAX', 'UU', 'QSI'")
tmp <- frostObj$getElements(oldElementCodes=paste(old_element,collapse=","),format='jsonld')
if (!is.null(tmp)){
nbs <- tmp$totalItemCount
res <- data.frame(category= character(0),
oldelementId= character(0),
elementId = character(0),
timeOffset = character(0),
timeResolution = character(0),
level.value = numeric(0),
level.levelType = character(0))
for ( i in 1:nbs) {
df <- short_element_df(tmp=tmp,indice=i)
res <- rbind(res,df)
}
#res <- frostr$timeSeries(elements=tmp$data[[1]]$id,format='jsonld')
} else {
res <- data.frame(category= character(0),
oldelementId= character(0),
elementId = character(0),
timeOffset = character(0),
timeResolution = character(0),
level.value = numeric(0),
level.levelType = character(0))
}
return(res)
}
short_element_df <- function(tmp,indice){
category <- ifelse(is.null(tmp$data[[indice]]$category),NA,tmp$data[[indice]]$category)
oldelementId <- ifelse(is.null(tmp$data[[indice]]$oldConvention$elementCodes[[1]]),NA,tmp$data[[indice]]$oldConvention$elementCodes[[1]])
elementId <- ifelse(is.null(tmp$data[[indice]]$id),NA,tmp$data[[indice]]$id)
timeOffset <- ifelse(is.null(tmp$data[[indice]]$timeOffsets$values[[1]]),NA,tmp$data[[indice]]$timeOffsets$values[[1]])
timeResolution <- ifelse(is.null(tmp$data[[indice]]$calculationMethod$period),NA,tmp$data[[indice]]$calculationMethod$period)
level.value <- ifelse(is.null(tmp$data[[indice]]$sensorLevels$values[[1]]),NA,paste(unlist(tmp$data[[indice]]$sensorLevels$values),collapse=","))
level.levelType <- ifelse(is.null(tmp$data[[indice]]$sensorLevels$levelType),NA,tmp$data[[indice]]$sensorLevels$levelType)
df <- data.frame(category = category,
oldelementId = oldelementId,
elementId = elementId,
timeOffset = timeOffset,
timeResolution = timeResolution,
level.value = level.value,
level.levelType = level.levelType)
return(df)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_new_element.R
\name{get_short_new_element}
\alias{get_short_new_element}
\title{get_short_new_element
get_short_new_element}
\usage{
get_short_new_element(frostObj, old_element = NULL)
}
\arguments{
\item{frostObj}{frostObj}
\item{old_element}{old_element}
}
\description{
get_short_new_element
get_short_new_element
}
\keyword{frostr}
---
title: "get_meta"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{get_meta}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
library(frostr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```
## Get easily metadata
```R
id <- "your id"
frostr <- frostr::api(httpauth = 1,userpwd=paste0(id,":"))
old_element <- c("TAM","RR","FF","TAX")
elem <- frostr::get_short_new_element(frostObj=frostr,old_element=old_element)
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment