当前位置: 首页>>代码示例>>Python>>正文


Python Mixpanel.request方法代码示例

本文整理汇总了Python中mixpanel.Mixpanel.request方法的典型用法代码示例。如果您正苦于以下问题:Python Mixpanel.request方法的具体用法?Python Mixpanel.request怎么用?Python Mixpanel.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mixpanel.Mixpanel的用法示例。


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

示例1: get_event_data

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
def get_event_data(events, unit=DEFAULT_UNIT, interval=DEFAULT_INTERVAL):
    """Retrieve event data for a list of events"""

    MIXPANEL_API_KEY = os.environ["MIXPANEL_API_KEY"]
    MIXPANEL_API_SECRET = os.environ["MIXPANEL_API_SECRET"]

    client = Mixpanel(api_key=MIXPANEL_API_KEY, api_secret=MIXPANEL_API_SECRET)

    response = client.request('events', 'general', {
        'event' : events,
        'unit' : unit,
        'interval' : interval
    })

    return response['data']['values']
开发者ID:bradjasper,项目名称:Mixpanel-Statistics,代码行数:17,代码来源:utils.py

示例2: MixpanelTest

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
class MixpanelTest(object):

	def __init__(self):
		with open('etc/mp.yml', 'r') as f:
			mp = yaml.load(f)
		self.api = Mixpanel(
			api_key=mp['api_key'],
			api_secret=mp['api_secret']
		)

	def request(self, funnel_id, seg_property, from_date):
		data = self.api.request(['funnels'], {
			'funnel_id': funnel_id,
			'on': 'properties["%s"]' % seg_property,
			'from_date': from_date,
			'to_date': datetime.date.today().isoformat(),
			'interval': 60
		})['data']

		return data[from_date]

	def test(self, data, control, variations):
		update = {}
		buckets = [control] + variations
		for bucket in buckets:
			total = data[bucket][0]['count']
			successes = data[bucket][1]['count']
			update[bucket] = (successes, total - successes)

		test = Trials(buckets)
		test.update(update)

		dominances = test.evaluate('dominance', control=control)
		lifts = test.evaluate('expected lift', control=control)
		intervals = test.evaluate('lift CI', control=control, level=95)

		for variation in variations:
			print('Variation {name}:'.format(name=variation))
			s, t = update[variation]
			print('* Successes: {0}, Total: {1}, Percent: {2:2.3f}%'.format(s, t, 100*float(s)/t))
			print('* E[lift] = {value:.2%}'.format(value=lifts[variation]))
			print('* P({lower:.2%} < lift < {upper:.2%}) = 95%'.format(lower=intervals[variation][0], upper=intervals[variation][2]))
			print('* P({name} > {control}) = {value:.2%}'.format(name=variation, control=control, value=dominances[variation]))
			print
开发者ID:alexanderfabry,项目名称:abtest,代码行数:46,代码来源:mixpanel_test.py

示例3: mixpanel_main

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
def mixpanel_main():
	api_client = Mixpanel(mp['APIKEY'], mp['APISECRET'])
	data = api_client.request(['events'], {
        'event' : ['create_feature', 'signup', 'add_member'],
        'unit' : 'week',
        'interval' : 2,
        'type': 'general'
    })
	date = data['data']['series'][0]
	print "Metrics for the week\n"
	print "Mixpanel\n"
	global mp_signups
	global mp_members
	global mp_features
	mp_signups = data['data']['values']['signup'][date]
	mp_members = data['data']['values']['add_member'][date]
	mp_features = data['data']['values']['create_feature'][date]
	print "Signups: " + str(mp_signups)
	print "Members added: " + str(mp_members)
	print "Created first feature: " + str(mp_features)
开发者ID:jkodumal,项目名称:mktg-metrics-recorder,代码行数:22,代码来源:main.py

