Beispiel #1
0
    def get(self, team_id):
        app.logger.info('Get classroom training model api called')
        current_user = get_jwt_identity().get('id')
        if get_user_team_access(current_user, team_id) is False:
            return {'message': 'bad request'}, 400
        team_details = get_team_details(team_id)
        member_stat = []
        member_list = team_details.get('member_list', [])
        for member in member_list:
            user_details = get_user_details_by_handle_name(member['user_handle'])
            if user_details is None:
                continue
            user_public_info = get_user_details_public(user_details['id'])
            skill_list = search_top_skilled_categoires_for_user(user_details['id'], 'root', 'category_id', 15, True)
            user_public_info['status'] = 'pending'
            for f in user_public_info:
                member[f] = user_public_info[f]
            store = {
                'user_handle': member['user_handle'],
                'skill_color': member['skill_color'],
                'skill_list': skill_list
            }
            member_stat.append(store)
        team_details['member_stat'] = member_stat

        category_list = []
        for cat in member_stat[0]['skill_list']:
            category_list.append(cat['category_info'])

        team_details['category_list'] = category_list

        return team_details
def sync_overall_stat_for_team(team_id, skill_value=None):
    try:
        team_details = get_team_details(team_id)
        mark_problem = {}
        solve_count = 0
        for member in team_details['member_list']:
            user_details = get_user_details_by_handle_name(
                member['user_handle'])
            if user_details is None:
                continue
            user_id = user_details['id']
            problem_list = find_problems_for_user_by_status_filtered(
                ['SOLVED'], user_id)
            for problem in problem_list:
                if problem not in mark_problem:
                    mark_problem[problem] = 1
                    solve_count += 1

        if skill_value is None:
            skill_value = generate_skill_value_for_user(team_id)
        skill_obj = Skill()
        skill_title = skill_obj.get_skill_title(skill_value)
        skill_data = {
            'skill_value': int(skill_value),
            'solve_count': int(solve_count),
            'skill_title': skill_title,
        }
        app.logger.info('Team final stat to update: ' + json.dumps(skill_data))
        update_team_details(team_id, skill_data)
    except Exception as e:
        raise e
def team_training_model_sync(team_id):
    app.logger.info(f'team_training_model_sync service called for team: {team_id}')
    app.logger.info('sync sync_category_score_for_team')
    sync_category_score_for_team(team_id)
    app.logger.info('sync sync_root_category_score_for_team')
    skill_value = sync_root_category_score_for_team(team_id)
    app.logger.info('sync sync_overall_stat_for_team')
    sync_overall_stat_for_team(team_id, skill_value)
    skill = Skill()
    user_skill_level = skill.get_skill_level_from_skill(skill_value)
    app.logger.info('sync get_skill_level_from_skill done')
    sync_problem_score_for_team(team_id, user_skill_level)
    app.logger.info('sync sync_problem_score_for_team done')

    team_details = get_team_details(team_id)
    app.logger.info(f' end team_details{team_details}')
    member_list = team_details.get('member_list', [])
    for member in member_list:
        member_details = get_user_details_by_handle_name(member['user_handle'])
        app.logger.info(f' member_details {member_details}')
        notification_data = {
            'user_id': member_details['id'],
            'sender_id': 'System',
            'notification_type': 'System Notification',
            'redirect_url': '',
            'notification_text': 'Training model for your team ' + team_details['team_name'] + ' has been synced by',
            'status': 'UNREAD',
        }
        app.logger.info(f' add_notification {notification_data}')
        add_notification(notification_data)
    app.logger.info(f'team_training_model_sync service completed')
Beispiel #4
0
def team_list_sync():
    team_list = search_teams({}, 0, _es_size)
    for team in team_list:
        id = team['id']
        team_training_model_sync(id)
        details_info = get_team_details(id)
        member_id_list = []
        for member in details_info['member_list']:
            member_id_list.append(member['user_id'])

        skill_value = details_info.get('skill_value', 0)
        solve_count = details_info.get('solve_count', 0)
        previous_problem_score = details_info['total_score']
        current_problem_score = get_total_problem_score_for_user(
            member_id_list)
        updated_data = {'total_score': current_problem_score}
        decrease_factor = 0
        if current_problem_score < previous_problem_score + details_info[
                'target_score']:
            decrease_amount = previous_problem_score + details_info[
                'target_score'] - current_problem_score
            decrease_factor = math.sqrt(decrease_amount)

        skill = Skill()
        updated_data['decreased_skill_value'] = details_info[
            'decreased_skill_value'] + decrease_factor
        current_skill = skill_value - updated_data['decreased_skill_value']
        current_skill_level = skill.get_skill_level_from_skill(current_skill)
        updated_data['target_score'] = skill.generate_next_week_prediction(
            current_skill_level)
        add_user_ratings(id, current_skill, solve_count)
        update_team_details(id, updated_data)
    app.logger.info(f'team_list_sync completed')
def sync_root_category_score_for_team(team_id):
    try:
        team_details = get_team_details(team_id)
        solved_problems = []
        for member in team_details['member_list']:
            user_details = get_user_details_by_handle_name(
                member['user_handle'])
            if user_details is None:
                continue
            user_id = user_details['id']
            problem_list = find_problems_for_user_by_status_filtered(
                ['SOLVED'], user_id)
            for problem in problem_list:
                if problem not in solved_problems:
                    solved_problems.append(problem)

        root_solved_count = root_category_solved_count_by_solved_problem_list(
            solved_problems)
        category_list = search_categories({'category_root': 'root'}, 0, 100)
        skill_value = 0
        for category in category_list:
            data = generate_sync_data_for_root_category(
                team_id, category, root_solved_count)
            add_user_category_data(team_id, category['category_id'], data)
            skill_value += data['skill_value_by_percentage']

        return skill_value
    except Exception as e:
        raise e
