示例#1
0
文件: actions.py 项目: C3SL/hotmapper
def remap(table, auto_confirmation=True, verify_definitions=False):
    '''Applies change made in mapping protocols to database'''
    table = gen_data_table(table, META)
    table.gen_definitions()
    table.map_from_database()

    table.remap(auto_confirmation, verify_definitions)
示例#2
0
文件: actions.py 项目: C3SL/hotmapper
def create(table, ignore_definitions=False):
    '''Creates table from mapping_protocol metadata'''
    table = gen_data_table(table, META)
    table.gen_definitions()

    with ENGINE.connect() as connection:
        trans = connection.begin()
        table.create(bind=connection, ignore_definitions=ignore_definitions)
        table.set_source(bind=connection)
        table.create_mapping_table(bind=connection)
        trans.commit()
示例#3
0
文件: actions.py 项目: C3SL/hotmapper
def csv_from_tabbed(table_name, input_file, output_file, year, sep=';'):
    table = gen_data_table(table_name, META)

    protocol = table.get_protocol()
    column_names, column_mappings = protocol.get_tabbed_mapping(year)

    copy_tabbed_to_csv(input_file,
                       column_mappings,
                       settings.CHUNK_SIZE,
                       output_file,
                       column_names=column_names,
                       sep=sep)
示例#4
0
文件: actions.py 项目: C3SL/hotmapper
def run_aggregations(table, year):
    '''
    Runs aggregation queries from protocol
    '''
    table = gen_data_table(table, META)
    table.map_from_database()

    with ENGINE.connect() as connection:
        trans = connection.begin()

        table.run_aggregations(year, bind=connection)

        trans.commit()
示例#5
0
文件: actions.py 项目: C3SL/hotmapper
def insert(file_name,
           table,
           year,
           offset=2,
           delimiters=[';', '\\n', '"'],
           null='',
           notifybackup=None):
    '''Inserts contents of csv in file_name in table using year as index for mapping'''
    table = gen_data_table(table, META)
    table.map_from_database()
    if not table.exists():
        raise MissingTableError(table.name)

    with ENGINE.connect() as connection:
        trans = connection.begin()

        ttable = temporary_data(connection, file_name, table, year, offset,
                                delimiters, null)
        table.insert_from_temporary(ttable, bind=connection)

        trans.commit()
示例#6
0
文件: actions.py 项目: C3SL/hotmapper
def update_from_file(file_name,
                     table,
                     year,
                     columns=None,
                     offset=2,
                     delimiters=[';', '\\n', '"'],
                     null=''):
    '''Updates table columns from an input csv file'''
    table = gen_data_table(table, META)
    table.map_from_database()
    if not table.exists():
        raise MissingTableError(table.name)

    if columns is None:
        columns = [c.name for c in table.columns]

    with ENGINE.connect() as connection:
        trans = connection.begin()

        ttable = temporary_data(connection, file_name, table, year, offset,
                                delimiters, null)
        table.update_from_temporary(ttable, columns, bind=connection)

        trans.commit()
示例#7
0
文件: actions.py 项目: C3SL/hotmapper
def drop(table):
    '''Drops table'''
    table = gen_data_table(table, META)

    table.drop()