예제 #1
0
class Jobs(Base):
    __tablename__ = 'jobs'

    def __init__(self, status, model_id):
        self.status = status
        self.model_id = model_id

    job_id = db.Column(db.Integer, primary_key=True)
    status = db.Column(db.Enum(JobStatus))
    history_loss = db.Column(db.JSON(), nullable=True)
    history_acc = db.Column(db.JSON(), nullable=True)
    evaluation_loss = db.Column(db.Float, nullable=True)
    evaluation_acc = db.Column(db.Float, nullable=True)
    model_id = db.Column(db.Integer, db.ForeignKey('models.model_id'))

    model = db.relationship('Models')
예제 #2
0
파일: Client.py 프로젝트: kegeer/flask-pdf
class Client(db.Model, CRUD):
    __tablename__ = 'clients'

    id = db.Column(db.String(45), primary_key=True)
    # 必需参数
    source_id = db.Column(db.String(45), db.ForeignKey('sources.id'))
    name = db.Column(db.String(255))
    gender = db.Column(db.SmallInteger())
    age = db.Column(db.SmallInteger())
    info = db.Column(db.JSON(), nullable=True)
    results = db.relationship('Result', backref="client", lazy="dynamic")

    # original_id = db.Column(db.String(45))
    # phone_num = db.Column(db.String(45), nullable=True)
    # height = db.Column(db.Float(), nullable=True)
    # weight = db.Column(db.Float(), nullable=True)
    # bmi = db.Column(db.Float(), nullable=True)

    # smoke = db.Column(db.Boolean(), default=False)
    # drink = db.Column(db.Boolean(), default=False)
    # triglyceride = db.Column(db.Float(), nullable=True)
    # cholesterol = db.Column(db.Float(), nullable=True)
    # h_lipoprotein = db.Column(db.Float(), nullable=True)
    # l_lipoprotein = db.Column(db.Float(), nullable=True)
    # fbg = db.Column(db.Float(), nullable=True)
    # defecate = db.Column(db.SmallInteger(), nullable=True)
    # medical_history = db.Column(db.Text(), nullable=True)
    # family_history = db.Column(db.Text(), nullable=True)
    # medicine = db.Column(db.Text(), nullable=True)
    # remarks = db.Column(db.Text(), nullable=True)

    # define relationship with result
    # results = db.relationship(
    #     'Result',
    #     backref='client',
    #     lazy='dynamic'
    # )

    def __init__(self):
        self.id = str(uuid4())

    def __repr__(self):
        return "<Model Client `{}`>".format(self.name)

    def import_data(self, data):
        try:
            self.name = data['name']
            self.source_id = data['source_id']
            self.gender = int(data['gender'])
            self.age = int(data['age'])
            self.info = data['info']
        except KeyError as e:
            raise ValidationError("Invalid Information: missing " + e.args[0])
예제 #3
0
class Indicator(db.Model):
    id = db.Column(db.Integer(), primary_key=True)

    name = db.Column(db.String(120), nullable=False, index=True)
    source = db.Column(db.JSON(), nullable=False)
    unit = db.Column(db.String(20), nullable=False, default='')
    aggregation = db.Column(db.String(80), default='average')
    is_deleted = db.Column(db.Boolean(),
                           default=False,
                           index=True,
                           server_default=false())

    product_id = db.Column(db.Integer(),
                           db.ForeignKey('product.id'),
                           nullable=False,
                           index=True)

    slug = db.Column(db.String(120), nullable=False, index=True)

    targets = db.relationship('Target',
                              backref=db.backref('indicator', lazy='joined'),
                              lazy='dynamic')
    values = db.relationship('IndicatorValue',
                             backref='indicator',
                             lazy='dynamic',
                             passive_deletes=True)

    username = db.Column(db.String(120), default='')
    created = db.Column(db.DateTime(), default=datetime.utcnow)
    updated = db.Column(db.DateTime(),
                        onupdate=datetime.utcnow,
                        default=datetime.utcnow)

    __table_args__ = (db.UniqueConstraint(
        'name',
        'product_id',
        'is_deleted',
        name='indicator_name_product_id_key'), )

    def get_owner(self):
        return self.product.product_group.name

    def __repr__(self):
        return '<SLI {} | {} | {}>'.format(self.product.name, self.name,
                                           self.source)
예제 #4
0
class Adv(db.Model, BaseMixin, ModelHelper):
    __tablename__ = 'advs'
    __table_args__ = {'extend_existing': True}
    except_fields = ['password_hash']
    id = db.Column(GUID(), primary_key=True, default=uuid4)
    username = db.Column(db.String(100), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=True)
    fullname = db.Column(db.String(100), nullable=True)
    password_hash = db.Column(db.String(255), nullable=True)
    meta_data = db.Column(db.JSON(), default=None, nullable=True)

    @property
    def password(self):
        raise AttributeError('Password is not accessible')

    @password.setter
    def password(self, plaintext):
        self.password_hash = generate_password_hash(plaintext)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
