A python API Client for Cloogy
Project description
Cloogy
Python client for Cloogy
See Demo.ipynb for a working Jupyter Notebook
0. Install cloogy
In your terminal: pip3 install cloogy
or in a python shell or notebook:
import pip
pip.main(['install', 'cloogy'])
import yaml
from cloogy import CloogyClient
1. Get your credentials
Get your login and password.
In this example we'll load it from a YAML file.
with open('credentials.yaml', 'r') as f:
credentials = yaml.load(f)
login = credentials['login']
password = credentials['password']
2. Create a CloogyClient
If you supply a login and password, authentication will be handled for you.
client = CloogyClient(login=login, password=password)
3. List your Units
units = client.get_units()
units
4. Get a specific Unit by ID
# Lets grab the first ID from the list above
unit_id = units[0]['Id']
print(unit_id)
unit = client.get_unit(unit_id=unit_id)
unit
5. Find out some stuff about your unit
The Unit
class is an extension to the regular python dict. This means it behaves like a normal dict, but adds some extra features.
# Get date and time of the last communication
unit.get_last_communication_date()
6. List all available Tags for your login
client.get_tags()
7. List available Tags for a Unit
tags = unit.get_tags()
tags
[tag['Id'] for tag in tags]
8. Get a specific Tag directly
tag_id = tags[0]['Id']
print(tag_id)
tag = client.get_tag(tag_id=tag_id)
tag
tag.get_last_communication_date()
9. Get consumptions
# pick a start and end time, as POSIX timestamp
import pandas as pd
start = int(pd.Timestamp('20180414').timestamp() * 1000)
end = int(pd.Timestamp('20180416').timestamp() * 1000)
print(start, end)
client.get_consumptions(
granularity='hourly', # can be Instant, Hourly, Daily, Monthly, Yearly
start=start,
end=end,
tags=[tag_id], # List of tag Id's
instants_type=None # How instant measurements should be aggregated. Can be Avg, Max, Min, Stdev. Default is Avg.
)
10. Get consumptions as a DataFrame
For some easy analysis, methods to get data as a Pandas DataFrame are included
Let's say we want to analyse the active energy consumption, which has TagTypeId 20001
tags = client.get_tags(where='TagTypeId=20001')
tag_ids = [tag['Id'] for tag in tags]
start = pd.Timestamp('20180101')
end = pd.Timestamp('20180417')
client.get_consumptions_dataframe(granularity='monthly', start=start, end=end, tags=tag_ids)
A flat table like this is nice, but it can contain multiple TagIds, and it has way to many columns we don't need.
We can also get a table for only the readings:
df = client.get_readings_dataframe(granularity='monthly', start=start, end=end, tags=tag_ids, metric='Read')
df
# make a plot!
%matplotlib inline
df.plot.bar()
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
Built Distribution
File details
Details for the file cloogy-0.1.0.tar.gz
.
File metadata
- Download URL: cloogy-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2bbe9cde228d9a0919512253f06e51662eeb82e6ccbd08aefe8049da648f67 |
|
MD5 | e9fe6a886f04af74290b130c4dbfe7e9 |
|
BLAKE2b-256 | fba902f7f6495eb671f4a1f37b3f4294b560e7eb64fce6d508b8f30f5d1716c1 |
File details
Details for the file cloogy-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: cloogy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 382ce0426492a8e43b780041d5c1a711e14e987acaae3b6efd7ae364a5c3703d |
|
MD5 | a3f30f1a8a99ab32150e8169cbcbe431 |
|
BLAKE2b-256 | 57a691c32d986608105abb9a3dd5b8c96545dc8be22781936b29b0b9cc471cfb |