def post(self): query = InstallMetric.all() query.order('-installed_at') cursor = self.request.get('cursor') if cursor != None: query.with_cursor(cursor) install_metrics = query.fetch(25) for install_metric in install_metrics: post_install_activity_metric = PostInstallActivityMetric.gql("WHERE user = :1", install_metric.user).get() if post_install_activity_metric == None: post_install_activity_metric = PostInstallActivityMetric( fb_user_id = install_metric.user.fb_user_id, user = install_metric.user, installed_at = install_metric.installed_at ) else: post_install_activity_metric.fb_user_id = install_metric.user.fb_user_id post_install_activity_metric.user = install_metric.user post_install_activity_metric.installed_at = install_metric.installed_at for day in [1,2,3,4,5,6,7]: day_start = install_metric.installed_at + datetime.timedelta(days=day) day_end = install_metric.installed_at + datetime.timedelta(days=(day+1)) page_view_in_day = PageView.gql( "WHERE user = :1 AND created_at >= :2 AND created_at < :3", install_metric.user, day_start, day_end).get() if page_view_in_day != None: setattr(post_install_activity_metric, "active_day_%s" % day, True) post_install_activity_metric.put() self.response.out.write(simplejson.dumps({'status': 'ok', 'cursor': str(query.cursor()), 'count': len(install_metrics) }))
def get(self): last_metric_at = PostInstallActivityMetric.gql("ORDER BY updated_at DESC").get() if last_metric_at == None: last_metric_at = "[Never]" else: last_metric_at = last_metric_at.updated_at h.output(self, '<html><head><link href="/public/css/admin/admin.css" type="text/css" rel="stylesheet" /></head><body><div id="loading-msg">Loading...</div><div id="auto-fetch-post-install-activity-metrics"></div><div>Post Install Activity Re-Calculation Status: <span id="status">Last Run at: '+str(last_metric_at)+'</span> <a id="calculate-post-install-activity-metrics-button" href="#">RE-CALCULATE NOW!</a></div><div>Total Users: <span id="total-users">...</span></div><div>Histogram for Post Install Activity: <div id="histogram-text">...</div></div><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script><script src="/public/js/admin/install-metrics.js" type="text/javascript"></script><script src="/public/js/admin/post-install-activity-metrics.js" type="text/javascript"></script></body></html>')