Giter VIP home page Giter VIP logo

openfaas-get-mileage's Introduction

OpenFaaS function for calling Google Map Distance API

  • Platform - Written for use with the OpenFaaS function as a service platform, across all container schedulers (Docker Swarm/Kubernetes)
  • Language - Written for Python3

Public Docker Hub Image

Example Output

curl http://openfaas.url.com/function/get-mileage -d '[{
        "date": "10/4",
        "start": "Roseville, Ca",
        "end": "Disneyland, Ca"
    },{
        "date": "10/4",
        "start": "Roseville, Ca",
        "end": "Sacramento, Ca"
    },{
        "date": "10/4",
        "start": "Sacramento Train Museum",
        "end": "BJs Brewery Roseville Ca"
    }]'
{u'date': u'10/4', u'start': u'Roseville, Ca', u'end': u'Disneyland, Ca'}
{u'date': u'10/4', u'start': u'Roseville, Ca', u'end': u'Sacramento, Ca'}
{u'date': u'10/4', u'start': u'Sacramento Train Museum', u'end': u'BJs Brewery Roseville Ca'}
+------+-----------------------------------------+-----------------------------------------------+----------------+
| Date |              Starting Point             |                  Ending Point                 | Miles Traveled |
+------+-----------------------------------------+-----------------------------------------------+----------------+
| 10/4 |            Roseville, CA, USA           |   1313 Disneyland Dr, Anaheim, CA 92802, USA  |     429 mi     |
| 10/4 |            Roseville, CA, USA           |              Sacramento, CA, USA              |    18.8 mi     |
| 10/4 | 125 I Street, Sacramento, CA 95814, USA | 1200 Roseville Pkwy, Roseville, CA 95678, USA |    23.1 mi     |
+------+-----------------------------------------+-----------------------------------------------+----------------+

Requirements:

The expected format for travel details is follows... (python list is expected)

[
    {
        "date": "10/4",
        "start": "Roseville, Ca",
        "end": "Disneyland, Ca"
    },
    {
        "date": "10/4",
        "start": "Roseville, Ca",
        "end": "Sacramento, Ca"
    },
    {
        "date": "10/4",
        "start": "Sacramento Train Museum",
        "end": "BJs Brewery Roseville Ca"
    }
]

Features

  • Utilizes Google API's to make calls. Able to resolve text entries into logical addresses.
  • Returns date, source address, detination address, and mileage.

Modifications

Review https://developers.google.com/maps/documentation/distance-matrix/intro for details

Switch from Miles to Kilometers by modifying the following block within handler.py from

payload = {
            'origins' : '|'.join(origins),
            'destinations' : '|'.join(destinations), 
            'mode' : 'driving',
            'units': 'imperial',
            'api_key' : api_key
        }

to

payload = {
            'origins' : '|'.join(origins),
            'destinations' : '|'.join(destinations), 
            'mode' : 'driving',
            'units': 'metric',
            'api_key' : api_key
        }

openfaas-get-mileage's People

Contributors

codyde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.