Exemple #1
0
def get_exploration_stats(exploration):
    """Returns a dict with stats for the given exploration."""

    num_visits = Statistics.get_exploration_stats(
        STATS_ENUMS.exploration_visited, exploration.id)

    num_completions = Statistics.get_exploration_stats(
        STATS_ENUMS.exploration_completed, exploration.id)

    answers = Statistics.get_exploration_stats(
        STATS_ENUMS.rule_hit, exploration.id)

    state_counts = Statistics.get_exploration_stats(
        STATS_ENUMS.state_hit, exploration.id)

    state_stats = {}
    for state_id in answers.keys():
        state_stats[state_id] = {
            'name': answers[state_id]['name'],
            'count': state_counts[state_id]['count'],
            'rule_stats': {},
        }
        for rule in answers[state_id]['rules'].keys():
            state_stats[state_id]['rule_stats'][rule] = answers[state_id]['rules'][rule]
            state_stats[state_id]['rule_stats'][rule]['count'] = 0
            for _, count in answers[state_id]['rules'][rule]['answers']:
                state_stats[state_id]['rule_stats'][rule]['count'] += count

    return {
        'num_visits': num_visits,
        'num_completions': num_completions,
        'state_stats': state_stats,
    }
Exemple #2
0
def get_exploration_stats(exploration):
    """Returns a dict with stats for the given exploration."""

    num_visits = Statistics.get_exploration_stats(
        STATS_ENUMS.exploration_visited, exploration.id)

    num_completions = Statistics.get_exploration_stats(
        STATS_ENUMS.exploration_completed, exploration.id)

    answers = Statistics.get_exploration_stats(
        STATS_ENUMS.rule_hit, exploration.id)

    state_counts = Statistics.get_exploration_stats(
        STATS_ENUMS.state_hit, exploration.id)

    state_stats = {}
    for state_id in answers.keys():
        state_stats[state_id] = {
            'name': answers[state_id]['name'],
            'count': state_counts[state_id]['count'],
            'rule_stats': {},
        }
        all_rule_count = 0
        state_count = state_counts[state_id]['count']
        for rule in answers[state_id]['rules'].keys():
            state_stats[state_id]['rule_stats'][rule] = answers[state_id]['rules'][rule]
            rule_count = 0
            for _, count in answers[state_id]['rules'][rule]['answers']:
                rule_count += count
                all_rule_count += count
            state_stats[state_id]['rule_stats'][rule]['chartData'] = [
                ['', 'This rule', 'Other answers'],
                ['', rule_count, state_count - rule_count]]
        state_stats[state_id]['no_answer_chartdata'] = [
            ['', 'No answer', 'Answer given'],
            ['',  state_count - all_rule_count, all_rule_count]]

    return {
        'num_visits': num_visits,
        'num_completions': num_completions,
        'state_stats': state_stats,
    }