Skip to content

feat(eventprocessor): Datamodel for event processor #192

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

Merged
merged 14 commits into from
Sep 12, 2019

Conversation

msohailhussain
Copy link
Contributor

@msohailhussain msohailhussain commented Jul 23, 2019

Summary

  • Data models to represent Impression/Conversion event on client/server side.

Test plan

  • Unit tests to verify after serialization datamodel is converted into expected server payload
    Impression Event
    Conversion Event

@coveralls
Copy link

coveralls commented Jul 23, 2019

Coverage Status

Coverage decreased (-2.0%) to 96.424% when pulling a6ff8fe on sohail/pr-189 into f5b0d0c on master.

@msohailhussain msohailhussain changed the title test PR - Sohail/pr 189 feat(eventprocessor): Datamodel for event processor Jul 23, 2019
@msohailhussain msohailhussain requested review from mikeproeng37 and a team July 24, 2019 05:24
# limitations under the License.
from .. import version

SDK_VERSION = 'python-sdk'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not SDK_VERSION

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .. import version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say

from optimizely import version

from .user_event import UserEvent


class ImpressionEvent(UserEvent):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This classification under entity is vague.

ImpressionEvent ideally belongs under event/ and not under event/entity.

Similarly ConversionEvent and UserEvent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend putting all 3 of them in a single fine in optimizely/event/user_event.py

# limitations under the License.


class Decision(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend putting all classes related to event payload in a single file. I would recommend calling the file optimizely/event/payload.py or something.

@msohailhussain
Copy link
Contributor Author

@aliabbasrizvi I will get back to you on this PR today.

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More feedback.

@@ -0,0 +1,76 @@
# Copyright 2019 Optimizely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word event in event_payload is redundant as it is already under event package. Perhaps just say payload.py


from optimizely import version

SDK_TYPE = 'python-sdk'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to CLIENT_NAME

def __init__(self, entity_id, key, event_type, value):
self.entity_id = entity_id
self.key = key
self.type = event_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd refrain from using a variable called type as it is a keyword in Python.

May be just say attribute_type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attribute type is expected as 'type' keyword on server side and even if changed to 'attribute_type', it will have to be converted to 'type' eventually before sending to server.
Followed C# and Java SDKs implementation here and both of these SDKs are also using 'type' as attribute type key.

self.visitor_id = visitor_id


class VisitorAttribute(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just call this Attribute and all references to it as attribute

class VisitorAttribute(object):
""" Class representing Visitor Attribute. """

def __init__(self, entity_id, key, event_type, value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be attribute_type



class EventPayloadTest(base.BaseTest):
def _validate_event_object(self, expected_params, event_obj):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should ideally override __eq__ method on the event object and not worry about the logic here.

@zashraf1985
Copy link
Contributor

@aliabbasrizvi .. This is ready for another review. It would be great if you can take another look and provide feedback.

self.client_version = client_version
self.anonymize_ip = anonymize_ip
self.enrich_decisions = enrich_decisions
self.visitors = visitors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be self.visitors = visitors or []. That will make it valid.

class ImpressionEvent(UserEvent):
""" Class representing Impression Event. """

def __init__(self, event_context, user_id, experiment, visitor_attributes, variation, bot_filtering=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably move user_id, bot_filtering and attributes to UserEvent as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback not addressed. Is there a reason for not moving this?

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Minor feedback.

# limitations under the License.

from optimizely import version
from optimizely.event.payload import Decision, EventBatch, Snapshot, SnapshotEvent, Visitor, VisitorAttribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Why not import payload and reference each of them directly?

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback was missed. Can you take a look?

@aliabbasrizvi aliabbasrizvi merged commit 96b4d55 into master Sep 12, 2019
@oakbani oakbani deleted the sohail/pr-189 branch September 24, 2019 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants