def exercisemetrics(): if "chapter" not in request.vars: logger.error( "It Appears exercisemetrics was called without any request vars") session.flash = "Cannot call exercisemetrics directly" redirect(URL("dashboard", "index")) chapter = request.vars["chapter"] base_course = (db(db.courses.course_name == auth.user.course_name).select().first().base_course) chapter = (db(((db.chapters.course_id == auth.user.course_name) | (db.chapters.course_id == base_course)) & (db.chapters.chapter_label == chapter)).select().first()) if not chapter: logger.error("Error -- No Chapter information for {} and {}".format( auth.user.course_name, request.vars["chapter"])) session.flash = "No Chapter information for {} and {}".format( auth.user.course_name, request.vars["chapter"]) redirect(URL("dashboard", "index")) # TODO: When all old style courses were gone this can be just a base course data_analyzer = DashboardDataAnalyzer(auth.user.course_id, chapter) data_analyzer.load_exercise_metrics(request.vars["id"]) problem_metrics = data_analyzer.problem_metrics prob_id = request.vars["id"] answers = [] attempt_histogram = [] logger.debug(problem_metrics.problems) try: problem_metric = problem_metrics.problems[prob_id] except KeyError: session.flash = f"Not enough data for {prob_id}" redirect(request.env.http_referer) response_frequency = problem_metric.aggregate_responses for username, user_responses in six.iteritems( problem_metric.user_responses): responses = user_responses.responses[:4] responses += [""] * (4 - len(responses)) answers.append({ "user": user_responses.user, "username": user_responses.username, "answers": responses, }) for attempts, count in six.iteritems( problem_metric.user_number_responses()): attempt_histogram.append({"attempts": attempts, "frequency": count}) return dict( course=get_course_row(db.courses.ALL), answers=answers, response_frequency=response_frequency, attempt_histogram=attempt_histogram, exercise_label=problem_metric.problem_text, )
def exercisemetrics(): if 'chapter' not in request.vars: logger.error( "It Appears exercisemetrics was called without any request vars") session.flash = "Cannot call exercisemetrics directly" redirect(URL('dashboard', 'index')) chapter = request.get_vars['chapter'] chapter = db((db.chapters.course_id == auth.user.course_name) & (db.chapters.chapter_label == chapter)).select().first() data_analyzer = DashboardDataAnalyzer(auth.user.course_id, chapter) data_analyzer.load_exercise_metrics(request.get_vars["id"]) problem_metrics = data_analyzer.problem_metrics prob_id = request.get_vars["id"] answers = [] attempt_histogram = [] logger.debug(problem_metrics.problems) problem_metric = problem_metrics.problems[prob_id] response_frequency = problem_metric.aggregate_responses for username, user_responses in six.iteritems( problem_metric.user_responses): responses = user_responses.responses[:4] responses += [''] * (4 - len(responses)) answers.append({ "user": user_responses.user, "username": user_responses.username, "answers": responses }) for attempts, count in six.iteritems( problem_metric.user_number_responses()): attempt_histogram.append({"attempts": attempts, "frequency": count}) return dict(course=get_course_row(db.courses.ALL), answers=answers, response_frequency=response_frequency, attempt_histogram=attempt_histogram, exercise_label=problem_metric.problem_text)