def _inc(cls, event_key): """Increments the counter corresponding to an event key.""" counter = Counter.get(event_key, name=event_key, strict=False) if not counter: counter = Counter(id=event_key, name=event_key) counter.value += 1 counter.put()
def _inc(cls, event_id): """Increments the counter corresponding to an event id.""" counter = Counter.get(event_id, strict=False) if not counter: counter = Counter(id=event_id) counter.value += 1 counter.put()
def get_exploration_stats(event_name, exploration_id): """Retrieves statistics for the given event name and exploration id.""" if event_name == STATS_ENUMS.exploration_visited: event_key = get_event_key(event_name, exploration_id) counter = Counter.get(event_key, strict=False) if not counter: return 0 return counter.value if event_name == STATS_ENUMS.exploration_completed: event_key = get_event_key(event_name, exploration_id) counter = Counter.get(event_key, strict=False) if not counter: return 0 return counter.value if event_name == STATS_ENUMS.rule_hit: result = {} exploration = Exploration.get(exploration_id) for state_id in exploration.state_ids: state = exploration.get_state_by_id(state_id) result[state.id] = { 'name': state.name, 'rules': {} } for handler in state.widget.handlers: for rule in handler.rules: rule_name = create_rule_name(rule) event_key = get_event_key( event_name, '.'.join( [exploration_id, state.id, rule_name])) journal = Journal.get(event_key, strict=False) if journal: top_ten = collections.Counter( journal.values).most_common(10) else: top_ten = [] result[state.id]['rules'][rule_name] = { 'answers': top_ten, } return result if event_name == STATS_ENUMS.state_hit: result = {} exploration = Exploration.get(exploration_id) for state_id in exploration.state_ids: state = exploration.get_state_by_id(state_id) event_key = get_event_key( event_name, '.'.join([exploration_id, state.id])) counter = Counter.get(event_key, strict=False) if not counter: count = 0 else: count = counter.value result[state.id] = { 'name': state.name, 'count': count, } return result