예제 #5
0
파일: user.py 프로젝트: produvia/kryptos
class StrategyModel(db.Model):
    __tablename__ = "strategies"

    id = db.Column(db.Integer, nullable=False, unique=True, primary_key=True)
    uuid = db.Column(db.String(), unique=True, default=shortuuid.uuid())
    name = db.Column(db.String(), nullable=False, unique=False)
    created_at = db.Column(db.DateTime(), default=datetime.datetime.now())
    trading_config = db.Column(db.JSON(), nullable=False, unique=False)
    dataset_config = db.Column(db.JSON(), nullable=False, unique=False)
    indicators_config = db.Column(db.JSON(), nullable=False, unique=False)
    signals_config = db.Column(db.JSON(), nullable=False, unique=False)

    status = db.Column(db.String(),
                       nullable=True,
                       unique=False,
                       primary_key=False)

    result_json = db.Column(db.JSON(), nullable=True, unique=False)

    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))

    @classmethod
    def from_json(cls, strat_json, user_id=None):
        d = json.loads(strat_json)
        instance = cls()

        instance.uuid = shortuuid.uuid()
        instance.name = d.get("name")
        instance.trading_config = d.get("trading")
        instance.dataset_config = d.get("datasets")
        instance.indicators_config = d.get("indicators")
        instance.signals_config = d.get("signals")

        if user_id is not None:
            instance.user_id = user_id

        return instance

    def update_from_job(self, job):
        self.status = job.status
        current_app.logger.debug(
            f"Updating strategy {self.id} status: {self.status}")
        if job.result:
            current_app.logger.debug(f"Strategy {self.id} job has finished")
            self.result_json = job.result

        db.session.commit()

    def config_to_json(self):
        d = {
            "id": self.id,
            "name": self.name,
            "trading": self.trading_config,
            "datasets": self.dataset_config,
            "indicator": self.indicators_config,
            "signals_config": self.signals_config,
        }
        return json.dumps(d)

    @property
    def parsed_result_json(self):
        if self.result_json is None:
            return {}
        d = json.loads(self.result_json)
        clean_result = {}
        for k, v in d.items():
            # nested dict with trading type as key
            metric, val = k, v.get("Backtest", v)
            clean_result[metric] = val
        return clean_result

    def pretty_result(self):
        string = ""
        if self.result_json is None:
            return None
        result_dict = json.loads(self.result_json)
        for k, v in result_dict.items():
            # nested dict with trading type as key
            metric, val = k, v["Backtest"]
            string += f"{metric}: {val}\n"
        return string
예제 #6
0
class Offer(db.Model, BaseMixin, ModelHelper):
    __tablename__ = 'offers'
    __table_args__ = {'extend_existing': True}
    id = db.Column(GUID(), primary_key=True, default=uuid4)
    alias = db.Column(db.String(20), unique=True, nullable=False)
    name = db.Column(db.String(100), nullable=False)
    geo = db.Column(db.String(20), nullable=True)
    img = db.Column(db.Text, nullable=True)
    category_id = db.Column(GUID(),
                            db.ForeignKey('categories.id', ondelete="CASCADE"),
                            nullable=True)
    category = db.relationship('Category')
    description = db.Column(db.Text, nullable=True)
    short_desc = db.Column(db.Text, nullable=True)
    country_code = db.Column(db.String(20), nullable=True)
    payout_share = db.Column(db.Float(), nullable=True, default=0.0)
    ecpc = db.Column(db.Float(), nullable=True, default=0.0)
    price = db.Column(db.Float(), nullable=True, default=0.0)
    meta_data = db.Column(db.JSON(), nullable=True, default=None)
    adv_id = db.Column(GUID(),
                       db.ForeignKey('advs.id', ondelete="CASCADE"),
                       nullable=True)

    @staticmethod
    def from_arguments(args):
        """
            arguments from create offer
            'alias': {'type': 'string'},
            'description': {'type': 'string'},
            'short_desc': {'type': 'string'},
            'geo': {'type': 'string'},
            'name': {'type': 'string'},
            'img': {'type': 'string', 'format': 'uri'},
            'category_id': {'type': 'string', 'format': 'uuid'},
            'country_code': {'type': 'integer'},
            'payout_share': {'type': 'number'},
            'ecpc': {'type': 'number'},
            'price': {'type': 'number'},
            'adv_id': {'type': 'string', 'format': 'uuid'},
            'aff_sub_pub': {'type': 'string'},
            'aff_sub_order': {'type': 'string'},
            'aff_click_id': {'type': 'string'},
            'aff_pub_sub2': {'type': 'string'},
            'account_name':  {'type': 'string'},
            'required': ['name', 'alias', 'description', 'category_id', 'adv_id', 'price', 'img'],
        """
        name = args.get('name')
        alias = args.get('alias')
        geo = args.get('geo', 'global')
        price = args.get('price', 0.0)
        payout_share = args.get('payout_share', 0.0)
        ecpc = args.get('ecpec', 0.0)
        img = args.get('img')
        adv_id = args.get('adv_id')
        category_id = args.get('category_id')
        aff_sub_pub = args.get('aff_sub_pub')
        aff_sub_order = args.get('aff_sub_order')
        aff_click_id = args.get('aff_click_id')
        aff_pub_sub2 = args.get('aff_pub_sub2')
        description = args.get('description')
        short_desc = args.get('short_desc')
        account_name = args.get('account_name')
        meta_data = {
            'aff_sub_pub': aff_sub_pub,
            'aff_sub_order': aff_sub_order,
            'aff_click_id': aff_click_id,
            'aff_pub_sub2': aff_pub_sub2,
            'account_name': account_name
        }
        offer = Offer(name=name,
                      alias=alias,
                      geo=geo,
                      price=price,
                      payout_share=payout_share,
                      ecpc=ecpc,
                      img=img,
                      adv_id=adv_id,
                      category_id=category_id,
                      description=description,
                      short_desc=short_desc,
                      meta_data=meta_data)
        return offer