Beispiel #6
0
def create_problem_set(data, contest_id):
    try:
        contest_type = data['contest_type']
        user_list = []
        if contest_type != 'individual':
            team_details = get_team_details(data['contest_ref_id'])
            for member in team_details['member_list']:
                user_list.append(member['id'])
        else:
            user_list.append(data['contest_ref_id'])
        solved_problem_list = find_problems_by_status_filtered_for_user_list(
            ['SOLVED'], user_list)
        print('solved_problem_list done')
        print('solved_problem_list length: ', len(solved_problem_list))
        param_list = data.get('param_list', [])
        category_configs_by_level = find_contest_configs(data['contest_level'])
        print('category_configs_by_level done: ', category_configs_by_level)
        contest_mdoel = ContestModel()
        problem_set = contest_mdoel.create_problem_set_for_contest(
            param_list, category_configs_by_level, data['problem_count'],
            solved_problem_list)
        pos = 1
        for problem in problem_set:
            add_problem_for_contest(problem, contest_id, pos)
            pos += 1
        return problem_set
    except Exception as e:
        raise e
 def get(self, team_id):
     app.logger.info('Get team_details method called')
     print('team_id: ', team_id)
     try:
         team_info = get_team_details(team_id)
         return team_info, 200
     
     except Exception as e:
         return {'message': str(e)}, 500
Beispiel #8
0
    def get(self, team_id):
        try:
            app.logger.info('Get team_details method called')
            current_user = get_jwt_identity().get('id')
            if get_user_team_access(current_user, team_id) is False:
                return {'message': 'bad request'}, 400
            print('team_id: ', team_id)
            team_info = get_team_details(team_id)
            return team_info, 200

        except Exception as e:
            return {'message': str(e)}, 500
def sync_category_score_for_team(team_id):
    try:
        team_details = get_team_details(team_id)
        user_list = []
        for member in team_details['member_list']:
            user_details = get_user_details_by_handle_name(
                member['user_handle'])
            if user_details is None:
                continue
            user_list.append(user_details['id'])

        category_list = category_wise_problem_solve_for_users(user_list)
        for category in category_list:
            if category['category_root'] == 'root':
                continue
            data = generate_sync_data_for_category(team_id, category)
            add_user_category_data(team_id, category['category_id'], data)
    except Exception as e:
        raise e
Beispiel #10
0
 def post(self, team_id):
     app.logger.info('Get individual training model api called')
     param = request.get_json()
     team_details = get_team_details(team_id)
     if 'training_problems' in param and param['training_problems']:
         team_details['problem_stat'] = search_top_skilled_problems_for_user(team_id, 'relevant_score', 10, True)
     if 'training_categories' in param and param['training_categories']:
         team_details['category_stat'] = search_top_skilled_categoires_for_user(team_id, 'ALL', 'relevant_score', 10, True)
     if 'category_skill' in param and param['category_skill']:
         team_details['category_skill_list'] = search_top_skilled_categoires_for_user(team_id, 'ALL', 'skill_value', 200, True)
     if 'root_category_skill' in param and param['root_category_skill']:
         team_details['root_category_skill_list'] = search_top_skilled_categoires_for_user(team_id, 'root', 'category_id', 20, True)
     if 'skill_comparison_info' in param and param['skill_comparison_info']:
         team_details['skill_info'] = []
         member_list = team_details.get('member_list', [])
         for member in member_list:
             user_details = get_user_details_by_handle_name(member['user_handle'])
             if user_details is None:
                 continue
             skill_list = search_top_skilled_categoires_for_user(user_details['id'], 'root', 'category_id', 15, True)
             team_details['skill_info'].append({'skill_list': skill_list})
     return team_details
def sync_problem_score_for_team(team_id, user_skill_level):
    try:
        team_details = get_team_details(team_id)
        marked_list = {}
        for member in team_details['member_list']:
            user_details = get_user_details_by_handle_name(
                member['user_handle'])
            if user_details is None:
                continue
            user_id = user_details['id']
            problem_list = available_problems_for_user(user_id)
            for problem in problem_list:
                problem_id = problem['id']
                if problem_id in marked_list:
                    continue
                marked_list[problem_id] = 1
                data = generate_sync_data_for_problem(team_id,
                                                      user_skill_level,
                                                      problem)
                add_user_problem_status(team_id, problem['id'], data)
    except Exception as e:
        raise e
Beispiel #12
0
def contest_standings(contest_id, user_id=None):
    try:
        contest_details = get_contest_details(contest_id)

        user_list = []
        if user_id:
            user_list = get_following_list(user_id)

        if contest_details['contest_type'] == 'individual':
            user_list.append(contest_details['contest_ref_id'])
        else:
            team_details = get_team_details(contest_details['contest_ref_id'])
            team_members = team_details['member_list']

            for member in team_members:
                if member['user_id'] not in user_list:
                    user_list.append(member['user_id'])

        standings = generate_contest_standings(contest_id, user_list)
        return standings
    except Exception as e:
        raise e