Exemple #1
0
class ClassificationSample(MappedClass, JsonOdmHelper):
    """Python classification sample (training and/or predicted) in MongoDB."""

    class __mongometa__:
        session = session
        name = 'classification_sample'
        indexes = [('model',), ('sharedId',)]
        unique_indexes = [('model', 'seqHash')]

    _id = FieldProperty(schema.ObjectId)
    model = FieldProperty(schema.String)
    seq = FieldProperty(schema.String)
    sharedId = FieldProperty(schema.String)
    seqHash = FieldProperty(schema.String)
    training_labels = FieldProperty(
        schema.Array(schema.Object(fields={'topic': schema.String})))
    # Keep separate to control which samples should
    # be used even if more have training_labels.
    use_for_training = FieldProperty(schema.Bool)
    predicted_labels = FieldProperty(
        schema.Array(
            schema.Object(fields={
                'topic': schema.String,
                'quality': schema.Float
            })))
    update_timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)


Mapper.compile_all()
Mapper.ensure_all_indexes()
    image_name = key.key
    # Download S3 file
    download_s3_file(image_name)
""" DATABASE CONNECTION """

# Create database session
session = ThreadLocalODMSession(bind=create_datastore(app.config['MONGO_URI']))

# Create recipe variable
recipes_collection = session.db.recipes

# Create user variable
users_collection = session.db.users

# Ensure all indexes
index_mapper = Mapper.ensure_all_indexes()

# Drop search index
drop_index = recipes_collection.drop_index('$**_text')

# Create search index
create_index = recipes_collection.create_index([('$**', 'text')])
""" LOGIN MANAGER """

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'


class User(UserMixin):
    def __init__(self, id):