Then run this script on the above collection Usage: python activities_with_lower_completion.py ''' from collections import defaultdict from common.base_edx import EdXConnection from common.generate_csv_report import CSV # Connect to MongoDB and extra the tracking collection connection = EdXConnection('user_attempts_per_problem_id') collection = connection.get_access_to_collection() cursor = collection['user_attempts_per_problem_id'].find() result = defaultdict(lambda: defaultdict(int)) for index,document in enumerate(cursor): # If there is a correct attempts, accept as answered correctly, else accept #as incorrect only once per student per problem id if 'correct' in document['attempts']: result[document['_id']['problem_id']]['correct'] += 1 else: result[document['_id']['problem_id']]['incorrect'] += 1 csv_result = [[item, result[item]['correct'], result[item]['incorrect']] for item in result] output = CSV(csv_result, ['Problem Id', 'Correct Count', 'Incorrect Count'], output_file='activities_with_lower_completion.csv') output.generate_csv()
print(start_event_time) #when a start event is found set the end event to blank end_event_time = {'blank'} continue #assign all other event types to end #Note: currently seek_video events count as an end_event else: end_event_time = datetime.strptime(item['time'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") print 'end' print(end_event_time) continue except: count_errors = count_errors + 1 errors.append([index, item]) #print watch_durations print print len(watch_durations) print errors output = CSV(watch_durations, [ 'Username', 'video_id', 'youtube id (video_code)', 'time_point (seconds)', 'start_event_time', 'end_event_time', 'duration (minutes)' ], output_file=db_name + 'video_watch_duration.csv', row_limit=200000) output.generate_csv() output_errors = CSV(errors, ['Errors'], output_file=db_name + 'video_watch_duration_errors.csv', row_limit=200000) output_errors.generate_csv()
Usage: python activities_with_lower_completion.py ''' from collections import defaultdict from common.base_edx import EdXConnection from common.generate_csv_report import CSV # Connect to MongoDB and extra the tracking collection connection = EdXConnection('user_attempts_per_problem_id') collection = connection.get_access_to_collection() cursor = collection['user_attempts_per_problem_id'].find() result = defaultdict(lambda: defaultdict(int)) for index, document in enumerate(cursor): # If there is a correct attempts, accept as answered correctly, else accept #as incorrect only once per student per problem id if 'correct' in document['attempts']: result[document['_id']['problem_id']]['correct'] += 1 else: result[document['_id']['problem_id']]['incorrect'] += 1 csv_result = [[item, result[item]['correct'], result[item]['incorrect']] for item in result] output = CSV(csv_result, ['Problem Id', 'Correct Count', 'Incorrect Count'], output_file='activities_with_lower_completion.csv') output.generate_csv()
if item['event_type'] == 'play_video': start_event_time = datetime.strptime(item['time'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") #get values related to video identification video = item['event'] video_code = video['code'] video_id = video['id'] time_point = video['currentTime'] print 'start' print (start_event_time) #when a start event is found set the end event to blank end_event_time = {'blank'} continue #assign all other event types to end #Note: currently seek_video events count as an end_event else: end_event_time = datetime.strptime(item['time'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") print 'end' print (end_event_time) continue except: count_errors = count_errors+1 errors.append([index,item]) #print watch_durations print print len(watch_durations) print errors output = CSV(watch_durations, ['Username','video_id','youtube id (video_code)','time_point (seconds)','start_event_time','end_event_time', 'duration (minutes)'], output_file=db_name+'video_watch_duration.csv', row_limit=200000) output.generate_csv() output_errors = CSV(errors, ['Errors'], output_file=db_name+'video_watch_duration_errors.csv', row_limit=200000) output_errors.generate_csv()