Exemple #1
0
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,
    })
Exemple #2
0
def experiment_csv(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))

    variations = list(Variation.objects.filter(experiment=exp).order_by('num'))

    graph_data = abdb.get_graphs(exp.id)

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=%s.%s.csv' % (
        exp.slug,
        datetime.date.today()
    )
    writer = csv.writer(response)

    data = defaultdict(lambda: {})
    all_dts = set()
    all_headers = []

    for choice in sorted(graph_data.keys()):
        choice_name = 'Baseline' if choice == -1 else variations[choice].name

        success_col_name = choice_name + ' Successes'
        trial_col_name = choice_name + ' Trials'

        if success_col_name not in all_headers:
            all_headers.extend([success_col_name, trial_col_name])

        for dt in graph_data[choice].keys():
            all_dts.add(dt)
            data[dt].update({
                success_col_name: graph_data[choice][dt]['successes'],
                trial_col_name: graph_data[choice][dt]['trials'],
            })

    writer.writerow(['Date'] + all_headers)

    for dt in sorted(all_dts):
        row = [str(dt)]
        for header in all_headers:
            val = data[dt].get(header)
            row.append(str(val) if val else '0')
        writer.writerow(row)

    return response