forked from griddb/python_client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample2.py
More file actions
executable file
·37 lines (28 loc) · 1 KB
/
sample2.py
File metadata and controls
executable file
·37 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
import griddb_python as griddb
import sys
import datetime
factory = griddb.StoreFactory.get_instance()
argv = sys.argv
#Get GridStore object
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
#Create TimeSeries
conInfo = griddb.ContainerInfo("point01",
[["timestamp", griddb.Type.TIMESTAMP],
["active", griddb.Type.BOOL],
["voltage", griddb.Type.DOUBLE]],
griddb.ContainerType.TIME_SERIES, True)
ts = gridstore.put_container(conInfo)
#Put row to timeseries with current timestamp
now = datetime.datetime.utcnow()
ts.put([now, False, 100])
#Create normal query for range of timestamp from 6 hours ago to now
query = ts.query("select * where timestamp > TIMESTAMPADD(HOUR, NOW(), -6)")
rs = query.fetch()
#Get result
while rs.has_next():
data = rs.next()
timestamp = str(data[0])
active = data[1]
voltage = data[2]
print("Time={0} Active={1} Voltage={2}".format(timestamp, active, voltage))