Giter Club home page Giter Club logo

bikeshare-data's Introduction

bikeshare-data

Python module to facilitate the acquisition and analysis of Indego bikeshare data

Usage

  1. Download all CSV files with: indego scrape
  2. Move these files from your download folder to a better spot
  3. Import the CSV files to PostgreSQL with: indego import-to-sql

TODO:

  1. Aggregate trips based upon an input polygon shapefile

Development

Create a virtual environment using conda:

conda env create -f environment.yml

Activate the environment:

conda activate bikeshare-data

Create a .env file to store configuration parameters:

DEFAULT_DB_URI = postgresql://postgres:password@localhost:5432/indego
DEFAULT_DATA_FOLDER = /path/to/data/dir
STUDY_AREA = "ST_SetSRID(ST_GeomFromText('POLYGON((-75.179070999792 39.9561219999082, ...etc...))'), 4326)"

Make sure that the database defined by DEFAULT_DB_URI already exists and that the postgis extension can be (or has been) enabled.

Usage

1) Download all CSV files hosted on Indego's data page:

indego scrape-trips

This will download all CSV files to your computer's Downloads folder. Cut and paste these files into the DEFAULT_DATA_FOLDER before continuing to the next step.

2 ) To import the CSV files into SQL, run:

indego import-to-sql

This imports all CSVs into a single table named raw_trips with 4.3 million rows (as of 8/2021), and then generates a cleaned up version named trips. This will take approximately 8 minutes to run.

3) Load the authoritative station geojson file directly to SQL with:

indego scrape-stations

This creates a spatial table in the database named station_shapes

4) Generate xlsx output files:

indego analyze

Notes

The study area boundary is defined using WKT to facilitate future integration into a backend API that will communicate with a webmap frontend where users point/click to define a custom study area.

<script src="https://cdn.rawgit.com/mapbox/wellknown/master/wellknown.js"></script>


let my_wkt = wellknown.stringify(data.features[0].geometry);

This returns a well-known-text description of the shape:

POLYGON ((-75.179070999792 39.9561219999082,-75.179121999973 39.9559839999298,-75.1793000003484 39.9559849996663))

To work with spatial queries, wrap the WKT within:

ST_SetSRID(
    ST_GeomFromText('my_wkt'),
    4326
)

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.