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)
TC7.6: How to get data from API into R Studio | Snap4City

Error

×

Error message

  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Unable to send e-mail. Contact the site administrator if the problem persists.
  • Notice: Trying to get property of non-object in user_is_logged_in() (line 1576 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_is_logged_in() (line 1576 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in og_field_access() (line 578 of /var/www/html/drupal/sites/default/modules/og/og.module).
  • Notice: Trying to get property of non-object in user_access() (line 806 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 818 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 819 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 825 of /var/www/html/drupal/modules/user/user.module).
  • Notice: Trying to get property of non-object in user_access() (line 828 of /var/www/html/drupal/modules/user/user.module).
  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/drupal/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/drupal/includes/bootstrap.inc).
  • Error: __clone method called on non-object in og_user_access_entity() (line 2249 of /var/www/html/drupal/sites/default/modules/og/og.module).
The website encountered an unexpected error. Please try again later.