Created
January 17, 2012 21:02
-
-
Save splee/1628845 to your computer and use it in GitHub Desktop.
Multi-dimensional defaultdict aggregation
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 parse_line(entry, e_dict): | |
leaderboard_req_re = '/api/publisher/([^/}{32}?)/proxy/.*leaderboard.*' | |
regex = re.compile(leaderboard_req_re) | |
e = entry.splt('\t') | |
for i in e: | |
if e[8] == 'loyalty.bigdoor.com': | |
match = regex.search(e[19]) | |
if match: | |
ts_slice = e_dict[e[14]] | |
ts_slice[match.group(0)] += 1 | |
ts_slice['total'] += 1 | |
# then, once you're done processing | |
ts_keys = e_dict.keys() | |
ts_keys.sort() | |
for ts in ts_keys: | |
for app_key, count in e_dict[ts].items(): | |
if app_key == 'total': | |
# we don't want the aggregate total yet | |
continue | |
print "[%s] App key: %s\nTotal calls: %d" % (ts, app_key, count) | |
print "[%s] Total calls: %d" % (ts, e_dict[ts]['total']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment