def _record_node_completion(self, story_id, node_id, completed_node_ids, ordered_nodes): """Records node completion.""" if not constants.ENABLE_NEW_STRUCTURE_VIEWER_UPDATES: raise self.PageNotFoundException try: story_fetchers.get_node_index_by_story_id_and_node_id( story_id, node_id) except Exception as e: raise self.PageNotFoundException(e) next_exp_ids = [] next_node_id = None if node_id not in completed_node_ids: story_services.record_completed_node_in_story_context( self.user_id, story_id, node_id) completed_nodes = story_fetchers.get_completed_nodes_in_story( self.user_id, story_id) completed_node_ids = [ completed_node.id for completed_node in completed_nodes ] for node in ordered_nodes: if node.id not in completed_node_ids: next_exp_ids = [node.exploration_id] next_node_id = node.id break return (next_exp_ids, next_node_id, completed_node_ids)
def post(self, story_id, node_id): if not constants.ENABLE_NEW_STRUCTURE_PLAYERS: raise self.PageNotFoundException try: story_fetchers.get_node_index_by_story_id_and_node_id( story_id, node_id) except Exception, e: raise self.PageNotFoundException(e)
def post(self, story_id, node_id): if not constants.ENABLE_NEW_STRUCTURE_VIEWER_UPDATES: raise self.PageNotFoundException try: story_fetchers.get_node_index_by_story_id_and_node_id( story_id, node_id) except Exception as e: raise self.PageNotFoundException(e) story = story_fetchers.get_story_by_id(story_id) completed_nodes = story_fetchers.get_completed_nodes_in_story( self.user_id, story_id) completed_node_ids = [ completed_node.id for completed_node in completed_nodes ] ordered_nodes = [ node for node in story.story_contents.get_ordered_nodes() ] next_exp_ids = [] next_node_id = None if not node_id in completed_node_ids: story_services.record_completed_node_in_story_context( self.user_id, story_id, node_id) completed_nodes = story_fetchers.get_completed_nodes_in_story( self.user_id, story_id) completed_node_ids = [ completed_node.id for completed_node in completed_nodes ] for node in ordered_nodes: if node.id not in completed_node_ids: next_exp_ids = [node.exploration_id] next_node_id = node.id break ready_for_review_test = False exp_summaries = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( next_exp_ids)) if ((len(exp_summaries) != 0 and len(completed_nodes) % constants.NUM_EXPLORATIONS_PER_REVIEW_TEST == 0) or (len(completed_nodes) == len(ordered_nodes))): ready_for_review_test = True return self.render_json({ 'summaries': exp_summaries, 'ready_for_review_test': ready_for_review_test, 'next_node_id': next_node_id })
def post(self, story_id, node_id): if not constants.ENABLE_NEW_STRUCTURE_VIEWER_UPDATES: raise self.PageNotFoundException try: story_fetchers.get_node_index_by_story_id_and_node_id( story_id, node_id) except Exception as e: raise self.PageNotFoundException(e) story_services.record_completed_node_in_story_context( self.user_id, story_id, node_id) return self.render_json({})
def test_get_node_index_by_story_id_and_node_id(self): # Tests correct node index should be returned when story and node exist. node_index = story_fetchers.get_node_index_by_story_id_and_node_id( self.STORY_ID, self.NODE_ID_1) self.assertEqual(node_index, 0) # Tests error should be raised if story or node doesn't exist. with self.assertRaisesRegexp( Exception, 'Story node with id node_5 does not exist in this story.'): story_fetchers.get_node_index_by_story_id_and_node_id( self.STORY_ID, 'node_5') with self.assertRaisesRegexp( Exception, 'Story with id story_id_2 does not exist.'): story_fetchers.get_node_index_by_story_id_and_node_id( 'story_id_2', self.NODE_ID_1)
def test_get_node_index_by_story_id_and_node_id(self) -> None: # Tests correct node index should be returned when story and node exist. node_index = story_fetchers.get_node_index_by_story_id_and_node_id( self.story_id, self.NODE_ID_1) self.assertEqual(node_index, 0) # Tests error should be raised if story or node doesn't exist. with self.assertRaisesRegex( # type: ignore[no-untyped-call] Exception, 'The node with id node_5 is not part of this story.'): story_fetchers.get_node_index_by_story_id_and_node_id( self.story_id, 'node_5') with self.assertRaisesRegex( # type: ignore[no-untyped-call] Exception, 'Story with id story_id_2 does not exist.'): story_fetchers.get_node_index_by_story_id_and_node_id( 'story_id_2', self.NODE_ID_1)
def post(self, story_id, node_id): if not constants.ENABLE_NEW_STRUCTURE_VIEWER_UPDATES: raise self.PageNotFoundException try: story_fetchers.get_node_index_by_story_id_and_node_id( story_id, node_id) except Exception as e: raise self.PageNotFoundException(e) story = story_fetchers.get_story_by_id(story_id) completed_nodes = story_fetchers.get_completed_nodes_in_story( self.user_id, story_id) completed_node_ids = [ completed_node.id for completed_node in completed_nodes ] ordered_nodes = [ node for node in story.story_contents.get_ordered_nodes() ] next_exp_ids = [] next_node_id = None if not node_id in completed_node_ids: story_services.record_completed_node_in_story_context( self.user_id, story_id, node_id) completed_nodes = story_fetchers.get_completed_nodes_in_story( self.user_id, story_id) completed_node_ids = [ completed_node.id for completed_node in completed_nodes ] for node in ordered_nodes: if node.id not in completed_node_ids: next_exp_ids = [node.exploration_id] next_node_id = node.id break ready_for_review_test = False exp_summaries = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( next_exp_ids)) # If there are no questions for any of the acquired skills that the # learner has completed, do not show review tests. acquired_skills = skill_fetchers.get_multi_skills( story.get_acquired_skill_ids_for_node_ids(completed_node_ids)) acquired_skill_ids = [skill.id for skill in acquired_skills] questions_available = len( question_services.get_questions_by_skill_ids( 1, acquired_skill_ids, False)) > 0 learner_completed_story = len(completed_nodes) == len(ordered_nodes) learner_at_review_point_in_story = ( len(exp_summaries) != 0 and (len(completed_nodes) & constants.NUM_EXPLORATIONS_PER_REVIEW_TEST == 0)) if questions_available and (learner_at_review_point_in_story or learner_completed_story): ready_for_review_test = True return self.render_json({ 'summaries': exp_summaries, 'ready_for_review_test': ready_for_review_test, 'next_node_id': next_node_id })