TC7.6: How to get data from API into R Studio

Test Case Title

TC7.6 - how to get data from API into R Studio

Goal

TBD

Prerequisites

Using a PC with a web browser. You need credentials to access to the Node-Red application.

The following functionalities are available only for specific Snap4city users with specific privileges.

Expected successful result

TBD

Steps

 

 

  1. Install the “jsonlite” package with the command install.packages(“jsonlite”) and load it with the command library(jsonlite).
     
  2. As first step is necessary to upload the Service Uris list.
    1. Service Uris related to the city of Helsinki for the sensor Noise_level_sensor: 
      query <- “https://www.snap4city.org/ServiceMap/api/v1/?selection=60.09497984705214;24.72198486328125;60.267236565637916;25.25482177734375&categories=Noise_level_sensor&maxResults=100&maxDists=0.1&format=json

      In the example, the considered sensor category is Noise_level_sensor but the category Weather_sensor is also available for Helsinki.
       
    2. Service Uris related to the city of Antwerp for the sensor Weather_sensor:
      query <- “https://www.snap4city.org/ServiceMap/api/v1/?selection=51.1356318430504;4.0656280517578125;51.36299224099361;4.718971252...
       
  1. Upload Service Uris in R.
    The function fromJSON of the jsonlite package allows to upload a list that contains all Service Uris:

    sensorCategoryJson <- fromJSON(query)

    Creation of the ServiceUris vector:

    suri <- sensorCategoryJson$Services$features$properties$serviceUri
     
  2. Using API to upload Data in R Studio.
    1. For each Service Uri is possible to upload in R the data using API.
      https://www.snap4city.org/ServiceMap/api/v1/?serviceUri= http://...... &fromTime=n-hour

      or

      https://www.snap4city.org/ServiceMap/api/v1/?serviceUri= http://...... &fromTime=n-day

      Example using a Weather_sensor Service Uri of Helsinki, considering a time slot of 2 hours:

      api <- https://www.snap4city.org/ServiceMap/api/v1/?serviceUri=http://www.disit.org/km4city/resource/hel_weather_sensor_100971&fromTime=2-hour

      The function fromJSON of the jsonlite package allows to upload the list that contains all data for the considered Service Uri.

      sensorCategoryData <- fromJSON(api)