示例4: getShownSubModal

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
def getShownSubModal(api_key, api_secret, startDate, endDate):
    # print 'Requesting Mixpanel data'
    api = Mixpanel(
        api_key = api_key,
        api_secret = api_secret
    )
    data = api.request(['export'], {
        'event' : ['Show subscription modal',],
        'from_date' : startDate,
        'to_date' : endDate
    })
    
    uniques = set()
    # biggestDate = 0

    lines = data.split('\n')
    # print "Received %d entries" % len(lines)
    for line in lines:
        try:
            if len(line) is 0: continue
            event = json.loads(line)
            properties = event['properties']
            if not event['event'] in ['Show subscription modal']:
                print 'Unexpected event ' + event['event']
                break
            # print 'Processing', event['event'], properties['time'], properties['dateCreated']
            if 'distinct_id' in properties and not properties['distinct_id'] in uniques:
                uniques.add(properties['distinct_id'])
            # if int(properties['time']) > biggestDate:
            #     biggestDate = int(properties['time'])
        except:
            print "Unexpected error:", sys.exc_info()[0]
            print line
            break
    # print 'Biggest date:', datetime.utcfromtimestamp(int(properties['time']))
    return len(uniques)
开发者ID:1007650105,项目名称:codecombat,代码行数:38,代码来源:parseMixpanelPayments.py

示例5: printPriceConversionRates

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
def printPriceConversionRates(api_key, api_secret, startDate, endDate):
    # dateCreated is in UTC

    # Dec 8th subscribe copy A/B test added

    # 599 - 1st HoC 599 sale started: Dec 9 6:23am PST
    # 999 - 1st HoC 599 sale ended: Dec 10 4:34pm PST
    # 1499 - sub price test starts: Dec 10 5:00pm PST
        # Only for dateCreated >= 5pm PST
    # 399 - 2nd HoC 399 sale started: Dec 11 7:21pm PST
    # 999 - 2nd HoC sale ended: Dec 13 9:30am PST
    # UTC is +8 hrs

    api = Mixpanel(
        api_key = api_key,
        api_secret = api_secret
    )

    print 'Requesting Mixpanel data'
    # data = api.request(['events'], {
    #     'event' : ['Finished subscription purchase',],
    #     'unit' : 'hour',
    #     'interval' : 24,
    #     'type': 'general'
    # })
    # data = api.request(['funnels', 'list'], {})
    data = api.request(['export'], {
        'event' : ['Show subscription modal', 'Finished subscription purchase',],
        # 'event' : ['Finished subscription purchase',],
        # 'event' : ['Show subscription modal',],
        'from_date' : startDate,
        'to_date' : endDate
    })
    
    prices = {
        '399': {
            'start': datetime(2014, 12, 12, 3, 21),
            'end': datetime(2014, 12, 13, 17, 30)
        },
        '599': {
            'start': datetime(2014, 12, 9, 14, 23),
            'end': datetime(2014, 12, 11, 0, 34)
        },
        '999': {
            'start': datetime(2014, 9, 1),
            'end': datetime(2014, 12, 9, 14, 23),
            'start2': datetime(2014, 12, 11, 0, 34),
            'end2': datetime(2014, 12, 12, 3, 21),
            'start3': datetime(2014, 12, 13, 17, 30)
        },
        '1499': {
            'start': datetime(2014, 12, 11, 1),
            'end': datetime(2014, 12, 12, 3, 21)
        }
    }

    # id vs distinct_id ?
    def addEvent(price, event, id):
        if not event in price:
            price[event] = {}
            price[event][id] = True
        elif not id in price[event]:
            price[event][id] = True
            
    def getPriceStr(eventDateStr, userDateStr):
        priceStr = '999'
        eventCreated = datetime.utcfromtimestamp(int(eventDateStr))
        # Put events in buckets based on creation times
        if eventCreated >= prices['599']['start'] and eventCreated < prices['599']['end']:
            priceStr = '599'
        elif eventCreated >= prices['999']['start2'] and eventCreated < prices['999']['end2']:
            # In 999/1499 zone
            # Create a datetime from: 2014-12-11T12:37:59
            userCreated = datetime(int(userDateStr[0:4]), int(userDateStr[5:7]), int(userDateStr[8:10]), int(userDateStr[11:13]), int(userDateStr[14:16]), int(userDateStr[17:19]))
            if userCreated >= prices['1499']['start']:
                priceStr = '1499'
        elif eventCreated >= prices['399']['start'] and eventCreated < prices['399']['end']:
            priceStr = '399'
        return priceStr

    lines = data.split('\n')
    print "Received %d entries" % len(lines)
    for line in lines:
        try:
            if len(line) is 0: continue
            event = json.loads(line)
            properties = event['properties']
            if not event['event'] in ['Show subscription modal', 'Finished subscription purchase']:
                print 'Unexpected event ' + event['event']
                break
            # print 'Processing', event['event'], properties['time'], properties['dateCreated']
            if 'dateCreated' in properties and 'time' in properties and 'distinct_id' in properties:
                # NOTE: mixpanel conversions don't account for refunds
                # NOTE: So we have an extra 1499 hit for [email protected] / 5488ee8a600bc8b206771ba3
                if properties['distinct_id'] == '5488ee8a600bc8b206771ba3':
                    # ch_155tz8KaReE7xLUdQpsa9aqe, cus_5GQqAosNHuRQCQ
                    # print 'Skipping [email protected] / 5488ee8a600bc8b206771ba3'
                    # print event['event'], properties['distinct_id']
                    continue
                # if properties['distinct_id'] == '54790dacfd5b8f550584aaf3':
