本文整理汇总了Python中tempodb.Client.write_key方法的典型用法代码示例。如果您正苦于以下问题:Python Client.write_key方法的具体用法?Python Client.write_key怎么用?Python Client.write_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempodb.Client
的用法示例。
在下文中一共展示了Client.write_key方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: push
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
def push(self, database, series, value):
"""
Pushes a single value with current timestamp to the given database/series
"""
try:
db = self._databases[database]
client = Client(db['api_key'], db['api_secret'])
data = [DataPoint(datetime.now(), float(value))]
client.write_key(series, data)
self.last_response = 'OK'
return True
except Exception as e:
self.last_response = e
return False
示例2: import_samples
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
def import_samples():
sin = [math.sin(math.radians(d)) for d in range(0,3600)]
cos = [math.cos(math.radians(d)) for d in range(0,3600)]
sin_data = []
cos_data = []
start_time = datetime.datetime(2013,07,26)
for i in range(len(sin)):
current_time = start_time + datetime.timedelta(minutes=i)
sin_data.append(DataPoint(current_time, sin[i]))
cos_data.append(DataPoint(current_time, cos[i]))
client = Client(API_KEY, API_SECRET)
client.write_key('type:trig.function:sin.1',sin_data)
client.write_key('type:trig.function:cos.1', cos_data)
示例3: TempoDBOutput
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
class TempoDBOutput(Output):
def __init__(self, **tempo_kwargs):
self.client = Client(**tempo_kwargs)
def __repr__(self):
return '<%s>' % self.__class__.__name__
def send(self, key, value):
if isinstance(value, bool):
value = 1 if value else 0
self.client.write_key(
key,
[DataPoint(datetime.now(), value)]
)
示例4: Client
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
"""
http://tempo-db.com/api/write-series/#write-series-by-key
"""
import datetime
import random
from tempodb import Client, DataPoint
# Modify these with your credentials found at: http://tempo-db.com/manage/
API_KEY = '680d1adbbb0c42a398b5846c8e1517dd'
API_SECRET = 'f2db65d178634a36b4c25467f8bc2099'
SERIES_KEY = 'your-custom-key'
client = Client(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(date, random.random() * 50.0))
date = date + datetime.timedelta(minutes=1)
client.write_key(SERIES_KEY, data)
示例5: calculate_temp
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
temp = 1 / (1/THERMISTOR_REF_TEMP + math.log(resistance / THERMISTOR_REF_RESISTANCE) / THERMISTOR_B_VALUE)
print "Temperature is: %f K, (%f degC)" % (temp, temp-273.15)
return temp-273.15
ser = serial.Serial('/dev/tty.usbserial-A800etDk', 9600)
temperature_array = []
while 1:
r = ser.readline()
split = r.split(",")
if(len(split) == 3):
# Deal with the temperature pin first
value = split[0].strip()
temp = calculate_temp(value)
temperature_array.append(temp)
if(len(temperature_array) >= 20):
mean = sum(temperature_array) / float(len(temperature_array))
print "Saving off this minute's mean: %f" % mean
client.write_key('temperature', [DataPoint(datetime.datetime.utcnow(), mean)])
temperature_array = []
# And now the LDR resistance
value = split[1].strip()
voltage = float(value) / 1024 * 5
resistance = POTENTIAL_DIVIDER_RESISTOR / (5 / voltage - 1)
print "LDR resistance is: %f Ohms" % resistance
# And finally, the humidity
value = split[2].strip()
print "Humidity reading is: %d" % float(value)
示例6: ClientTest
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
#.........这里部分代码省略.........
self.client.session.delete.assert_called_once_with(
'https://example.com/v1/series/key/key1/data/?start=2012-03-27T00%3A00%3A00&end=2012-03-28T00%3A00%3A00',
auth=('key', 'secret'),
headers=self.delete_headers
)
self.assertEquals(result, '')
def test_delete_key_escape(self):
self.client.session.delete.return_value = MockResponse(200, "")
start = datetime.datetime(2012, 3, 27)
end = datetime.datetime(2012, 3, 28)
result = self.client.delete_key("ke:y/1", start, end)
self.client.session.delete.assert_called_once_with(
'https://example.com/v1/series/key/ke%3Ay%2F1/data/?start=2012-03-27T00%3A00%3A00&end=2012-03-28T00%3A00%3A00',
auth=('key', 'secret'),
headers=self.delete_headers
)
self.assertEquals(result, '')
def test_write_id(self):
self.client.session.post.return_value = MockResponse(200, "")
data = [DataPoint(datetime.datetime(2012, 3, 27), 12.34)]
result = self.client.write_id("id1", data)
self.client.session.post.assert_called_once_with(
'https://example.com/v1/series/id/id1/data/',
auth=('key', 'secret'),
data="""[{"t": "2012-03-27T00:00:00", "v": 12.34}]""",
headers=self.post_headers
)
self.assertEquals(result, '')
def test_write_key(self):
self.client.session.post.return_value = MockResponse(200, "")
data = [DataPoint(datetime.datetime(2012, 3, 27), 12.34)]
result = self.client.write_key("key1", data)
self.client.session.post.assert_called_once_with(
'https://example.com/v1/series/key/key1/data/',
auth=('key', 'secret'),
data="""[{"t": "2012-03-27T00:00:00", "v": 12.34}]""",
headers=self.post_headers
)
self.assertEquals(result, '')
def test_write_key_escape(self):
self.client.session.post.return_value = MockResponse(200, "")
data = [DataPoint(datetime.datetime(2012, 3, 27), 12.34)]
result = self.client.write_key("ke:y/1", data)
self.client.session.post.assert_called_once_with(
'https://example.com/v1/series/key/ke%3Ay%2F1/data/',
auth=('key', 'secret'),
data="""[{"t": "2012-03-27T00:00:00", "v": 12.34}]""",
headers=self.post_headers
)
self.assertEquals(result, '')
def test_increment_id(self):
self.client.session.post.return_value = MockResponse(200, "")
data = [DataPoint(datetime.datetime(2012, 3, 27), 1)]
result = self.client.increment_id("id1", data)
self.client.session.post.assert_called_once_with(
'https://example.com/v1/series/id/id1/increment/',
示例7: Client
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
"""
http://tempo-db.com/api/write-series/#write-series-by-key
"""
import datetime
import random
from tempodb import Client, DataPoint
client = Client('your-api-key', 'your-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(date, random.random() * 50.0))
date = date + datetime.timedelta(minutes=1)
client.write_key('your-custom-key', data)
示例8: getenv
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
from datetime import datetime
from time import sleep
import random
from tempodb import Client, DataPoint
import tempodb
from os import getenv
API_KEY = getenv('API_KEY')
assert API_KEY, "API_KEY is required"
API_SECRET = getenv('API_SECRET')
assert API_SECRET, "API_SECRET is required"
SERIES_KEY = getenv('SERIES_KEY', 'prng')
API_HOST = getenv('API_HOST', tempodb.client.API_HOST)
API_PORT = int(getenv('API_PORT', tempodb.client.API_PORT))
API_SECURE = bool(getenv('API_SECURE', True))
client = Client(API_KEY, API_SECRET, API_HOST, API_PORT, API_SECURE)
while True:
client.write_key(SERIES_KEY, [DataPoint(datetime.now(), random.random() * 50.0)])
sleep(1)
示例9:
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
date = datetime.datetime.now()
# 1: Pressure
# correct pressure for height above sea level
# see http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Reduktion_auf_Meeresh.C3.B6he
# baro[0] is the current temperature of the sensor
# baro[1] is the absolute atmospheric pressure
# p0 is the corrected atmospheric pressure adjusted to HEIGHT
temperature = baro[0]
temperature = 6
efactor=5.6402 * (-0.0916 + math.exp(0.06 * temperature))
xfactor = (9.80665 / (287.05 * ((273.15 + temperature) + .12 * efactor + 0.0065 * (HEIGHT/2)))) * HEIGHT
p0 = baro[1] * math.exp(xfactor)
# upload to tempoDB
data = []
data.append(DataPoint(date, p0))
tmp=tempodbclient.write_key(SERIES_KEY1, data)
# 2. Temperature
data = []
data.append(DataPoint(date, temperature))
tmp=tempodbclient.write_key(SERIES_KEY2, data)
print tmp
sys.stdout.flush()
# wait 5minutes
time.sleep(300.0)
tag.disconnect()
del tag
示例10: Client
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
import datetime, time
from tempodb import Client, DataPoint
from Temperature import Temperature
from config import USER, PWD, API_KEY, API_SECRET
UPDATE_INTERVAL = 60 # seconds
tempoDB = Client(API_KEY, API_SECRET)
core = Temperature(USER, PWD, 'mutant_jetpack')
core.setInterval(UPDATE_INTERVAL)
core.setRGB(0)
print core
while core.isConnected():
tempc = core.temperature()
date = datetime.datetime.utcnow()
if tempc:
tempoDB.write_key("TEMPERATURE", [DataPoint(date, tempc)])
print "%s, %1.2f" % (datetime.datetime.now(), tempc)
time.sleep(UPDATE_INTERVAL)
示例11: Client
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
"""
http://tempo-db.com/api/write-series/#write-series-by-key
"""
from datetime import datetime, timedelta
import random
from tempodb import Client, DataPoint
client = Client('a93feb1d6a7e49919331b09eab299967', '67fd4ee803df456b845cdeb5e675d465')
# for id in range(1,33):
# station='station_'+str(id)
# series = client.create_series(station)
date = datetime(2012, 1, 1)
for day in range(1, 10):
# print out the current day we are sending data for
print date
for id in range(1,33):
data = []
# 1440 minutes in one day
for min in range (1, 1441):
data.append(DataPoint(date, random.random() * 50.0))
date = date + timedelta(minutes=1)
station='station_'+str(id)
client.write_key(station, data)
示例12: Client
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
import math, datetime
from tempodb import Client, DataPoint
client = Client("a755539a9e124278b04f988d39bc5ef9", "43f97dc4dbbc46499bd6694a3455210c")
sin = [math.sin(math.radians(d)) for d in range(0,3600)]
cos = [math.cos(math.radians(d)) for d in range(0,3600)]
start = datetime.datetime(2013,01,01)
sin_data = []
cos_data = []
for i in range(len(sin)):
sin_data.append(DataPoint(start + datetime.timedelta(minutes=i), sin[i]))
cos_data.append(DataPoint(start + datetime.timedelta(minutes=i), cos[i]))
client.write_key('type:sin.1',sin_data)
client.write_key('type:cos.1', cos_data)
client.read_key('type:sin.1', start, datetime.datetime(2013,01,05))
attributes={
"type": "sin"
}
client.read(start, datetime.datetime(2013,01,05), attributes= attributes)
示例13: int
# 需要导入模块: from tempodb import Client [as 别名]
# 或者: from tempodb.Client import write_key [as 别名]
sys.exit()
volstep = (int(vollimitup) - int(vollimitdown)) / 10
print "[INIT]: ",AMIXER," limits from ",vollimitdown," to ",vollimitup,". Current volume is ",volvalue,". Volume Step is ",volstep
i=0
tempArray = []
lightArray = []
softArray = []
client = Client(API_KEY, API_SECRET)
while 1:
sensors = ser.readline()
#Temp: 26.66. Light: 125. softPot: 99
sensorsRegEx = re.compile("Temp: ([0-9.]*). Light: (\d{0,3}). softPot: (\d{0,3})")
sensorsLine = sensorsRegEx.search(sensors)
if i == 1000:
sys.stderr.write("Sending data to tempodb...\n")
client.write_key("light", lightArray)
client.write_key("soft", softArray)
client.write_key("temp", tempArray)
tempArray = []
lightArray = []
softArray = []
i = 0
i+=1
if sensorsLine:
temp = sensorsLine.group(1)
light = sensorsLine.group(2)
slide = int(sensorsLine.group(3))
curtime = datetime.datetime.now()
tempArray.append(DataPoint(curtime,float(temp)))
lightArray.append(DataPoint(curtime,float(light)))
softArray.append(DataPoint(curtime,float(slide)))