示例#1
0
    def __init__(self):
        self.client = Client(API_KEY, API_KEY, API_SECRET)
        self.series_filename = os.path.join(EXPORT_DIR, "series_info")

        if not os.path.exists(EXPORT_DIR):
            print "Making export directory"
            os.makedirs(EXPORT_DIR)
示例#2
0
    def __init__(self, base_key, columns):
        try:
            api_key = os.environ['TEMPODB_API_KEY']
            api_sec = os.environ['TEMPODB_API_SECRET']
        except KeyError:
            raise RuntimeError("You must define environment variables "
                               "TEMPODB_API_KEY and TEMPODB_API_SECRET")

        self.base_key = base_key
        self.columns = columns
        self.client = Client(self.DATABASE_ID, api_key, api_sec)
示例#3
0
def import_channel_to_tempodb(tdms_channel, series_key=None, chunk_size=2000):
    """
    :param tdms_channel: TDMS channel
    :param series_key: If none, it will try to use the name found in the TDMS_object
    :return:
    """
    if series_key is None:
        series_key = tdms_channel.path

    print "\n", series_key

    tc_data = tdms_channel.data
    tc_time = tdms_channel.time_track()
    wf_start_time = tdms_channel.property('wf_start_time')
    data_size = len(tc_data)
    time_size = len(tc_time)

    if data_size != time_size:
        raise "Length of channel data and time are not equal (%i != %i)" % data_size, time_size

    client = Client(DATABASE_ID, API_KEY, API_SECRET)

    write_channel_attributes(tdms_channel, series_key, client)

    tempo_data = []
    start_time = datetime.now()

    i = 0
    for item_t, item_d in itertools.izip(tc_time, tc_data):

        # TODO: see if DataPoint.from_data can be any faster ... possibly create a CSV and then import the CSV
        # TODO: determine if item_d could lose some precision by casting to float
        # TODO: use proper units (e.g. look for h for hour or s for seconds)
        tempo_data.append(
            DataPoint.from_data(
                convert_offset_to_iso8601(item_t, wf_start_time),
                float(item_d)))

        if i % chunk_size == 0 and i > 0:
            write_to_tempo_db(client, i, series_key, tempo_data)
            tempo_data = []
        i += 1

    if len(tempo_data) > 0:
        write_to_tempo_db(client, i, series_key, tempo_data)
        del tempo_data

    end_time = datetime.now()
    duration = end_time - start_time
    print start_time, end_time, duration
    print "Data size: %i" % data_size
    print "Points/sec: %.2f" % (data_size / duration.total_seconds())
    return
示例#4
0
from tempodb.client import Client


#
# API_KEY = 'a68ffbe8f6fe4fb3bbda2782002680f0'
# API_SECRET = '3fe37f49b1bb4ae481dec13932c9bb92'
# SERIES_KEY = 'paul-python-1'


DATABASE_ID = 'fisi'
# API_KEY = DATABASE_ID    # Currently API_KEY is the same as DATABASE_ID
API_KEY = 'a68ffbe8f6fe4fb3bbda2782002680f0'
API_SECRET = '3fe37f49b1bb4ae481dec13932c9bb92'

client = Client(DATABASE_ID, API_KEY, API_SECRET)
try:
    client.create_series('paul-python-2014-06-12')
except tempodb.response.ResponseException as e:
    print "There was an error"
    print e

response = client.get_series('paul-python-2014-06-12')
series1 = response.data
series1.name = 'foobar'
series1.tags = ['baz', 'abc']
series1.attributes = {'foo': 'bar'}
client.update_series(series1)

import datetime
import random
from __future__ import print_function
import sys, os
from tempodb.client import Client
from flask import Flask, request, Response
app = Flask(__name__)

for k in ['TEMPODB_DATABASE_ID', 'TEMPODB_API_KEY', 'TEMPODB_API_SECRET']:
    if k not in os.environ:
        print("Missing environment variable: {}".format(k), file=sys.stderr)
        sys.exit(1)

client = Client(os.environ['TEMPODB_DATABASE_ID'],
                os.environ['TEMPODB_API_KEY'],
                os.environ['TEMPODB_API_SECRET'])

# From http://gear11.com/2013/12/python-proxy-server/
CHUNK_SIZE = 1024


def convert_response(r):
    headers = dict(r.headers)

    def generate():
        for chunk in r.iter_content(CHUNK_SIZE):
            yield chunk

    headers['Access-Control-Allow-Origin'] = '*'
    return Response(generate(), status=r.status_code, headers=headers)


@app.route('/tempodb/<path:path>')