selected_data = data_set.map(lambda x: x['student']).distinct() for student in selected_data: if participation_table.has_key(student): participation_table[student].append(index) else: participation_table[student] = [index] # print participation_table ################################################ ### Figure for number of labs joined per lab ### ################################################ plot_data = [[0 for i in xrange(LAB_NUMBER)] for j in xrange(LAB_NUMBER)] for student in participation_table: status = participation_table[student] for lab in status: plot_data[LAB_NUMBER - len(status)][lab] += 1 fig, ax = toolkit.prepare_plot(gridWidth=0) tem_bottom = [0] * LAB_NUMBER color = plt.cm.Blues_r(np.linspace(.2, .8, LAB_NUMBER)) p = [] ind = np.arange(LAB_NUMBER) width = .5 for i in range(LAB_NUMBER): bar = plt.bar(ind, plot_data[i], width, color=color[i], bottom=tem_bottom, edgecolor=color[i]) p.append(bar) for j in range(LAB_NUMBER): tem_bottom[j] += plot_data[i][j]
selected_data = data_set.map(lambda x: x['student']).distinct() for student in selected_data: if participation_table.has_key(student): participation_table[student].append(index) else: participation_table[student] = [index] # print participation_table ################################################ ### Figure for number of labs joined per lab ### ################################################ plot_data = [[0 for i in xrange(LAB_NUMBER)] for j in xrange(LAB_NUMBER)] for student in participation_table: status = participation_table[student] for lab in status: plot_data[LAB_NUMBER-len(status)][lab] += 1 fig, ax = toolkit.prepare_plot(gridWidth=0) tem_bottom = [0] * LAB_NUMBER color = plt.cm.Blues_r(np.linspace(.2, .8, LAB_NUMBER)) p = [] ind = np.arange(LAB_NUMBER) width=.5 for i in range(LAB_NUMBER): bar = plt.bar(ind, plot_data[i], width, color=color[i], bottom=tem_bottom, edgecolor=color[i]) p.append(bar) for j in range(LAB_NUMBER): tem_bottom[j] += plot_data[i][j] plt.ylabel('Number of students') plt.title('Number of other labs a student has participated in') plt.xticks(ind+width/2., LABS) # plt.yticks(np.arange(0,81,10)) plt.legend(p, ('{} other lab(s)'.format(LAB_NUMBER-x-1) for x in range(LAB_NUMBER)))
###################################### ### Number of sessions per student ### ###################################### session_counter = [] tem_data = data_set.sort_by(lambda x: x['a_time']).group_by(lambda x: x['student']) for item in tem_data: # WARNING: This may throw an exception! session_cnt = toolkit.get_session_info(item[1]) if session_cnt == 0: continue while session_cnt > len(session_counter): session_counter.append(0) session_counter[session_cnt-1] += 1 # Print it out fig, ax = toolkit.prepare_plot(gridWidth=0) x = np.arange(len(session_counter)) width = 0.5 rects = plt.bar(x, session_counter, width, color='gray', alpha=0.7, edgecolor="gray") plt.ylabel('Number of students') plt.xticks(x + width/2., ["{:,} session(s)".format(item+1) for item in range(len(session_counter))]) toolkit.autolabel(rects, ax) plt.savefig('session_cnt.png') ######################################## ### Number of submissions per prompt ### ######################################## submission_counter = [0] * NUM_QUESTION for prompt in range(NUM_QUESTION): submission_counter[prompt] = data_set.filter_by(lambda x: x['specifier']==prompt).count()