Created
November 7, 2011 20:59
-
-
Save dokipen/1346164 to your computer and use it in GitHub Desktop.
Proclog Psuedo Code
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
| def process(log): | |
| api_key, urls, status = parse(log) | |
| if status in (200,404): | |
| rounded_timestamp = round(log.timestamp) | |
| url_ids = hash_urls(urls) | |
| customer_id = get_customer_id(api_key) | |
| zkey = "hourly::$customer_id::$rounded_timestamp" | |
| redis.multi() | |
| # count unique URLs for hour before adding new set | |
| start = redis.zcard(zkey) | |
| for url_id in url_ids: | |
| redis.zincrby(zkey, url_id, 1) | |
| # count unique URLs for the hour after adding new set | |
| end = redis.zcard(zkey) | |
| redis.exec() | |
| new_url_count = end - start | |
| pkey = "usage::$customer_id::$period_end" | |
| new_period_count = redis.incrby(pkey, new_url_count) | |
| old_period_count = new_period_count - new_url_count | |
| for threshold in thresholds: | |
| if new_period_count >= threshold and \ | |
| old_period_count < threshold: | |
| threshold.action(customer_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment