Created
November 20, 2012 18:47
-
-
Save elcuervo/4120070 to your computer and use it in GitHub Desktop.
Minuteman usage example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Running benchmarks: | |
Minuteman 1 10 100 1000 10000 | |
bench_AND 0.000838 0.000279 0.000287 0.000319 0.000307 | |
bench_MINUS 0.000393 0.000490 0.000513 0.000491 0.000510 | |
bench_NOT 0.000273 0.000269 0.000320 0.000353 0.000685 | |
bench_OR 0.000363 0.000282 0.000356 0.000330 0.000326 | |
bench_XOR 0.000263 0.000277 0.000308 0.000306 0.000358 | |
bench_complex_operations 0.000389 0.000507 0.000505 0.000600 0.000725 | |
bench_intersections_not_using_cache 0.003044 0.002763 0.002347 0.002549 0.002507 | |
bench_intersections_using_cache 0.000828 0.000061 0.000049 0.000099 0.000049 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install minuteman |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paid = analytics.month("buy:complete") | |
payed_from_miami = paid & User.find_all_by_state("MIA").map(&:id) | |
payed_from_miami.size | |
#=> 43 | |
payed_users_from_miami = payed_from_miami.map { |id| User.find(id) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "minuteman" | |
# Accepts an options hash that will be sent as is to Redis.new | |
analytics = Minuteman.new | |
# Mark an event for a given id | |
analytics.track("login:successful", user.id) | |
analytics.track("login:successful", other_user.id) | |
# Mark in bulk | |
analytics.track("programming:love:ruby", User.where(favorite: "ruby").pluck(:id)) | |
# Fetch events for a given time | |
today_events = analytics.day("login:successful", Time.now.utc) | |
# This also exists | |
analytics.year("login:successful", Time.now.utc) | |
analytics.month("login:successful", Time.now.utc) | |
analytics.week("login:successful", Time.now.utc) | |
analytics.day("login:successful", Time.now.utc) | |
analytics.hour("login:successful", Time.now.utc) | |
analytics.minute("login:successful", Time.now.utc) | |
# Lists all the tracked events | |
analytics.events | |
#=> ["login:successful", "programming:login:ruby"] | |
# Check event length on a given time | |
today_events.length | |
#=> 2 | |
# Check for existance | |
today_events.include?(user.id) | |
#=> true | |
today_events.include?(admin.id) | |
#=> false | |
# Bulk check | |
today_events.include?(User.all.pluck(:id)) | |
#=> [true, true, false, false] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic operations | |
invited = analytics.month("email:invitation", Time.now.utc) | |
successful_buys = analytics.month("buy:complete", Time.now.utc) | |
successful_buys_after_invitation = invited & successful_buys | |
successful_buys_after_invitation.include?(user.id) | |
# Clean up all the operations cache | |
analytics.reset_operations_cache | |
# Complex operations | |
invited = analytics.month("email:invitation") | |
from_adsense = analytics.month("adsense:promo") | |
successful_buys = analytics.month("buy:complete") | |
conversion_rate = (invited | from_adsense) & successful_buys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment