Exemple #1
0
class Cryptocurrency(Currency):
    __tablename__ = 'cryptocurrency'
    __mapper_args__ = {
        'polymorphic_identity': __tablename__,
    }

    symbol = Field(
        Unicode(10),
        ForeignKey(Currency.symbol),
        min_length=1,
        max_length=10,
        pattern=r'^[A-Z0-9]{1,10}$',
        primary_key=True
    )

    # A reference to an external cryptocurrency wallet
    wallet_id = Field(Unicode(32))
    wallet_latest_sync = Field(Integer(), default=0)

    withdraw_min = Field(DECIMAL(18, 8), default=Decimal('0.00001000'))
    withdraw_max = Field(DECIMAL(18, 8), default=Decimal('100.00000000'))
    withdraw_static_commission = Field(DECIMAL(18, 8), default=Decimal('0.00000000'))
    withdraw_commission_rate = Field(Unicode(10), default="0.005")
    withdraw_max_commission = Field(DECIMAL(18, 8), default=Decimal('0.00000000'))

    deposit_min = Field(DECIMAL(18, 8), default=Decimal('0.00000001'))
    deposit_max = Field(DECIMAL(18, 8), default=Decimal('100.00000000'))
    deposit_static_commission = Field(DECIMAL(18, 8), default=Decimal('0.00000000'))
    deposit_commission_rate = Field(Unicode(10), default="0.000")
    deposit_max_commission = Field(DECIMAL(18, 8), default=Decimal('0.00000000'))

    def calculate_withdraw_commission(self, amount: Decimal):
        commission = self.withdraw_static_commission
        if self.withdraw_commission_rate != Decimal(0):
            commission += amount * Decimal(self.withdraw_commission_rate)
        return min(
            commission, self.withdraw_max_commission
        ) if self.withdraw_max_commission != Decimal(0) else commission

    def calculate_deposit_commission(self, amount: Decimal):
        commission = self.deposit_static_commission
        if self.deposit_commission_rate != Decimal(0):
            commission += amount * Decimal(self.deposit_commission_rate)
        return min(
            commission, self.deposit_max_commission
        ) if self.deposit_max_commission != Decimal(0) else commission

    def to_dict(self):
        result = super().to_dict()
        # TODO: Get the current user's wallet_tier_policy about this currency
        # result['tirePolicy'] = {}
        result['withdrawMin'] = self.normalized_to_output(self.withdraw_min)
        result['withdrawMax'] = self.normalized_to_output(self.withdraw_max)
        result['withdrawStaticCommission'] = self.normalized_to_output(self.withdraw_static_commission)
        result['withdrawMaxCommission'] = self.normalized_to_output(self.withdraw_max_commission)
        result['depositMin'] = self.normalized_to_output(self.deposit_min)
        result['depositMax'] = self.normalized_to_output(self.deposit_max)
        result['depositStaticCommission'] = self.normalized_to_output(self.deposit_static_commission)
        result['depositMaxCommission'] = self.normalized_to_output(self.deposit_max_commission)
        return result
class Billing(Base):
    __tablename__ = 'Billing'
    id = Column(Integer, primary_key=True)
    usage_date = Column(DATETIME)
    cost = Column(FLOAT)
    project_id = Column(String(16))
    resource_type = Column(String(128))
    account_id = Column(String(24))
    usage_value = Column(DECIMAL(25, 4))
    measurement_unit = Column(String(16))

    def __init__(self, usage_date, cost, project_id, resource_type, account_id,
                 usage_value, measurement_unit):
        self.usage_date = usage_date
        self.cost = cost
        self.project_id = project_id
        self.resource_type = resource_type
        self.account_id = account_id
        self.usage_value = usage_value
        self.measurement_unit = measurement_unit

    def __repr__(self):
        return '<Usage %r %r %r %r %r %r %r >' % (
            self.usage_date, self.cost, self.project_id, self.resource_type,
            self.account_id, self.usage_value, self.measurement_unit)
Exemple #3
0
class Money_table(Base):
    __tablename__ = 'money'
    id = Column(Integer(), primary_key=True, nullable=False)
    money_id = Column(Integer(), ForeignKey("user.user_id"), nullable=False)
    money_sum = Column(DECIMAL(10, 3), nullable=False)

    def __repr__(self):
        return "Money_table(money_id='{self.money_id}', money_sum='{self.money_sum}')".format(
            self=self)
Exemple #4
0
class Audit_table(Base):
    __tablename__ = 'audit'
    audit_id = Column(Integer(), primary_key=True, nullable=False)
    audit_transfer_time = Column(DateTime(),
                                 default=datetime.now,
                                 onupdate=datetime.now,
                                 nullable=False)
    autid_transfer_id = Column(Integer(), nullable=False)
    autid_totransfer_id = Column(Integer(), nullable=False)
    autid_transfer_money = Column(DECIMAL(10, 3), nullable=False)

    def __repr__(self):
        return "Audit_table(audit_id='{self.audit_id}',audit_transfer_time='{self.audit_transfer_time}', autid_transfer_id='{self.autid_transfer_id}',\
        autid_totransfer_id='{self.autid_totransfer_id}', autid_transfer_money='{self.autid_transfer_money}')".format(
            self=self)
Exemple #5
0
class Data(Base):
    __tablename__ = "projectgrants"
    id = Column(Integer, primary_key=True, autoincrement=True, comment="id")
    ProjectCode = Column(String(20), nullable=True, comment="项目批准号")
    ProjectName = Column(String(200), nullable=True, comment="")
    ProjectType = Column(String(50), nullable=True, comment="")
    Institution = Column(String(100), nullable=False, comment="")
    Leader = Column(String(50), nullable=True, comment="")
    Amount = Column(DECIMAL(7), nullable=True, comment="")
    YearOfApproval = Column(DATE, nullable=True, comment="")
    ClassificationCode = Column(String(10), nullable=True, comment="")
    Classification = Column(String(100), nullable=True, comment="")
    StartDate = Column(DATE, nullable=False, comment="")
    EndDate = Column(DATE, nullable=False, comment="")
    KeyWord = Column(String(500), nullable=False, comment="")
    EnKeyWord = Column(String(500), nullable=False, comment="")
    Url = Column(String(500), nullable=True, comment="")
    Status = Column(Integer, nullable=True, comment="")
    curPage = Column(Integer, nullable=True, comment="")
Exemple #6
0

@pytest.mark.parametrize(
    "type_str, sql_type",
    parse_cases_testcases.items(),
    ids=parse_cases_testcases.keys(),
)
def test_parse_cases(type_str: str, sql_type: TypeEngine, assert_sqltype):
    actual_type = datatype.parse_sqltype(type_str)
    assert_sqltype(actual_type, sql_type)


parse_type_options_testcases = {
    "CHAR(10)": CHAR(10),
    "VARCHAR(10)": VARCHAR(10),
    "DECIMAL(20)": DECIMAL(20),
    "DECIMAL(20, 3)": DECIMAL(20, 3),
    # TODO: support parametric timestamps (https://github.com/trinodb/trino-python-client/issues/107)
}


@pytest.mark.parametrize(
    "type_str, sql_type",
    parse_type_options_testcases.items(),
    ids=parse_type_options_testcases.keys(),
)
def test_parse_type_options(type_str: str, sql_type: TypeEngine, assert_sqltype):
    actual_type = datatype.parse_sqltype(type_str)
    assert_sqltype(actual_type, sql_type)