Coder Social home page Coder Social logo

metropolitan-council / streetlightr Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 11.35 MB

R wrapper for StreetLight InSight® API

Home Page: https://metropolitan-council.github.io/streetlightR/

License: Other

R 97.26% CSS 2.74%
api r-package rstats transportation pkgdown streetlight-data

streetlightr's Introduction

streetlightR

R build status

streetlightR is an R wrapper for StreetLight Data’s InSight® API that makes it easier for users to create analyses, upload zone sets, fetch results, and more.

To get a sense for what you can do with this package, see our presentation to the StreetLight API users group in November 2022.

Installation

remotes::install_github("Metropolitan-Council/streetlightR")

StreetLight API

StreetLight Data offers a limited-feature API for subscribers. Contact StreetLight support to request an API key. Documentation is available at the StreetLight Developer Hub.

API key management

Contact StreetLight Data support to request an API key. Then, use streetlight_api_key() to save the key for future use.

library(streetlightR)
streetlight_api_key(key = "9999999", install = TRUE)

Contributing

We welcome contributions!

Please review our CONTRIBUTING guide before making a contribution.

Thanks everyone who has contributed one way or another: @ehesch, @ravenmcknight, and @eroten.

Notes

This package is not affiliated with nor maintained by StreetLight Data. This package is tool for StreetLight API users authored by StreetLight API users.

streetlightr's People

Contributors

eroten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

streetlightr's Issues

Check status returns error

library(streetlightR)
streetlight_api_key("9bxxxxxx")
#> ℹ Your API key has been added to your environment for this session only.
#> ℹ To install your API key for use in future sessions, run this function with
#>   `install = TRUE`.
check_streetlight_api() # passes
#> ✔ API connection live
#> [1] "PASS"

# Insights status "Data Available"
check_analysis_status("bike_gate_nov16_test")
#> <httr2_response>
#> POST https://insight.streetlightdata.com/api/v2/analyses/status
#> Status: 500 Internal Server Error
#> Content-Type: text/html
#> Body: In memory (21 bytes)

Sys.sleep(1)

# Insights status "Available"
check_analysis_status("legacy-summer21-od-test-traveller")
#> <httr2_response>
#> POST https://insight.streetlightdata.com/api/v2/analyses/status
#> Status: 200 OK
#> Content-Type: application/json
#> Body: In memory (441 bytes)

Created on 2022-11-18 with reprex v2.0.2

Reconciling API key, login email, and API organization

API keys and login emails are tied to specific API organizations. However, if users are collaborating and their email is not registered with the same API org, it causes errors.

check_streetlight_api() only checks the API key itself, not any associated login emails. You won't run into any errors until you try to create or access an analysis using a different login email.

Liz's email is registered "mndot_metcouncil_api"
Raven's is registered with "mndot_master"

Both of us have access to StreetLight through the same contract with MnDOT.

function login_email api_key status
check_streetlight_api() NA "Myxxxxx" ✔️
check_streetlight_api() NA "9bxxxxx" ✔️
create_streetlight_analysis() raven.mcknight "9bxxxxx" ✔️
create_streetlight_analysis() raven.mcknight "Myxxxxx"
create_streetlight_analysis() liz.roten "Myxxxxx" ✔️
create_streetlight_analysis() liz.roten "9bxxxxx"

Worked examples

Here, we use Raven's key and Raven's email to create a new analysis and get "Analysis name must be unique" ✔️

library(streetlightR)
streetlight_api_key("9bxxxxxxxx")
#> ℹ Your API key has been added to your environment for this session only.
#> ℹ To install your API key for use in future sessions, run this function with
#>   `install = TRUE`.
check_streetlight_api() # passes
#> ✔ API connection live
#> [1] "PASS"

create_streetlight_analysis(login_email = "[email protected]",
                            analysis_type = "Zone_Activity_Analysis",
                            analysis_name = "bike_gate_nov16_test",
                            travel_mode_type = "Bicycle",
                            output_type = "Volume",
                            origin_zone_set = "mndot_gate_validation_osm_nov16",
                            tags = list("streetlightR"))
#> Warning: Create analysis failed with message:
#> Analysis name has to be unique.

Created on 2022-11-18 with reprex v2.0.2

Here, we run with Liz's API key, and Raven's email, but get an error ❌

library(streetlightR)
streetlight_api_key("Myxxxxxxx")
#> ℹ Your API key has been added to your environment for this session only.
#> ℹ To install your API key for use in future sessions, run this function with
#>   `install = TRUE`.
check_streetlight_api() # passes
#> ✔ API connection live
#> [1] "PASS"

create_streetlight_analysis(login_email = "[email protected]",
                            analysis_type = "Zone_Activity_Analysis",
                            analysis_name = "bike_gate_nov16_test",
                            travel_mode_type = "Bicycle",
                            output_type = "Volume",
                            origin_zone_set = "mndot_gate_validation_osm_nov16",
                            tags = list("streetlightR"))
#> Warning: Create analysis failed with message:
#> User '[email protected]' does not have access to the current api
#> organization.

Created on 2022-11-18 with reprex v2.0.2

However, if we try with Raven's key and Liz's email, we get an error ❌

library(streetlightR)
streetlight_api_key("9bxxxxxxxxx")
#> ℹ Your API key has been added to your environment for this session only.
#> ℹ To install your API key for use in future sessions, run this function with
#>   `install = TRUE`.
check_streetlight_api() # passes
#> ✔ API connection live
#> [1] "PASS"

create_streetlight_analysis(login_email = "[email protected]",
                            analysis_type = "Zone_Activity_Analysis",
                            analysis_name = "bike_gate_nov16_test",
                            travel_mode_type = "Bicycle",
                            output_type = "Volume",
                            origin_zone_set = "mndot_gate_validation_osm_nov16",
                            tags = list("streetlightR"))
#> Warning: Create analysis failed with message:
#> Analysis name has to be unique.

Created on 2022-11-18 with reprex v2.0.2

Fix grammar

Several function titles refer to "a analysis"

Hex logo

Lets make a nice hex logo for this project!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.