Code Monkey home page Code Monkey logo

municipios-api's Introduction

What

This is source code for generating a graph representation of Puerto Rico municipalities as well as for running a Flask API that can retrieve useful data from the graph.

Where

You can use the API at municipios.rauln.com. There are two endpoints: /distance and /adjacent. The API is very simple and can be explained with two examples:

  • GET https://municipios.rauln.com/distance/san-juan/mayaguez
{
  "result": {
    "distance": 8,
    "path": [
      "san-juan",
      "toa-baja",
      "dorado",
      "vega-alta",
      "manati",
      "ciales",
      "utuado",
      "lares",
      "las-marias",
      "mayaguez"
    ]
  }
}
  • GET https://municipios.rauln.com/adjacent/san-juan?distance=1
{
  "result": [
    "aguas-buenas",
    "caguas",
    "carolina",
    "catano",
    "guaynabo",
    "toa-baja",
    "trujillo-alto"
  ]
}

How

The data was obtained from from publicly available sources (see Credits). Graph creation and traversal is handled by NetworkX. The API was written using Flask, the code runs in AWS Lambda behind an AWS API Gateway and is managed via Zappa.

Why

I needed to know the answer to the following type of question: What are the three municipalities nearest to Guaynabo? I'm building an open source API which would find that sort of information useful. I'm sharing the information via code/API in case someone else finds it useful too!

Processes

  1. Manually edit the country adjacency text file to make it easier to parse

  2. Parse the text file with utils/parse_country_adjacency.py

  3. Store the resulting JSON in data/municipality_adjacency.json

  4. Process the JSON, generate a graph and write the graph to a file with utils/generate_adjacency_list.py

  5. Use the resulting data/adjacency_list.gz in the API to calculate adjacency and distance data for municipalities.

Credits

Municipality adjacency data obtained from publicly available Census data.

municipios-api's People

Contributors

rnegron avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

municipios-api's Issues

Añadir codigo de conducta

Todo proyecto en Code 4 Puerto Rico debería tener un codigo de conducta que sea compatible con a de Code 4 Puerto Rico.

Puede ser tan sencillo como añadir un archivo CODE_OF_CONDUCT.md y apuntar al codigo de conducta de Code 4 PR.

Add CONTRIBUTING.md

Adding a this will help contributors know exactly how to interact with your repo and what to expect.

Creo que SuministrosPR tiene un buen ejemplo.

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.