Code Monkey home page Code Monkey logo

canal's Introduction

canal

A fairly crude attempt at an application-layer schema for python influxdb clients

It makes no assumptions about the client-side library, it just provides utilities to serialize/deserialize payloads to/from an influxdb instance. This makes it suitable for usage in both synchronous (ex. Django) or asynchronous (ex. Tornado) applications

Documentation is on my to-do list, apologies!

Example

Authors Warning: I make no guarantees that this example is still functional, as the API is still heavily in flux...

import datetime

import canal
from influxdb import InfluxDBClient


class IMU(canal.Measurement):
    accelerometer_x = canal.IntegerField()
    accelerometer_y = canal.IntegerField()
    accelerometer_z = canal.IntegerField()
    gyroscope_x = canal.IntegerField()
    gyroscope_y = canal.IntegerField()
    gyroscope_z = canal.IntegerField()
    user_id = canal.Tag()


if __name__ == "__main__":
    start_date = datetime.datetime.now(datetime.timezone.utc)
    duration = datetime.timedelta(seconds=60)
    user_id = 12345678

    client = InfluxDBClient(
        host="localhost",
        port=8086,
        database="canal"
    )

    # Write some dummy IMU data, sampled once per second
    num_imu_samples = int(duration.total_seconds())
    imu = IMU(
        time=[start_date + datetime.timedelta(seconds=d) for d in
              range(num_imu_samples)],
        acc_x=range(0, 1 * num_imu_samples, 1),
        acc_y=range(0, 2 * num_imu_samples, 2),
        acc_z=range(0, 3 * num_imu_samples, 3),
        gyro_x=range(0, 4 * num_imu_samples, 4),
        gyro_y=range(0, 5 * num_imu_samples, 5),
        gyro_z=range(0, 6 * num_imu_samples, 6),
        user_id=user_id
    )
    client.write(
        data=imu.to_line_protocol(),
        params=dict(
            db="canal"
        )
    )

    # Read back the IMU data
    imu_resp = client.query(IMU.make_query_string(
        time__gte=start_date,
        time__lte=start_date + duration,
        user_id=user_id
    ))
    assert imu == IMU.from_json(imu_resp.raw)
    

canal's People

Contributors

adverbly avatar dan-stone avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

adverbly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.