示例#1
0
class PostgresStorage(BaseModel, PrintStorage):
    """Storage container for Postgresql database."""

    date = DateTimeTZField()
    url = TextField(null=True)
    scheme = TextField(null=True)
    host = TextField(null=True)
    path = TextField(null=True)
    method = CharField(null=True)
    referrer = TextField(null=True)
    remote_addr = TextField(null=True)
    real_ip = CharField(null=True)
    forwarded_proto = CharField(null=True)
    connecting_ip = CharField(null=True)
    ip_country = CharField(null=True)
    visitor = TextField(null=True)
    status = IntegerField(null=True)
    args = PickleField(null=True)
    user_agent = PickleField(null=True)
    access_route = ArrayField(CharField, null=True)
    headers = PickleField(null=True)
    cookies = PickleField(null=True)
    speed = FloatField(null=True)

    class Meta:
        table_name = 'tracking'
示例#2
0
class ExperimentModel(BaseModel):
    cls_name = CharField()
    group = CharField()
    config = PickleField()
    parameters = PickleField()
    result = PickleField()
    derived = PickleField()
示例#3
0
    def __init__(self,
                 key_field=None,
                 value_field=None,
                 ordered=False,
                 database=None,
                 table_name='keyvalue'):
        if key_field is None:
            key_field = CharField(max_length=255, primary_key=True)
        if not key_field.primary_key:
            raise ValueError('key_field must have primary_key=True.')

        if value_field is None:
            value_field = PickleField()

        self._key_field = key_field
        self._value_field = value_field
        self._ordered = ordered
        self._database = database or SqliteExtDatabase(':memory:')
        self._table_name = table_name
        self._has_upsert = not isinstance(self._database, PostgresqlDatabase)

        self.model = self.create_model()
        self.key = self.model.key
        self.value = self.model.value

        # Ensure table exists.
        self.model.create_table()
示例#4
0
文件: kv.py 项目: vbsoftpl/peewee
    def __init__(self, key_field=None, value_field=None, ordered=False,
                 database=None, table_name='keyvalue'):
        if key_field is None:
            key_field = CharField(max_length=255, primary_key=True)
        if not key_field.primary_key:
            raise ValueError('key_field must have primary_key=True.')

        if value_field is None:
            value_field = PickleField()

        self._key_field = key_field
        self._value_field = value_field
        self._ordered = ordered
        self._database = database or SqliteExtDatabase(':memory:')
        self._table_name = table_name
        support_on_conflict = (isinstance(self._database, PostgresqlDatabase) or
                              (isinstance(self._database, SqliteDatabase) and
                               self._database.server_version >= (3, 24)))
        if support_on_conflict:
            self.upsert = self._postgres_upsert
            self.update = self._postgres_update
        else:
            self.upsert = self._upsert
            self.update = self._update

        self.model = self.create_model()
        self.key = self.model.key
        self.value = self.model.value

        # Ensure table exists.
        self.model.create_table()
示例#5
0
class Cache(flask_db.Model):
    code = pw.CharField(unique=True)
    content = PickleField()
    timestamp = pw.DateTimeField(default=dt.datetime.now, index=True)

    @property
    def expired(self):
        now = dt.datetime.now()
        return (now - self.timestamp).seconds >= TTL
示例#6
0
class Entry(BaseModel):
    """
    Class for definition and instantiation of Entry Obj

    classmethods create_entry

    """
    user = ForeignKeyField(

        model=User,
        backref='entries'
    )

    title = CharField(max_length=75)
    date = DateField(formats='%d/%m/%Y')
    time_spent = TimeField()
    knowledge = TextField()
    resources = PickleField()

    @classmethod
    def create_entry(
            cls, user, title, date, time_spent,
            knowledge, resources,
    ):
        """
        classmethod controls instantiation of models.Entry objects
        @param user: foreign key
        @type user: models.User
        @param title: Entry attr
        @type title: str
        @param date:Entry attr
        @type date: datetime.date
        @param time_spent: Entry attr
        @type time_spent: datetime.timedelta
        @param knowledge: Entry attr
        @type knowledge: str
        @param resources:Entry attr
        @type resources: List[str]
        """
        try:
            with cls._meta.database.transaction():
                cls.create(
                    user=user,
                    title=title,
                    date=date,
                    time_spent=time_spent,
                    knowledge=knowledge,
                    resources=resources
                )

        except InternalError:
            raise DatabaseError('could not create a entry: database failure')
