예제 #1
0
파일: models.py 프로젝트: gis-support/cloud
class Project(BaseModel):
    class Meta:
        schema = "system"

    id = AutoField(primary_key=True)
    name = TextField()
    owner_name = TextField()
    active_layer_id = TextField()
    additional_layers_ids = BinaryJSONField(default=[])
    service_layers_ids = BinaryJSONField(default=[])
    map_center = GeometryField("point", 4326)
    map_zoom = IntegerField()

    @classmethod
    def update_active_layer_id(cls, old_layer_id: str, new_layer_id: str):
        cls.update(active_layer_id=new_layer_id).where(
            cls.active_layer_id == old_layer_id).execute()

    @classmethod
    def update_additional_layers_ids(cls, old_layer_id: str,
                                     new_layer_id: str):
        cls.update(additional_layers_ids=Cast(
            fn.REPLACE(Cast(cls.additional_layers_ids, "text"), old_layer_id,
                       new_layer_id), "jsonb")).execute()

    @classmethod
    def delete_additional_layer_id(cls, layer_id: str):
        database.execute_sql(
            """
        UPDATE system.project SET additional_layers_ids = additional_layers_ids-%s;
        """, (layer_id, ))
예제 #2
0
class problem(BaseModel):
    ID = IntegerField(primary_key=True)
    is_public = BooleanField()
    title = TextField()
    description = TextField()
    input_description = TextField()
    output_description = TextField()
    samples = BinaryJSONField()
    test_case_score = BinaryJSONField()
    hint = TextField()
    languages = BinaryJSONField()
    template = BinaryJSONField()
    create_time = TimestampField()
    last_update_time = TimestampField()
    time_limit = IntegerField()
    memory_limit = IntegerField()
    difficulty = IntegerField()
    source = TextField()
    total_score = IntegerField()
    submission_number = BigIntegerField()
    accepted_number = BigIntegerField()
    statistic_info = BinaryJSONField()
    created_by_id = CharField(max_length=50)

    class Meta:
        db_table = "problem"
예제 #3
0
class LogoAnnotation(BaseModel):
    """Annotation(s) for an image prediction
    (an image prediction might lead to several annotations)

    At the moment, this is mostly for logo (see run_object_detection),
    when we have a logo prediction above a certain threshold we create an entry,
    to ask user for annotation on the logo (https://hunger.openfoodfacts.org/logos)
    and eventual annotation will land there.
    """

    image_prediction = peewee.ForeignKeyField(ImagePrediction,
                                              null=False,
                                              backref="logo_detections")
    index = peewee.IntegerField(null=False,
                                constraints=[peewee.Check("index >= 0")])
    bounding_box = BinaryJSONField(null=False)
    score = peewee.FloatField(null=False)
    annotation_value = peewee.CharField(null=True, index=True)
    annotation_value_tag = peewee.CharField(null=True, index=True)
    taxonomy_value = peewee.CharField(null=True, index=True)
    annotation_type = peewee.CharField(null=True, index=True)
    username = peewee.TextField(null=True, index=True)
    completed_at = peewee.DateTimeField(null=True, index=True)
    nearest_neighbors = BinaryJSONField(null=True)

    class Meta:
        constraints = [peewee.SQL("UNIQUE(image_prediction_id, index)")]

    def get_crop_image_url(self) -> str:
        return crop_image_url(self.image_prediction.image.source_image,
                              self.bounding_box)
