• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tasks.EventTracker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mixpanel.tasks.EventTracker的典型用法代码示例。如果您正苦于以下问题:Python EventTracker类的具体用法?Python EventTracker怎么用?Python EventTracker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了EventTracker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_handle_properties_given

    def test_handle_properties_given(self):
        et = EventTracker()

        properties = et._handle_properties({'token': 'bar'}, None)
        self.assertEqual('bar', properties['token'])

        properties = et._handle_properties({'token': 'bar'}, 'foo')
        self.assertEqual('bar', properties['token'])
开发者ID:andela,项目名称:mixpanel-celery,代码行数:8,代码来源:test_tasks.py


示例2: test_old_run

    def test_old_run(self):
        """non-recorded events should return False"""
        et = EventTracker()
        # Times older than 3 hours don't get recorded according to: http://mixpanel.com/api/docs/specification
        # equests will be rejected that are 3 hours older than present time
        result = et.run('event_foo', {'time': 1245613885})

        self.assertFalse(result)
开发者ID:Crowdbooster,项目名称:mixpanel-celery,代码行数:8,代码来源:test_tasks.py


示例3: test_disable

    def test_disable(self):
        et = EventTracker()
        mp_settings.MIXPANEL_DISABLE = True

        def _fake_get_connection():
            assert False, "Should bail out before trying to get a connection."
        et._get_connection = _fake_get_connection

        et('foo')
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:9,代码来源:test_tasks.py


示例4: test_non_recorded

    def test_non_recorded(self):
        """non-recorded events should return False"""
        self.response.read.return_value = '0'

        et = EventTracker()
        # Times older than 3 hours don't get recorded according to:
        # http://mixpanel.com/api/docs/specification
        # requests will be rejected that are 3 hours older than present time
        # (though actually this is returnin False because of mocking network)
        result = et.run('event_foo', {'time': 1245613885})

        self.assertFalse(result)
开发者ID:datafyit,项目名称:mixpanel-celery,代码行数:12,代码来源:test_tasks.py


示例5: test_build_params

    def test_build_params(self):
        et = EventTracker()

        event = 'foo_event'
        is_test = 1
        properties = {'token': 'testtoken'}
        params = {'event': event, 'properties': properties}

        url_params = et._build_params(event, properties, is_test)

        expected_params = urllib.urlencode({
            'data': base64.b64encode(simplejson.dumps(params)),
            'test': is_test,
        })

        self.assertEqual(expected_params, url_params)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:16,代码来源:test_tasks.py


示例6: test_failed_request

    def test_failed_request(self):
        EventTracker.endpoint = 'brokenurl'

        with eager_tasks():
            result = EventTracker.delay('event_foo')

        self.assertNotEqual(result.traceback, None)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:7,代码来源:test_tasks.py


示例7: test_build_and_encode_params

    def test_build_and_encode_params(self):
        et = EventTracker()

        event = 'foo_event'
        test = True
        properties = {'token': 'testtoken'}
        params = {'event': event, 'properties': properties}

        params = et._build_params(event, properties)
        url_params = et._encode_params(params, test)

        expected_params = urllib.parse.urlencode({
            'data': base64.b64encode(json.dumps(params).encode('utf8')),
            'test': '1'
        })

        self.assertEqual(expected_params, url_params)
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:17,代码来源:test_tasks.py


示例8: test_failed_socket_request

    def test_failed_socket_request(self):
        def new_read(*args, **kwargs):
            raise socket.error('BOOM')

        self.response.read = new_read
        with eager_tasks():
            result = EventTracker.delay('event_foo')
        self.assertNotEqual(result.traceback, None)
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:8,代码来源:test_tasks.py


示例9: send_mixpanel_event

def send_mixpanel_event(event_name, user, event_dict=None):
    """
    Helper function that takes from various views an event name, an event_dict and an user and populates the event dict with
    a) distinct_id of the user with key 'distinct_id'
    b) 'username' = user.firstname + user.lastname
    c) 'age' = in years, today - DOB
    d) 'gender' = user.gender
    e) total em
    f) redeemable em
    g) time on earthmiles = today - joining date
    and then calls EventTracker.delay() with the modified dictionary
    """
    from dateutil.relativedelta import relativedelta
    from datetime import datetime, date

    if event_dict == None:
        event_dict = {}
    try:
        age = relativedelta(datetime.today(), user.age, ).years
        days_on_em = (datetime.today() - user.date_joined.replace(tzinfo=None)).days
        event_dict.update(
            {
                'distinct_id': user.id,
                'Username': user.__str__(),
                'Age': age,
                'Gender': user.gender,
                'Days on Earthmiles': days_on_em,
                'Total Earthmiles': user.total_earthmiles,
                'Redeemable Earthmiles': user.redeemable_earthmiles,
            }
        )
    except AttributeError as e:
        event_dict.update(
            {
                'distinct_id': user.id,
            }
        )


    #Try to send event to mixpanel. If there is an error, it could be because we're testing on localhost, in which case, pass, else raise the error
    try:
        EventTracker.delay(event_name, event_dict)
    except ConnectionError as e:
        if 'localhost' not in str(e):
            raise
