예제 #1
0
파일: views.py 프로젝트: zhoufan2013/clutch
def experiment_stats(request, app_slug=None, experiment_id=None):
    app, apps = _get_app_apps(request, app_slug)

    exp = get_object_or_404(Experiment, id=int(experiment_id))

    confidence = abdb.get_confidence_data(exp.id)
    graph_data = abdb.get_graphs(exp.id)

    graphs = {-1: [{'successes': 0, 'trials': 0}]}
    for variation in Variation.objects.filter(experiment=exp).order_by('num'):
        graphs[variation.num - 1] = [{'successes': 0, 'trials': 0}]
        confidence.setdefault(variation.num - 1, [0, 0])

    # Convert the series into something nicer and convert datetimes to floats
    for choice in sorted(graph_data.keys()):
        graph = []
        for dt in sorted(graph_data[choice].keys()):
            item = graph_data[choice][dt].copy()
            item['timestamp'] = datetime_to_timestamp(dt)
            graph.append(item)
        graphs[choice] = graph

    return JSONResponse(request, {
        'graphs': graphs,
        'confidence': confidence,
    })
예제 #2
0
파일: models.py 프로젝트: BetaDesign/clutch
 def data(self):
     return {
         'id': self.id,
         'app': self.app_id,
         'key': self.key,
         'status': self.status,
         'date_created': datetime_to_timestamp(self.date_created),
     }
예제 #3
0
 def data(self):
     return {
         'id': self.id,
         'app': self.app_id,
         'key': self.key,
         'status': self.status,
         'date_created': datetime_to_timestamp(self.date_created),
     }
예제 #4
0
def _prepare_json(stats, period):
    if period == PERIODS.TODAY:
        display = lambda item: item.strftime('%I%p UTC').lstrip('0')
    else:
        display = lambda item: item.strftime('%b %d')
    return [{
        'timestamp': datetime_to_timestamp(item['timestamp']),
        'timestamp_fmt': display(item['timestamp']),
        'stat': item['stat'],
        'show': item['timestamp'] <= now(),
    } for item in stats]
예제 #5
0
def get_monthly_actives(app, month=None):
    app_id = app.id if isinstance(app, App) else app
    if month is None:
        month = now()
    month = month.replace(day=1, hour=0, minute=0, second=0, microsecond=0)

    cache_key = hashlib.sha1("monthly-actives-%s-%s" % (app_id, datetime_to_timestamp(month))).hexdigest()

    resp = cache.get(cache_key)
    if resp is not None:
        return resp
    resp = _get_monthly_actives(app_id, month)
    cache.set(cache_key, resp, 60)
    return resp
예제 #6
0
파일: views.py 프로젝트: BetaDesign/clutch
def _prepare_json(stats, period):
    if period == PERIODS.TODAY:
        display = lambda item: item.strftime('%I%p UTC').lstrip('0')
    else:
        display = lambda item: item.strftime('%b %d')
    return [
        {
            'timestamp': datetime_to_timestamp(item['timestamp']),
            'timestamp_fmt': display(item['timestamp']),
            'stat': item['stat'],
            'show': item['timestamp'] <= now(),
        }
        for item in stats
    ]
예제 #7
0
def get_monthly_actives(app, month=None):
    app_id = app.id if isinstance(app, App) else app
    if month is None:
        month = now()
    month = month.replace(day=1, hour=0, minute=0, second=0, microsecond=0)

    cache_key = hashlib.sha1('monthly-actives-%s-%s' % (
        app_id,
        datetime_to_timestamp(month),
    )).hexdigest()

    resp = cache.get(cache_key)
    if resp is not None:
        return resp
    resp = _get_monthly_actives(app_id, month)
    cache.set(cache_key, resp, 60)
    return resp