Skip to content

Instantly share code, notes, and snippets.

@yannick
Created March 31, 2016 13:38
Show Gist options
  • Select an option

  • Save yannick/674f92890157a8a2581f8ac392902f7d to your computer and use it in GitHub Desktop.

Select an option

Save yannick/674f92890157a8a2581f8ac392902f7d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from __future__ import print_function
import ujson as json
#import demjson
import sys
from hashlib import md5
import datetime
from collections import defaultdict
def warning(*objs):
print("WARNING: ", *objs, file=sys.stderr)
total_hits = 0
ids = ['mainId', 'gadsid', 'hash_id', 'cxs', 'cxp']
trackable_hits = 0
tracker_ids = defaultdict(set)
tracker_hits = defaultdict(int)
while True:
try:
line = sys.stdin.readline()
if not line:
break
jsn = json.loads(line)
total_hits += 1
for idname in ids:
mainID = jsn[idname]
if mainID in tracker_ids[idname]:
tracker_hits[idname] += 1
if mainID:
tracker_ids[idname].add(mainID)
except Exception as e:
warning(e)
print("total hits: %s" % total_hits )
for k,v in tracker_ids.items():
hits = tracker_hits[k]
print("%s\t perc of total: %0.2f hits: %s, unique: %s, ratio: %s" % (k, hits / total_hits, hits, len(v), hits / len(v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment