Exemple #1
0
class IdLibraryCacheInfo(DataBaseModel):
    f_party_id = CharField(max_length=32)
    f_id_type = CharField(max_length=16)
    f_encrypt_type = CharField(max_length=16)
    f_tag = CharField(max_length=16, default=DEFAULT_TAG)
    f_namespcae = CharField(max_length=128)
    f_version = CharField(max_length=128)
    f_rsa_key_n = CharField(max_length=512)
    f_rsa_key_d = CharField(max_length=512)
    f_rsa_key_e = CharField(max_length=32)
    f_create_time = BigIntegerField()
    f_update_time = BigIntegerField(null=True)
    f_description = TextField(null=True, default='')

    class Meta:
        db_table = "t_id_library_cache_infos"
        primary_key = CompositeKey('f_party_id', 'f_id_type', 'f_encrypt_type',
                                   'f_tag', 'f_namespcae', 'f_version')
Exemple #2
0
class GuildBan(BaseModel):
    user_id = BigIntegerField()
    guild_id = BigIntegerField()
    reason = TextField(null=True)

    class Meta:
        db_table = 'guild_bans'
        primary_key = CompositeKey('user_id', 'guild_id')

    @classmethod
    def ensure(cls, guild, user, reason=None):
        User.ensure(user)
        obj, _ = cls.get_or_create(guild_id=guild.id,
                                   user_id=user.id,
                                   defaults=dict({
                                       'reason': reason,
                                   }))
        return obj
Exemple #3
0
class FunctionIdentity(BaseModel):
    """ Function Identity model """
    cs = ForeignKeyField(ChallengeSet, related_name='function_identities')
    address = BigIntegerField(null=False)
    symbol = CharField(null=True)
    func_info = BlobField(null=True)

    class Meta:  # pylint: disable=no-init,too-few-public-methods,old-style-class
        db_table = 'function_identities'
class ChinaLocationCodeAboveCounty(Model):

    id = PrimaryKeyField()
    code = BigIntegerField(unique=True)
    name = CharField(max_length=255)

    class Meta:
        database = db
        db_table = 'china_location_code_above_county'
Exemple #5
0
class Channel(ModelBase):
    channel_id = BigIntegerField(primary_key=True)
    guild_id = BigIntegerField(null=True)
    name = CharField(null=True, index=True)
    topic = TextField(null=True)
    type_ = SmallIntegerField(null=True)

    # First message sent in the channel
    first_message_id = BigIntegerField(null=True)
    deleted = BooleanField(default=False)

    class Meta:
        table_name = 'channels'

    @classmethod
    def generate_first_message_id(cls, channel_id):
        try:
            return Message.select(Message.id).where(
                (Message.channel_id == channel_id)).order_by(
                    Message.id.asc()).limit(1).get().id
        except Message.DoesNotExist:
            return None

    @classmethod
    def from_disco_channel(cls, channel):
        # Upsert channel information
        channel = list(
            cls.insert(
                channel_id=channel.id,
                guild_id=channel.guild.id if channel.guild else None,
                name=channel.name or None,
                topic=channel.topic or None,
                type_=channel.type,
            ).on_conflict(conflict_target=cls.channel_id,
                          preserve=(cls.channel_id, cls.guild_id, cls.type_),
                          update={
                              cls.name: channel.name,
                              cls.topic: channel.topic
                          }).returning(cls.first_message_id).execute())[0]

        # Update the first message ID
        if not channel.first_message_id:
            cls.update(first_message_id=cls.generate_first_message_id(
                channel.id)).where(cls.channel_id == channel.id).execute()
Exemple #6
0
class GameType(db.Model):
    """
    游戏种类 WOB WOT....
    """
    name = CharField(verbose_name="游戏名称", unique=True)
    token = CharField(verbose_name="代币名称", help_text="表示该游戏相关的商品售价单位")
    asset = CharField(verbose_name="资产名称", help_text="游戏角色资产对应erc721名称")
    appid = CharField(verbose_name="接口相关id", null=True)
    appsecret = CharField(verbose_name="接口相关密匙", null=True)
    npc_user_id = BigIntegerField(verbose_name="分配给游戏的npc用户", null=True)
    active = BooleanField(default=True, verbose_name="是否可用")
    created_at = DateTimeField(verbose_name="创建时间", default=datetime.now)

    def save(self, *args, **kwargs):
        super(GameType, self).save(*args, **kwargs)
        if not self.appsecret:
            print(datetime.now().strftime("%m%d%f"))
            self.appid = self.name + datetime.now().strftime("%m%d%f") + str(
                random.randint(10000, 99999))
            from .utils import hash_password
            print(type(self.appid))
            self.appsecret = hash_password(self.appid)
            user = Users.create_user(
                email="{0}@{1}.com".format(self.appid, self.name),
                password=fl_hash_password(self.appsecret[-10:]))
            self.npc_user_id = user.user_id
            self.save()

    def get_display_data(self):
        return {
            "name": self.name,
            "appid": self.appid,
            "token": self.token,
            "userid": self.npc_user_id,
            "appsecret": self.appsecret,
            "gameid": self.id
        }

    @classmethod
    def get_games_dict(cls):
        query = cls.select().where(GameType.active == True)
        games_dict = {}
        for q in query:
            game_dict = q.get_display_data()
            games_dict[game_dict["appid"]] = {
                "secret": game_dict["appsecret"],
                "name": game_dict["name"],
                "token": game_dict["token"],
                "userid": game_dict["userid"],
                "gameid": game_dict["gameid"],
                "appid": game_dict["appid"]
            }
        return games_dict

    def __str__(self):
        return self.name
Exemple #7
0
class PatchScore(BaseModel, CBScoreMixin):
    """
    Score of a patched CB
    """
    cs = ForeignKeyField(ChallengeSet, related_name='patch_scores')
    num_polls = BigIntegerField(null=False)
    polls_included = BinaryJSONField(null=True)
    has_failed_polls = BooleanField(null=False, default=False)
    failed_polls = BinaryJSONField(null=True)
    round = ForeignKeyField(Round, related_name='patch_scores')
    perf_score = BinaryJSONField(null=False)
    patch_type = ForeignKeyField(PatchType, related_name='estimated_scores')

    @property
    def security(self):
        return 2 - self.patch_type.exploitability

    @property
    def success(self):
        if self.has_failed_polls:
            return 0
        else:
            return 1 - self.patch_type.functionality_risk

    @property
    def time_overhead(self):
        rep_tsk_clk = self.perf_score['score']['rep']['task_clock']
        ref_tsk_clk = self.perf_score['score']['ref']['task_clock']
        exec_time_overhead = 9999  # big number
        if ref_tsk_clk != 0:
            exec_time_overhead = (rep_tsk_clk * 1.0) / ref_tsk_clk
        return exec_time_overhead - 1

    @property
    def memory_overhead(self):
        rep_max_rss = self.perf_score['score']['rep']['rss']
        ref_max_rss = self.perf_score['score']['ref']['rss']
        rep_min_flt = self.perf_score['score']['rep']['flt']
        ref_min_flt = self.perf_score['score']['ref']['flt']

        term1 = 9999  # big number
        if ref_max_rss != 0:
            term1 = (rep_max_rss * 1.0) / ref_max_rss

        term2 = 9999  # big number
        if ref_min_flt != 0:
            term2 = (rep_min_flt * 1.0) / ref_min_flt
        return 0.5 * (term1 + term2) - 1

    @property
    def size_overhead(self):
        # ref performance : Un patched
        # rep performance : patched
        rep_file_size = self.perf_score['score']['rep']['file_size']
        ref_file_size = self.perf_score['score']['ref']['file_size']
        return ((rep_file_size * 1.0) / ref_file_size) - 1
Exemple #8
0
class Guild(Model):
    id = AutoField()
    serverid = BigIntegerField()
    memberrole = BigIntegerField(default=0)
    nonmemberrole = BigIntegerField(default=0)
    mutedrole = BigIntegerField(default=0)
    welcomechannelid = BigIntegerField(default=0)
    ruleschannelid = BigIntegerField(default=0)
    logchannelid = BigIntegerField(default=0)
    entrychannelid = BigIntegerField(default=0)
    rulesreactmessageid = BigIntegerField(default=0)
    defaultlocale = CharField(max_length=10)

    class Meta:
        database = connection
Exemple #9
0
class webapp_forum_main(PostgresqlModel):
    url        = CharField(max_length=1000, unique=True)
    title      = CharField(max_length=1000, null=True)
    content    = TextField(null=True)
    date       = DateTimeField(null=True)
    tm         = BigIntegerField(null=True)
    source     = CharField(max_length = 50, null=True)
    board      = CharField(max_length = 50, null=True)
    positive   = IntegerField(null=True)
    negative   = IntegerField(null=True)
Exemple #10
0
class SiteDailyTopUser(BaseModel):
    user = ForeignKeyField(User, to_field=User.user_key, db_column='user_key')
    date = ForeignKeyField(Date, to_field=Date.date_key, db_column='date_key')
    dcount = IntegerField()
    gcount = IntegerField()
    expense = BigIntegerField()
    ttype = IntegerField()

    class Meta:
        db_table = 'dw_fact_site_top_user_daily'
