bitmapist 3.119__tar.gz → 4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,11 @@
1
+ Copyright (c) <year> <owner>.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: bitmapist
3
- Version: 3.119
3
+ Version: 4.0
4
4
  Summary: Implements a powerful analytics library using Redis bitmaps.
5
- Project-URL: Repository, https://github.com/Doist/bitmapist
5
+ Project-URL: Repository, https://github.com/todoist/bitmapist
6
6
  Author-email: Amir Salihefendic <dev@doist.com>, Doist Developers <dev@doist.com>
7
7
  License-Expression: BSD-3-Clause
8
8
  License-File: AUTHORS
@@ -13,19 +13,17 @@ Classifier: Intended Audience :: Developers
13
13
  Classifier: Operating System :: OS Independent
14
14
  Classifier: Programming Language :: Python
15
15
  Classifier: Programming Language :: Python :: 3 :: Only
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
16
  Classifier: Programming Language :: Python :: 3.11
19
17
  Classifier: Programming Language :: Python :: 3.12
20
18
  Classifier: Programming Language :: Python :: 3.13
21
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
- Requires-Python: <3.14,>=3.9
20
+ Requires-Python: <3.14,>=3.11
23
21
  Requires-Dist: mako<2,>=1.0.4
24
22
  Requires-Dist: python-dateutil
25
23
  Requires-Dist: redis<6.0,>=2.10
26
24
  Description-Content-Type: text/markdown
27
25
 
