def query(request): '''Perform a query against Google Analytics server.''' user = request.user first = lambda x: x[0] second = lambda x: x[1] account_id = request.REQUEST.get('account_id') # retrieving result from google API is pretty slow. # so, we're using caching. cache_key = '%s:%s:%s' % ('query', user.pk, account_id) # result = cache.get(cache_key) result = None # disable caching for now. if result is None: logging.debug('cache miss') puller = DataPuller.from_user(user) result = puller.query(account_id, metrics='visits', dimensions=['date'], sort=None) # cache.set(cache_key, result, 3600) else: logging.debug('cache hit') rows = result['rows'] dates = imap(first, rows) stats = map(int, imap(second, rows)) dates = ['%s/%s/%s' % (x[4:6], x[6:8], x[0:4]) for x in dates] d = { 'stats': stats, 'dates': dates, } return render_as_json(request, d)
def query(request): """Perform a query against Google Analytics server.""" user = request.user first = lambda x: x[0] second = lambda x: x[1] account_id = request.REQUEST.get("account_id") # retrieving result from google API is pretty slow. # so, we're using caching. cache_key = "%s:%s:%s" % ("query", user.pk, account_id) # result = cache.get(cache_key) result = None # disable caching for now. if result is None: logging.debug("cache miss") puller = DataPuller.from_user(user) result = puller.query(account_id, metrics="visits", dimensions=["date"], sort=None) # cache.set(cache_key, result, 3600) else: logging.debug("cache hit") rows = result["rows"] dates = imap(first, rows) stats = map(int, imap(second, rows)) dates = ["%s/%s/%s" % (x[4:6], x[6:8], x[0:4]) for x in dates] d = {"stats": stats, "dates": dates} return render_as_json(request, d)
def setUp(self): start_date = datetime.strptime('2007-01-01','%Y-%m-%d') self.user = User.objects.get(email='*****@*****.**') self.puller = DataPuller.from_user(self.user,start_date=start_date)
def refresh_profile(request): puller = DataPuller.from_user(request.user) puller.save_profiles() d = {} return render_as_json(request, d)
def setUp(self): start_date = datetime.strptime("2007-01-01", "%Y-%m-%d") self.user = User.objects.get(email="*****@*****.**") self.puller = DataPuller.from_user(self.user, start_date=start_date)