/RiverAggregator

API which surfaces up to date flow information for NZ rivers

Primary LanguageJavaScript

Flow Aggregator

Restful API which surfaces aggregated New Zealand river data from various sources. A live end point can be hit at https://aggflow.herokuapp.com/ though this endpoint may not be keep up to date with the latest changes.

Quick Start

# Install dependencies
npm install

# Add Database Config Directory
mkdir config

# Create db.js file
touch db.js

# Add following code to db.js
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect(<mongodb-uri>).catch(err => console.log(err));

# Run Flow Aggregator
npm start

# Server runs on http://localhost:3030

Requests

Get all river data

# GET
http://localhost:3030
Example response

// GET
// http://localhost:3030
{
    "metaData":{
        "dataLength":301,
        "lastUpdated":"02/06/2018 1:46am"
    },
    "data": [
        {
            "siteName":"Waiau Toa/Clarence Jollies (NIWA)",
            "region":"Canterbury (North)",
            "currentFlow":"12.585",
            "currentLevel":"0.293",
            "lastUpdated":"02/06/2018 1:00am",
            "coordinates": {
                "lat":"-42.45731",
                "lng":"172.906357"
            }
        },
        {
            "siteName":"Waiau Toa/Clarence at Clarence Valley Rd Br",
            "region":"Canterbury (North)",
            "currentLevel":"0.626",
            "lastUpdated":"02/06/2018 1:00am",
            "coordinates": {
                "lat":"-42.1106262",
                "lng":"173.841934"
            }
        },
        ...,
        ...
    ]
}

Get river data by site name

# GET
http://localhost:3030/<siteName>
Example response

// GET
// http://localhost:3030/Taieri%20at%20Outram
{
    "metaData": { "lastUpdate": "02/06/2018 3:00pm" },
    "data": {
        "siteName": "Taieri at Outram",
        "region": "Otago",
        "currentFlow": "25.346",
        "currentLevel": "34.6",
        "lastUpdate": "02/06/2018 2:15pm",
        "coordinates": {
            "lat": "-45.849812",
            "lng": "170.242773"
        }
    }
}

Get historical river data by site name

# GET
http://localhost:3030/<siteName>/history
Example response

// GET
// http://localhost:3030/Taieri%20at%20Outram/history
{
    "metData":{
        "siteName":"Taieri at Outram",
        "lastUpdated":"03/06/2018 1:00pm"
    },
    "data":[
        {
            "time":"03/06/2018 10:00am",
            "flow":"25.134",
            "level": "34.6"
        },
        {
            "time":"03/06/2018 10:30am",
            "flow":"24.572",
            "level": "33.8"
        },
        ...,
        ...
    ]
}

Data Sources

All data sources are open source and free. Our thanks and gratitude to the developers and engineers who keep this information available for public use

  1. Otago Region Council
  2. Environment Canterbury
  3. Environment Southland
  4. Marlborough District Council
  5. Taranaki Regional Council

App Info

Author

Fergus Farrell

Version

1.0.0

License

This project is licensed under the MIT license