def assign_groups_class(courseCode, max_size=5): course_qs = UnitOffering.objects.filter(code='%s' % courseCode) course_users = User.objects.filter(usersinunitoffering__in=course_qs) #print(course_users) group_n = 1 max_grp_size = max_size group = [] for index in range( 1, (len(course_users) + 1)): #range from 1 - n; instead of 0-n #print index #print course_users[index-1], course_users[index-1].id try: #e = User.objects.filter(pk=course_users[index-1])[0] #print e group.append((course_users[index - 1], group_n)) except Exception as e: print(e) if (index % max_grp_size is 0): group_n = group_n + 1 #print(group) for (user, group_id) in group: g = GroupMap(userId=user, course_code=courseCode, groupId=group_id) g.save() print("Mapped UserId: " + str(user.id) + " in course: " + str(courseCode) + " to group " + str(group_id))
def assign_groups_class(courseCode, max_size=5): course_qs = UnitOffering.objects.filter(code = '%s' % courseCode) course_users = User.objects.filter(usersinunitoffering__in=course_qs) #print(course_users) group_n = 1 max_grp_size = max_size group = [] for index in range(1,(len(course_users)+1)): #range from 1 - n; instead of 0-n #print index #print course_users[index-1], course_users[index-1].id try: #e = User.objects.filter(pk=course_users[index-1])[0] #print e group.append((course_users[index-1], group_n)) except Exception as e: print(e) if (index%max_grp_size is 0): group_n = group_n+1 #print(group) for (user, group_id) in group: g = GroupMap(userId=user, course_code=courseCode, groupId=group_id) g.save() print("Mapped UserId: "+str(user.id)+" in course: "+str(courseCode)+" to group "+str(group_id));
def myclassifications(request): context = RequestContext(request) course_code = None platform = None user = request.user username = user.username uid = user.id course_code = request.GET.get('course_code') platform = request.GET.get('platform') #get enable_group_coi_classifier boolean flag from UnitOffering unit = UnitOffering.objects.filter(code=course_code).get() enable_group_coi_classifier = unit.enable_group_coi_classifier group_id_seed = None if enable_group_coi_classifier: # check if the user has a grp number assigned group_id_seed = GroupMap.objects.filter(userId=user, course_code=course_code).values_list('groupId') if len(group_id_seed)<0: # (Table GroupMap requires an associated UserProfile as a foreign key) grpmapentries = [] # max_grp_size set to 5 for development. Easily made customisable by setting this value when creating a unit # which can then be pulled from the associated UnitOffering instance in the DB. max_grp_size = 5 # Get the current highest group number (to assign user to unit group) # Default is 1 (i.e. no other groups have been created) highest_grp_num = 1 # Find the most current group ID highest_grp_dict = GroupMap.objects.filter(course_code=unit.code).aggregate(Max('groupId')) if highest_grp_dict['groupId__max'] is not None: highest_grp_num = int(highest_grp_dict['groupId__max']) # Now we figure out if there's space in this group (constrained by var max_grp_size) members_in_hgrp = GroupMap.objects.filter(groupId=highest_grp_num).count() if members_in_hgrp < max_grp_size: grpmapentries.append((course_code, highest_grp_num)) else: grpmapentries.append((course_code, highest_grp_num+1)) #Once the UserProfile has been saved, we can assign user to unit groups for (unit,grp_num) in grpmapentries: grpmap = GroupMap(userId=user, course_code=unit, groupId=grp_num) grpmap.save() group_id_seed = GroupMap.objects.filter(userId=user, course_code=course_code).values_list('groupId') inner_q = UserClassification.objects.filter(username=username).values_list('classification_id') #Need to add unique identifier to models to distinguish between classes classifier_name = "nb_%s_%s.model" % (course_code,platform) kwargs = {'classifier':classifier_name, 'xapistatement__course_code': course_code} if enable_group_coi_classifier: kwargs['xapistatement__username'] = username classifications_list = list(Classification.objects.filter(**kwargs).exclude(id__in = inner_q)) if enable_group_coi_classifier: random.seed(group_id_seed) random.shuffle(classifications_list) context_dict = {'course_code':course_code, 'platform':platform, 'title': "Community of Inquiry Classification", 'username':username, 'uid':uid, 'classifications': classifications_list } return render_to_response('dashboard/myclassifications.html', context_dict, context)
def myclassifications(request): context = RequestContext(request) course_code = None platform = None user = request.user username = user.username uid = user.id course_code = request.GET.get('course_code') platform = request.GET.get('platform') #get enable_group_coi_classifier boolean flag from UnitOffering unit = UnitOffering.objects.filter(code=course_code).get() enable_group_coi_classifier = unit.enable_group_coi_classifier group_id_seed = None if enable_group_coi_classifier: # check if the user has a grp number assigned group_id_seed = GroupMap.objects.filter( userId=user, course_code=course_code).values_list('groupId') if len(group_id_seed) < 0: # (Table GroupMap requires an associated UserProfile as a foreign key) grpmapentries = [] # max_grp_size set to 5 for development. Easily made customisable by setting this value when creating a unit # which can then be pulled from the associated UnitOffering instance in the DB. max_grp_size = 5 # Get the current highest group number (to assign user to unit group) # Default is 1 (i.e. no other groups have been created) highest_grp_num = 1 # Find the most current group ID highest_grp_dict = GroupMap.objects.filter( course_code=unit.code).aggregate(Max('groupId')) if highest_grp_dict['groupId__max'] is not None: highest_grp_num = int(highest_grp_dict['groupId__max']) # Now we figure out if there's space in this group (constrained by var max_grp_size) members_in_hgrp = GroupMap.objects.filter( groupId=highest_grp_num).count() if members_in_hgrp < max_grp_size: grpmapentries.append((course_code, highest_grp_num)) else: grpmapentries.append((course_code, highest_grp_num + 1)) #Once the UserProfile has been saved, we can assign user to unit groups for (unit, grp_num) in grpmapentries: grpmap = GroupMap(userId=user, course_code=unit, groupId=grp_num) grpmap.save() group_id_seed = GroupMap.objects.filter( userId=user, course_code=course_code).values_list('groupId') inner_q = UserClassification.objects.filter( username=username).values_list('classification_id') #Need to add unique identifier to models to distinguish between classes classifier_name = "nb_%s_%s.model" % (course_code, platform) kwargs = { 'classifier': classifier_name, 'xapistatement__course_code': course_code } if enable_group_coi_classifier: kwargs['xapistatement__username'] = username classifications_list = list( Classification.objects.filter(**kwargs).exclude(id__in=inner_q)) if enable_group_coi_classifier: random.seed(group_id_seed) random.shuffle(classifications_list) context_dict = { 'course_code': course_code, 'platform': platform, 'title': "Community of Inquiry Classification", 'username': username, 'uid': uid, 'classifications': classifications_list } return render_to_response('dashboard/myclassifications.html', context_dict, context)