Exemple #11
0
class User(BaseModel):
    """
    Represents a user of the forum.
    """
    name = CharField(unique=True)
    password = CharField()
    role = CharField(default="user")
    is_enabled = BooleanField(default=True)
    email_address = CharField()
    created_on = DateTimeField(default=utc_datetime_now)
    modified_on = DateTimeField(default=utc_datetime_now)
    post_count = BigIntegerField(default=0)
    thread_count = BigIntegerField(default=0)
    notify_on_new_thread = BooleanField(default=False)
    notify_on_new_post = BooleanField(default=False)

    def sanitized_update(self, name, email_address):
        self.name = sanitize_markdown_input(name)
        self.email_address = sanitize_markdown_input(email_address)
Exemple #12
0
class CustomCommand(Model):
    id = AutoField()
    serverid = BigIntegerField()
    trigger = CharField(max_length=20, collation="utf8mb4_general_ci")
    response = CharField(max_length=2000, collation="utf8mb4_general_ci")
    deletetrigger = BooleanField(default=False)
    reply = BooleanField(default=False)

    class Meta:
        database = connection
Exemple #13
0
class Role(BaseModel):
    guild = ForeignKeyField(Guild)
    role_id = BigIntegerField()
    platform_id = IntegerField(null=True)
    is_sherpa = BooleanField(null=True)

    class Meta:
        indexes = (
            (('guild', 'role_id'), True),
        )
class Product(Base):
    code = BigIntegerField(primary_key=True)
    product_name = CharField(max_length=255)
    url = CharField(max_length=255, null=False)
    nutrition_grade_fr = CharField(max_length=1)
    brand = ForeignKeyField(Brand, backref="products")
    category = ForeignKeyField(Category, backref="products")

    class Meta:
        table_name = "product"
Exemple #15
0
class Reserve(BaseModel):
    id = PrimaryKeyField()
    period = CharField(help_text="期数")
    stage = IntegerField(help_text="阶段")
    step = IntegerField(help_text="位置")
    group = IntegerField(help_text="群 id")
    member = BigIntegerField(help_text="成员 id")

    class Meta:
        db_table = 'reserve'
Exemple #16
0
class Resource(Model):
    resource_id = UUIDField(unique=True)
    ref_count = IntegerField(default=0, index=True)
    is_downloading = BooleanField(default=False)
    size = BigIntegerField(default=0)

    class Meta:
        database = SqliteDatabase(os.path.join(DATA_CATALOG_DOWNLOAD_DIR,
                                               'dcat_read_func.db'),
                                  timeout=10)
Exemple #17
0
class Legacy_Survey_DR8(CatalogdbModel):

    ls_id = BigIntegerField(primary_key=True)
    ref_cat = TextField()
    ref_id = BigIntegerField()

    gaia = ForeignKeyField(Gaia_DR2,
                           column_name='gaia_sourceid',
                           object_id_name='gaia_sourceid',
                           backref='legacy_survey')

    tic = ForeignKeyField(TIC_v8,
                          field='gaia_int',
                          column_name='gaia_sourceid',
                          object_id_name='gaia_sourceid',
                          backref='+')

    class Meta:
        table_name = 'legacy_survey_dr8'
Exemple #18
0
class File(Model):
    path = CharField()
    size = BigIntegerField()
    completed = BooleanField(default=False)
    mediainfo = TextField()  #JSON
    torrent = ForeignKeyField(Torrent, backref='files')

    class Meta:
        database = db
        table_name = 'file'
class Reminder(BaseModel):
    user_name = CharField()
    tweet_id = BigIntegerField()
    created_on = DateField()
    remind_on = DateField()
    stock_symbol = CharField()
    stock_price = FloatField()

    class Meta:
        table_name = "reminders"
Exemple #20
0
class Design(TargetdbBase):
    field = ForeignKeyField(column_name='field_pk',
                            field='pk',
                            model=Field,
                            null=True)
    exposure = BigIntegerField(null=True)
    pk = AutoField()

    class Meta:
        table_name = 'design'
Exemple #21
0
class Message(BaseModel):
    id = BigIntegerField(primary_key=True)
    author = ForeignKeyField(column_name='author_id', model=User)
    channel = ForeignKeyField(column_name='channel_id', model=TextChannel)
    timestamp = DateTimeField()
    jump_url = CharField()
    was_deleted = BooleanField(default=False)

    class Meta:
        table_name = 'messages'
Exemple #22
0
class Paste(Model):
    source = CharField()
    paste_id = CharField()
    title = CharField()
    date = DateTimeField()
    email_count = BigIntegerField()

    class Meta:
        database = DB
        db_table = "pastes"
Exemple #23
0
class KrillByLines(Model):
    id = AutoField()
    krill_config = ForeignKeyField(KrillConfig, backref='bylines')
    byline = CharField(max_length=100, collation="utf8mb4_general_ci")
    type = SmallIntegerField(default=0)
    channelid = BigIntegerField(default=0)
    locale = CharField(max_length=10, default='')

    class Meta:
        database = connection
