Esempio n. 1
0
    def post(self):
        span_in_days = int(self.request.get('span_in_days'))
        query = InstallMetric.all()
        query.order('-installed_at')
        cursor = self.request.get('cursor')
        if cursor != None:
            query.with_cursor(cursor)

        install_metrics = query.fetch(25)

        # There's one kvaluemetric per day, so find all `span_in_days` of them
        for install_metric in install_metrics:
            for kvalue_day in range(0, span_in_days):
                date = (install_metric.installed_at + datetime.timedelta(days=kvalue_day)).date()
                k_value_metric = KValueMetric.gql("WHERE date = :1 AND span_in_days = :2", date, span_in_days).get()
                if k_value_metric == None:
                    k_value_metric = KValueMetric(span_in_days = span_in_days, date = date)
                
                if install_metric.installed_via_newsfeed == True:
                    if k_value_metric.viral_signups == None:
                        k_value_metric.viral_signups = 0
                    k_value_metric.viral_signups += 1
                
                if k_value_metric.total_signups == None:
                    k_value_metric.total_signups = 0
                k_value_metric.total_signups +=1
                k_value_metric.put()

        self.response.out.write(simplejson.dumps({'status': 'ok', 'cursor': str(query.cursor()), 'count': len(install_metrics) }))
Esempio n. 2
0
    def get(self):
        span_in_days = self.request.get('span_in_days')
        last_metric_at = KValueMetric.gql("WHERE span_in_days = :1 ORDER BY updated_at DESC", span_in_days).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-k-value-metrics"></div><div>K-Value Re-Calculation Status: <span id="status">Last Run at: '+str(last_metric_at)+'</span> <a id="calculate-k-value-metrics-button" href="#">RE-CALCULATE NOW!</a></div><div>Chart for K-Value: <div id="graph">...</div></div><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script><script type="text/javascript" src="http://www.google.com/jsapi"></script><script src="/public/js/admin/install-metrics.js" type="text/javascript"></script><script src="/public/js/admin/k-value-metrics.js" type="text/javascript"></script></body></html>')