Exemplo n.º 1
0
def main():
    """This is the main method for adding team pairings.

  Pairings are read from a file with one team on each line.  The format
  is team name,username 1, username 2.

  """

    db_user = raw_input('DB username: '******'oraclech_oracle')

    contest_id = raw_input('Current Contest ID? ')
    contest_id = int(contest_id)

    file_path = '/home/oraclech/contest_%d_teams' % (contest_id)
    file = open(file_path, 'r')

    #  team_pattern = re.compile('\s*\d+\.\s*([^/]+)/([^-]+?)\s+\-\s*Team\s*(.+)')
    team_pattern = re.compile('\s*([^,]+),([^,]+),(.+)')

    for line in file:  # page.split('\r\n'):
        print line
        match = team_pattern.search(line)
        team_name, user1, user2 = match.groups()
        user_id1 = odb.GetUserId(user1)
        if user_id1 is None:
            user_id1 = GetUserId(odb, user1, add_alt=1)
        user_id2 = odb.GetUserId(user2)
        if user_id2 is None:
            user_id2 = GetUserId(odb, user2, add_alt=1)

        odb.CreateTeam(contest_id, user_id1, user_id2, team_name)
Exemplo n.º 2
0
def main():
    """This is the main function for generating user standings.

  """

    start_match = 887
    #  end_match = 569

    db_user = raw_input('DB username: '******'oraclech_oracle')

    # Get the id of the most recent match, and update up to that match.
    now = datetime.datetime.now()
    yesterday = now - datetime.timedelta(hours=12)
    end_match = odb.GetMatchByDate(yesterday)['MatchId']

    print start_match, end_match
    for i in range(start_match, end_match + 1):
        match_scores = odb.GetMatchScores(i)
        for user in match_scores:
            odb.SetMatchRanking(user['UserId'], i, user['Ranking'])
            odb.SetMatchScore(user['UserId'], i, user['Score'])
        overall_scores = odb.GetContestScores(i)
        for user in overall_scores:
            odb.SetOverallRanking(user['UserId'], i, user['Ranking'])
Exemplo n.º 3
0
def main():
    """This is the main function which imports user predictions.

  It reads in the prediction file from one contest and adds each
  prediction to the database.

  """

    contest_id = 7
    comp_type = 'series'

    db_user = raw_input('DB username: '******'oraclech_oracle')

    prediction_file = open('2k6_final_predictions.csv', 'r')
    predictions = prediction_file.read()
    lines = predictions.split('\n')

    for line in lines:
        # Read each line, which contains one user's predictions, and add them to
        # the database.

        cells = line.split(',')
        user = re.search('"([^"]+)"', cells[0]).group(1)
        user_id = odb.GetUserId(user)

        # Unlike the original predictions import, here we only have to deal
        # with one match in the whole page.

        winner_re = re.compile('"([^"]+)"')
        percent_re = re.compile(r'(\d+\.?\d*)%')

        winner_match = winner_re.search(cells[1])
        percent_match = percent_re.search(cells[2])

        if winner_match is not None and percent_match is not None:
            # Get the match_id and add the prediction to the database.

            winner_name = winner_match.group(1)
            percent = percent_match.group(1)

            match_id = 380
            winner_id = add_predictions.DecipherName(odb, winner_name,
                                                     winner_name, comp_type)

            odb.SetPrediction(user_id, match_id, winner_id, percent, 0)

            print "Match %s" % (match_id)
            print "%s predicts %s with %s" % (user, winner_name, percent)
Exemplo n.º 4
0
def main():
    """This is the main prediction adding function.

  It starts by grabbing a file to open from standard in, which contains
  one message board page.  It processes each message contained in the page.

  NOTE: If there are multiple pages, they must be processed in order.
  However, after a page is complete (50 messages), it only needs to
  be processed once.

  """

    # db_user = raw_input('DB username: '******'oraclech'
    pw = getpass.getpass()

    odb = oracle_db.OracleDb(db_user, pw, database='oraclech_new')

    contest_id = raw_input('Current Contest ID? ')
    round_num = raw_input('Current Round Number? ')
    round_nums = round_num.split(',')
    topic_num = raw_input('Current Topic Number? ')
    page_num = raw_input('Current Page Number? ')

    contest = odb.GetContest(contest_id)

    try:
        file_path = '%s/r%dt%dp%02d.html' % (contest['Name'].lower(),
                                             int(round_nums[-1]),
                                             int(topic_num), int(page_num))
        file_path = '/home/oraclech/topics/' + file_path
        print file_path
        file = open(file_path, 'r')
    except IOError:
        file_path = raw_input('File to open (in /home/oraclech/topics/): ')
        file_path = '/home/oraclech/topics/' + file_path
        file = open(file_path, 'r')
    page = file.read()
    parser = message_board.Parser()
    messages = parser.Parse(page)

    for message in messages:
        message['Timestamp'] -= datetime.timedelta(minutes=TIME_OFFSET)
        ParsePredictions(odb, message, contest, round_nums)

    odb.Commit()
