Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: make the timestamps part of the payload optional #173

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def compose_stop(*, start, event_counter, poison_pill,
return doc


def compose_event_page(*, descriptor, event_counter, data, timestamps, seq_num,
def compose_event_page(*, descriptor, event_counter, data, timestamps=None, seq_num,
filled=None, uid=None, time=None, validate=True):
N = len(seq_num)
if uid is None:
Expand All @@ -1518,13 +1518,15 @@ def compose_event_page(*, descriptor, event_counter, data, timestamps, seq_num,
doc = {'uid': uid,
'time': time,
'data': data,
'timestamps': timestamps,
'seq_num': seq_num,
'filled': filled,
'descriptor': descriptor['uid']}
if timestamps is not None:
doc['timestamps'] = timestamps
if validate:
schema_validators[DocumentNames.event_page].validate(doc)
if not (descriptor['data_keys'].keys() == data.keys() == timestamps.keys()):
if not (descriptor['data_keys'].keys() == data.keys() and
(timestamps is None or data.keys() == timestamps.keys())):
raise EventModelValidationError(
"These sets of keys must match:\n"
"event['data'].keys(): {}\n"
Expand All @@ -1539,7 +1541,7 @@ def compose_event_page(*, descriptor, event_counter, data, timestamps, seq_num,
return doc


def compose_event(*, descriptor, event_counter, data, timestamps, seq_num=None,
def compose_event(*, descriptor, event_counter, data, timestamps=None, seq_num=None,
filled=None, uid=None, time=None, validate=True):
if seq_num is None:
seq_num = event_counter[descriptor['name']]
Expand All @@ -1552,13 +1554,15 @@ def compose_event(*, descriptor, event_counter, data, timestamps, seq_num=None,
doc = {'uid': uid,
'time': time,
'data': data,
'timestamps': timestamps,
'seq_num': seq_num,
'filled': filled,
'descriptor': descriptor['uid']}
if timestamps is not None:
doc['timestamps'] = timestamps
if validate:
schema_validators[DocumentNames.event].validate(doc)
if not (descriptor['data_keys'].keys() == data.keys() == timestamps.keys()):
if not (descriptor['data_keys'].keys() == data.keys() and
(timestamps is None or data.keys() == timestamps.keys())):
raise EventModelValidationError(
"These sets of keys must match:\n"
"event['data'].keys(): {}\n"
Expand Down
1 change: 0 additions & 1 deletion event_model/schemas/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"required": [
"uid",
"data",
"timestamps",
"time",
"descriptor",
"seq_num"
Expand Down
1 change: 0 additions & 1 deletion event_model/schemas/event_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"descriptor",
"uid",
"data",
"timestamps",
"time",
"seq_num"
],
Expand Down