示例#1
0
def update_users_stats(cur: MySQLdb.cursors.BaseCursor,
                       dbconn: MySQLdb.connections.Connection,
                       date: datetime.date) -> None:
    '''Updates all the information and ranks related to users'''
    logging.info('Updating users stats...')
    try:
        try:
            scores = update_user_rank(cur)
            update_user_rank_cutoffs(cur, scores)
            dbconn.commit()
        except:  # noqa: bare-except
            logging.exception('Failed to update user ranking')
            raise

        try:
            update_coder_of_the_month_candidates(cur, date, 'all')
            dbconn.commit()
        except:  # noqa: bare-except
            logging.exception(
                'Failed to update candidates to coder of the month')
            raise

        try:
            update_coder_of_the_month_candidates(cur, date, 'female')
            dbconn.commit()
        except:  # noqa: bare-except
            logging.exception(
                'Failed to update candidates to coder of the month female')
            raise
        logging.info('Users stats updated')
    except:  # noqa: bare-except
        logging.exception('Failed to update all users stats')
示例#2
0
def update_schools_stats(cur: MySQLdb.cursors.BaseCursor,
                         dbconn: MySQLdb.connections.Connection,
                         date: datetime.date) -> None:
    '''Updates all the information and ranks related to schools'''
    logging.info('Updating schools stats...')
    try:
        try:
            update_schools_solved_problems(cur)
            dbconn.commit()
        except:  # noqa: bare-except
            logging.exception('Failed to update schools solved problems')
            raise

        try:
            update_school_rank(cur)
            dbconn.commit()
        except:  # noqa: bare-except
            logging.exception('Failed to update school ranking')
            raise

        try:
            update_school_of_the_month_candidates(cur, date)
            dbconn.commit()
        except:  # noqa: bare-except
            logging.exception(
                'Failed to update candidates to school of the month')
            raise
        logging.info('Schools stats updated')
    except:  # noqa: bare-except
        logging.exception('Failed to update all schools stats')
示例#3
0
def update_users_stats(
        cur: MySQLdb.cursors.BaseCursor,
        dbconn: MySQLdb.connections.Connection,
        date: datetime.date,
        update_coder_of_the_month: bool) -> None:
    '''Updates all the information and ranks related to users'''
    logging.info('Updating users stats...')
    try:
        try:
            scores = update_user_rank(cur)
            update_user_rank_cutoffs(cur, scores)
        except:  # noqa: bare-except
            logging.exception('Failed to update user ranking')
            raise

        try:
            update_author_rank(cur)
        except:  # noqa: bare-except
            logging.exception('Failed to update authors ranking')
            raise
        # We update both the general rank and the author's rank in the same
        # transaction since both are stored in the same DB table.
        dbconn.commit()

        if update_coder_of_the_month:
            try:
                update_coder_of_the_month_candidates(cur, date, 'all')
                dbconn.commit()
            except:  # noqa: bare-except
                logging.exception(
                    'Failed to update candidates to coder of the month')
                raise

            try:
                update_coder_of_the_month_candidates(cur, date, 'female')
                dbconn.commit()
            except:  # noqa: bare-except
                logging.exception(
                    'Failed to update candidates to coder of the month female')
                raise
        else:
            logging.info('Skipping updating Coder of the Month')

        logging.info('Users stats updated')
    except:  # noqa: bare-except
        logging.exception('Failed to update all users stats')