datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-74ug-57tr
Icon for Socrata external plugin

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-74ug-57tr:latest"."enhancing_microsimulation_models_for_improved_work"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "run_id", -- ID of the data collection run (foreign key to runs table)
    "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_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.
    "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.
    "current_lane", -- Current travel lane, numbered from 1 (leftmost lane) to num_lanes (rightmost lane).
    "rural_urban", -- Whether the road is urban or rural. Valid values are: U: Urban. Instances within 2 miles of an on-ramp or off-ramp to Springfield, MA are considered urban. R: Rural. Other instances are considered rural.
    "num_lanes", -- Number of travel lanes in the direction of travel.
    "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.
    "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.  IS: Interstate. A numbered Interstate highway with two or more lanes. In this dataset, this is I-91. 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. Because some work zones traversed along this route were collected on arterials as well as freeways, “HW” or “IS” are appended to the end of codes AW, TZ, WZ1, WZ2 to indicate the type of road being worked on.
    "signage", -- Temporary signage in the advanced warning zone, or message board signage in the taper zone. Valid values include: W20-1, W20-3, W4-2, W20-4, W8-1: see MUTCD sign designations for description. FA: flashing arrow on message board. Multiple values can be present in this field (comma-separated).
    "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 driver.
    "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.
    "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.
    "wz_markers", -- This field indicates the type of physical delineators used in the work zone. Valid values include: C: Cones. D: Drums or Barrels. JB: Jersey Barriers. Multiple values can be present in this field (comma-separated).
    "wz_status", -- Indicates if the work zone is passive or active. Valid values include: P: no workers present; A: active work zone, workers present.
    "wz_enforcement", -- Whether law enforcement vehicles or officers were present at the time of data capture. Valid values include: Y: yes; N: no.
    "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.
    "speed_limit", -- The speed limit of the section of route on which the driver is traveling, in miles per hour.
    "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-74ug-57tr: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-74ug-57tr with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at datahub.transportation.gov. When you querydatahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-74ug-57tr:latest on the DDN, we "mount" the repository using the socrata mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT is only guaranteed for subsequent queries that land on the same node.

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 (like this repository), 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, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by datahub.transportation.gov, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone to get the data. Instead, you can use the socrata adapter with the sgr mount command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

Mount the table with sgr mount

sgr mount socrata \
  "datahub-transportation-gov/enhancing-microsimulation-models-for-improved-work-74ug-57tr" \
  --handler-options '{
    "domain": "datahub.transportation.gov",
    "tables": {
        "enhancing_microsimulation_models_for_improved_work": "74ug-57tr"
    }
}'

That's it! Now you can query the data in the mounted table like any other Postgres table.

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-74ug-57tr is just another Postgres schema.