def GET(self, id=None, format='json'): if id: if id.startswith("/"): id = id[1:] id = unquote(id) #if id.find("%3A") != -1: # id = ":".join(id.split("%3A")) params = {'pid': id} params['label'] = titlelookup(id) params['dlist'], params['dates'], params['total'] = item_stats( id, r) if params['dlist']: params['sparkline_url'] = get_dateline_url( params['dlist'], params['dates']) else: params[ 'sparkline_url'] = "http://ora.ouls.ox.ac.uk/ora_logo.png" params['entities'] = get_entities_in_pid(id, r) options = web.input() if 'geo' in options: params['geousage_url'] = get_gchart_map_for_pid(id, r) format = options.get('format', format) if format == "html": return render.item(**params) return simplejson.dumps(params) else: return render.item_form()
def get_top_dls(r, size=10): topitems = [] scores = [] for total_key in r.keys("t:dls:uuid*"): score = r.get(total_key) heappush(scores, (int(score), total_key[6:])) for item in nlargest(size, scores): topitems.append((item[0], item[1], titlelookup(item[1]))) return topitems
def print_item_stats(pid,r,gen_charts=False): dlist, dates, total = item_stats(pid, r) print "Results for %s" % pid print "Title: %s" % titlelookup(pid) print "Totals - Views: %(v)s, Downloads: %(d)s, Other: %(o)s" % total print "Breakdown:" for date in dlist: print "%s" % date + " - Views: %(v)s, Downloads: %(d)s, Other: %(o)s" % dates[date] if gen_charts: print "Google Chart url for the user breakdown - (Red - heaviest usage, yellow - weakest)" print "%s" % get_gchart_map_for_pid(pid, r) print "Google Sparkline for item activity" print get_dateline_url(dlist, dates)
def analyse_past_days_dls(r, keyname, days=30, size=None, exclude=[]): n = datetime.now() dl_keys = [] for day in xrange(days): tdate = n + timedelta(days=-day) dl_keys.extend([x for x in r.keys("%s:uuid*" % (tdate.strftime("%Y-%m-%d"))) if x.endswith("d")]) tally = {} for k in dl_keys: pid = "uuid:" + k.split(":")[2] if pid not in exclude: if not tally.has_key(pid): tally[pid] = 0 tally[pid] = tally[pid] + r.scard(k) heap = [] for pid in tally: heappush(heap, (tally[pid], pid, titlelookup(pid))) if size and isinstance(size, int): heap = nlargest(size, heap) r.set("analysis:%s" % keyname, simplejson.dumps({'now':n.isoformat(), 'days':days, 'size':size, 'results':heap}) ) return heap
def GET(self, id = None, format = 'json'): if id: if id.startswith("/"): id = id[1:] id = unquote(id) #if id.find("%3A") != -1: # id = ":".join(id.split("%3A")) params = {'pid':id} params['label'] = titlelookup(id) params['dlist'], params['dates'], params['total'] = item_stats(id, r) if params['dlist']: params['sparkline_url'] = get_dateline_url(params['dlist'], params['dates']) else: params['sparkline_url'] = "http://ora.ouls.ox.ac.uk/ora_logo.png" params['entities'] = get_entities_in_pid(id, r) options = web.input() if 'geo' in options: params['geousage_url'] = get_gchart_map_for_pid(id, r) format = options.get('format', format) if format == "html": return render.item(**params) return simplejson.dumps(params) else: return render.item_form()
def entity_found_in_items(phrase, r): return [(titlelookup(pid), pid) for pid in (r.smembers("e:%s" % phrase) or [])]
print "Generating geo charts" gen_charts = True else: phrase_tokens.append(argv) phrase = " ".join(phrase_tokens) if phrase in prefixes: if csvfile: save_set(phrase, r, limit, startswith, csvfile, verbose=True) else: print_browse_set(phrase, r, limit, startswith) elif phrase.count(":") == 1: if phrase.startswith("uuid") or phrase.startswith("ora"): print_item_stats(phrase, r, gen_charts) else: print_entity_report(phrase, r, gen_charts) else: print "Trying to find freetext %s" % phrase for tagtype in prefixes: tag = entity_existence(phrase, tagtype, r) if tag and (limit == 0 or combined_count(r.get("t:views:%s" % tag), r.get("t:dls:%s" % tag)) > limit): print "Found %s (type: %s) for %s" % (tag, tagtype, phrase) print "Views: %s, Downloads: %s, Other: %s" % (r.get("t:views:%s" % tag), r.get("t:dls:%s" % tag), r.get("t:other:%s" % tag)) print "Entity %s(in %s) found in the following items" % (phrase, tagtype) for pid in (r.smembers("e:%s" % tag) or []): print '"%s" - %s' % (titlelookup(pid), pid) if gen_charts: print "Geo-breakdown (yellow -> red) %s" % get_gchart_map_for_pid(pid, r) print "------------------------------------------------------"