Skip to main content

Client to access the VertexOne WaterSmart water data

Project description

Vertex One WaterSmart (Water Utilities) data module

This project aims at making data from the Santa Cruz Municipal Utilies website available for programatic use.

There is no REST API per say, despite the naming of the url, but there are 2 useful data endpoints used to render charts on the site:

  • Daily consumption, which includes daily weather reference data.
  • Hourly consumption (in gallons), with some 'leak' flag, although it never seems to be set.

There are several caveats to using these endpoints:

  • The datasets available are datasets meant to render the charts in the website, therefore they include a range of data, not just the latest datapoint.

  • The data sent to the front-end is always the full dataset, and there is no range query parameters that I could find. (Note that the hourly dataset seems to be covering over a year's worth of data, and the daily more than 3 years so it is not clear how the 'start' point is defined; It is probably when the meter was upgraded).

  • Most importantly, the hourly data is only available about twice a day, so it is not 'real-time' per say. I have seen the data be updated up to 9:00AM, 12:00PM as well as 12:00AM, so it is not clear what the schedule is.

  • Sometimes, the weather data is not available, but it will show later.

Functionality

The module provides a way to fetch the latest dataset for both hourly and daily consumption. This can be used as-is, but the user will need to manage it's own resulting datastream (i.e. merge overlapping ranges from sequential fetches, and/or filter by time range)

To facilitate extraction of a non-overlapping dataset, as well as range queries, an optional local storage mechanism is provided (leveraging SQLAlchemy and SQLite for now, but expandable to other SQLAlchemy backends). It merges the datasets each time it they are fetched, and allow for retrieval of historical data by time range.

Install

pip install vertexone-watersmart

Usage

Synchronous Client

import os

from vertexone_watersmart.client import Client
from vertexone_watersmart.sqlite import SQLiteStorage

username = os.environ.get('V1WS_USERNAME')
password = os.environ.get('V1WS_PASSWORD')

# optional, instantiate a backend store
db = SQLiteStorage('scmu.db', echo=True) # set echo=False to turn logs off
# instantiate the client, choosing a known provider
scmu = Client(provider='santacruz', storage_engine=db)
scmu.login(username=username, password=password)
# fetch latest dataset
daily_data = scmu.daily.fetch()
print(daily_data[:10])
hourly_data = scmu.hourly.fetch()
print(hourly_data[:10])

# get history (all params are optional, from and to are unix timestamps)
daily_data = scmu.daily.get_history(from_ts=1685494800, to_ts=1686974400, limit=10, offset=0, ascending=True)
print(daily_data[:10])
hourly_data = scmu.hourly.get_history(from_ts=1685494800, to_ts=1686974400, limit=10, offset=0, ascending=True)
print(hourly_data[:10])

Async Client

To support modern use cases, the client support async requests by simply setting the parameter async=True on creation, and then using the async/await syntax.

import asyncio
import os
from datetime import datetime

from vertexone_watersmart.client import Client
from vertexone_watersmart.sqlite import SQLiteStorage


async def main():
    username = os.environ.get('V1WS_USERNAME')
    password = os.environ.get('V1WS_PASSWORD')

    db = SQLiteStorage('scmu.db', echo=True) # set echo=False to turn logs off
    scmu = Client(provider='santacruz', storage_engine=db, is_async=True)
    
    scmu.login(username=username, password=password)
    # fetch latest dataset
    [daily_data, hourly_data] = await asyncio.gather(*[
        scmu.daily.fetch(),
        scmu.hourly.fetch()
    ])
    print(daily_data[:10])
    print(hourly_data[:10])

    # get history (all params are optional, from and to are unix timestamps)
    daily_data = scmu.daily.get_history(from_ts=1685494800, to_ts=1686974400, limit=10, offset=0, ascending=True)
    print(daily_data[:10])
    hourly_data = scmu.hourly.get_history(from_ts=1685494800, to_ts=1686974400, limit=10, offset=0, ascending=True)
    print(hourly_data[:10])

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vertexone_watersmart-0.1.4.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

vertexone_watersmart-0.1.4-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file vertexone_watersmart-0.1.4.tar.gz.

File metadata

  • Download URL: vertexone_watersmart-0.1.4.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for vertexone_watersmart-0.1.4.tar.gz
Algorithm Hash digest
SHA256 508d0732aed87cb02ad29a74925dcc2b74b6cb6ebf4897ec2ae626f9c20db0ea
MD5 4ff4d6a8536cb802ff3f52af5c81723a
BLAKE2b-256 3bd2ac04bf042982307e0fe672d2ee9bc1c12f912d18c8e299ba1436caa5c494

See more details on using hashes here.

File details

Details for the file vertexone_watersmart-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for vertexone_watersmart-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e1ed26994af1f43b53e99bbf55695383d56a69b37d03ad144156d0a237cc00b7
MD5 9ecff0d346534b674257ad53bad840ee
BLAKE2b-256 a58ae9888bfa97fc16c250420c1207e198279f32265165e1b8a92901bf7bb076

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page