Over the past 5 years, the UK government has made a push to make government datasets easily accessible to the general public. These public datasets, when combined with Orchestrate (DBaaS) and a PaaS, prove to be a quite powerful combination. With a few lines of server code and a simple front end web app, you can build powerful tools to explore them.

Using a public dataset, a minimal go-based server app, a Polymer-based front-end, and Pivotal’s Cloud Foundry PaaS, we will demonstrate this power.

The Dataset

It’s widely believed that electric cars will play a large role in the future of personal transport. Fortunately for those living on the bleeding edge, the UK Government publishes a registry of all the UK’s electric car charge points.

UK Chargepoints map

The dataset can be downloaded in a number of formats under the permissive OGL license.

Orchestrate

To analyze and visualize the dataset we need to load the data into something we can query both based on metadata and geo-coordinates. Orchestrate to the rescue:

  1. Downloaded the JSON formatted dataset
  2. Converted strings that contained numeric data into JSON numbers and omit fields with null values. A finalized record will look like:
    {
    "Accessible24Hours": false,
    "ChargeDeviceId": "9c8661befae6dbcd08304dbf4dcaf0db",
    "ChargeDeviceLocation": {
        "Address": {
            "Country": "gb",
            "PostCode": "BT2 7JH",
            "PostTown": "Belfast",
            "Street": "Little Victoria Street",
        },
        "Latitude": 54.592605,
        "LocationLongDescription": "DRD Roads Service Car Park on Little Victoria Street",
        "LocationShortDescription": "Little Victoria Street DRD Car Park",
        "Longitude": -5.933197
    },
    "ChargeDeviceName": "DRD Little Victoria Street DRD Car Park",
    "ChargeDeviceRef": "SC22",
    "ChargeDeviceText": "DRD Roads Service Car Park",
    "Connector": [
        {
            "ChargeMethod": "Three Phase AC",
            "ChargeMode": 3,
            "ChargePointStatus": "In service",
            "ConnectorId": "LBBD06001087/LBBD06001087",
            "ConnectorType": "IEC 62196-2 type 2",
            "RatedOutputCurrent": 32,
            "RatedOutputkW": 22.0,
            "TetheredCable": 0
        },
        {
            "ChargeMethod": "Three Phase AC",
            "ChargeMode": 3,
            "ChargePointStatus": "In service",
            "ConnectorId": "LBBD06001087/LBBD06001083",
            "ConnectorType": "IEC 62196-2 type 2",
            "RatedOutputCurrent": 32,
            "RatedOutputkW": 22.0,
            "TetheredCable": 0
        }
    ],
    "OnStreetFlag": false,
    "PaymentRequiredFlag": false,
    "PhysicalRestrictionFlag": false,
    "SubscriptionRequiredFlag": true
    }
    
  3. Loaded the data into Orchestrate using a small Go-based JSON import tool. That’s it. Simple and easy.

The next step is to design our queries. Given that a Google Maps view is a natural bounding box, I used Orchestrate’s bounding box query feature. The bounding box URL query string (without URL encoding for readability’s sake) looks something like:

query=value.ChargeDeviceLocation:IN:{north:51.737135097674845 east:0.703125 south:51.22140696627941 west:-0.703125}

Additionally, I provide the ability to filter by 24 hour access, free only, and the minimum power. You can inspect the queries used by the final app by clicking the info button in the bottom right hand corner.

Go

To proxy requests between Orchestrate and our front-end, I’ve built a minimal Go web server that both serves the static HTML that makes up the front-end and takes search request from the front-end and sends them with our app credentials to Orchestrate. The entire Go app is less than 100 lines of code.

The project is deployable to PaaS like Cloud Foundry and Heroku or can be containerized using Docker and deployed on any modern linux server. You can find the complete project on Github.

Polymer

Polymer is a relatively new front-end web development platform from Google based on what they call “web components”:

Web Components usher in a new era of web development based on encapsulated and interoperable custom elements that extend HTML itself. Built atop these new standards, Polymer makes it easier and faster to create anything from a button to a complete application across desktop, mobile, and beyond.

Polymer comes with a default set of components and some higher level components based on Google’s material design. Further, some really useful components are available on the web, namely a Google Maps component which we will utilize.

Cloud Foundry

Cloud Foundry is an open source Platform as a Service that’s gives everyone the power to host their own PaaS. Cloud Foundry boasts many great features, including compatibility with Heroku buildpacks.

You have many options for hosting Cloud Foundry applications, including two CenturyLink options that are Cloud Foundry Certified: we have our multi-tenant PaaS AppFog, as well as Managed Pivotal Cloud Foundry.

In either case, deploying to Cloud Foundry couldn’t be simpler:

  1. Sign up and create a space and an application.
  2. Install the Cloud Foundry CLI tool.
  3. Link the newly installed CLI tool to your Pivotal Cloud Foundry account.
  4. Push the app using the Heroku Go Buildpack. The command will look like:
> cf push chargepoints -b https://github.com/kr/heroku-buildpack-go

The App

The deployed app is running on AppFog. Not bad for a 100 lines of Go and a single page web app, huh?

You can find the source code for the entire project on Github.