Skip to content

Commit

Permalink
Get the stats graph to read from the old models until we have a prope…
Browse files Browse the repository at this point in the history
…r migration process in place.
  • Loading branch information
seanlip committed Jun 17, 2014
1 parent c92284c commit 56e111e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 3 additions & 1 deletion core/controllers/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from core.controllers import base
from core import jobs_registry


class StatisticsHandler(base.BaseHandler):
"""Handler for statistics cron job."""

def get(self):
"""Handles get requests."""
"""Handles GET requests."""
for klass in jobs_registry.JOB_MANAGER_CLASSES:
if klass.__name__ == 'StatisticsPageJobManager':
klass.enqueue(klass.create_new())
Expand Down
9 changes: 5 additions & 4 deletions core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,12 @@ def get(self, exploration_id):
exp_services.get_exploration_by_id(exploration_id)
except:
raise self.PageNotFoundException
exploration_annotations = stats_services.get_exploration_annotations(
exploration_id)

self.render_json({
'num_visits': exploration_annotations.num_visits,
'num_completions': exploration_annotations.num_completions,
'num_visits': stats_services.get_exploration_visit_count(
exploration_id),
'num_completions': stats_services.get_exploration_completed_count(
exploration_id),
'state_stats': stats_services.get_state_stats_for_exploration(
exploration_id),
'improvements': stats_services.get_state_improvements(
Expand Down
22 changes: 22 additions & 0 deletions core/domain/stats_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from core.domain import stats_domain
from core.platform import models
(stats_models,) = models.Registry.import_models([models.NAMES.statistics])
import feconf


IMPROVE_TYPE_DEFAULT = 'default'
Expand Down Expand Up @@ -74,6 +75,22 @@ def maybe_leave_exploration(
params, play_type)


def get_exploration_visit_count(exploration_id):
"""Returns the number of times this exploration has been accessed."""
# TODO(sll): Delete this when we move to the new MapReduce infrastructure.
exploration = exp_services.get_exploration_by_id(exploration_id)
return stats_domain.StateCounter.get(
exploration_id, exploration.init_state_name).first_entry_count


def get_exploration_completed_count(exploration_id):
"""Returns the number of times this exploration has been completed."""
# Note that the subsequent_entries_count for END_DEST should be 0.
# TODO(sll): Delete this when we move to the new MapReduce infrastructure.
return stats_domain.StateCounter.get(
exploration_id, feconf.END_DEST).first_entry_count


def get_top_unresolved_answers_for_default_rule(exploration_id, state_name):
return {
answer: count for (answer, count) in
Expand Down Expand Up @@ -118,6 +135,11 @@ def get_state_rules_stats(exploration_id, state_name):


def get_exploration_annotations(exp_id):
"""Gets exploration annotations.
NB: Currently unused.
"""
# TODO(sll): This should return a domain object, not an ndb.Model instance.
exp_annotations = stats_models.ExplorationAnnotationsModel.get(
exp_id, strict=False)
if not exp_annotations:
Expand Down
3 changes: 0 additions & 3 deletions cron.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
cron:
- description: periodic statistics calculations
url: /cron/statistics
schedule: every 6 hours

0 comments on commit 56e111e

Please sign in to comment.