示例#1
0
def insert_features_layers_pixel_types_db_ids(connection, request_id, features, layers, pixel_types):
    """
    Associates the given features, layers and pixel types to the provided request ID
    :param connection: The database connection
    :param request_id: The ID of the HDF5 request
    :param features: The features requested
    :param layers: The layers requested
    :param pixel_types: The pixel types requested
    :return: Nothing
    """

    for feature in features:
        entry = connection.execute(select([HDF5_FEATURE]).where(HDF5_FEATURE.c.argument_name == feature)).first()

        if not entry:
            LOG.info("Bad feature. Feature does not exist: {0}".format(feature))
        else:
            connection.execute(HDF5_REQUEST_FEATURE.insert(), hdf5_request_id=request_id,
                               hdf5_feature_id=entry['hdf5_feature_id'])

    for layer in layers:
        entry = connection.execute(select([HDF5_LAYER]).where(HDF5_LAYER.c.argument_name == layer)).first()

        if not entry:
            LOG.info("Bad layer. Layer does not exist: {0}".format(layer))
        else:
            connection.execute(HDF5_REQUEST_LAYER.insert(), hdf5_request_id=request_id,
                               hdf5_layer_id=entry['hdf5_layer_id'])

    for pixel_type in pixel_types:
        entry = connection.execute(select([HDF5_PIXEL_TYPE])
                                   .where(HDF5_PIXEL_TYPE.c.argument_name == pixel_type)).first()

        if not entry:
            LOG.info("Bad pixel type. Pixel type does not exist: {0}".format(pixel_type))
        else:
            connection.execute(HDF5_REQUEST_PIXEL_TYPE.insert(), hdf5_request_id=request_id,
                               hdf5_pixel_type_id=entry['hdf5_pixel_type_id'])
示例#2
0
connection = engine.connect()

features, layers, pixel_types = get_features_and_layers_pixeltypes_cmd_line(args)
if len(features) == 0 or len(layers) == 0:
    parser.print_help()
    exit(1)

# Create a new request
# Need to make:
# HDF5_request
# HDF5_request_feature
# HDF5_request_galaxy
# HDF5_request_layer
# HDF5_request_pixel
transaction = connection.begin()
result = connection.execute(HDF5_REQUEST.insert(), profile_id=47016, email=args['email'], created_at=time.time())

connection.execute(HDF5_REQUEST_GALAXY.insert(), hdf5_request_id=result.inserted_primary_key, galaxy_id=args['galaxy_id'])

for pixel_type in pixel_types:
    connection.execute(HDF5_REQUEST_PIXEL_TYPE.insert(), hdf5_request_id=result.inserted_primary_key, hdf5_pixel_type_id=pixel_type+1) # database entries start at 1

for layer in layers:
    connection.execute(HDF5_REQUEST_LAYER.insert(), hdf5_request_id=result.inserted_primary_key, hdf5_layer_id=LAYERS[layer]+1)

for feature in features:
    connection.execute(HDF5_REQUEST_FEATURE.insert(), hdf5_request_id=result.inserted_primary_key, hdf5_feature_id=FEATURES[feature]+1)
transaction.commit()
LOG.info('All done')
connection.close()