datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6
Loading...

Query the Data Delivery Network

Query the DDN

The easiest way to query any data on Splitgraph is via the "Data Delivery Network" (DDN). The DDN is a single endpoint that speaks the PostgreSQL wire protocol. Any Splitgraph user can connect to it at data.splitgraph.com:5432 and query any version of over 40,000 datasets that are hosted or proxied by Splitgraph.

For example, you can query the enhancing_microsimulation_models_for_improved_work table in this repository, by referencing it like:

"datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6:latest"."enhancing_microsimulation_models_for_improved_work"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "start_time", -- The start time of the car-following instance, measured since the start of the data collection run, in HH:MM:SS.sss format.
    "leader_radar", -- Records the sensor that was used to measure information about the lead vehicle. Valid values are: 0: The lead vehicle was detected by the front radar. 1: The lead vehicle was detected by the rear radar. 10: The IRV is the lead vehicle.
    "speed_limit", -- The speed limit of the section of route on which the driver is traveling, in miles per hour.
    "end_time", -- The end time of the car-following instance, measured since the start of the data collection run, in HH:MM:SS.sss format.
    "run_instance_id", -- An ID was assigned by the data processing team to each car-following instance recorded during each driver’s run. Note that this count resets for each run.
    "run_id", -- ID assigned to the run/driver (foreign key to runs table)
    "parent_instance_id", -- During some car-following instances, the road characteristics (road_type, congestion, or speed_limit) changed while the same leader/follower pair continued to follow each other. These instances are represented by multiple records in the table, which have the same parent_instance_id but different run_instance_id values.
    "road_type", -- A description of the road the vehicle is traveling on. Valid values are: HW: Highway. A U.S. or State route, which is not an interstate. In this dataset, this only includes the George Washington Memorial Parkway. IS: Interstate. An Interstate highway with two or more lanes (no work zone present). In this dataset, these include I-395 and I-95. AW: Advanced Warning. The vehicle is traveling on the freeway towards the work zone.  The vehicle has already passed advanced warning signage for the work zone (ex. "Work Zone in 1 mile") TZ: Taper Zone. The vehicle is entering and/or traversing the freeway work zone's taper zone WZ1: Work Zone with Lane Closure. The vehicle is traversing the buffer zone and/or the work zone, for a freeway work zone with lane closure. WZ2: Work Zone without Lane Closure. The vehicle is traversing the buffer zone and/or the work zone, for a freeway work zone without lane closure. (Note: in this dataset, all work zones encountered were on Interstates).
    "leader_veh_type", -- A description of the type of the lead vehicle. Valid values are: PC: passenger car. HV: heavy vehicle. B: bus. M: motorcycle.
    "follower_veh_type", -- A description of the type of the following vehicle. Valid values are: PC: passenger car. HV: heavy vehicle. B: bus. M: motorcycle.
    "congestion", -- Records the traffic conditions. Valid values are: C: Congested. Because of surrounding traffic, the travel speed of the subject vehicle is below 35 mph (or 15.6 m/s) in a non-work zone, or below 25 mph (or 11.1 m/s) in a work zone. U: Uncongested. Traffic conditions allow the subject vehicle to travel 35 mph (or 15.6 m/s) or faster in a non-work zone, or 25 mph (or 11.1 m/s) or faster in a work zone.
    "follower_radar", -- Records the sensor that was used to measure information about the following vehicle. Valid values are: 0: The following vehicle was detected by the front radar. 1: The following vehicle was detected by the rear radar. 10: The IRV is the following vehicle.
    "global_instance_id" -- Unique identifier of each instance record (primary key). Defined by (run_id*1000 + run_instance_id) 
FROM
    "datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6:latest"."enhancing_microsimulation_models_for_improved_work"
LIMIT 100;

Connecting to the DDN is easy. All you need is an existing SQL client that can connect to Postgres. As long as you have a SQL client ready, you'll be able to query datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6 with SQL in under 60 seconds.

Query Your Local Engine

Install Splitgraph Locally
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
 

Read the installation docs.

Splitgraph Cloud is built around Splitgraph Core (GitHub), which includes a local Splitgraph Engine packaged as a Docker image. Splitgraph Cloud is basically a scaled-up version of that local Engine. When you query the Data Delivery Network or the REST API, we mount the relevant datasets in an Engine on our servers and execute your query on it.

It's possible to run this engine locally. You'll need a Mac, Windows or Linux system to install sgr, and a Docker installation to run the engine. You don't need to know how to actually use Docker; sgrcan manage the image, container and volume for you.

There are a few ways to ingest data into the local engine.

For external repositories, the Splitgraph Engine can "mount" upstream data sources by using sgr mount. This feature is built around Postgres Foreign Data Wrappers (FDW). You can write custom "mount handlers" for any upstream data source. For an example, we blogged about making a custom mount handler for HackerNews stories.

For hosted datasets (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Cloning Data

Because datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6:latest is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.

First, install Splitgraph if you haven't already.

Clone the metadata with sgr clone

This will be quick, and does not download the actual data.

sgr clone datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6

Checkout the data

Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest tag:

sgr checkout datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6:latest

This will download all the objects for the latest tag of datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6 and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.

Alternatively, use "layered checkout" to avoid downloading all the data

The data in datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6:latest is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:

sgr checkout --layered datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6:latest

This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.

Read the layered querying documentation to learn about when and why you might want to use layered queries.

Query the data with your existing tools

Once you've loaded the data into your local Splitgraph Engine, you can query it with any of your existing tools. As far as they're concerned, datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-k74u-yqu6 is just another Postgres schema.

Related Documentation:

Loading...