-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
add journal table and JournalWriter helper class #89
Conversation
if event_type is None: | ||
if payload is None: | ||
event_type = "null" | ||
else: | ||
event_type = type(payload).__name__ | ||
|
||
if payload.person_id is None: | ||
payload.person_id = self.person_id | ||
if payload.post_id is None: | ||
payload.post_id = post_id | ||
if payload.workpackage_id is None: | ||
payload.workpackage_id = workpackage_id | ||
if payload.task_type is None: | ||
payload.task_type = task_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write it in a shorter way :
if event_type is None:
event_type = "null" if payload is None else type(payload).__name__
payload.person_id = payload.person_id or self.person_id
payload.post_id = payload.post_id or post_id
payload.workpackage_id = payload.workpackage_id or workpackage_id
payload.task_type = payload.task_type or task_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for the tip. Just to keep it short I could even also write
event_type = payload and type(payload).__name__ or "null"
It is a matter of taste ... I am personally not the biggest fan of the python ternary operator.
def generate_time_uuid(node=None, clock_seq=None): | ||
"""Create a lexicographically sortable time ordered custom (non-standard) UUID by reordering the timestamp fields of a version 1 UUID.""" | ||
(time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node) = uuid1(node, clock_seq).fields | ||
# reconstruct 60 bit timestamp, see version 1 uuid: https://www.rfc-editor.org/rfc/rfc4122 | ||
timestamp = (time_hi_version & 0xFFF) << 48 | (time_mid << 32) | time_low | ||
version = time_hi_version >> 12 | ||
assert version == 1 | ||
a = timestamp >> 28 # bits 28-59 | ||
b = (timestamp >> 12) & 0xFFFF # bits 12-27 | ||
c = timestamp & 0xFFF # bits 0-11 (clear version bits) | ||
clock_seq_hi_variant &= 0xF # (clear variant bits) | ||
return UUID(fields=(a, b, c, clock_seq_hi_variant, clock_seq_low, node), version=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of using time ordered uuid? Shouldn't we rely on created_date
if we ever need to do something related to the time (e.g. weekly leaderboard).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may know the snowflake datatype (as used by twitter or discord). The idea here is the same: Time ordered unique ids that can be client-side generated on different machines. It will be used by integrator processes to track up to which point in time events have been processed.
Log user responses chronologically in a journal table #72. Ratings and Rankings are directly stored in the journal, text-replies currently not.