def api_top_drops(request): """ Used by the pie graph on the index page """ def parse(x): return {'name': x[1], 'y': x[0], 'url': '/drink/%s' % x[2]} if 'machine_id' in request.params: return map(parse, drink_log.top_drinks_for_machine(request.params['machine_id'], 15)) elif 'username' in request.params: return map(parse, drink_log.top_drinks(15, request.params['username'])) else: start_date, end_date = get_timerange(request) return map(parse, drink_log.top_drinks(15, start_date = start_date, end_date = end_date))
def machines_view(request): machine_id = int(request.matchdict["machine_id"]) machine_name = machines.get_machine_name(machine_id) top_drinks = drink_log.top_drinks_for_machine(machine_id) top_hours = drink_log.top_hours(machine_id=machine_id) return {"top_drops": top_drinks, "hours": top_hours, "machine_id": machine_id, "machine_name": machine_name}
def machines_view(request): machine_id = int(request.matchdict['machine_id']) machine_name = machines.get_machine_name(machine_id) top_drops = drink_log.top_drinks_for_machine(machine_id, limit = 15) return {'top_drops': top_drops, 'machine_id': machine_id, 'machine_name': machine_name}