Exemple #1
0
def pivot_detail(request, syllabus_tag=None, pivot_type=None, pivot_id=None):
    """
    Describes a single pivot in detail.
    """
    if pivot_type not in ['k', 'w'] or pivot_id is None:
        raise Http404
    pivot_id = int(pivot_id)

    context = {}
    context['pivot_type'] = pivot_type
    context['syllabus'] = usermodel_models.Syllabus.objects.get(
        tag=syllabus_tag.replace('_', ' '))

    if pivot_type == 'k':
        pivot = usermodel_models.PartialKanji.objects.get(id=pivot_id)
    else:
        assert pivot_type == 'w'
        pivot = usermodel_models.PartialLexeme.objects.get(id=pivot_id)

    context['pivot'] = pivot

    base_response_stats = stats.get_pivot_response_stats(pivot.id, pivot_type)
    context['response_dists'] = [(l, charts.PieChart(d.items(),
                                                     size='750x200'))
                                 for (l, d) in base_response_stats]

    return render_to_response('analysis/pivot_detail.html', context,
                              RequestContext(request))
Exemple #2
0
def _build_user_graph(name):
    if name.endswith('lang'):
        name = name[:-len('lang')]
        dist = stats.get_language_data(name)
        return charts.PieChart(dist.items(), max_options=8)

    elif name == 'dropout':
        data = stats.get_dropout_figures()
        approx_data = stats.approximate(data)
        chart = charts.MultiLineChart(approx_data,
                                      data_name='histogram',
                                      x_axis=(0.4, 1.0, 0.1),
                                      y_axis=(0, 1.0, 0.1))
        chart.add_data('raw', data)
        return chart

    elif name == 'prepostdiff':
        data = [
            r['pre_post_diff'] for r in stats.get_global_rater_stats()
            if r['n_tests'] > 2 and r['pre_post_diff']
        ]
        hist_data = stats.histogram(data,
                                    n_bins=11,
                                    normalize=False,
                                    x_min=-0.7,
                                    x_max=0.7)
        chart = charts.LineChart(hist_data,
                                 data_name='histogram',
                                 x_axis=(-0.8, 0.8, 0.2))
        chart.add_data('raw', data)
        return chart

    elif name == 'abilityjlpt3':
        data = stats.get_user_scores('jlpt 3')
        hist_data = stats.histogram(data,
                                    x_min=0.0,
                                    x_max=1.0,
                                    normalize=False)
        chart = charts.LineChart(hist_data,
                                 data_name='histogram',
                                 x_axis=(0.0, 1.0, 0.1))
        chart.add_data('raw', data)
        return chart

    elif name == 'abilityjlpt4':
        data = stats.get_user_scores('jlpt 4')
        hist_data = stats.histogram(data,
                                    x_min=0.0,
                                    x_max=1.0,
                                    normalize=False)
        chart = charts.LineChart(hist_data,
                                 data_name='histogram',
                                 x_axis=(0.0, 1.0, 0.1))
        chart.add_data('raw', data)
        return chart

    raise KeyError(name)
Exemple #3
0
def _build_plugin_graph(name):
    if '_' in name:
        name, subpart = name.split('_', 1)
    else:
        subpart = None

    if name == 'questions':
        data = []
        for plugin in models.QuestionPlugin.objects.all():
            data.append((
                    plugin.name + \
                    ((plugin.is_adaptive) and ' [adaptive]' or ' [simple]'),
                    plugin.question_set.count(),
                ))
        return charts.PieChart(data)

    elif name == 'error':
        raw_data = stats.get_mean_error_by_plugin()
        data = _accumulate_plugin_errors(raw_data)
        k = (1 + settings.N_DISTRACTORS)
        data.append(('[random guess]', (k - 1) / float(k)))
        chart = charts.BarChart(data, y_axis=(0, 1.0, 0.2))
        chart.add_data('raw', raw_data)
        return chart

    elif name == 'errorbin':
        data_sets = stats.get_power_binned_error_by_plugin()
        is_error_chart = True
        if subpart == 'early':
            raw_data = data_sets[0]
            data = _accumulate_plugin_errors(raw_data)
        elif subpart == 'mid':
            raw_data = data_sets[1]
            data = _accumulate_plugin_errors(raw_data)
        elif subpart == 'late':
            raw_data = data_sets[2]
            data = _accumulate_plugin_errors(raw_data)
        elif subpart == 'volume':
            is_error_chart = False
            data = zip(['Early', 'Mid', 'Late'], map(len, data_sets))
        else:
            raise KeyError(name)

        if is_error_chart:
            chart = charts.BarChart(data)  #, y_axis=(0, 0.5, 0.1))
            chart.add_data('raw', raw_data)
        else:
            chart = charts.BarChart(data)
        return chart

    raise KeyError(name)
Exemple #4
0
def _build_test_graph(name):
    if name == 'mean':
        score_data = stats.get_mean_score_nth_test()
        data = stats.group_by_points(score_data, y_max=1.0, y_min=0.0)
        chart = charts.MultiLineChart(data,
                                      y_axis=(0, 1, 0.1),
                                      data_name='grouped')
        chart.add_data('raw', score_data)
        return chart

    elif name == 'volume':
        user_data = stats.get_users_by_n_tests()
        return charts.LineChart(user_data)

    elif name == 'length':
        return charts.PieChart(stats.get_test_length_volume())

    elif name == 'normtime':
        user_data = stats.get_score_over_norm_time()
        return charts.LineChart(user_data)

    elif name == 'time':
        base_data = stats.get_score_over_time()
        data = stats.approximate(base_data)
        chart = charts.MultiLineChart(data,
                                      y_axis=(0, 1.05, 0.1),
                                      data_name='approximate')
        chart.add_data('raw', base_data)
        two_colours = charts.color_desc(2).split(',')
        three_colours = ','.join(
            (two_colours[0], two_colours[1], two_colours[1]))
        chart['chco'] = three_colours
        return chart

    elif name == 'dropout':
        return charts.LineChart(stats.get_mean_score_by_n_tests())

    elif name == 'firstlast':
        data = stats.get_first_last_test()
        hist_data = stats.histogram(data,
                                    n_bins=11,
                                    normalize=False,
                                    x_min=-0.5,
                                    x_max=0.5)
        chart = charts.LineChart(hist_data,
                                 data_name='histogram',
                                 x_axis=(-0.5, 0.5, 0.1))
        chart.add_data('raw', data)
        return chart

    raise KeyError(name)
Exemple #5
0
def _build_syllabus_graph(name):
    if name == 'volume':
        return charts.PieChart(stats.get_syllabus_volume())

    raise KeyError(name)