def create_roles_table(conn, roles, table_name='roles'): column_constraints = { 'id': 'primary key', } with conn: schema = tables.generate_table_schema( roles, column_constraints=column_constraints) tables.create_table(conn, schema, table_name) tables.populate_table(conn, schema, table_name, roles)
def create_players_table(conn, players, table_name='players'): column_constraints = { 'id': 'primary key', 'team': 'references teams(id)', 'element_type': 'references roles(id)' } with conn: schema = tables.generate_table_schema( players, column_constraints=column_constraints) tables.create_table(conn, schema, table_name) tables.populate_table(conn, schema, table_name, players)
def create_teams_table(conn, teams, table_name='teams'): column_constraints = {'id': 'primary key'} exclude_columns = {'current_event_fixture', 'next_event_fixture', 'form'} with conn: schema = tables.generate_table_schema( teams, exclude_columns=exclude_columns, column_constraints=column_constraints) tables.create_table(conn, schema, table_name) tables.populate_table(conn, schema, table_name, teams, exclude_columns=exclude_columns)
def create_player_match_details_table(conn, element_summaries, table_name='player_match_details'): example = element_summaries[0] column_constraints = { 'id': 'primary key', 'fixture': 'references fixtures(id)', 'element': 'references players(id)', 'round': 'references events(id)', 'opponent_team': 'references teams(id)' } with conn: schema = tables.generate_table_schema( example, column_constraints=column_constraints) tables.create_table(conn, schema, table_name) for e in element_summaries: tables.populate_table(conn, schema, table_name, e)
def create_fixtures_table(conn, fixtures, table_name='fixtures'): exclude_columns = {'stats'} column_constraints = { 'id': 'primary key', 'team_a': 'references teams(id)', 'team_h': 'references teams(id)', 'event': 'references events(id)' } with conn: schema = tables.generate_table_schema( fixtures, exclude_columns=exclude_columns, column_constraints=column_constraints) tables.create_table(conn, schema, table_name) tables.populate_table(conn, schema, table_name, fixtures, exclude_columns=exclude_columns)
def create_roles_table(conn, roles, table_name='roles'): column_constraints = { 'id': 'primary key', } exclude_columns = { "chip_plays", "top_element_info", "sub_positions_locked", "team_division" } with conn: schema = tables.generate_table_schema( roles, exclude_columns=exclude_columns, column_constraints=column_constraints) tables.create_table(conn, schema, table_name) tables.populate_table(conn, schema, table_name, roles, exclude_columns=exclude_columns)