Skip to content

Commit

Permalink
feat: updates to use tuple timeperiods
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Jul 4, 2024
1 parent d7c8792 commit d91c54b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/examples/query_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
start = now

query = "RETURN=0;"
res = client.query(query, "1970-01-01", "2100-01-01")
start_date = datetime(1970, 1, 1, tzinfo=timezone.utc)
end_date = datetime(2100, 1, 1, tzinfo=timezone.utc)

# Note that the timeperiods are a list of tuples
timeperiods = [(start_date, end_date)]
res = client.query(query, timeperiods=timeperiods)
print(res) # Should print 0

bucket_id = "{}_{}".format("test-client-bucket", client.client_hostname)
Expand All @@ -33,22 +38,23 @@ def insert_events(label: str, count: int):

insert_events("a", 5)

query = "RETURN = query_bucket('{}');".format(bucket_id)
query = 'RETURN = query_bucket("{}");'.format(bucket_id)

res = client.query(query, "1970", "2100")
res = client.query(query,timeperiods=timeperiods)
print(res) # Should print the last 5 events

res = client.query(query, start + timedelta(seconds=1), now - timedelta(seconds=2))
timeperiods_2 = [(start+timedelta(seconds=1), now-timedelta(seconds=2))]
res = client.query(query, timeperiods=timeperiods_2)
print(res) # Should print three events

insert_events("b", 10)

query = """
events = query_bucket('{}');
merged_events = merge_events_by_keys(events, 'label');
events = query_bucket("{}");
merged_events = merge_events_by_keys(events, ["label"]);
RETURN=merged_events;
""".format(bucket_id)
res = client.query(query, "1970", "2100")
res = client.query(query, timeperiods=timeperiods)
# Should print two merged events
# Event "a" with a duration of 5s and event "b" with a duration of 10s
print(res)
Expand Down

0 comments on commit d91c54b

Please sign in to comment.