Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example script for loading historical data #9

Merged
merged 9 commits into from
Oct 16, 2024
1 change: 1 addition & 0 deletions examples/dump_data/dump_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def main():
sensors_data.extend(device.get_analog_inputs())
sensors_data.extend(device.get_analog_temperature_sensors())
sensors_data.extend(device.get_boiler_adapters())
sensors_data.extend(device.get_heating_circuits())

print(json.dumps(sensors_data, ensure_ascii=False))

Expand Down
28 changes: 28 additions & 0 deletions examples/dump_data/dump_timeseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3

import sys
import json
from datetime import datetime, timedelta
from zont_api import ZontAPI, DATA_TYPES_Z3K


def main():
zapi = ZontAPI()
devices = zapi.get_devices()

dt_to = datetime.now()
dt_from = dt_to - timedelta(minutes=5)

data = []

for device in devices:
interval = (dt_from.timestamp(), dt_to.timestamp())
data.append(
zapi.load_data(device.id, data_types=DATA_TYPES_Z3K, interval=interval)
)

print(json.dumps(data, ensure_ascii=False))


if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions examples/load_data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
12 changes: 12 additions & 0 deletions examples/load_data/check_sorted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if [ ! -d "data" ]; then
exit 0
fi

trap "rm -f tmp.$$" EXIT

for f in $(find data/ -type f -name "*.csv"); do
cat $f | sort -k1 -n -t ',' >tmp.$$
diff -u $f tmp.$$
done
Loading