示例#7
0
        class Trials(pw.Model):
            trial_id = pw.AutoField(primary_key=True)
            config_id = pw.CharField(default="")
            task_id = pw.CharField(default="")
            hdl_id = pw.CharField(default="")
            experiment_id = pw.IntegerField(default=0)
            estimator = pw.CharField(default="")
            loss = pw.FloatField(default=65535)
            losses = self.JSONField(default=[])
            test_loss = self.JSONField(default=[])
            all_score = self.JSONField(default={})
            all_scores = self.JSONField(default=[])
            test_all_score = self.JSONField(default={})
            models_path = pw.TextField(default="")
            final_model_path = pw.TextField(default="")
            # 都是将python对象进行序列化存储,是否合适?
            y_true_indexes = PickleField(default=0)
            y_preds = PickleField(default=0)
            y_test_true = PickleField(default=0)
            y_test_pred = PickleField(default=0)
            # --理论上测试集的结果是不可知的,这两个field由用户手动填写-----
            y_test_score = pw.FloatField(default=0)
            y_test_scores = self.JSONField(default={})
            # ------------被附加的额外信息---------------
            additional_info = self.JSONField(default={})
            # -------------------------------------
            smac_hyper_param = PickleField(default=0)
            dict_hyper_param = self.JSONField(default={})
            cost_time = pw.FloatField(default=65535)
            status = pw.CharField(default="SUCCESS")
            failed_info = pw.TextField(default="")
            warning_info = pw.TextField(default="")
            intermediate_result_path = pw.TextField(default=""),
            timestamp = pw.DateTimeField(default=datetime.datetime.now)
            user = pw.CharField(default=getuser)
            pid = pw.IntegerField(default=os.getpid)

            class Meta:
                database = self.trials_db
示例#8
0
class Misc(Model):
    """Store singular data (e.g. date for recurring action)

    Usable through the misc_data, instance of MiscData"""
    pk: T.Union[str, CharField] = CharField(primary_key=True)
    data: T.Any = PickleField()

    repr_data = {
        'ein': 'ein',
        'name': 'Interna',
        'id': 'Name'
    }
    str_fields = (pk,)
    pk_name = 'pk'
示例#9
0
class ReadingList(BaseModel):
    name = CharField()
    slug = CharField(primary_key=True)
    data = PickleField(null=True)
    comics = ManyToManyField(Comic,
                             backref="readinglists",
                             through_model=ComicIndexDeferred)
    cb_limit_active = BooleanField(null=True)
    limit_num = IntegerField(null=True)
    cb_only_read_active = BooleanField(null=True)
    cb_purge_active = BooleanField(null=True)
    cb_optimize_size_active = BooleanField(null=True)
    sw_syn_this_active = BooleanField(null=True)
    end_last_sync_num = IntegerField(default=0)
    totalCount = IntegerField()
示例#10
0
class Comic(BaseModel):
    Id = CharField(primary_key=True)
    Number = CharField()
    Series = CharField(null=True)
    Year = IntegerField(null=True)
    Month = IntegerField(null=True)
    UserLastPageRead = IntegerField()
    UserCurrentPage = IntegerField()
    PageCount = IntegerField()
    Summary = TextField(null=True)
    FilePath = CharField(null=True)
    Volume = CharField(null=True)
    data = PickleField(null=True)
    local_file = CharField(null=True)
    is_sync = BooleanField(default=False)
    been_sync = BooleanField(default=False)
示例#11
0
class Pickled(TestModel):
    key = TextField()
    data = PickleField()