def _get_usage_key(self): try: block_id = 'block-v1:' + self.block_id_string self.usage_key = UsageKey.from_string(block_id) except InvalidKeyError: course_key = CourseKey.from_string(self.block_id_string) pattern = u"{course_key}+{BLOCK_TYPE_PREFIX}@{block_type}+{BLOCK_PREFIX}@{block_id}" block_id = pattern.format( course_key=course_key._to_string(), BLOCK_TYPE_PREFIX=course_key.BLOCK_TYPE_PREFIX, block_type='course', BLOCK_PREFIX=course_key.BLOCK_PREFIX, block_id='course') self.usage_key = BlockUsageLocator._from_string(block_id) except: self.usage_key = None
def chart_update(request): results = {'success' : False} chart_info_json = dumps(results) if request.method == u'GET': GET = request.GET user_id = GET[u'user_id'] user_id = request.user if user_id == "" else user_id chart = int(GET[u'chart']) course_key = get_course_key(GET[u'course_id']) if chart == VISUALIZATIONS_ID['LA_chapter_time']: cs, st = get_DB_course_spent_time(course_key, student_id=user_id) student_spent_time = chapter_time_to_js(cs, st) chart_info_json = dumps(student_spent_time) elif chart == VISUALIZATIONS_ID['LA_course_accesses']: cs, sa = get_DB_course_section_accesses(course_key, student_id=user_id) student_course_accesses = course_accesses_to_js(cs, sa) chart_info_json = dumps(student_course_accesses) elif chart == VISUALIZATIONS_ID['LA_student_grades']: students_grades = get_DB_student_grades(course_key, student_id=user_id) chart_info_json = dumps(students_grades) elif chart == VISUALIZATIONS_ID['LA_time_schedule']: student_time_schedule = get_DB_time_schedule(course_key, student_id=user_id) chart_info_json = dumps(student_time_schedule) elif chart == VISUALIZATIONS_ID['LA_vid_prob_prog']: student_prob_vid_progress = get_DB_course_video_problem_progress(course_key, student_id=user_id) chart_info_json = dumps(student_prob_vid_progress) elif chart == VISUALIZATIONS_ID['LA_video_progress']: # Video progress visualization. Video percentage seen total and non-overlapped. course = get_course_with_access(user_id, action='load', course_key=course_key, depth=None, check_if_enrolled=False) video_descriptors = videos_problems_in(course)[0] video_durations = get_info_videos_descriptors(video_descriptors)[2] video_names, avg_video_time, video_percentages = get_module_consumption(user_id, course_key, 'video', 'video_progress') if avg_video_time != []: all_video_time_percent = map(truediv, avg_video_time, video_durations) all_video_time_percent = [int(round(x*100,0)) for x in all_video_time_percent] else: all_video_time_percent = avg_video_time column_headers = ['Video', 'Different video time', 'Total video time'] chart_info_json = ready_for_arraytodatatable(column_headers, video_names, video_percentages, all_video_time_percent) elif chart == VISUALIZATIONS_ID['LA_video_time']: # Time spent on every video resource video_names, all_video_time = get_module_consumption(user_id, course_key, 'video', 'total_time_vid_prob')[0:2] column_headers = ['Video', 'Time watched'] chart_info_json = ready_for_arraytodatatable(column_headers, video_names, all_video_time) elif chart == VISUALIZATIONS_ID['LA_problem_time']: # Time spent on every problem resource problem_names, time_x_problem = get_module_consumption(user_id, course_key, 'problem', 'total_time_vid_prob')[0:2] column_headers = ['Problem', 'Time on problem'] chart_info_json = ready_for_arraytodatatable(column_headers, problem_names, time_x_problem) elif chart == VISUALIZATIONS_ID['LA_repetition_video_interval']: # Repetitions per video intervals video_name = GET[u'video'] video_id = BlockUsageLocator._from_string(video_name) video_id = Location.from_deprecated_string(video_id._to_deprecated_string()) chart_info_json = get_user_video_intervals(user_id, video_id) elif chart == VISUALIZATIONS_ID['LA_daily_time']: # Daily time spent on video and/or problem resources video_days, video_daily_time = get_daily_consumption(user_id, course_key, 'video') problem_days, problem_daily_time = get_daily_consumption(user_id, course_key, 'problem') chart_info_json = join_video_problem_time(video_days, video_daily_time, problem_days, problem_daily_time) elif chart == VISUALIZATIONS_ID['LA_video_events']: # Video events dispersion within video length video_name = GET[u'video'] video_id = BlockUsageLocator._from_string(video_name) video_id = Location.from_deprecated_string(video_id._to_deprecated_string()) chart_info_json = get_video_events_info(user_id, video_id) return HttpResponse(chart_info_json, mimetype='application/json')
def chart_update(request): results = {'success': False} chart_info_json = dumps(results) if request.method == u'GET': GET = request.GET user_id = GET[u'user_id'] user_id = request.user if user_id == "" else user_id chart = int(GET[u'chart']) course_key = get_course_key(GET[u'course_id']) if chart == VISUALIZATIONS_ID['LA_chapter_time']: cs, st = get_DB_course_spent_time(course_key, student_id=user_id) student_spent_time = chapter_time_to_js(cs, st) chart_info_json = dumps(student_spent_time) elif chart == VISUALIZATIONS_ID['LA_course_accesses']: cs, sa = get_DB_course_section_accesses(course_key, student_id=user_id) student_course_accesses = course_accesses_to_js(cs, sa) chart_info_json = dumps(student_course_accesses) elif chart == VISUALIZATIONS_ID['LA_student_grades']: students_grades = get_DB_student_grades(course_key, student_id=user_id) chart_info_json = dumps(students_grades) elif chart == VISUALIZATIONS_ID['LA_time_schedule']: student_time_schedule = get_DB_time_schedule(course_key, student_id=user_id) chart_info_json = dumps(student_time_schedule) elif chart == VISUALIZATIONS_ID['LA_vid_prob_prog']: student_prob_vid_progress = get_DB_course_video_problem_progress( course_key, student_id=user_id) chart_info_json = dumps(student_prob_vid_progress) elif chart == VISUALIZATIONS_ID['LA_video_progress']: # Video progress visualization. Video percentage seen total and non-overlapped. course = get_course_with_access(user_id, action='load', course_key=course_key, depth=None, check_if_enrolled=False) video_descriptors = videos_problems_in(course)[0] video_durations = get_info_videos_descriptors(video_descriptors)[2] video_names, avg_video_time, video_percentages = get_module_consumption( user_id, course_key, 'video', 'video_progress') if avg_video_time != []: all_video_time_percent = map(truediv, avg_video_time, video_durations) all_video_time_percent = [ int(round(x * 100, 0)) for x in all_video_time_percent ] else: all_video_time_percent = avg_video_time column_headers = [ 'Video', 'Different video time', 'Total video time' ] chart_info_json = ready_for_arraytodatatable( column_headers, video_names, video_percentages, all_video_time_percent) elif chart == VISUALIZATIONS_ID['LA_video_time']: # Time spent on every video resource video_names, all_video_time = get_module_consumption( user_id, course_key, 'video', 'total_time_vid_prob')[0:2] column_headers = ['Video', 'Time watched'] chart_info_json = ready_for_arraytodatatable( column_headers, video_names, all_video_time) elif chart == VISUALIZATIONS_ID['LA_problem_time']: # Time spent on every problem resource problem_names, time_x_problem = get_module_consumption( user_id, course_key, 'problem', 'total_time_vid_prob')[0:2] column_headers = ['Problem', 'Time on problem'] chart_info_json = ready_for_arraytodatatable( column_headers, problem_names, time_x_problem) elif chart == VISUALIZATIONS_ID['LA_repetition_video_interval']: # Repetitions per video intervals video_name = GET[u'video'] video_id = BlockUsageLocator._from_string(video_name) video_id = Location.from_deprecated_string( video_id._to_deprecated_string()) chart_info_json = get_user_video_intervals(user_id, video_id) elif chart == VISUALIZATIONS_ID['LA_daily_time']: # Daily time spent on video and/or problem resources video_days, video_daily_time = get_daily_consumption( user_id, course_key, 'video') problem_days, problem_daily_time = get_daily_consumption( user_id, course_key, 'problem') chart_info_json = join_video_problem_time(video_days, video_daily_time, problem_days, problem_daily_time) elif chart == VISUALIZATIONS_ID['LA_video_events']: # Video events dispersion within video length video_name = GET[u'video'] video_id = BlockUsageLocator._from_string(video_name) video_id = Location.from_deprecated_string( video_id._to_deprecated_string()) chart_info_json = get_video_events_info(user_id, video_id) return HttpResponse(chart_info_json, mimetype='application/json')