parameters: (bt_table, game_data, last_game)
docstring: Write all eval_records to eval_table
  
      In addition to writing new rows table_state must be updated in
      row `table_state` columns `metadata:eval_game_counter`
  
      Args:
        bt_table: bigtable table to add rows to.
        game_data:  metadata pairs (column name, value) for each eval record.
        last_game:  last_game in metadata:table_state
docstring_summary: Write all eval_records to eval_table
docstring_tokens: Write all eval_records to eval_table
function: def write_eval_records(bt_table, game_data, last_game):
      """Write all eval_records to eval_table
  
      In addition to writing new rows table_state must be updated in
      row `table_state` columns `metadata:eval_game_counter`
  
      Args:
        bt_table: bigtable table to add rows to.
        game_data:  metadata pairs (column name, value) for each eval record.
        last_game:  last_game in metadata:table_state
      """
      eval_num = last_game
  
      # Each column counts as a mutation so max rows is ~10000
      GAMES_PER_COMMIT = 2000
      for games in grouper(tqdm(game_data), GAMES_PER_COMMIT):
          assert bt_table.read_row(EVAL_PREFIX.format(eval_num)), "Prev row doesn't exists"
          assert bt_table.read_row(EVAL_PREFIX.format(eval_num+1)) is None, "Row already exists"
  
          rows = []
          for i, metadata in enumerate(games):
              eval_num += 1
              metadata["path"] = canonical_name(metadata["path"])
              metadata["tool"] = "eval_sgf_to_cbt"
  
              row_name = EVAL_PREFIX.format(eval_num)
              row = bt_table.row(row_name)
              for column, value in metadata.items():
                  row.set_cell(METADATA, column, value)
              rows.append(row)
              # For each batch of games print a couple of the rows being added.
              if i < 5 or i + 5 > len(games):
                  print("\t", i, row_name, metadata[6][1])
  
          if eval_num == last_game + len(games):
              test = input("Commit ('y'/'yes' required): ")
              if test.lower() not in ('y', 'yes'):
                  break
  
          # TODO(derek): Figure out how to condition on atomic counter update.
          # Condition all updates on the current value of last_game
  
          game_num_update = bt_table.row(TABLE_STATE)
          game_num_update.set_cell(METADATA, EVAL_GAME_COUNTER, eval_num)
          print(TABLE_STATE, eval_num)
  
          response = bt_table.mutate_rows(rows)
  
          # validate that all rows were written successfully
          any_bad = False
          for i, status in enumerate(response):
              if status.code is not 0:
                  print("Row number {} failed to write {}".format(i, status))
                  any_bad = True
          if any_bad:
              break
  
          game_num_update.commit()
function_tokens: def write_eval_records ( bt_table , game_data , last_game ) : eval_num = last_game # Each column counts as a mutation so max rows is ~10000 GAMES_PER_COMMIT = 2000 for games in grouper ( tqdm ( game_data ) , GAMES_PER_COMMIT ) : assert bt_table . read_row ( EVAL_PREFIX . format ( eval_num ) ) , "Prev row doesn't exists" assert bt_table . read_row ( EVAL_PREFIX . format ( eval_num + 1 ) ) is None , "Row already exists" rows = [ ] for i , metadata in enumerate ( games ) : eval_num += 1 metadata [ "path" ] = canonical_name ( metadata [ "path" ] ) metadata [ "tool" ] = "eval_sgf_to_cbt" row_name = EVAL_PREFIX . format ( eval_num ) row = bt_table . row ( row_name ) for column , value in metadata . items ( ) : row . set_cell ( METADATA , column , value ) rows . append ( row ) # For each batch of games print a couple of the rows being added. if i < 5 or i + 5 > len ( games ) : print ( "\t" , i , row_name , metadata [ 6 ] [ 1 ] ) if eval_num == last_game + len ( games ) : test = input ( "Commit ('y'/'yes' required): " ) if test . lower ( ) not in ( 'y' , 'yes' ) : break # TODO(derek): Figure out how to condition on atomic counter update. # Condition all updates on the current value of last_game game_num_update = bt_table . row ( TABLE_STATE ) game_num_update . set_cell ( METADATA , EVAL_GAME_COUNTER , eval_num ) print ( TABLE_STATE , eval_num ) response = bt_table . mutate_rows ( rows ) # validate that all rows were written successfully any_bad = False for i , status in enumerate ( response ) : if status . code is not 0 : print ( "Row number {} failed to write {}" . format ( i , status ) ) any_bad = True if any_bad : break game_num_update . commit ( )