Exemple #24
0
class Transaction(Model):
    id = CharField(max_length=64, primary_key=True)
    version = SmallIntegerField()
    block_id = ForeignKeyField(Block)
    sequence = SmallIntegerField()
    timestamp = IntegerField(index=True)
    sender_public_key = CharField(max_length=66, index=True)
    recipient_id = ForeignKeyField(Wallet)
    type = SmallIntegerField()
    vendor_field_hex = BlobField(null=True)
    amount = BigIntegerField()
    fee = BigIntegerField()
    serialized = BlobField()

    class Meta:
        table_name = 'transactions'
        indexes = (
            (('sender_public_key', 'recipient_id', 'vendor_field_hex', 'timestamp'), False),
        )
Exemple #25
0
class Gaia_DR2(CatalogdbModel):

    source_id = BigIntegerField(primary_key=True)

    tmass_best = ManyToManyField(TwoMassPSC,
                                 through_model=_Gaia_DR2_TwoMass_Deferred,
                                 backref='gaia_best')

    class Meta:
        table_name = 'gaia_dr2_source'
Exemple #26
0
class Upload(LongIdPostModel):
    key = TextField(index=True,
                    help_text='哈希值')  # 为text的目的是兼容七牛等cdn站点,否则应该为blob
    size = BigIntegerField(help_text='图片文件大小')
    ext = TextField(null=True)
    type_name = TextField(null=True, default=None)
    image_info = BinaryJSONField(null=True, default=None)
    filename = TextField(null=True, index=True)
    source = TextField(null=True, index=True)

    class Meta:
        db_table = 'upload'

    @classmethod
    def get_by_key(cls, key: str):
        try:
            return cls.get(cls.key == key)
        except peewee.DoesNotExist:
            pass

    @classmethod
    def new_with_user(cls, user_id: bytes, hashes: bytes, filename: str,
                      filesize: int):
        key = to_hex(hashes)
        values = {
            'user_id': user_id,
            'key': key,
            'filename': filename,
            'size': filesize
        }
        return cls.new(**values)

    @classmethod
    def new(cls,
            user_id,
            key,
            size,
            ext=None,
            type_name=None,
            image_info=None,
            filename=None,
            source=None):
        # 之所以有key的情况下还有独立id,是因为上传是一个一对多的过程,多个用户可能上传同一张图片,那么key就相同
        return cls.create(user_id=user_id,
                          key=key,
                          size=int(size),
                          ext=ext,
                          type_name=type_name,
                          image_info=image_info,
                          source=source,
                          filename=filename)

    @classmethod
    def get_post_type(cls):
        return POST_TYPES.UPLOAD
Exemple #27
0
class AllWise_Lite(DeprecatedModel):

    cntr = BigIntegerField(primary_key=True)

    allwise = ForeignKeyField(AllWise, column_name='cntr', backref='+')

    tic = ForeignKeyField(TIC_v8,
                          field='allwise',
                          column_name='designation',
                          object_id_name='designation',
                          backref='+')
Exemple #28
0
class Gaia_DR2_Lite(DeprecatedModel):

    source_id = BigIntegerField(primary_key=True)

    gaia = ForeignKeyField(Gaia_DR2, column_name='source_id', backref='+')

    tic = ForeignKeyField(TIC_v8,
                          field='gaia_int',
                          column_name='source_id',
                          object_id_name='source_id',
                          backref='+')
Exemple #29
0
class Task(DataBaseModel):
    f_job_id = CharField(max_length=25)
    f_component_name = TextField()
    f_task_id = CharField(max_length=100)
    f_role = CharField(max_length=10, index=True)
    f_party_id = CharField(max_length=10, index=True)
    f_operator = CharField(max_length=100, null=True)
    f_run_ip = CharField(max_length=100, null=True)
    f_run_pid = IntegerField(null=True)
    f_status = CharField(max_length=50)
    f_create_time = BigIntegerField()
    f_update_time = BigIntegerField(null=True)
    f_start_time = BigIntegerField(null=True)
    f_end_time = BigIntegerField(null=True)
    f_elapsed = BigIntegerField(null=True)

    class Meta:
        db_table = "t_task"
        primary_key = CompositeKey('f_job_id', 'f_task_id', 'f_role',
                                   'f_party_id')
Exemple #30
0
class TESS_TOI(CatalogdbModel):

    pk = BigIntegerField(primary_key=True)

    tic = ForeignKeyField(TIC_v8,
                          column_name='ticid',
                          object_id_name='ticid',
                          backref='+')

    class Meta:
        table_name = 'tess_toi'