예제 #4
0
class Event(Model):
    id: int = PrimaryKeyField()
    received: datetime = DateTimeField(default=fn.now)

    received_from: Server = ForeignKeyField(Server,
                                            null=True,
                                            on_update='cascade')
    """
    Server that we got this Event from.
    In general, this has nothing to do with which server produced the event originally.
    """

    server: str = TextField()
    """Name of the server on which the post affected by this event is published."""

    authors: List[str] = ArrayField(TextField)
    """Name of the user who should be the «owner» of the post."""

    parent: str = TextField(null=True)
    """Full identifier of parent post."""

    path: str = TextField(null=True)
    """
    Identification of the post affected by this event.
    This is the same path as in :data:`Post.path`.
    """

    diff: Dict[str, Any] = BinaryJSONField(
        default={}, constraints=[Check("jsonb_typeof(diff) = 'object'")])
    """Changes which should be applied to the post."""

    signatures: Dict[str, str] = BinaryJSONField(
        default={}, constraints=[Check("jsonb_typeof(signatures) = 'object'")])
    """
예제 #5
0
 class MLModel(Base):
     id = AutoField()
     name = CharField(unique=True)
     type = CharField()
     resource = CharField()
     extra_params = BinaryJSONField(null=True)  # used for additional metadata specific to a given type of model
     model_params = BinaryJSONField(null=False)  # used for model parameters and weights serializable to JSON
     extra_data = BlobField(null=True)  # for model parameters/weights serializable to specific file format (e.g. h5)
예제 #6
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
예제 #7
0
class Keywords(db.Model):
    keyword = CharField(max_length=48, unique=True)
    images = BinaryJSONField()
    images_meta = BinaryJSONField()
    updated_at = DateTimeField(default=generate_utcnow_str)

    def to_dict(self):
        result = model_to_dict(self, recurse=False)
        result["updated_at"] = str(result["updated_at"]) + "+00:00"
        return result
예제 #8
0
class Transaction(BaseModel):
    txid = CharField(max_length=64, unique=True, index=True)
    block = CharField(max_length=64, null=True, index=True)
    block_height = IntegerField(null=True)
    timestamp = DateTimeField(index=True)
    vin = BinaryJSONField()
    addresses_in = BinaryJSONField()
    addresses_out = BinaryJSONField()
    vout = BinaryJSONField()
    input_value = BigIntegerField()
    output_value = BigIntegerField()
예제 #9
0
class m(BaseModel):
    '''
    create by bigzhu at 15/12/09 15:33:04 直接存message
    '''
    id_str = TextField(null=True)  # 外部的id
    m_type = TextField()  # twitter or instagram or github
    m_user_id = TextField()  # 对应的社交帐号的user_id
    created_at = DateTimeField()
    content = BinaryJSONField(null=True)  # 带结构的内容github
    text = TextField(null=True)  # 文本内容
    extended_entities = BinaryJSONField(null=True)  # 扩展内容,图片什么
    href = TextField(null=True)  # message 的link
    type = TextField(null=True)  # media type
예제 #10
0
class Machine(Model):
    name = CharField(index=True, unique=True)
    dataset = BinaryJSONField()
    model = BinaryJSONField()
    metadata = BinaryJSONField()

    class Meta:
        primary_key = False
        database = db
        table_name = "machine"

    def __repr__(self):
        return f"Machine {self.__data__} "
예제 #11
0
class Evaluation(BaseModel):
    """Evaluation model"""
    round = ForeignKeyField(Round, related_name='evaluations')
    team = ForeignKeyField(Team, related_name='evaluations')
    ids = BinaryJSONField()
    cbs = BinaryJSONField()

    @classmethod
    def update_or_create(cls, round_, team, **kwargs):
        """Update or create evaluation"""
        update = cls.update(updated_at=datetime.now(),
                            **kwargs).where(cls.round == round_,
                                            cls.team == team)
        if update.execute() == 0:
            cls.create(round=round_, team=team, **kwargs)
예제 #12
0
class Machine(Model):
    name = CharField(index=True, unique=True)
    metadata = BinaryJSONField()
    train_start_date = DateTimeTZField()
    train_end_date = DateTimeTZField()

    class Meta:
        database = db

    @classmethod
    def from_endpoint(cls, ep):
        """
        Returns a Machine object constructed from a valid endpoint.

        Parameters
        ----------
        ep: Dict
            Endpoint from watchman

        Returns
        -------
        Machine

        """
        return cls(**endpoint_to_machine_data(ep))

    def __repr__(self):
        return f"Machine {self.__data__} "
예제 #13
0
class Transactions(BaseModel):
    client = peewee.ForeignKeyField(Client, null=False, backref='transactions')
    amount = peewee.DecimalField(12, 2, null=False)
    currency = peewee.CharField(null=False)
    opened = peewee.DateTimeField()
    closed = peewee.DateTimeField()
    result = BinaryJSONField()
예제 #14
0
파일: core_tab.py 프로젝트: spacefan/TorCMS
class TabMember(BaseModel):
    '''
    role:  the index and value should not greater than 3.
    "0123"
    read,add,edit,delete,manage
    [0]: for wiki, and post editing.
    [1]: post create, and management.
    [2]: keep
    [3]: keep
    And, could be extended.
    The Value:
    0: for view
    1: for basic editing
    2: for management
    3:
    '''
    uid = peewee.CharField(null=False, index=True, unique=True,
                           primary_key=True, max_length=36, help_text='', )
    user_name = peewee.CharField(null=False, index=True,
                                 unique=True, max_length=16, help_text='User Name', )
    user_email = peewee.CharField(null=False, unique=True,
                                  max_length=255, help_text='User Email', )
    user_pass = peewee.CharField(null=False, max_length=255,
                                 help_text='User Password')
    role = peewee.CharField(null=False, default='1000',
                            help_text='Member Privilege', max_length='4')
    time_reset_passwd = peewee.IntegerField(null=False, default=0)
    time_login = peewee.IntegerField(null=False, default=0)
    time_create = peewee.IntegerField(null=False, default=0)
    time_update = peewee.IntegerField(null=False, default=0)
    time_email = peewee.IntegerField(null=False, default=0, help_text='Time auto send email.')
    extinfo = BinaryJSONField(null=False, default={}, help_text='Extra data in JSON.')
예제 #15
0
class ImagePrediction(BaseModel):
    """Table to store computer vision predictions (object detection,
    image segmentation,...) made by custom models.

    They are created by api `ImagePredictorResource`, `ImagePredictionImporterResource`
    or cli `import_logos`

    Predictions come from a model, from settings `OBJECT_DETECTION_TF_SERVING_MODELS`
    this can be a nutriscore, a logo, etc...
    """

    type = peewee.CharField(max_length=256)
    model_name = peewee.CharField(max_length=100, null=False, index=True)
    model_version = peewee.CharField(max_length=256, null=False, index=True)
    data = BinaryJSONField(index=True)
    timestamp = peewee.DateTimeField(null=True)
    image = peewee.ForeignKeyField(ImageModel,
                                   null=False,
                                   backref="predictions")
    max_confidence = peewee.FloatField(
        null=True,
        index=True,
        help_text=
        "for object detection models, confidence of the highest confident"
        "object detected, null if no object was detected",
    )
예제 #16
0
class Block(BaseModel):
    height = IntegerField(index=True)
    hash = CharField(max_length=64, unique=True, index=True)
    timestamp = DateTimeField(index=True)
    merkle_root = CharField(max_length=64, unique=True)
    tx = BinaryJSONField()
    difficulty = FloatField()
    size = IntegerField()
    version = BlobField()
    bits = BlobField()
    nonce = BigIntegerField()
    coinbase = BlobField()
    tx_count = IntegerField()
    orphaned = BooleanField(default=False, index=True)

    def to_json(self):
        pool = None
        cb = bytes(self.coinbase)
        for key, value in POOLS.items():
            if cb.find(key.encode()) != -1:
                pool = value
        return {
            'height': self.height,
            'hash': self.hash,
            'timestamp': int(self.timestamp.timestamp()),
            'merkle_root': self.merkle_root,
            'tx': self.tx,
            'difficulty': self.difficulty,
            'size': self.size,
            'version_hex': bytes(self.version).hex(),
            'version': struct.unpack('i', bytes(self.version))[0],
            'bits': bytes(self.bits).hex(),
            'nonce': self.nonce,
            'pool': pool
        }
예제 #17
0
파일: event.py 프로젝트: elderlabs/jetski
class Event(BaseModel):
    session = CharField()
    seq = BigIntegerField()

    timestamp = DateTimeField(default=datetime.utcnow)
    event = CharField()
    data = BinaryJSONField()

    class Meta:
        table_name = 'events'
        primary_key = CompositeKey('session', 'seq')
        indexes = (
            (('timestamp', ), False),
            (('event', ), False),
        )

    @classmethod
    def truncate(cls, hours=12):
        return cls.delete().where(
            (cls.timestamp <
             (datetime.utcnow() - timedelta(hours=hours)))).execute()

    @classmethod
    def prepare(cls, session, event):
        return {
            'session': session,
            'seq': event['s'],
            'timestamp': datetime.utcnow(),
            'event': event['t'],
            'data': event['d'],
        }
예제 #18
0
class Upload(LongIdPostModel):
    id = BlobField(primary_key=True)
    key = TextField(index=True)
    size = BigIntegerField()
    ext = TextField(null=True)
    type_name = TextField(null=True, default=None)
    image_info = BinaryJSONField(null=True, default=None)

    class Meta:
        db_table = 'upload'

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

    @classmethod
    def get_post_type(cls):
        return POST_TYPES.UPLOAD
예제 #19
0
파일: core_tab.py 프로젝트: 662d7/TorCMS
class g_Post(BaseModel):
    uid = peewee.CharField(
        null=False,
        index=True,
        unique=True,
        primary_key=True,
        default='00000',
        max_length=5,
        help_text='',
    )
    title = peewee.CharField(null=False, help_text='Title')
    keywords = peewee.CharField(null=False, default='', help_text='Keywords')
    date = peewee.DateTimeField(null=False, help_text='')
    time_create = peewee.IntegerField()
    user_name = peewee.CharField(
        null=False,
        default='',
        max_length=36,
        help_text='UserName',
    )
    time_update = peewee.IntegerField()
    view_count = peewee.IntegerField()
    logo = peewee.CharField(default='')
    valid = peewee.IntegerField(null=False,
                                default=1,
                                help_text='Whether the infor would show.')
    cnt_md = peewee.TextField()
    cnt_html = peewee.TextField()
    kind = peewee.CharField(
        null=False,
        max_length=1,
        default='1',
        help_text='Post type: 1 for doc, 2 for inor',
    )
    extinfo = BinaryJSONField(default={})
예제 #20
0
class Document(BaseModel):

    # TODO: Include manifest data.

    path = CharField(unique=True)
    metadata = BinaryJSONField(default={})

    class Meta:
        database = config.get_table_db('document')

    @classmethod
    def insert_documents(cls):
        """
        Insert a document row for each syllabus in the corpus.
        """

        for syllabus in Corpus.from_env().syllabi_bar():
            try:
                cls.create(path=syllabus.relative_path)
            except:
                pass

    @property
    def syllabus(self):
        """
        Wrap the row as an OSP Syllabus instance.
        """

        return Syllabus.from_env(self.path)
예제 #21
0
def run_migrate(*args):
    '''
    running some migration.
    :return:
    '''

    print('Begin migrate ...')

    torcms_migrator = migrate.PostgresqlMigrator(config.DB_CON)

    memo_field = migrate.TextField(null=False, default='', help_text='Memo', )
    try:
        migrate.migrate(torcms_migrator.add_column('tabpost', 'memo', memo_field))
    except:
        pass

    desc_field = migrate.CharField(null=False, default='', max_length=255, help_text='')
    try:
        migrate.migrate(torcms_migrator.add_column('tabentity', 'desc', desc_field))
    except:
        pass

    extinfo_field = BinaryJSONField(null=False, default={}, help_text='Extra data in JSON.')
    try:
        migrate.migrate(torcms_migrator.add_column('tabmember', 'extinfo', extinfo_field))
    except:
        pass

    print('Migration finished.')
예제 #22
0
파일: ext_tab.py 프로젝트: lxxgreat/TorCMS
class TabApp(BaseModel):
    uid = peewee.CharField(max_length=4,
                           null=False,
                           unique=True,
                           help_text='',
                           primary_key=True)
    title = peewee.CharField(
        null=False,
        help_text='标题',
    )
    keywords = peewee.CharField(null=True, default='')
    user_name = peewee.CharField(
        null=False,
        default='',
        max_length=36,
        help_text='UserName',
    )
    logo = peewee.CharField(default='')
    date = peewee.DateTimeField(null=False, help_text='显示出来的日期时间')
    run_count = peewee.IntegerField(null=False, default=0, help_text='运行次数')
    view_count = peewee.IntegerField(null=False, default=0, help_text='查看次数')
    run_time = peewee.IntegerField(null=False, default=0, help_text='上次运行时间')
    create_time = peewee.IntegerField(null=False, default=0, help_text='创建时间')
    time_update = peewee.IntegerField(null=False, default=0, help_text='更新时间')
    type = peewee.IntegerField(null=False, default=1)
    html_path = peewee.CharField(default='')
    cnt_md = peewee.TextField(null=True)
    cnt_html = peewee.TextField(null=True)
    extinfo = BinaryJSONField()
예제 #23
0
class Invoice(BaseModel):
    id = peewee.CharField(primary_key=True, max_length=28)
    serial_number = peewee.IntegerField()
    amount = peewee.IntegerField()
    status = peewee.CharField()
    payment_method = peewee.CharField()
    type = peewee.CharField()
    period_start_date = DateTimeTZField()
    period_end_date = DateTimeTZField()
    metadata = BinaryJSONField()

    class Meta:
        db_table = "Invoices"

    @classmethod
    def format_from_response(cls, data):
        return dict(
            id=data["id"],
            serial_number=data["serial_number"],
            amount=data["amount"],
            status=data["status"],
            payment_method=data["payment_method"],
            type=data["type"],
            period_start_date=time_utils.from_iso(data["period_start_date"]),
            period_end_date=time_utils.from_iso(data["period_end_date"]),
            metadata=data["metadata"])
예제 #24
0
파일: sql_models.py 프로젝트: mindis/LiveAI
class EventStatus(SQLModel):
    _id = TextField(primary_key=True, unique=True, default=uuid_generater())
    data = BinaryJSONField(dumps=None)
    created_at = DateTimeField(default=datetime.now(JST))

    class Meta:
        db_table = 'event_status'
예제 #25
0
class Stats(BaseModel):
    trending_region = ForeignKeyField(Region, null=True)
    video = ForeignKeyField(Video, backref='stats')
    stats = BinaryJSONField(default={})

    class Meta:
        indexes = ((('video', 'trending_region'), True), )
예제 #26
0
class Transfer(BaseModel):
    id = peewee.IntegerField(primary_key=True)
    status = peewee.CharField()
    amount = peewee.IntegerField()
    fee = peewee.IntegerField()
    type = peewee.CharField()
    transaction_id = peewee.IntegerField(null=True)
    recipient_id = peewee.CharField(max_length=28, null=True)
    created_at = DateTimeTZField()
    source_type = peewee.CharField()
    source_id = peewee.CharField(max_length=28)
    target_type = peewee.CharField()
    target_id = peewee.CharField(max_length=28)
    metadata = BinaryJSONField(null=True, default={})

    class Meta:
        db_table = "Transfers"

    @classmethod
    def format_from_response(cls, data):
        return dict(id=data["id"],
                    status=data["status"],
                    amount=data["amount"],
                    fee=data["fee"],
                    type=data["type"],
                    transaction_id=data["transaction_id"],
                    recipient_id=data["source_id"],
                    created_at=time_utils.from_iso(data["date_created"]),
                    source_type=data["source_type"],
                    source_id=data["source_id"],
                    target_type=data["target_type"],
                    target_id=data["target_id"],
                    metadata=data["metadata"],
                    bank_account=data["bank_account"])
예제 #27
0
class Statistic24hLog(BaseModel):
    id = BlobField(primary_key=True)
    time = MyTimestampField(index=True)
    data = BinaryJSONField(dumps=json_ex_dumps)

    class Meta:
        db_table = 'statistic24h_log'
예제 #28
0
class InventoryHosts(BaseModel):
    """inventory.hosts cyndi view"""
    id = UUIDField(null=False, primary_key=True)
    account = CharField(null=False, max_length=10)
    display_name = CharField(null=False, max_length=200)
    created = DateTimeField(null=False)
    updated = DateTimeField(null=False)
    stale_timestamp = DateTimeField(null=False)
    stale_warning_timestamp = DateTimeField(null=False)
    culled_timestamp = DateTimeField(null=False)
    tags = BinaryJSONField(null=False)
    system_profile = BinaryJSONField(null=False)

    class Meta:
        """inventory.hosts view metadata"""
        schema = "inventory"
        table_name = "hosts"
예제 #29
0
 class Object(pw.Model):
     array_field = ArrayField()
     binary_json_field = BinaryJSONField()
     dattime_tz_field = DateTimeTZField()
     hstore_field = HStoreField()
     interval_field = IntervalField()
     json_field = JSONField()
     ts_vector_field = TSVectorField()
예제 #30
0
파일: models.py 프로젝트: anti1869/aeroport
class Destination(BaseModel):
    """
    Persistent layer for destination settings.
    """
    class_name = peewee.CharField()
    name = peewee.CharField(index=True)
    enabled = peewee.BooleanField()
    settings = BinaryJSONField()