#.........这里部分代码省略.........
开发者ID:1007650105,项目名称:codecombat,代码行数:103,代码来源:parseMixpanelPayments.py

示例6: len

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
 if not len(sys.argv) is 3:
     print "Script format: <script> <api_key> <api_secret>"
 else:
     api_key = sys.argv[1]
     api_secret = sys.argv[2]
     api = Mixpanel(
         api_key = api_key,
         api_secret = api_secret
     )
     
     startDate = '2014-12-14'
     endDate = '2014-12-21'
     print("Requesting data for {0} to {1}".format(startDate, endDate))
     data = api.request(['export'], {
         'event' : ['Show subscription modal', 'Started subscription purchase', 'Finished subscription purchase'],
         'from_date' : startDate,
         'to_date' : endDate
     })
     
     userProgressionGroupA = {}
     userProgressionGroupB = {}
     
     lines = data.split('\n')
     print "Received %d entries" % len(lines)
     for line in lines:
         try:
             if len(line) is 0: continue
             eventData = json.loads(line)
             eventName = eventData['event']
             properties = eventData['properties']
             if not eventName in ['Show subscription modal', 'Started subscription purchase', 'Finished subscription purchase']:
开发者ID:1007650105,项目名称:codecombat,代码行数:33,代码来源:mixpanelABSubscribeCopy.py

示例7: Mixpanel

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
    else:
        api_key = sys.argv[1]
        api_secret = sys.argv[2]
        api = Mixpanel(
            api_key = api_key,
            api_secret = api_secret
        )

        startDate = '2015-01-15'
        startDate = '2014-11-25'
        endDate = '2015-02-11'

        print("Requesting data for {0} to {1}".format(startDate, endDate))
        data = api.request(['export'], {
            'event' : ['Started purchase', 'Finished gem purchase'],
            'from_date' : startDate,
            'to_date' : endDate
        })

        userProgressionGroupA = {}
        userProgressionGroupB = {}

        lines = data.split('\n')
        print "Received %d entries" % len(lines)
        for line in lines:
            try:
                if len(line) is 0: continue
                eventData = json.loads(line)
                eventName = eventData['event']
                properties = eventData['properties']
                if not eventName in ['Started purchase', 'Finished gem purchase']:
开发者ID:Kavignon,项目名称:codecombat,代码行数:33,代码来源:mixpanelABGemPrompt.py

示例8: Mixpanel

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
        api = Mixpanel(
            api_key = api_key,
            api_secret = api_secret
        )

        startDate = '2015-01-01'
        endDate = '2015-01-26'

        startEvent = eventFunnel[0]
        endEvent = eventFunnel[-1]

        print("Requesting data for {0} to {1}".format(startDate, endDate))
        data = api.request(['export'], {
            # 'where': '"539c630f30a67c3b05d98d95" == properties["id"]',
            # 'where': "('539c630f30a67c3b05d98d95' == properties['id'] or '539c630f30a67c3b05d98d95' == properties['distinct_id'])",
            'event': eventFunnel,
            'from_date': startDate,
            'to_date': endDate
        })


        weirdUserIDs = []
        eventUsers = {}
        levelEventUserDayMap = {}
        levelUserEventDayMap = {}
        lines = data.split('\n')
        print "Received %d entries" % len(lines)
        for line in lines:
            try:
                if len(line) is 0: continue
                eventData = json.loads(line)
