Code Monkey home page Code Monkey logo

ecobici's Introduction

Analysis of 38 Million Ecobici Rides in Mexico City

Accompanying code for blog post: 38 Million Ecobici Trips in Mexico City

Also included are shapefiles for Mexico City streets and colonias (neighberhoods), filtered to only include those relevant to the parts of the city covered by Ecobici, as well as json file of Ecobici stations.

Streets:

/data/Streets/cdmx

Raw data comes from Open Streetmap data and was downloaded from http://download.geofabrik.de/osm/north-america/mexico-latest-free.shp.zip

Colonias:

/data/Colonias/df

Raw data was downloaded from http://shapesdemexico.wixsite.com/shapes/agebs

Stations:

/data/stations.json

Obtained from https://www.ecobici.cdmx.gob.mx/es/mapa-de-cicloestaciones

Instructions

Getting set up

  1. Download data
python get_data.py
  1. Clean the start and end dates for some months (this is necessary because for most months the dates are in the format yyyy-mm-dd, however for three months in 2016 they are in the format dd/mm/yyyy)
python clean_dates.py
  1. Initialize the database and load the data
./load_trips.sh

Obtaining Google Maps Instructions

  1. Add the table for saving the individual trip legs from Google Maps:
psql ecobici -f create_trip_legs.sql
  1. Extract the relevant routes for obtaining directions from Google:
mkdir output
python extract_station_pairs.py
  1. Use the google_instructions.py script to obtain directions from Google Maps for each distinct route (free account only allows for 2,500 queries per day)
python google_instructions.py -i 'Starting Index' -t 'Num Trips to Process'

Analysis

  1. Prepare for analysis
psql ecobici -f prepare_analysis.sql
  1. Count the different legs based on the Google Maps directions to identify most popular routes:
psql ecobici -f count_trip_legs.sql
pgsql2shp -f "line_segments/line_segments" -h 'HOST' -u 'USER' ecobici "SELECT * FROM leg_trips_counts ORDER BY num_legs ASC;"
  1. Run analysis for Day in The Life and Popular Routes:
python day_in_the_life.py
  1. Create hexagon bin-tiling and extract shapefile with relevant hexagons:
psql ecobici -f hexagon_tiling.sql
mkdir hexagons
pgsql2shp -f "hexagons/hexagons" -h 'HOST' -u 'USER' ecobici "SELECT hexagon_id, ST_Force2D(the_geom) FROM hex_grid WHERE hexagon_id IN (SELECT DISTINCT(hexagon_id) FROM stations);"
  1. Core analysis:
python analysis.py

ecobici's People

Contributors

simonb83 avatar

Watchers

James Cloos avatar  avatar

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.