Ejemplo n.º 1
0
def populate_event_player_table(event_names, event_id):
  query = "select player_id, norm_name_1, norm_name_2, norm_name_3 from player_table where "
  or_ = False
  for name in event_names:
    if not or_:
      query += "or "
    or_ = True
    query += "norm_name_1 like '{0}%' or norm_name_2 like '{0}%' or norm_name_3 like '{0}%' ".format(name)
  cursor = Cursor()
  player_table_names = cursor.execute(query)
  found_names = []
  new_names = []
  for name in event_names:
    found = False
    for idx, row in enumerate(player_table_names):
      if name in row:
        if found:
          raise 'two matches found for name ' + name
        found_names.append({'player_id':row[0], 'normalized_name':name, 'event_id':event_id})
        found = True
    if not found:
      new_names.append(name)
  player_id = cursor.execute("select max(player_id) from player_table")[0][0]
  new_players = []
  for name in new_names:
    player_id += 1
    new_players.append({'player_id':player_id, 'norm_name_1':name, 'first_event':event_id})
    found_names.append({'player_id':player_id, 'normalized_name':name, 'event_id':event_id})
  cursor.insert('event_player_table', found_names)
  cursor.insert('player_table', new_players)
  cursor.close()
Ejemplo n.º 2
0
def update_event(event_info):
    if 'event_link' not in event_info:
        return None
    cursor = Cursor()
    query = "select * from event_table where event_link = '{}'".format(event_info['event_link'])
    result = cursor.execute(query)
    if len(result) == 0:
        event_info['results_loaded'] = 0
        cursor.insert('event_table', [event_info])
    cursor.close()
    return
Ejemplo n.º 3
0
def upload_round_results(results_table, event_id, round_num):
    # results_table must all have same round_num and represent all results for that round!!
    print
    print '==========Processing Results for Event {}, Round {}=========='.format(event_id, round_num)
    cursor = Cursor()
    print 'Writing {} rows'.format(len(results_table))
    cursor.insert(RAW_TABLE_NAME, results_table)
    cursor.close()
    cursor = Cursor()
    print 'New {} row count: {}'.format(RAW_TABLE_NAME, cursor.execute('select count(1) from {}'.format(RAW_TABLE_NAME))[0][0])
    cursor.close(commit=False)