开发者ID:praveenjha527,项目名称:eatio-server,代码行数:45,代码来源:mixpanel_helper.py


示例10: test_is_test

    def test_is_test(self):
        et = EventTracker()

        self.assertEqual(et._is_test(None), 1)
        self.assertEqual(et._is_test(False), 0)
        self.assertEqual(et._is_test(True), 1)

        mp_settings.MIXPANEL_TEST_ONLY = False
        self.assertEqual(et._is_test(None), 0)
        self.assertEqual(et._is_test(False), 0)
        self.assertEqual(et._is_test(True), 1)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:11,代码来源:test_tasks.py


示例11: send_event

def send_event(event_name, **kwargs):
  if not event_name: raise ValueError("event name is required")
  EventTracker.delay(event_name, **kwargs)
开发者ID:huokedu,项目名称:dynamic-scrapy,代码行数:3,代码来源:analytics_service.py


示例12: test_failed_socket_request

 def test_failed_socket_request(self):
     self.response.read = Mock(side_effect=socket.error('BOOM'))
     with eager_tasks():
         result = EventTracker.delay('event_foo')
     self.assertNotEqual(result.traceback, None)
开发者ID:datafyit,项目名称:mixpanel-celery,代码行数:5,代码来源:test_tasks.py


示例13: test_handle_properties_empty

    def test_handle_properties_empty(self):
        et = EventTracker()
        mp_settings.MIXPANEL_API_TOKEN = 'bar'

        properties = et._handle_properties(None, None)
        self.assertEqual('bar', properties['token'])
开发者ID:andela,项目名称:mixpanel-celery,代码行数:6,代码来源:test_tasks.py


示例14: test_handle_properties_w_token

    def test_handle_properties_w_token(self):
        et = EventTracker()

        properties = et._handle_properties({}, 'foo')
        self.assertEqual('foo', properties['token'])
开发者ID:andela,项目名称:mixpanel-celery,代码行数:5,代码来源:test_tasks.py


示例15: test_failed_socket_request

    def test_failed_socket_request(self):
        mp_settings.MIXPANEL_API_SERVER = '127.0.0.1:60000'

        with eager_tasks():
            result = EventTracker.delay('event_foo')
        self.assertNotEqual(result.traceback, None)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:6,代码来源:test_tasks.py


示例16: test_debug_logger

    def test_debug_logger(self):
        et = EventTracker()
        result = et.run('event_foo', {}, loglevel=logging.DEBUG)

        self.assertTrue(result)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:5,代码来源:test_tasks.py


示例17: test_run

    def test_run(self):
        # "correct" result obtained from: http://mixpanel.com/api/docs/console
        et = EventTracker()
        result = et.run('event_foo', {})

        self.assertTrue(result)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:6,代码来源:test_tasks.py


示例18: EventTracker

from guelphapi.api.utils.log import get_data

from tastypie.resources import Resource, ModelResource

from mixpanel.tasks import EventTracker

tracker = EventTracker()
track_event = lambda *a, **kw: tracker.run(*a, **kw)

class LoggingResource(Resource):
    def dispatch(self, request_type, request, **kwargs):
        # Let the "real" dispatch do its thing.
        # This includes checking a throttle, authentication, authorization, etc
        response = super(LoggingResource, self).dispatch(request_type, request, **kwargs)
        # Only log "good" requests for now
        # We know once we're down here, that things are fine
        data = get_data(request_type, request, kwargs)
        track_event('request-%s' % request.META.get('REQUEST_METHOD', request_type), data)
        return response

class LoggingModelResource(ModelResource):
    def dispatch(self, request_type, request, **kwargs):
        # Let the "real" dispatch do its thing.
        # This includes checking a throttle, authentication, authorization, etc.
        response = super(LoggingModelResource, self).dispatch(request_type, request, **kwargs)
        # Only log "good" requests for now
        # We know once we're down here, that things are fine
        data = get_data(request_type, request, kwargs)
        track_event('request-%s' % request.META.get('REQUEST_METHOD', request_type), data)
        return response
开发者ID:Fogest,项目名称:guelphdev-api-service,代码行数:30,代码来源:resource.py


示例19: index

def index(request):
    et = EventTracker()
    et.run('dj_event', {'distinct_id': 1}, token=settings.token )
    return HttpResponse("Hello, world!.")
开发者ID:shamiksharma,项目名称:tutorials,代码行数:4,代码来源:views.py


示例20: test_failed_request

 def test_failed_request(self):
     self.response.status = 400
     with eager_tasks():
         result = EventTracker.delay('event_foo')
     self.assertNotEqual(result.traceback, None)
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:5,代码来源:test_tasks.py



注:本文中的mixpanel.tasks.EventTracker类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python build.build函数代码示例发布时间:2022-05-27
下一篇:
Python mixpanel.Mixpanel类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap