forked from Doist/bitmapist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·133 lines (98 loc) · 4.59 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# Copyright (c) 2007 Qtrac Ltd. All rights reserved.
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
import os
from setuptools import setup
setup(name='bitmapist',
version = '2.4',
author="amix",
author_email="[email protected]",
url="http://www.amix.dk/",
install_requires = ['redis>=2.7.1', 'python-dateutil'],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
],
packages=['bitmapist', 'bitmapist.cohort'],
include_package_data=True,
zip_safe=False,
platforms=["Any"],
license="BSD",
keywords='redis bitmap analytics bitmaps realtime cohort',
description="Implements a powerful analytics library using Redis bitmaps.",
long_description="""\
bitmapist
---------------
Implements a powerful analytics library using Redis bitmaps.
This library makes it possible to implement real-time, highly scalable analytics that can answer following questions:
* Has user 123 been online today? This week? This month?
* Has user 123 performed action "X"?
* How many users have been active have this month? This hour?
* How many unique users have performed action "X" this week?
* How many % of users that were active last week are still active?
* How many % of users that were active last month are still active this month?
This library is very easy to use and enables you to create your own reports easily.
Using Redis bitmaps you can store events for millions of users in a very little amount of memory (megabytes).
You should be careful about using huge ids (e.g. 2^32 or bigger) as this could require larger amounts of memory.
Now with Cohort charts! Read more here:
* Releasing bitmapist.cohort - or how we saved over $2000/month: http://amix.dk/blog/post/19718
If you want to read more about bitmaps please read following:
* http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/
* http://redis.io/commands/setbit
* http://en.wikipedia.org/wiki/Bit_array
* http://www.slideshare.net/crashlytics/crashlytics-on-redis-analytics
* http://amix.dk/blog/post/19714 [my blog post]
Requires Redis 2.6+ and newest version of redis-py.
Examples
---------------
Setting things up::
from datetime import datetime, timedelta
from bitmapist import setup_redis, delete_all_events, mark_event,\
MonthEvents, WeekEvents, DayEvents, HourEvents,\
BitOpAnd, BitOpOr
now = datetime.utcnow()
last_month = datetime.utcnow() - timedelta(days=30)
Mark user 123 as active and has played a song::
mark_event('active', 123)
mark_event('song:played', 123)
Answer if user 123 has been active this month::
assert 123 in MonthEvents('active', now.year, now.month)
assert 123 in MonthEvents('song:played', now.year, now.month)
assert MonthEvents('active', now.year, now.month).has_events_marked() == True
How many users have been active this week?::
print len(WeekEvents('active', now.year, now.isocalendar()[1]))
Perform bit operations. How many users that have been active last month are still active this month?::
active_2_months = BitOpAnd(
MonthEvents('active', last_month.year, last_month.month),
MonthEvents('active', now.year, now.month)
)
print len(active_2_months)
# Is 123 active for 2 months?
assert 123 in active_2_months
Work with nested bit operations (imagine what you can do with this ;-))::
active_2_months = BitOpAnd(
BitOpAnd(
MonthEvents('active', last_month.year, last_month.month),
MonthEvents('active', now.year, now.month)
),
MonthEvents('active', now.year, now.month)
)
print len(active_2_months)
assert 123 in active_2_months
# Delete the temporary AND operation
active_2_months.delete()
As something new tracking hourly is disabled (to save memory!) To enable it as default do::
import bitmapist
bitmapist.TRACK_HOURLY = True
Additionally you can supply an extra argument to mark_event to bypass the default value::
mark_event('active', 123, track_hourly=False)
Copyright: 2012 by Doist Ltd.
Developer: Amir Salihefendic ( http://amix.dk )
License: BSD""")