Exemplo n.º 5
0
def main():
    """This is the main prediction adding function.

  It starts by grabbing a file to open from standard in, which contains
  one message board page.  It processes each message contained in the page.

  NOTE: If there are multiple pages, they must be processed in order.
  However, after a page is complete (50 messages), it only needs to
  be processed once.

  """

    db_user = raw_input('DB username: '******'oraclech_oracle')

    contest_id = raw_input('Current Contest ID? ')
    round_num = raw_input('Current Round Number? ')
    round_nums = round_num.split(',')
    topic_num = raw_input('Current Topic Number? ')
    #  page_num = raw_input('Current Page Number? ')

    contest = odb.GetContest(contest_id)

    for page_num in range(1, 10):
        try:
            file_path = '%s/r%st%dp%02d.html' % (contest['Name'].lower(),
                                                 round_num[-1:],
                                                 int(topic_num), int(page_num))
            file_path = '/home/oraclech/topics/' + file_path
            print file_path
            file = open(file_path, 'r')
        except IOError:
            print 'Failed to open %s' % file_path
            raise
            file_path = raw_input('File to open (in /home/oraclech/topics/): ')
            file_path = '/home/oraclech/topics/' + file_path
            file = open(file_path, 'r')
        page = file.read()
        InsertMessagesInPage(odb, page)
Exemplo n.º 6
0
def main():
  """Parse match history from sc2k5.com and store it in our database."""

  user = raw_input("Database username: "******"Database password: "******"<[^<>]+>([^<>]+)</a>", poll_str).group(1))
    date = fields[2]
    round_num = int(fields[3])
    division_name = fields[4]
    match_num = int(fields[5])
    winner_name = fields[7]
    winner_votes = int(fields[8])
    winner_percent = fields[9].replace('%', '')
    loser_name = fields[11]
    loser_votes = int(fields[12])
    loser_percent = fields[13].replace('%', '')
    
    # Now we need to get the competitors' ids, and if they aren't in our
    # database, add them.

    winner_id = odb.LookupCompetitorId(winner_name)
    if winner_id is None:
      odb.AddCompetitor(winner_name)
      winner_id = odb.LookupCompetitorId(winner_name)

    loser_id = odb.LookupCompetitorId(loser_name)
    if loser_id is None:
      odb.AddCompetitor(loser_name)
      loser_id = odb.LookupCompetitorId(loser_name)

    # Get the contest id for this match.  I'll use a lame hack because we're
    # only going to be importing old data once.  I don't think there's a
    # need in the abstract for a identifying the contest of an un-entered
    # match (what would the criterion be?)

    contest_id = 0
    if poll_id <= 1002:
      contest_id = 1
    elif poll_id <= 1367:
      contest_id = 2
    elif poll_id <= 1663:
      contest_id = 3
    elif poll_id <= 1780:
      contest_id = 4
    elif poll_id <= 2019:
      contest_id = 5
    else:
      contest_id = 6

    # Get the division id for the match.

    if '/' in division_name:
      division_name = "Final Four"

    division_id = odb.LookupDivisionId(division_name, contest_id)
    if division_id is None:
      odb.AddDivision(division_name, contest_id)
      division_id = odb.LookupDivisionId(division_name, contest_id)

    # Check if the match is in the database, just in case.

    match_id = odb.LookupMatchId(winner_id, round_num, contest_id)
    if match_id is None:
      match_id = odb.AddMatch(match_num, round_num, poll_id, contest_id,
                              division_id, date)

    odb.AddResult(match_id, winner_id, votes=winner_votes,
                  percentage=winner_percent, is_winner=1)
    odb.AddResult(match_id, loser_id, votes=loser_votes,
                  percentage=loser_percent, is_winner=0)
    def __init__(self):
        """Class constructor."""

        self.__odb = oracle_db.OracleDb(DB_USER,
                                        PW,
                                        database='oraclech_oracle')
Exemplo n.º 8
0
def main():
    """This is the main function which imports user predictions.

  It reads in the prediction file from one contest and adds each
  prediction to the database.

  """

    contest_id = 5
    comp_type = 'character'

    db_user = raw_input('DB username: '******'oraclech_oracle')

    prediction_file = open('spc2k5_predictions.csv', 'r')
    predictions = prediction_file.read()
    lines = predictions.split('\n')

    for line in lines:
        # Read each line, which contains one user's predictions, and add them to
        # the database.

        cells = line.split(',')
        user = re.search('"([^"]+)"', cells[0]).group(1)
        user_id = odb.GetUserId(user)

        # Each match has three cells devoted to it, so we will have a counter
        # pointing to the first cell of the current match, as well as a
        # counter indicating the match number that we're currently on.  This
        # Will give us all the information (along with contest_id) to know
        # exactly what is being predicted.

        winner_re = re.compile('"([^"]+)"')
        percent_re = re.compile(r'(\d+\.?\d*)%')

        i = 2
        match_num = 1

        while (i < len(cells) - 1):
            winner_match = winner_re.search(cells[i])
            percent_match = percent_re.search(cells[i + 1])

            if winner_match is not None and percent_match is not None:
                # Get the match_id and add the prediction to the database.

                winner_name = winner_match.group(1)
                percent = percent_match.group(1)

                match_id = odb.LookupMatchIdByNumber(contest_id, match_num)
                winner_id = add_predictions.DecipherName(
                    odb, winner_name, winner_name)

                odb.SetPrediction(user_id, match_id, winner_id, percent, 0)

                print "Match %s" % (match_id)
                print "%s predicts %s with %s" % (user, winner_name, percent)

            i += 3
            match_num += 1