Esempio n. 1
0
class Model1(Model):
    id = Column(Integer, primary_key=True)
    field_string = Column(String(50), unique=True, nullable=False)
    field_integer = Column(Integer())
    field_float = Column(Float())
    field_date = Column(Date())
    field_file = FileColumn()
    field_image = ImageColumn()

    def __repr__(self):
        return str(self.field_string)
Esempio n. 2
0
class MLM(Model, AuditMixin):
    """ A machine learning model """
    __tablename__ = 'mlm'
    id = Column(Integer, primary_key=True)
    name = Column(String(100), unique=True, nullable=False)
    type_id = Column(Integer, ForeignKey('mlmtype.id'), nullable=False)
    params =  Column(Text)
    type = relationship(
        'MLMType',
        foreign_keys=[type_id],
        backref=backref('queries', cascade='all, delete-orphan')
    )
    file = Column(FileColumn())
    tags = relationship('Tag',
                        secondary=tags_mlms,
                        backref=backref('mlm', lazy='dynamic'))
    projects = db.relationship('Project', secondary=projects_mlms,
                               backref=db.backref('mlm', lazy='dynamic'))
        
    #mlm_file = relationship('MLMFile', uselist=False, back_populates='mlm') 
    # mlm_file_id = Column(Integer, ForeignKey('mlmfile.id'), nullable=False)
    # mlm_file = relationship(
    #     'MLMFile',
    #     foreign_keys=[mlm_file_id],
    #     backref=backref('queries', cascade='all, delete-orphan')
    # )
 
    def __repr__(self):
        return self.name

    # def download(self):
    #     return Markup(
    #         '<a href="' + url_for('MLMModelView.download', filename=os.path.join(config['UPLOAD_FOLDER'],str(self.file))) + '">Download</a>')

    def file_name(self):
        return '<a href="' + url_for('Emelem.download', filename=str(self.file)) + '">' + get_file_original_name(str(self.file)) + '</a>' 
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('columns', sa.Column('geojson_file', FileColumn(), nullable=True))

    op.add_column('table_columns', sa.Column('geojson_file', FileColumn(), nullable=True))
Esempio n. 4
0
class BaseColumn(AuditMixinNullable, ImportMixin):
    """Interface for column"""

    __tablename__ = None  # {connector_name}_column

    id = Column(Integer, primary_key=True)
    column_name = Column(String(255))
    verbose_name = Column(String(1024))
    is_active = Column(Boolean, default=True)
    type = Column(String(32))
    groupby = Column(Boolean, default=False)
    count_distinct = Column(Boolean, default=False)
    sum = Column(Boolean, default=False)
    avg = Column(Boolean, default=False)
    max = Column(Boolean, default=False)
    min = Column(Boolean, default=False)
    filterable = Column(Boolean, default=False)
    geofilterable = Column(Boolean, default=False)
    geojson_file = Column(FileColumn())
    geojson_filter_name_key = Column(String(225), default=False)
    description = Column(Text)
    is_dttm = None

    # [optional] Set this to support import/export functionality
    export_fields = []

    def __repr__(self):
        return self.column_name

    num_types = (
        'DOUBLE',
        'FLOAT',
        'INT',
        'BIGINT',
        'LONG',
        'REAL',
        'NUMERIC',
        'DECIMAL',
        'MONEY',
    )
    date_types = ('DATE', 'TIME', 'DATETIME')
    str_types = ('VARCHAR', 'STRING', 'CHAR')

    @property
    def is_num(self):
        return (self.type
                and any([t in self.type.upper() for t in self.num_types]))

    @property
    def is_time(self):
        return (self.type
                and any([t in self.type.upper() for t in self.date_types]))

    @property
    def is_string(self):
        return (self.type
                and any([t in self.type.upper() for t in self.str_types]))

    @property
    def expression(self):
        raise NotImplementedError()

    @property
    def data(self):
        attrs = (
            'id',
            'column_name',
            'verbose_name',
            'description',
            'expression',
            'filterable',
            'groupby',
            'geofilterable',
            'is_dttm',
            'type',
            'database_expression',
            'python_date_format',
        )
        return {s: getattr(self, s) for s in attrs if hasattr(self, s)}