Skip to content

Commit 6fa46fb

Browse files
committed
copy samples to old folder
1 parent bac8c19 commit 6fa46fb

3 files changed

Lines changed: 142 additions & 0 deletions

File tree

sample/old/sample1.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
blob = bytearray([65, 66, 67, 68, 69, 70, 71, 72, 73, 74])
11+
update = True
12+
13+
try:
14+
#Get GridStore object
15+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
16+
17+
#Create Collection
18+
conInfo = griddb.ContainerInfo("col01",
19+
[["name", griddb.GS_TYPE_STRING],
20+
["status", griddb.GS_TYPE_BOOL],
21+
["count", griddb.GS_TYPE_LONG],
22+
["lob", griddb.GS_TYPE_BLOB]],
23+
griddb.GS_CONTAINER_COLLECTION, True)
24+
col = gridstore.put_container(conInfo)
25+
26+
#Change auto commit mode to false
27+
col.set_auto_commit(False)
28+
29+
#Set an index on the Row-key Column
30+
col.create_index("name", griddb.GS_INDEX_FLAG_DEFAULT)
31+
32+
#Set an index on the Column
33+
col.create_index("count", griddb.GS_INDEX_FLAG_DEFAULT)
34+
35+
#Put row: RowKey is "name01"
36+
ret = col.put(["name01", False, 1, blob])
37+
#Remove row with RowKey "name01"
38+
col.remove("name01")
39+
40+
#Put row: RowKey is "name02"
41+
col.put(["name02", False, 1, blob])
42+
col.commit();
43+
44+
mlist = col.get("name02")
45+
#print(mlist)
46+
47+
#Create normal query
48+
query=col.query("select * where name = 'name02'")
49+
50+
#Execute query
51+
rs = query.fetch(update)
52+
while rs.has_next():
53+
data = rs.next()
54+
55+
data[2] = data[2] + 1
56+
print("Person: name={0} status={1} count={2} lob=[{3}]".format(data[0], data[1], data[2], ', '.join(str(e) for e in data[3])))
57+
58+
#Update row
59+
rs.update(data)
60+
61+
#End transaction
62+
col.commit()
63+
64+
except griddb.GSException as e:
65+
for i in range(e.get_error_stack_size()):
66+
print("[", i, "]")
67+
print(e.get_error_code(i))
68+
print(e.get_location(i))
69+
print(e.get_message(i))

sample/old/sample2.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
import datetime
6+
7+
factory = griddb.StoreFactory.get_instance()
8+
9+
argv = sys.argv
10+
11+
#Get GridStore object
12+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
13+
14+
#Create TimeSeries
15+
conInfo = griddb.ContainerInfo("point01",
16+
[["timestamp", griddb.GS_TYPE_TIMESTAMP],
17+
["active", griddb.GS_TYPE_BOOL],
18+
["voltage", griddb.GS_TYPE_DOUBLE]],
19+
griddb.GS_CONTAINER_TIME_SERIES, True)
20+
ts = gridstore.put_container(conInfo)
21+
22+
#Put row to timeseries with current timestamp
23+
now = datetime.datetime.utcnow()
24+
ts.put([now, False, 100])
25+
26+
#Create normal query for range of timestamp from 6 hours ago to now
27+
query = ts.query("select * where timestamp > TIMESTAMPADD(HOUR, NOW(), -6)")
28+
rs = query.fetch()
29+
30+
#Get result
31+
while rs.has_next():
32+
data = rs.next()
33+
timestamp = str(data[0])
34+
active = data[1]
35+
voltage = data[2]
36+
print("Time={0} Active={1} Voltage={2}".format(timestamp, active, voltage))
37+

sample/old/sample3.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys, calendar
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
#Get GridStore object
11+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
12+
13+
#Get TimeSeries
14+
#Reuse TimeSeries and data from sample 2
15+
ts = gridstore.get_container("point01")
16+
17+
#Create normal query to get all row where active = FAlSE and voltage > 50
18+
query = ts.query("select * from point01 where not active and voltage > 50")
19+
rs = query.fetch()
20+
21+
#Get result
22+
while rs.has_next():
23+
data = rs.next()
24+
timestamp = calendar.timegm(data[0].timetuple())
25+
gsTS = (griddb.TimestampUtils.get_time_millis(timestamp));
26+
27+
#Perform aggregation query to get average value
28+
#during 10 minutes later and 10 minutes earlier from this point
29+
aggCommand = "select AVG(voltage) from point01 where timestamp > TIMESTAMPADD(MINUTE, TO_TIMESTAMP_MS({0}), -10) AND timestamp < TIMESTAMPADD(MINUTE, TO_TIMESTAMP_MS({1}), 10)".format(gsTS, gsTS)
30+
aggQuery = ts.query(aggCommand)
31+
aggRs = aggQuery.fetch()
32+
while aggRs.has_next():
33+
#Get aggregation result
34+
aggResult = aggRs.next()
35+
#Convert result to double and print out
36+
print("[Timestamp={0}] Average voltage = {1}".format(timestamp, aggResult.get(griddb.GS_TYPE_DOUBLE )))

0 commit comments

Comments
 (0)