Пример #1
0
    def get_evaluated_quizitems_count(self,
                                      correct_ans_flag=False,
                                      incorrect_ans_flag=False):

        if not hasattr(self, 'list_of_qi_ids') and not hasattr(
                self, 'total_qi_cur'):
            self.total_qi_cur = self.get_attempted_quizitems_count(True)
            self.list_of_qi_ids = []
            for each_qi in self.total_qi_cur:
                correct_ans_list = None
                if each_qi.origin:
                    prior_node_id = each_qi.origin[0].get(
                        'prior_node_id_of_thread', None)
                    if prior_node_id:
                        prior_node_obj = node_collection.one(
                            {'_id': ObjectId(prior_node_id)}, {
                                '_id': 1,
                                'attribute_set': 1
                            })
                        if prior_node_obj.attribute_set:
                            for pr_each_attr in prior_node_obj.attribute_set:
                                if pr_each_attr and 'correct_answer' in pr_each_attr:
                                    correct_ans_list = pr_each_attr[
                                        'correct_answer']
                                    break
                    if each_qi.attribute_set:
                        for each_attr in each_qi.attribute_set:
                            if each_attr and 'quizitempost_user_submitted_ans' in each_attr:
                                if each_attr[
                                        'quizitempost_user_submitted_ans']:
                                    submitted_ans = each_attr[
                                        'quizitempost_user_submitted_ans']
                                    if all(
                                            type(edict) == dict
                                            for edict in submitted_ans):
                                        submitted_ans = get_dict_from_list_of_dicts(
                                            each_attr[
                                                'quizitempost_user_submitted_ans']
                                        )
                                        submitted_ans = reduce(
                                            lambda x, y: x + y,
                                            submitted_ans.values())
                                        if correct_ans_list and submitted_ans:
                                            if sublistExists(
                                                    submitted_ans,
                                                    correct_ans_list):
                                                if each_qi._id not in self.list_of_qi_ids:
                                                    self.list_of_qi_ids.append(
                                                        each_qi._id)
                                break

        if correct_ans_flag:
            return len(self.list_of_qi_ids)

        elif incorrect_ans_flag:
            return (self.total_qi_cur.count() - len(self.list_of_qi_ids))

        else:
            return 0
Пример #2
0
    def get_evaluated_quizitems_count(self, correct_ans_flag=False, incorrect_ans_flag=False):
        t0 = time.time()

        if not hasattr(self, "list_of_qi_ids") and not hasattr(self, "total_qi_cur"):
            self.total_qi_cur = self.get_attempted_quizitems_count(True)
            self.list_of_qi_ids = []
            for each_qi in self.total_qi_cur:
                if each_qi.origin:
                    prior_node_id = each_qi.origin[0].get("prior_node_id_of_thread", None)
                    if prior_node_id:
                        prior_node_obj = node_collection.one(
                            {"_id": ObjectId(prior_node_id)}, {"_id": 1, "attribute_set": 1}
                        )
                        if prior_node_obj.attribute_set:
                            for pr_each_attr in prior_node_obj.attribute_set:
                                if pr_each_attr and "correct_answer" in pr_each_attr:
                                    correct_ans_list = pr_each_attr["correct_answer"]
                    if each_qi.attribute_set:
                        for each_attr in each_qi.attribute_set:
                            if each_attr and "quizitempost_user_submitted_ans" in each_attr:
                                if each_attr["quizitempost_user_submitted_ans"]:
                                    submitted_ans = each_attr["quizitempost_user_submitted_ans"]
                                    if all(type(edict) == dict for edict in submitted_ans):
                                        submitted_ans = get_dict_from_list_of_dicts(
                                            each_attr["quizitempost_user_submitted_ans"]
                                        )
                                        submitted_ans = reduce(lambda x, y: x + y, submitted_ans.values())

                                        if correct_ans_list and submitted_ans:
                                            if sublistExists(submitted_ans, correct_ans_list):
                                                if each_qi._id not in self.list_of_qi_ids:
                                                    self.list_of_qi_ids.append(each_qi._id)
        if correct_ans_flag:
            t1 = time.time()
            time_diff = t1 - t0
            # print "\n get_evaluated_quizitems_count == ", time_diff

            return len(self.list_of_qi_ids)
        elif incorrect_ans_flag:
            t1 = time.time()
            time_diff = t1 - t0
            # print "\n get_evaluated_quizitems_count == ", time_diff

            return self.total_qi_cur.count() - len(self.list_of_qi_ids)
        else:
            return 0
Пример #3
0
	def get_evaluated_quizitems_count(self,correct_ans_flag=False, incorrect_ans_flag=False):
		

		if not hasattr(self,'list_of_qi_ids') and not hasattr(self,'total_qi_cur'):
			self.total_qi_cur = self.get_attempted_quizitems_count(True)
			self.list_of_qi_ids = []
			for each_qi in self.total_qi_cur:
				if each_qi.origin:
					prior_node_id = each_qi.origin[0].get('prior_node_id_of_thread',None)
					if prior_node_id:
						prior_node_obj = node_collection.one({'_id': ObjectId(prior_node_id)},{'_id':1, 'attribute_set':1})
						if prior_node_obj.attribute_set:
							for pr_each_attr in prior_node_obj.attribute_set:
								if pr_each_attr and 'correct_answer' in pr_each_attr:
									correct_ans_list = pr_each_attr['correct_answer']
									break
					if each_qi.attribute_set:
						for each_attr in each_qi.attribute_set:
							if each_attr and 'quizitempost_user_submitted_ans' in each_attr:
								if each_attr['quizitempost_user_submitted_ans']:
									submitted_ans = each_attr['quizitempost_user_submitted_ans']
									if all(type(edict)==dict for edict in submitted_ans):
										submitted_ans = get_dict_from_list_of_dicts(each_attr['quizitempost_user_submitted_ans'])
										submitted_ans = reduce(lambda x, y: x+y, submitted_ans.values())
										if correct_ans_list and submitted_ans:
											if sublistExists(submitted_ans, correct_ans_list):
												if each_qi._id not in self.list_of_qi_ids:
													self.list_of_qi_ids.append(each_qi._id)
								break
		if correct_ans_flag:
			
			

			return len(self.list_of_qi_ids)
		elif incorrect_ans_flag:
			
			

			return (self.total_qi_cur.count()-len(self.list_of_qi_ids))
		else:
			return 0
Пример #4
0
def get_filtered_topic_resources(request, group_id, node_id):

    selfilters = request.POST.get('filters', None)
    query_dict = get_filter_querydict(
        json.loads(selfilters)) if selfilters else {}
    # print query_dict

    node_rel_cur = node_collection.one(
        {
            '_id': ObjectId(node_id),
            'relation_set.taught_by': {
                '$exists': 'true'
            }
        }, {
            'relation_set.taught_by': 1,
            '_id': 0
        })

    node_rel_list = node_rel_cur.relation_set[0].get('taught_by', [])

    filtered_taught_by_res = node_collection.find({
        '_id': {
            '$in': node_rel_list
        },
        '$and': query_dict
    })

    primary_lang_resources = {}
    other_lang_resources = {}
    all_educationaluse = []
    language_selected = list(get_language_tuple(request.LANGUAGE_CODE))
    # print language_selected,"request.LANGUAGE_CODE: ", request.LANGUAGE_CODE

    # print filtered_taught_by_res.count()
    for each_res in filtered_taught_by_res:
        # if each_res.language :
        #     pass
        att_set_dict = get_dict_from_list_of_dicts(each_res.attribute_set)
        educationaluse = att_set_dict['educationaluse']

        all_educationaluse.append(educationaluse)

        if language_selected == each_res.language:
            temp = primary_lang_resources.get(educationaluse, [])
            temp.append(each_res)
            primary_lang_resources[educationaluse] = temp
            temp = ""
        else:
            temp = other_lang_resources.get(educationaluse, [])
            temp.append(each_res)
            other_lang_resources[educationaluse] = temp
            temp = ""

    # print "primary_lang_resources : ", primary_lang_resources
    # print "other_lang_resources: ", other_lang_resources

    all_educationaluse = list(set(all_educationaluse))

    # data = json.dumps({'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse })

    # return HttpResponse(data)

    # return HttpResponse({'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse })

    return render_to_response(
        'ndf/topic_resources_listing.html',
        {
            'primary_lang_resources': primary_lang_resources,
            'other_lang_resources': other_lang_resources,
            'all_educationaluse': all_educationaluse,
            # 'node': obj,'app_id': app_id,"theme_id": theme_id, "prior_obj": prior_obj,
            'group_id': group_id,
            'groupid': group_id,
            'filtered_topics': 'filtered_topics'
            # 'shelves': shelves,'topic': topic, 'nav_list':nav_li,
            # 'shelf_list': shelf_list,'breadcrumbs_list': breadcrumbs_list
        },
        context_instance=RequestContext(request))
Пример #5
0
def get_filtered_topic_resources(request, group_id, node_id):

    selfilters = request.POST.get('filters', None)
    query_dict = get_filter_querydict(json.loads(selfilters)) if selfilters else {}
    # print query_dict

    node_rel_cur = node_collection.one(
                                    {
                                        '_id': ObjectId( node_id ),
                                        'relation_set.taught_by': {'$exists': 'true'}
                                    },
                                    {
                                        'relation_set.taught_by': 1, '_id': 0
                                    }
                                )
    
    node_rel_list = node_rel_cur.relation_set[0].get('taught_by', [])

    filtered_taught_by_res = node_collection.find({
                        '_id': {'$in': node_rel_list},
                        '$and': query_dict
                    })

    primary_lang_resources = {}
    other_lang_resources = {}
    all_educationaluse = []
    language_selected = list(get_language_tuple(request.LANGUAGE_CODE))
    # print language_selected,"request.LANGUAGE_CODE: ", request.LANGUAGE_CODE

    # print filtered_taught_by_res.count()
    for each_res in filtered_taught_by_res:
        # if each_res.language :
        #     pass
        att_set_dict = get_dict_from_list_of_dicts(each_res.attribute_set)
        educationaluse = att_set_dict['educationaluse']

        all_educationaluse.append(educationaluse)

        if language_selected == each_res.language:
            temp = primary_lang_resources.get(educationaluse, [])
            temp.append(each_res)
            primary_lang_resources[educationaluse] = temp
            temp = ""
        else:
            temp = other_lang_resources.get(educationaluse, [])
            temp.append(each_res)
            other_lang_resources[educationaluse] = temp
            temp = ""

    # print "primary_lang_resources : ", primary_lang_resources
    # print "other_lang_resources: ", other_lang_resources

    all_educationaluse = list(set(all_educationaluse))

    # data = json.dumps({'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse })

    # return HttpResponse(data)

    # return HttpResponse({'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse })


    return render_to_response('ndf/topic_resources_listing.html', 
                                    { 
                                    'primary_lang_resources': primary_lang_resources, 'other_lang_resources': other_lang_resources, 'all_educationaluse': all_educationaluse,
                                    # 'node': obj,'app_id': app_id,"theme_id": theme_id, "prior_obj": prior_obj,
                                      'group_id': group_id,'groupid':group_id,
                                      'filtered_topics': 'filtered_topics'
                                      # 'shelves': shelves,'topic': topic, 'nav_list':nav_li,
                                      # 'shelf_list': shelf_list,'breadcrumbs_list': breadcrumbs_list
                                    },
                                    context_instance = RequestContext(request)
                            )