def write(self, data): t = data['time'] logger.debug("Data: %s", data) points = [DataPoint.from_data(t, float(data[k]), key='%s.%s' % (self.base_key, k)) for k in self.columns if k != 'time'] resp = self.client.write_multi(points) if resp.status != 200: raise Exception("TempoDB error [%d] %s" % (resp.status, resp.error))
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
def write(self, data): t = data['time'] logger.debug("Data: %s", data) points = [ DataPoint.from_data(t, float(data[k]), key='%s.%s' % (self.base_key, k)) for k in self.columns if k != 'time' ] resp = self.client.write_multi(points) if resp.status != 200: raise Exception("TempoDB error [%d] %s" % (resp.status, resp.error))
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
def insert_range(self, points_array): data = [] # put the points into the right format for point in points_array: pointDateTime = datetime.datetime.utcfromtimestamp(point.time) tempoPt = DataPoint.from_data(pointDateTime, point.value) data.append(tempoPt) # split data into chunks of 100 points for i in range(0, len(data), 100): chunk = data[i:i+100] # write points out self._client.write_data(self.SERIES_KEY, chunk) # if len(data) is not a multiple of 100, we have some points left over r = len(data)%100 last_chunk = data[-r:] self._client.write_data(self.SERIES_KEY, chunk)
__author__ = 'paulmestemaker' import datetime import random from tempodb.client import Client from tempodb.protocol import DataPoint from secrets import API_KEY, API_SECRET, DATABASE_ID # Modify these with your credentials found at: http://tempo-db.com/manage/ SERIES_KEYS = ['paul-multi-1-1', 'paul-multi-1-2', 'paul-multi-1-3'] client = Client(DATABASE_ID, API_KEY, API_SECRET) date = datetime.datetime(2012, 1, 1) for day in range(1, 10): # print out the current day we are sending data for print date data = [] # 1440 minutes in one day for min in range(1, 1441): for series in SERIES_KEYS: data.append(DataPoint.from_data(date, random.random() * 50.0, key=series)) date = date + datetime.timedelta(minutes=1) resp = client.write_multi(data) print 'Response code:', resp.status if resp.status != 200: print 'Error reason:', resp.error
import datetime import random from tempodb.client import Client from tempodb.protocol import DataPoint from secrets import API_KEY, API_SECRET, DATABASE_ID # Modify these with your credentials found at: http://tempo-db.com/manage/ # DATABASE_ID = 'my-id' # API_KEY = DATABASE_ID # API_SECRET = 'my-secret' SERIES_KEY = 'temp-1' client = Client(DATABASE_ID, API_KEY, API_SECRET) date = datetime.datetime(2012, 1, 1) for day in range(1, 10): # print out the current day we are sending data for print date data = [] # 1440 minutes in one day for min in range(1, 1441): data.append(DataPoint.from_data(date, random.random() * 50.0)) date = date + datetime.timedelta(minutes=1) resp = client.write_data(SERIES_KEY, data) print 'Response code:', resp.status if resp.status != 200: print 'Error reason:', resp.error