开发者ID:1007650105,项目名称:codecombat,代码行数:33,代码来源:mixpanelGetEvent.py

示例9: print

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
            api_secret = api_secret
        )

        # startDate = '2015-01-11'
        # endDate = '2015-01-17'
        startDate = '2015-01-23'
        endDate = '2015-01-23'
        # endDate = '2015-01-28'

        startEvent = eventFunnel[0]
        endEvent = eventFunnel[-1]

        print("Requesting data for {0} to {1}".format(startDate, endDate))
        data = api.request(['export'], {
            'event' : eventFunnel,
            'from_date' : startDate,
            'to_date' : endDate
        })


        # Map ordering: level, user, event, day
        userDataMap = {}
        lines = data.split('\n')
        print "Received %d entries" % len(lines)
        for line in lines:
            try:
                if len(line) is 0: continue
                eventData = json.loads(line)
                eventName = eventData['event']
                if not eventName in eventFunnel:
                    print 'Unexpected event ' + eventName
开发者ID:1007650105,项目名称:codecombat,代码行数:33,代码来源:mixpanelLevelRates.py

示例10: MixSwissKnife

# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import request [as 别名]
class MixSwissKnife(object):
    
    def __init__(self, api_key, api_secret, period_threshold = 1, usage_threshold = 1, where = "true", period = "week"):
        self.api_key = api_key
        self.api_secret = api_secret
        self.api = Mixpanel(self.api_key, self.api_secret)
        #self.users = []
        self.daily_threshold = period_threshold
        self.usage_threshold = usage_threshold
        self.where = where
        self.period = period
        self.user_data = {}
        pass
    
    def track_users_feature(self, feature, from_date, to_date):
        data = self.api.request(['segmentation'], {
            'event' : feature,
            'on': 'properties["username"]',
            'where': self.where,
            'from_date': from_date,
            'to_date': to_date,
            'unit' : self.period,
            'type': 'general',
            'limit': 1000
        })
        
        print data
        user_data = data['data']['values']

        for user in user_data:

            days = 0
            for d in user_data[user]:
                if user_data[user][d] > self.daily_threshold:
                    days = days + 1

            total_days = len(user_data[user])
            
            usage = float(days * 100) / total_days
            #print user, ' --> ', "%0.2f" % usage , '%'

            #if user not in self.users:
            #    self.users.append(user)
            
            if usage > 0:
                if not self.user_data.has_key(user):
                    self.user_data[user] = {}
                self.user_data[user][feature] = usage

    '''
        How many users use a feature?
    '''
    def analyze_feature(self, feature):
        users = 0
        frequency = []
        for user in self.users():
            user_info = self.user_data[user]
            if user_info.has_key(feature) and user_info[feature] > self.usage_threshold:
                users = users + 1
                frequency.append(user_info[feature])
        usage = float(users) * 100 / len(self.users())
        
        #print users, 'out of', len(self.users())
        #print frequency
        #print self.mean(frequency), '[', max(frequency), ',', min(frequency), ']'
        
        #lets calculate frequency
        
        return usage, self.mean(frequency)
        
    def num_users(self):
        return len(self.user_data.keys())
    
    def users(self):
        return self.user_data.keys()
    
    def mean(self, l):
        return float(sum(l))/len(l) if len(l) > 0 else float('nan')

    def median(self, l):
        sorts = sorted(l)
        length = len(sorts)
        if not length % 2:
            return (sorts[length / 2] + sorts[length / 2 - 1]) / 2.0
        return sorts[length / 2]
开发者ID:xorduna,项目名称:mixpanelswissarmyknive,代码行数:87,代码来源:swissknife.py


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