def get(self, exploration_id, exploration_version): """Handles GET requests.""" try: exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException self.render_json(stats_services.get_exploration_stats( exploration_id, exploration_version))
def get(self, exploration_id): """Handles GET requests.""" current_exploration = exp_fetchers.get_exploration_by_id( exploration_id) self.render_json( stats_services.get_exploration_stats( exploration_id, current_exploration.version).to_frontend_dict())
def get(self, exploration_id, exploration_version): """Handles GET requests.""" try: exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException self.render_json(stats_services.get_exploration_stats( exploration_id, exploration_version))
def get(self, exploration_id): """Handles GET requests.""" try: current_exploration = exp_services.get_exploration_by_id( exploration_id) except: raise self.PageNotFoundException self.render_json(stats_services.get_exploration_stats( exploration_id, current_exploration.version).to_frontend_dict())
def map(item): """Implements the map function (generator). Computes exploration data for every contributor and owner of the exploration. Args: item: ExpSummaryModel. An instance of ExpSummaryModel. Yields: This function may yield as many times as appropriate 2-tuples in the format (str, dict), where - str. The unique ID of the user. - dict: A dict that includes entries for all the explorations that this user contributes to or owns. Each entry has the following keys: - 'exploration_impact_score': float. The impact score of all the explorations contributed to by the user. - 'total_plays_for_owned_exp': int. Total plays of all explorations owned by the user. - 'average_rating_for_owned_exp': float. Average of average ratings of all explorations owned by the user. - 'num_ratings_for_owned_exp': int. Total number of ratings of all explorations owned by the user. """ if item.deleted: return exponent = 2.0 / 3 # This is set to False only when the exploration impact score is not # valid to be calculated. calculate_exploration_impact_score = True # Get average rating and value per user. total_rating = 0 for ratings_value in item.ratings: total_rating += item.ratings[ratings_value] * int(ratings_value) sum_of_ratings = sum(item.ratings.itervalues()) average_rating = ((total_rating / sum_of_ratings) if sum_of_ratings else None) if average_rating is not None: value_per_user = average_rating - 2 if value_per_user <= 0: calculate_exploration_impact_score = False else: calculate_exploration_impact_score = False exploration_stats = stats_services.get_exploration_stats( item.id, item.version) # For each state, find the number of first entries to the state. # This is considered to be approximately equal to the number of # users who answered the state because very few users enter a state # and leave without answering anything at all. answer_count = exploration_stats.get_sum_of_first_hit_counts() num_starts = exploration_stats.num_starts # Turn answer count into reach. reach = answer_count**exponent exploration_summary = exp_fetchers.get_exploration_summary_by_id( item.id) contributors = exploration_summary.contributors_summary total_commits = sum(contributors.itervalues()) if total_commits == 0: calculate_exploration_impact_score = False mapped_owner_ids = [] for contrib_id in contributors: exploration_data = {} # Set the value of exploration impact score only if it needs to be # calculated. if calculate_exploration_impact_score: # Find fractional contribution for each contributor. contribution = (contributors[contrib_id] / float(total_commits)) # Find score for this specific exploration. exploration_data.update({ 'exploration_impact_score': (value_per_user * reach * contribution) }) # If the user is an owner for the exploration, then update dict with # 'average ratings' and 'total plays' as well. if contrib_id in exploration_summary.owner_ids: mapped_owner_ids.append(contrib_id) # Get num starts (total plays) for the exploration. exploration_data.update({ 'total_plays_for_owned_exp': num_starts, }) # Update data with average rating only if it is not None. if average_rating is not None: exploration_data.update({ 'average_rating_for_owned_exp': average_rating, 'num_ratings_for_owned_exp': sum_of_ratings }) yield (contrib_id, exploration_data) for owner_id in exploration_summary.owner_ids: if owner_id not in mapped_owner_ids: mapped_owner_ids.append(owner_id) # Get num starts (total plays) for the exploration. exploration_data = { 'total_plays_for_owned_exp': num_starts, } # Update data with average rating only if it is not None. if average_rating is not None: exploration_data.update({ 'average_rating_for_owned_exp': average_rating, 'num_ratings_for_owned_exp': sum_of_ratings }) yield (owner_id, exploration_data)
def map(item): """Implements the map function (generator). Computes exploration data for every contributor and owner of the exploration. Args: item: ExpSummaryModel. An instance of ExpSummaryModel. Yields: This function may yield as many times as appropriate 2-tuples in the format (str, dict), where - str. The unique ID of the user. - dict: A dict that includes entries for all the explorations that this user contributes to or owns. Each entry has the following keys: - 'exploration_impact_score': float. The impact score of all the explorations contributed to by the user. - 'total_plays_for_owned_exp': int. Total plays of all explorations owned by the user. - 'average_rating_for_owned_exp': float. Average of average ratings of all explorations owned by the user. - 'num_ratings_for_owned_exp': int. Total number of ratings of all explorations owned by the user. """ if item.deleted: return exponent = 2.0 / 3 # This is set to False only when the exploration impact score is not # valid to be calculated. calculate_exploration_impact_score = True # Get average rating and value per user total_rating = 0 for ratings_value in item.ratings: total_rating += item.ratings[ratings_value] * int(ratings_value) sum_of_ratings = sum(item.ratings.itervalues()) average_rating = ((total_rating / sum_of_ratings) if sum_of_ratings else None) if average_rating is not None: value_per_user = average_rating - 2 if value_per_user <= 0: calculate_exploration_impact_score = False else: calculate_exploration_impact_score = False if feconf.ENABLE_NEW_STATS_FRAMEWORK: exploration_stats = stats_services.get_exploration_stats( item.id, item.version) # For each state, find the number of first entries to the state. # This is considered to be approximately equal to the number of # users who answered the state because very few users enter a state # and leave without answering anything at all. answer_count = exploration_stats.get_sum_of_first_hit_counts() num_starts = exploration_stats.num_starts else: statistics = ( stats_jobs_continuous.StatisticsAggregator.get_statistics( item.id, stats_jobs_continuous.VERSION_ALL)) answer_count = 0 # Find number of users per state (card), and subtract no answer # This will not count people who have been back to a state twice # but did not give an answer the second time, but is probably the # closest we can get with current statistics to "number of users # who gave an answer" since it is "number of users who always gave # an answer". for state_name in statistics['state_hit_counts']: state_stats = statistics['state_hit_counts'][state_name] first_entry_count = state_stats.get('first_entry_count', 0) no_answer_count = state_stats.get('no_answer_count', 0) answer_count += first_entry_count - no_answer_count num_starts = statistics['start_exploration_count'] # Turn answer count into reach reach = answer_count**exponent exploration_summary = exp_services.get_exploration_summary_by_id( item.id) contributors = exploration_summary.contributors_summary total_commits = sum(contributors.itervalues()) if total_commits == 0: calculate_exploration_impact_score = False mapped_owner_ids = [] for contrib_id in contributors: exploration_data = {} # Set the value of exploration impact score only if it needs to be # calculated. if calculate_exploration_impact_score: # Find fractional contribution for each contributor contribution = (contributors[contrib_id] / float(total_commits)) # Find score for this specific exploration exploration_data.update({ 'exploration_impact_score': (value_per_user * reach * contribution) }) # if the user is an owner for the exploration, then update dict with # 'average ratings' and 'total plays' as well. if contrib_id in exploration_summary.owner_ids: mapped_owner_ids.append(contrib_id) # Get num starts (total plays) for the exploration exploration_data.update({ 'total_plays_for_owned_exp': num_starts, }) # Update data with average rating only if it is not None. if average_rating is not None: exploration_data.update({ 'average_rating_for_owned_exp': average_rating, 'num_ratings_for_owned_exp': sum_of_ratings }) yield (contrib_id, exploration_data) for owner_id in exploration_summary.owner_ids: if owner_id not in mapped_owner_ids: mapped_owner_ids.append(owner_id) # Get num starts (total plays) for the exploration exploration_data = { 'total_plays_for_owned_exp': num_starts, } # Update data with average rating only if it is not None. if average_rating is not None: exploration_data.update({ 'average_rating_for_owned_exp': average_rating, 'num_ratings_for_owned_exp': sum_of_ratings }) yield (owner_id, exploration_data)