Commit 49b25701 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

put on gitlab

parents
^.*\.Rproj$
^\.Rproj\.user$
.Rproj.user
.Rhistory
.RData
Package: eipar
Type: Package
Version: 0.0.1
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")))
Title: eipar
Description: Extracting air quality timeseries from the Irish Environmental Protection Agency.
The irish EPA API provides free access to Irish air quality timeseries.
Depends:
R (>= 3.2.0)
Imports:
httr,
dplyr
Suggests:
knitr
License: GPL-3
Encoding: UTF-8
VignetteBuilder: knitr
LazyData: false
RoxygenNote: 5.0.1
# Generated by roxygen2: do not edit by hand
export(eipar_base_url)
export(endpoints_eipar)
export(endpoints_metadata)
export(endpoints_qa)
export(endpoints_timeseries)
export(get_timeseries)
export(resp_content)
export(resp_status)
export(session_key)
export(url_request)
#' eipar_base_url
#' eipar_base_url
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' eipar_base_url()
#' }
eipar_base_url <- function(){
res <- "https://air-tst.epa.ie"
return(res)
}
#' endpoints_eipar
#' endpoints_eipar
#' @param api api endpoint
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' endpoints_eipar()
#' }
endpoints_eipar <- function(api=c("timeseries","metadata","qa")){
api <- match.arg(api,c("timeseries","metadata"))
res <- switch(api,
"timeseries" = endpoints_timeseries(),
"metadata" = endpoints_metadata(),
"qa" = endpoints_qa(),
stop("endpoints not recognized"))
class(res) <- "eipar_endpoints"
return(res)
}
#' endpoints_timeseries
#' endpoints_timeseries
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' endpoints_timeseries()
#' }
endpoints_timeseries <- function(){
res <- eipar_url("aq_measurements")
return(res)
}
#' endpoints_metadata
#' endpoints_metadata
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' endpoints_metadata()
#' }
endpoints_metadata <- function(){
res <- eipar_url("aq_meta")
return(res)
}
#' endpoints_qa
#' endpoints_qa
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' endpoints_qa()
#' }
endpoints_qa <- function(){
res <- eipar_url("aq_qa")
return(res)
}
eipar_url <- function(...){
url <- eipar_base_url()
param <- c(as.list(environment()), list(...))
indice <- which(unlist(lapply(param,is.null)))
if (length(indice)) {
param <- param[-indice]
}
res <- do.call("file.path",param)
return(res)
}
#' get_timeseries
#' get_timeseries
#' @param stationIDs stationIDs
#' @param componentName componentName
#' @param fromDateTime fromDateTime
#' @param toDateTime toDateTime
#' @param username username
#' @param password password
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' get_timeseries()
#' }
get_timeseries <- function(stationIDs=NULL,componentName=NULL,fromDateTime=NULL,toDateTime=NULL,username,password){
epoint <- endpoints_eipar(api="timeseries")
url <- url_request(epoint=epoint,stationIDs=stationIDs,componentName=componentName,fromDateTime=fromDateTime,toDateTime=toDateTime)
tmp <- httr::GET(url,httr::authenticate(user=username, password=password,type="basic"),httr::add_headers("user-agent"="eipar-r-package"))
status_code <- tmp$status_code
if (status_code == 200L) {
tmp <- httr::content(tmp)
res <- dplyr::bind_rows(lapply(tmp$'_items',function(x) data.frame(t(x))))
res <- apply(res,2,function(x) unlist(as.character(x)))
rm(tmp)
} else res <- NULL
res <- list(status_code = status_code,
resp = res)
class(res) <- c("eipar_get_timeseries",class(res))
return(res)
}
#' url_request
#' url_request
#' @param epoint epoints obkect
#' @param ... parameters
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' url_request()
#' }
url_request <- function(epoint,...){
if (inherits(epoint,"eipar_endpoints")){
param <- list(...)
res <-paste0(epoint,"?")
if (length(param)>0) {
param_name <- names(param)
for (i in 1:length(param_name)){
tmp <- paste0(param_name[i],"=",param[[i]])
res <- paste0(res,"&",tmp)
}
}
class(res) <- c("eipar_url",class(res))
} else stop("epoint must be an eipar_endpoints object")
return(res)
}
# eiparr
## Description
The package is a client api to get air quality observation from the [Irish Environmental Protection Agency](http://epa.ie/).
The package is developed continuously with the development of the server API.
The package is working but might change at any time.
## Prerequisite
Install the "remotes" R-package
```R
source("https://raw.githubusercontent.com/r-lib/remotes/master/install-github.R")$value("r-lib/remotes")
```
## Installation
```R
library("remotes")
remotes::install_git("git@git.nilu.no:rextapi/eipar.git")
```
## Usage
Have a look at the vignettes
The R-package helps extracting data from the luftkval database.
The package has four purposes:
0. Code is written in order to avoid any SQL Injection Attack.
1. Quickly extracting stations informations.
2. Quickly extracting timeseries informations.
3. Quickly extracting dataset.
## Prerequisite
Some sql drivers are required: odbc and oracle
Please read the [documentation](https://git.nilu.no/rdbnilu/database-and-r/blob/master/01-pre-required.md) on gitlab.
Install the "remotes" R-package
```R
source("https://raw.githubusercontent.com/r-lib/remotes/master/install-github.R")$value("r-lib/remotes")
```
## Installation
```R
library(remotes)
remotes::install_git("git@git.nilu.no:rdbnilu/luftkvalr.git")
```
## Usage
```R
library("luftkvalr")
#settings
db <- luftkvalr()
db$start(username="********",password="********")
# get values at one station
tmp_st <- db$GetAQStations(stationIDs="665")$ST_ID
tmp_ts <- db$GetAQTimeseries(stationIDs=tmp_st,componentName=c("NO2"))$TS_ID
res <- db$GetAQData(stationIDs=tmp_st,timeSeriesIDs=tmp_ts,fromDateTime="2016-11-01 00:00:00",toDateTime="2016-11-02 00:00:00")
# get values at stations in Oslo
tmp_st <- db$GetAQStations(west=10.57911,south=59.75327,east=10.89911,north=60.07327)$ST_ID
tmp_ts <- db$GetAQTimeseries(stationIDs=unique(tmp_st),componentName=c("NO2"))$TS_ID
res <- db$GetAQData(stationIDs=unique(tmp_st),timeSeriesIDs=tmp_ts,fromDateTime="2016-11-01 00:00:00",toDateTime="2016-11-02 00:00:00")
# stop connection
db$stop()
```
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
Encoding: UTF-8
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
We finally have the AQ API up and running now:
URI: https://air-tst.epa.ie/aq_measurements
The basic curl command is:
curl -i -X GET \
-H "Authorization:Basic *****==" \
'https://air-tst.epa.ie/aq_measurements'
The framework is Python-Eve with HATEOAS enabled. The ‘_links’ meta tag contains the navigation URIs, e.g.
- Pagination is enabled with the ’page’ switch, e.g. https://air-tst.epa.ie/aq_measurements?page=- 3
- Results per page default to 25. This can be changed with the max_results switch, e.g. https://air-tst.epa.ie/aq_measurements?max_results=100
Please let me know if you have any queries, or would like to make any changes, e.g. field names.
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/base_url.R
\name{eipar_base_url}
\alias{eipar_base_url}
\title{eipar_base_url
eipar_base_url}
\usage{
eipar_base_url()
}
\description{
eipar_base_url
eipar_base_url
}
\examples{
\dontrun{
eipar_base_url()
}
}
\keyword{eipar}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_eipar}
\alias{endpoints_eipar}
\title{endpoints_eipar
endpoints_eipar}
\usage{
endpoints_eipar(api = c("timeseries", "metadata", "qa"))
}
\arguments{
\item{api}{api endpoint}
}
\description{
endpoints_eipar
endpoints_eipar
}
\examples{
\dontrun{
endpoints_eipar()
}
}
\keyword{eipar}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_metadata}
\alias{endpoints_metadata}
\title{endpoints_metadata
endpoints_metadata}
\usage{
endpoints_metadata()
}
\description{
endpoints_metadata
endpoints_metadata
}
\examples{
\dontrun{
endpoints_metadata()
}
}
\keyword{eipar}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_qa}
\alias{endpoints_qa}
\title{endpoints_qa
endpoints_qa}
\usage{
endpoints_qa()
}
\description{
endpoints_qa
endpoints_qa
}
\examples{
\dontrun{
endpoints_qa()
}
}
\keyword{eipar}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_timeseries}
\alias{endpoints_timeseries}
\title{endpoints_timeseries
endpoints_timeseries}
\usage{
endpoints_timeseries()
}
\description{
endpoints_timeseries
endpoints_timeseries
}
\examples{
\dontrun{
endpoints_timeseries()
}
}
\keyword{eipar}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_timeseries.R
\name{get_timeseries}
\alias{get_timeseries}
\title{get_timeseries
get_timeseries}
\usage{
get_timeseries(stationIDs = NULL, componentName = NULL,
fromDateTime = NULL, toDateTime = NULL, username, password)
}
\arguments{
\item{stationIDs}{stationIDs}
\item{componentName}{componentName}
\item{fromDateTime}{fromDateTime}
\item{toDateTime}{toDateTime}
\item{username}{username}
\item{password}{password}
}
\description{
get_timeseries
get_timeseries
}
\examples{
\dontrun{
get_timeseries()
}
}
\keyword{eipar}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{resp_content}
\alias{resp_content}
\title{resp_content
resp_content}
\usage{
resp_content(x, as = NULL, type = NULL, encoding = NULL, ...)
}
\arguments{
\item{x}{alpu_post_res or alpu_get_res object}
\item{as}{as}
\item{type}{type}
\item{encoding}{encoding}
\item{...}{other options}
}
\description{
resp_content
resp_content
}
\examples{
\dontrun{
resp_content()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{resp_status}
\alias{resp_status}
\title{resp_status
resp_status}
\usage{
resp_status(x)
}
\arguments{
\item{x}{alpu_post_res object}
}
\description{
resp_status
resp_status
}
\examples{
\dontrun{
resp_status()
}
}
\keyword{alapu}
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