28
- ![bitmapist](https://raw.githubusercontent.com/Doist/bitmapist/master/static/bitmapist.png "bitmapist")
26
+ ![bitmapist](https://raw.githubusercontent.com/todoist/bitmapist/master/static/bitmapist.png "bitmapist")
29
27
 
30
28
  [![Build Status](https://travis-ci.org/Doist/bitmapist.svg?branch=master)](https://travis-ci.org/Doist/bitmapist)
31
29
 
@@ -36,7 +34,7 @@ Bitmapist makes it possible to implement real-time, highly scalable analytics. T
36
34
  Leveraging Redis bitmaps, you can store events for millions of users using a very little amount of memory (megabytes).
37
35
 
38
36
  > [!TIP]
39
- > Instead of Redis as a backing store, consider using [bitmapist-server](https://github.com/Doist/bitmapist-server).
37
+ > Instead of Redis as a backing store, consider using [bitmapist-server](https://github.com/todoist/bitmapist-server).
40
38
  >
41
39
  > It is our custom data store that exposes a (partial) Redis-compatible API, fully compatible with Bitmapist. It is 443x more memory efficient for this particular use case, improving scalability and cost-effectiveness.
42
40
 
@@ -79,9 +77,17 @@ Setting things up:
79
77
 
80
78
  ```python
81
79
  from datetime import datetime, timedelta, timezone
82
- from bitmapist import setup_redis, delete_all_events, mark_event,\
83
- MonthEvents, WeekEvents, DayEvents, HourEvents,\
84
- BitOpAnd, BitOpOr
80
+ from bitmapist import (
81
+ setup_redis,
82
+ delete_all_events,
83
+ mark_event,
84
+ MonthEvents,
85
+ WeekEvents,
86
+ DayEvents,
87
+ HourEvents,
88
+ BitOpAnd,
89
+ BitOpOr,
90
+ )
85
91
 
86
92
  now = datetime.now(tz=timezone.utc)
87
93
  last_month = now - timedelta(days=30)
@@ -90,29 +96,29 @@ last_month = now - timedelta(days=30)
90
96
  Mark user 123 as active and has played a song:
91
97
 
92
98
  ```python
93
- mark_event('active', 123)
94
- mark_event('song:played', 123)
99
+ mark_event("active", 123)
100
+ mark_event("song:played", 123)
95
101
  ```
96
102
 
97
103
  Answer if user 123 has been active this month:
98
104
 
99
105
  ```python
100
- assert 123 in MonthEvents('active', now.year, now.month)
101
- assert 123 in MonthEvents('song:played', now.year, now.month)
102
- assert MonthEvents('active', now.year, now.month).has_events_marked() == True
106
+ assert 123 in MonthEvents("active", now.year, now.month)
107
+ assert 123 in MonthEvents("song:played", now.year, now.month)
108
+ assert MonthEvents("active", now.year, now.month).has_events_marked() == True
103
109
  ```
104
110
 
105
111
  How many users have been active this week?:
106
112
 
107
113
  ```python
108
114
  iso_year, iso_week, _ = now.isocalendar()
109
- print(len(WeekEvents('active', iso_year, iso_week)))
115
+ print(len(WeekEvents("active", iso_year, iso_week)))
110
116
  ```
111
117
 
112
118
  Iterate over all users active this week:
113
119
 
114
120
  ```python
115
- for uid in WeekEvents('active'):
121
+ for uid in WeekEvents("active"):
116
122
  print(uid)
117
123
  ```
118
124
 
@@ -122,25 +128,21 @@ arguments. Events will be populated with current time automatically.
122
128
  For example, these two calls are equivalent:
123
129
 
124
130
  ```python
125
-
126
- MonthEvents('active') == MonthEvents('active', now.year, now.month)
127
-
131
+ MonthEvents("active") == MonthEvents("active", now.year, now.month)
128
132
  ```
129
133
 
130
134
  Additionally, for the sake of uniformity, you can create an event from
131
135
  any datetime object with a `from_date` static method.
132
136
 
133
137
  ```python
134
-
135
- MonthEvents('active').from_date(now) == MonthEvents('active', now.year, now.month)
136
-
138
+ MonthEvents("active").from_date(now) == MonthEvents("active", now.year, now.month)
137
139
  ```
138
140
 
139
141
  Get the list of these users (user ids):
140
142
 
141
143
  ```python
142
144
  iso_year, iso_week, _ = now.isocalendar()
143
- print(list(WeekEvents('active', iso_year, iso_week)))
145
+ print(list(WeekEvents("active", iso_year, iso_week)))
144
146
  ```
145
147
 
146
148
  There are special methods `prev` and `next` returning "sibling" events and
@@ -150,12 +152,10 @@ more than one step. Uniform API allows you to use all types of base events
150
152
  (from hour to year) with the same code.
151
153
 
152
154
  ```python
153
-
154
155
  current_month = MonthEvents()
155
156
  prev_month = current_month.prev()
156
157
  next_month = current_month.next()
157
158
  year_ago = current_month.delta(-12)
158
-
159
159
  ```
160
160
 
161
161
  Every event object has `period_start` and `period_end` methods to find a
@@ -163,24 +163,23 @@ time span of the event. This can be useful for caching values when the caching
163
163
  of "events in future" is not desirable:
164
164
 
165
165
  ```python
166
-
167
- ev = MonthEvent('active', dt)
166
+ ev = MonthEvent("active", dt)
168
167
  if ev.period_end() < now:
169
- cache.set('active_users_<...>', len(ev))
170
-
168
+ cache.set("active_users_<...>", len(ev))
171
169
  ```
172
170
 
173
171
  As something new tracking hourly is disabled (to save memory!) To enable it as default do::
174
172
 
175
173
  ```python
176
174
  import bitmapist
175
+
177
176
  bitmapist.TRACK_HOURLY = True
178
177
  ```
179
178
 
180
179
  Additionally you can supply an extra argument to `mark_event` to bypass the default value::
181
180
 
182
181
  ```python
183
- mark_event('active', 123, track_hourly=False)
182
+ mark_event("active", 123, track_hourly=False)
184
183
  ```
185
184
 
186
185
  ### Unique events
@@ -195,10 +194,9 @@ You can combine unique events with other types of events.
195
194
  A/B testing example:
196
195
 
197
196
  ```python
198
-
199
- active_today = DailyEvents('active')
200
- a = UniqueEvents('signup_form:classic')
201
- b = UniqueEvents('signup_form:new')
197
+ active_today = DailyEvents("active")
198
+ a = UniqueEvents("signup_form:classic")
199
+ b = UniqueEvents("signup_form:new")
202
200
 
203
201
  print("Active users, signed up with classic form", len(active & a))
204
202
  print("Active users, signed up with new form", len(active & b))
@@ -207,20 +205,20 @@ print("Active users, signed up with new form", len(active & b))
207
205
  Generic filter example
208
206
 
209
207
  ```python
210
-
211
208
  def premium_up(uid):
212
209
  # called when user promoted to premium
213
210
  ...
214
- mark_unique('premium', uid)
211
+ mark_unique("premium", uid)
215
212
 
216
213
 
217
214
  def premium_down(uid):
218
215
  # called when user loses the premium status
219
216
  ...
220
- unmark_unique('premium', uid)
217
+ unmark_unique("premium", uid)
218
+
221
219
 
222
- active_today = DailyEvents('active')
223
- premium = UniqueEvents('premium')
220
+ active_today = DailyEvents("active")
221
+ premium = UniqueEvents("premium")
224
222
 
225
223
  # Add extra Karma for all premium users active today,
226
224
  # just because today is a special day
@@ -235,8 +233,7 @@ bitmapist events at the same time.
235
233
  def premium_up(uid):
236
234
  # called when user promoted to premium
237
235
  ...
238
- mark_event('premium', uid, track_unique=True)
239
-
236
+ mark_event("premium", uid, track_unique=True)
240
237
  ```
241
238
 
242
239
  ### Perform bit operations
@@ -245,8 +242,8 @@ How many users that have been active last month are still active this month?
245
242
 
246
243
  ```python
247
244
  active_2_months = BitOpAnd(
248
- MonthEvents('active', last_month.year, last_month.month),
249
- MonthEvents('active', now.year, now.month)
245
+ MonthEvents("active", last_month.year, last_month.month),
246
+ MonthEvents("active", now.year, now.month),
250
247
  )
251
248
  print(len(active_2_months))
252
249
 
@@ -257,8 +254,8 @@ assert 123 in active_2_months
257
254
  Alternatively, you can use standard Python syntax for bitwise operations.
258
255
 
259
256
  ```python
260
- last_month_event = MonthEvents('active', last_month.year, last_month.month)
261
- this_month_event = MonthEvents('active', now.year, now.month)
257
+ last_month_event = MonthEvents("active", last_month.year, last_month.month)
258
+ this_month_event = MonthEvents("active", now.year, now.month)
262
259
  active_two_months = last_month_event & this_month_event
263
260
  ```
264
261
 
@@ -269,10 +266,10 @@ Work with nested bit operations (imagine what you can do with this ;-))!
269
266
  ```python
270
267
  active_2_months = BitOpAnd(
271
268
  BitOpAnd(
272
- MonthEvents('active', last_month.year, last_month.month),
273
- MonthEvents('active', now.year, now.month)
269
+ MonthEvents("active", last_month.year, last_month.month),
270
+ MonthEvents("active", now.year, now.month),
274
271
  ),
275
- MonthEvents('active', now.year, now.month)
272
+ MonthEvents("active", now.year, now.month),
276
273
  )
277
274
  print(len(active_2_months))
278
275
  assert 123 in active_2_months
@@ -286,7 +283,7 @@ active_2_months.delete()
286
283
  If you want to permanently remove marked events for any time period you can use the `delete()` method:
287
284
 
288
285
  ```python
289
- last_month_event = MonthEvents('active', last_month.year, last_month.month)
286
+ last_month_event = MonthEvents("active", last_month.year, last_month.month)
290
287
  last_month_event.delete()
291
288
  ```
292
289
 
@@ -300,8 +297,8 @@ When using Bit Operations (ie `BitOpAnd`) you can (and probably should) delete t
300
297
 
301
298
  ```python
302
299
  active_2_months = BitOpAnd(
303
- MonthEvents('active', last_month.year, last_month.month),
304
- MonthEvents('active', now.year, now.month)
300
+ MonthEvents("active", last_month.year, last_month.month),
301
+ MonthEvents("active", now.year, now.month),
305
302
  )
306
303
  # Delete the temporary AND operation
307
304
  active_2_months.delete()
@@ -323,18 +320,21 @@ Here's a simple example of how to generate a form and a rendering of the data yo
323
320
  from bitmapist import cohort
324
321
 
325
322
  html_form = cohort.render_html_form(
326
- action_url='/_Cohort',
327
- selections1=[ ('Are Active', 'user:active'), ],
328
- selections2=[ ('Task completed', 'task:complete'), ]
323
+ action_url="/_Cohort",
324
+ selections1=[
325
+ ("Are Active", "user:active"),
326
+ ],
327
+ selections2=[
328
+ ("Task completed", "task:complete"),
329
+ ],
329
330
  )
330
331
  print(html_form)
331
332
 
332
- dates_data = cohort.get_dates_data(select1='user:active',
333
- select2='task:complete',
334
- time_group='days')
333
+ dates_data = cohort.get_dates_data(
334
+ select1="user:active", select2="task:complete", time_group="days"
335
+ )
335
336
 
336
- html_data = cohort.render_html_data(dates_data,
337
- time_group='days')
337
+ html_data = cohort.render_html_data(dates_data, time_group="days")
338
338
 
339
339
  print(html_data)
340
340
 
@@ -342,14 +342,37 @@ print(html_data)
342
342
  # but to make things more clear I have filled them in directly
343
343
  ```
344
344
 
345
+ `select1` and `select2` take one event or a list of events that must all match, e.g. `select1=['user:active', 'country:US']`. The form picks several events per side and submits them as repeated query parameters (`select1=a&select1=b`), so read `select1` and `select2` as lists in your handler. `select1b` and `select2b` still work and are ANDed in.
346
+
347
+ With hundreds of events, group them: a `'--- Title'` entry in a `selections*` list starts a named group (shown as a header in the searchable dropdown, and matched when searching), and a bare `'---'` starts an untitled one. The form HTML-escapes labels, event names, group titles and `action_url`, so pass them raw.
348
+
349
+ `render_html_data` also adds a collapsible **Visualize** section above the table with two charts: retention in a chosen period across cohorts, and the average retention curve. Both leave out periods that are still in progress.
350
+
351
+ The form and charts use Todoist's design tokens. To match another product, set these on `:root` (or any ancestor): `--cohort-primary` and `--cohort-primary-hover` for the submit button, and `--cohort-series` for the chart colour.
352
+
345
353
  This will render something similar to this:
346
354
 
347
- ![bitmapist cohort screenshot](https://raw.githubusercontent.com/Doist/bitmapist/master/static/cohort_screenshot.png "bitmapist cohort screenshot")
355
+ ![bitmapist cohort form, Visualize section and table](https://raw.githubusercontent.com/todoist/bitmapist/main/static/cohort_screenshot.png "bitmapist cohort screenshot")
356
+
357
+ To try the cohort UI locally with made-up data (needs `redis-server` on your `PATH`):
358
+
359
+ ```bash
360
+ uv run python examples/cohort_demo.py
361
+ ```
362
+
363
+ It seeds ~200 days of synthetic events into a throwaway Redis and serves the form and results at http://127.0.0.1:8099/.
364
+
365
+ ### Upgrading to 4.0
366
+
367
+ - Python 3.11 or newer.
368
+ - The form's event pickers are multi-selects, so they submit repeated `select1` and `select2` parameters (`select1=a&select1=b`). Read them as lists (e.g. `request.args.getlist("select1")`, or a `list[str]` query parameter) and pass the lists on to `get_dates_data` and `render_html_form`. A handler that reads a single value keeps only one of the events.
369
+ - `render_html_form` now escapes labels, event names, group titles and `action_url`. Stop escaping them yourself, or they'll show up escaped twice.
348
370
 
349
371
  ## References
350
372
 
351
373
  If you want to read more about bitmaps please read following:
352
374
 
375
+ - https://www.doist.dev/bitmapist/
353
376
  - http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/
354
377
  - http://redis.io/commands/setbit
355
378
  - http://en.wikipedia.org/wiki/Bit_array
@@ -397,7 +420,7 @@ To run tests with native binaries, you'll need at least one backend server insta
397
420
  - Ensure it's in your `PATH`, or set `BITMAPIST_REDIS_SERVER_PATH`
398
421
 
399
422
  **Bitmapist-server:**
400
- - Download from the [releases page](https://github.com/Doist/bitmapist-server/releases)
423
+ - Download from the [releases page](https://github.com/todoist/bitmapist-server/releases)
401
424
  - Ensure it's in your PATH, or set `BITMAPIST_SERVER_PATH`
402
425
 
403
426
  Then run: