Beispiel #1
0
def previous_scores(request):
    previous_test_scores_list = []
    try:
        user_entity_object = user_entity.find_one({'login_id': request.GET.get('student_id')})
        previous_scores_object = test_scores.find({'student_id': user_entity_object['_id']},
                                                  {'question_level_marks_list.topic_id': 0}).sort([
            ('date_of_test', pymongo.DESCENDING)])
        for previous_test_scores in previous_scores_object:
            previous_test_scores['student_id'] = str(previous_test_scores['student_id'])
            previous_test_scores['_id'] = str(previous_test_scores['_id'])
            previous_test_scores['date_of_test'] = str(previous_test_scores['date_of_test'].day) + '/' + \
                                                   str(previous_test_scores['date_of_test'].month) + '/' + \
                                                   str(previous_test_scores['date_of_test'].year)
            for answers in previous_test_scores['question_level_marks_list']:
                question_bank_object = question_bank.find_one({'_id': ObjectId(answers['question_id'])})
                answers['solution'] = question_bank_object['solution']
                answers['keywords'] = "Keywords to include "+str(question_bank_object['keywords'])
                answers['question'] = question_bank_object['question_description']
                link_list = link_scraping(answers['question'])
                answers['list_of_links'] = link_list
            previous_test_scores_list.append(previous_test_scores)

        return {'msg': 'previous test scores', 'status': True, 'list': previous_test_scores_list}
    except:
        return {'msg': 'unable to get test scores', 'status': False}
Beispiel #2
0
def fetch_mock_test(request):
    previous_answers_list = []
    try:
        user_entity_object = user_entity.find_one(
            {'login_id': request.GET.get('student_id')})
        previous_answers_object = test_scores.find(
            {
                'student_id': user_entity_object['_id']
            }, {
                'question_level_marks_list.topic_id': 0,
                'date_of_test': 0
            }).sort([('date_of_test', -1)]).limit(1)
        for previous_answers in previous_answers_object:
            previous_answers['student_id'] = str(
                previous_answers['student_id'])
            previous_answers['_id'] = str(previous_answers['_id'])
            for questions in previous_answers['question_level_marks_list']:
                question_object = question_bank.find_one(
                    {'_id': ObjectId(questions['question_id'])})
                questions['question'] = question_object['question_description']
            previous_answers_list.append(previous_answers)

        return {
            'msg': 'previous test answers',
            'status': True,
            'list': previous_answers_list
        }
    except:
        return {'msg': 'unable to get test answers', 'status': False}
Beispiel #3
0
def update_student_scores(request):
    try:
        entity_object = user_entity.find_one(
            {'login_id': request.data['student_id']})
        test_score_object = test_scores.find({
            'student_id': entity_object['_id']
        }).sort([('date_of_test', -1)]).limit(1)
        test_data_dict = dict()
        for test_object in test_score_object:
            test_data_dict = test_object
        for questions in test_data_dict['question_level_marks_list']:
            for scores in request.data['question_level_marks_list']:
                if questions['question_id'] == scores['question_id']:
                    questions['score'] = scores['score']

        test_scores.update_one(
            {
                'student_id': entity_object['_id'],
                'date_of_test': test_data_dict['date_of_test']
            }, {
                '$set': {
                    'total_marks_obtained.marks_obtained':
                    request.data['total_marks_obtained']['marks_obtained'],
                    'question_level_marks_list':
                    test_data_dict['question_level_marks_list']
                }
            })
        return {'msg': 'test scores updated successfully', 'status': True}
    except:
        return {'msg': 'could not update test scores', 'status': False}
Beispiel #4
0
def student_login(request):
    entity_object = user_entity.find_one({'login_id': request.GET.get('login_id')})
    if entity_object:
        bool_value = check_password(request.GET.get('password'), entity_object['password'])
        if bool_value is True:
            return {'msg': 'login successful', 'status': True}
        else:
            return {'msg': 'login id or password is wrong', 'status': False}
    else:
        return {'msg': 'entity does not exist', 'status': False}
Beispiel #5
0
def upload_student_answers(request):
    try:
        entity_object = user_entity.find_one({'login_id': request.data['student_id']})
        for question_object in request.data['question_level_marks_list']:
            question_bank_object = question_bank.find_one({'_id': ObjectId(question_object['question_id'])})
            question_object['total'] = int(question_bank_object['marks'])
            question_object['topic_id'] = question_bank_object['topic_id']
        test_scores.insert({'student_id': entity_object['_id'],
                            'total_marks_obtained': request.data['total_marks_obtained'],
                            'question_level_marks_list': request.data['question_level_marks_list'],
                            'date_of_test': datetime.datetime.now()})
        return {'msg': 'test details uploaded successfully', 'status': True}
    except:
        return {'msg': 'could not upload test details', 'status': False}
Beispiel #6
0
def generate_mock_test(request):
    ruleset = {'easy': easy,
               'medium': medium,
               'hard': hard}
    try:
        topic_ids_counter = []
        level_list = ['Easy', 'Medium', 'Hard']
        prev_mocktests = []
        entity_object = user_entity.find_one({'login_id': request.GET.get('student_id')})
        test_score_object = test_scores.find({'student_id': entity_object['_id']}).sort([("date_of_test", -1)]).limit(1)
        for test_score in test_score_object:
            for answers in test_score['question_level_marks_list']:
                topics_object = topics.find_one({'_id': answers['topic_id']})
                questions_bank_object = question_bank.find_one({'_id': ObjectId(answers['question_id'])})
                prev_mocktests.append(
                    (answers['question_id'], answers['score'], answers['total'], questions_bank_object['difficulty_level'],
                     topics_object['counter']))
                topic_ids_counter.append(topics_object['counter'])

        question_bank_list = []
        all_questions_object = question_bank.find()
        for questions in all_questions_object:
            topic_object_id = topics.find_one({'_id': questions['topic_id']})
            question_bank_list.append([str(questions['_id']), topic_object_id['counter'], questions['difficulty_level'],
                                       questions['question_description']])

        question_bankDF = pd.DataFrame(question_bank_list,
                                       columns=['question_id', 'topic', 'difficulty_level', 'question_desc'])

        prev_mocktestsDF = pd.DataFrame(prev_mocktests,
                                        columns=['question_id', 'marks_obtained', 'total_marks', 'difficulty_level',
                                                 'topic'])
        prev_mocktestsDF = prev_mocktestsDF.groupby(['topic', 'difficulty_level']).agg(
            {'marks_obtained': 'sum', 'total_marks': 'sum', 'question_id': lambda x: x.values.tolist()})
        prev_mocktestsDF['marks_percent'] = prev_mocktestsDF['marks_obtained'] / prev_mocktestsDF['total_marks']
        prev_mocktestsDF.reset_index(inplace=True)

        prev_mocktestsDF_ga = pd.DataFrame(prev_mocktests,
                                           columns=['question_id', 'marks_obtained', 'total_marks', 'difficulty_level',
                                                    'topic'])
        prev_mocktestsDF_ga = prev_mocktestsDF_ga.groupby(['topic']).agg(
            {'marks_obtained': 'sum', 'total_marks': 'sum', 'question_id': lambda x: x.values.tolist()})
        prev_mocktestsDF_ga['marks_percent'] = prev_mocktestsDF_ga['marks_obtained'] / prev_mocktestsDF_ga['total_marks']

        ga_input = [1 - x for x in prev_mocktestsDF_ga['marks_percent'].to_list()]
        ga_output = question_set_ga(ga_input, 1, 20)
        ga_output = ga_output.astype(int).tolist()

        temp = prev_mocktestsDF.head(1).copy()
        temp['marks_obtained'] = 0
        temp['total_marks'] = 0
        temp['question_id'] = [[]]
        temp['marks_percent'] = 0

        for i in prev_mocktestsDF['topic'].unique():
            for j in set(level_list).difference(prev_mocktestsDF[prev_mocktestsDF['topic'] == i].difficulty_level.unique()):
                temp['topic'] = i
                temp['difficulty_level'] = j
                prev_mocktestsDF = prev_mocktestsDF.append(temp, ignore_index=True)

        question_set = []
        for i in range(len(prev_mocktestsDF_ga.index)):
            dl = pd.read_csv(os.getcwd()+r'/difficulty_level.csv')
            topic = prev_mocktestsDF_ga.index[i]
            num_ques = ga_output[i]
            dl_list = prev_mocktestsDF[prev_mocktestsDF['topic'] == topic].sort_values(
                by=['difficulty_level']).marks_percent.to_list()
            dl_list01 = np.where(np.array((dl_list)) > 0.5, 1, 0).tolist()
            topic_difficulty_level = dl[
                (dl['hard'] == np.int64(dl_list01[1])) & (dl['medium'] == np.int64(dl_list01[2])) & (
                            dl['easy'] == np.int64(dl_list01[0]))]['difficulty_level'].item()
            questions_topic = ruleset[topic_difficulty_level](topic, num_ques, prev_mocktestsDF, question_bankDF)
            question_set.extend(questions_topic)

        question_bankDF[question_bankDF['question_id'].isin(question_set)].groupby(['topic']).agg({'question_id': 'count'})
        print(question_set)
        question_list = []
        for question_id in question_set:
            questions_object = question_bank.find_one({'_id': ObjectId(question_id)}, {'solution': 0, 'keywords': 0})
            questions_object['_id'] = str(questions_object['_id'])
            topic_object = topics.find_one({'_id': questions_object['topic_id']})
            questions_object['topic_name'] = topic_object['topic_name']
            questions_object['topic_id'] = str(questions_object['topic_id'])
            question_list.append(questions_object)
        shuffle(question_list)
        return {'msg': 'list of questions', 'question_list': question_list, 'status': True}
    except :
        return {'msg': 'unable to generate mock test', 'status': False}