class Car(peewee.Model): id = peewee.AutoField(primary_key=True) title = peewee.CharField(max_length=250) model = peewee.ForeignKeyField(CarModel, backref='cars', on_delete='CASCADE', on_update='CASCADE') year = peewee.IntegerField() kilometerage = peewee.BigIntegerField(verbose_name='Пробег') color = peewee.CharField(max_length=30) volume = peewee.DecimalField() fuel_type = peewee.CharField(max_length=30, verbose_name='Тип топлива') wheel_drive = peewee.CharField(max_length=20, verbose_name='Привод') gear_box = peewee.CharField(max_length=30, verbose_name='Коробка передач') wheel_position = peewee.CharField(max_length=10, verbose_name='Расположение руля') description = peewee.TextField() price = peewee.IntegerField() phone = peewee.CharField(20) created_at = peewee.DateTimeField(default=datetime.datetime.now()) owner = peewee.ForeignKeyField(User, backref='cars', on_delete='CASCADE', on_update='CASCADE') class Meta: database = database table_name = 'cars'
class File(BaseModel): id = peewee.AutoField(primary_key=True) path = peewee.TextField() contents = peewee.BlobField() mime_type = peewee.TextField(null=True) info = peewee.TextField(null=True, help_text="Output of `file`") service = peewee.ForeignKeyField(Service, backref='files', on_delete='CASCADE')
class Role(pw.Model): id = pw.AutoField() description = pw.TextField(null=True) name = pw.CharField(max_length=255, unique=True) class Meta: table_name = "role"
class Classifier(BaseModel): """. Attributes: name: Name of classiifer. category_names: Comma separated names of categories. Means category names can't have commas. trained_by_openFraming: Whether this is a classifier that openFraming provides, or a user trained. train_set: The train set for classififer. dev_set: The dev set for classififer. """ @classmethod def create( # type: ignore[override] cls, name: str, category_names: T.List[str], notify_at_email: str) -> "Classifier": """Mypy can't type check creation wihtout this.""" return super(Classifier, cls).create(name=name, category_names=category_names, notify_at_email=notify_at_email) classifier_id: int = pw.AutoField(primary_key=True) # type: ignore name: str = pw.TextField() # type: ignore category_names: T.List[str] = ListField() # type: ignore trained_by_openFraming: bool = pw.BooleanField( default=False) # type: ignore train_set: T.Optional[LabeledSet] = pw.ForeignKeyField( LabeledSet, null=True) # type: ignore notify_at_email: str = pw.TextField() # type: ignore dev_set: T.Optional[LabeledSet] = pw.ForeignKeyField( LabeledSet, null=True) # type: ignore test_sets: T.Iterable["TestSet"] # provided by backref on TestSet
class TopicModel(BaseModel): """.""" @classmethod def create( # type: ignore[override] cls, name: str, num_topics: int, notify_at_email: str, topic_names: T.List[str]) -> "TopicModel": assert len(topic_names) == num_topics return super(TopicModel, cls).create( name=name, num_topics=num_topics, notify_at_email=notify_at_email, topic_names=topic_names, ) id_: int = pw.AutoField() name: str = pw.CharField() num_topics: int = pw.IntegerField() topic_names: T.List[str] = ListField(null=True) # type: ignore lda_set: T.Optional[LDASet] = pw.ForeignKeyField(LDASet, null=True) # type: ignore notify_at_email: str = pw.TextField() # type: ignore # NOTE: The below is ONLY a type annotation. # The actual attribute is made available using "backreferences" in peewee semi_supervised_sets: T.Type["SemiSupervisedSet"] @property # https://github.com/coleifer/peewee/issues/1667#issuecomment-405095432 def semi_supervised_set(self) -> "SemiSupervisedSet": return self.semi_supervised_sets.get() # type: ignore
class UserUnreadMessage(pw.Model): id = pw.AutoField() uid = pw.ForeignKeyField(db_column="uid", model=User, field="uid") mid = pw.ForeignKeyField(db_column="mid", model=Message, field="mid") class Meta: table_name = "user_unread_message"
class Experiments(pw.Model): experiment_id = pw.AutoField(primary_key=True) general_experiment_timestamp = pw.DateTimeField( default=datetime.datetime.now) current_experiment_timestamp = pw.DateTimeField( default=datetime.datetime.now) hdl_id = pw.CharField(default="") task_id = pw.CharField(default="") hdl_constructors = self.JSONField(default=[]) hdl_constructor = pw.TextField(default="") raw_hdl = self.JSONField(default={}) hdl = self.JSONField(default={}) tuners = self.JSONField(default=[]) tuner = pw.TextField(default="") should_calc_all_metric = pw.BooleanField(default=True) data_manager_path = pw.TextField(default="") resource_manager_path = pw.TextField(default="") column_descriptions = self.JSONField(default={}) column2feature_groups = self.JSONField(default={}) dataset_metadata = self.JSONField(default={}) metric = pw.CharField(default=""), splitter = pw.CharField(default="") ml_task = pw.CharField(default="") should_store_intermediate_result = pw.BooleanField(default=False) fit_ensemble_params = pw.TextField(default="auto"), should_finally_fit = pw.BooleanField(default=False) additional_info = self.JSONField( default={}) # additional_info 应该存储在trials中 user = pw.CharField(default=getuser) class Meta: database = self.experiments_db
class Models(BaseModel): id = pv.AutoField() # Use auto-increment instead of time in Epoch seconds to ensure uniqueness name = pv.TextField(unique=True) flds = X1fField() css = pv.TextField(default="") def get_sfld_key(self): # we assume there's only one collection and everything is consistent col = Col.get() model_def = col.models.get(str(self.id), {}) for field in model_def['flds']: if field['sticky']: return field['name'] def fix_sfld_key(self): # we assume there's only one collection and everything is consistent col = Col.get() model_def = col.models.get(str(self.id), {}) first_field_def = None sticky_field = None for field in model_def['flds']: if not first_field_def: first_field_def = field if field['sticky']: sticky_field = field['name'] break if not sticky_field and first_field_def: first_field_def['sticky'] = True col.models[str(self.id)]['flds'][0] = first_field_def col.save()
class Image(IllusionDb): id = pw.AutoField() path = pw.CharField(max_length=4096, index=True, unique=True) md5 = pw.CharField( index=True ) # do not make this unique. this will be used to find duplicates faces_detected = pw.BooleanField(default=False) tags_detected = pw.BooleanField(default=False) @classmethod def create_image(cls, path=None, md5=None): if isinstance(path, Path): path = str(path.resolve()) return cls.create(path=path, md5=md5) @classmethod def get_image_if_exists(cls, id=None, path=None): if isinstance(path, Path): path = str(path.resolve()) try: if id is not None: return cls.get(id=id) if path is not None: return cls.get(path=path) except: return None @classmethod def get_all_images(cls): return cls.select() @classmethod def get_tags(cls, image_id): return cls.get_image_if_exists(id=image_id).tags
class Task(BaseModel): task_id = pw.AutoField() title = pw.CharField(max_length=255, help_text='Title of the task') description = pw.TextField(help_text='Description of the task', default='') status = pw.CharField(max_length=20, choices=[ "planned", "in_progress", "blocked", "completed", "abandoned" ], null=True, index=True) created_time = pw.DateTimeField( formats=['%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'], help_text='DateTime when task was created') start_time = pw.DateTimeField( formats=['%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'], help_text='DateTime when task was started', null=True) completed_time = pw.DateTimeField( formats=['%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'], help_text='DateTime when task was completed', null=True) due_date = pw.DateField( formats=['%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'], index=True, help_text='Date when task is due', null=True) last_updated_time = pw.DateTimeField( formats=['%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'], help_text='DateTime when task was updated', default=dt.datetime.now) expected_num_hours = pw.IntegerField( help_text='Expected number of hours to finish the task', default=None)
class SteamGame(pw.Model): id = pw.AutoField() label = pw.CharField(max_length=250) steam_app_id = pw.IntegerField() class Meta: table_name = "steamgame"
class RevisionAnswer(pw.Model): id = pw.AutoField() datetime = pw.DateTimeField() expected_ease = pw.IntegerField() chosen_ease = pw.IntegerField() card_due = pw.DateField() card_new_ivl = pw.DecimalField(auto_round=False, decimal_places=5, max_digits=10, rounding=ROUND_HALF_EVEN) card_old_ivl = pw.DecimalField(auto_round=False, decimal_places=5, max_digits=10, rounding=ROUND_HALF_EVEN) card_new_factor = pw.DecimalField(auto_round=False, decimal_places=5, max_digits=10, rounding=ROUND_HALF_EVEN) card_old_factor = pw.DecimalField(auto_round=False, decimal_places=5, max_digits=10, rounding=ROUND_HALF_EVEN) time_taken = pw.IntegerField() early = pw.BooleanField() rollover_hour = pw.IntegerField() class Meta: table_name = "revisionanswer"
class Notification(pw.Model): id = pw.AutoField() type = pw.CharField(max_length=255) sub = pw.ForeignKeyField(backref='notification_set', column_name='sid', field='sid', model=migrator.orm['sub'], null=True) post = pw.ForeignKeyField(backref='notification_set', column_name='pid', field='pid', model=migrator.orm['sub_post'], null=True) comment = pw.ForeignKeyField(backref='notification_set', column_name='cid', field='cid', model=migrator.orm['sub_post_comment'], null=True) sender = pw.ForeignKeyField(backref='notification_set', column_name='sentby', field='uid', model=migrator.orm['user'], null=True) target = pw.ForeignKeyField(backref='notification_set', column_name='receivedby', field='uid', model=migrator.orm['user'], null=True) read = pw.DateTimeField(null=True) content = pw.TextField(null=True) created = pw.DateTimeField() class Meta: table_name = "notification"
class Personne(BaseModel): id_personne = peewee.AutoField(primary_key=True) sexe = peewee.CharField(5) tranche_age = peewee.CharField(20) statut_social = peewee.CharField(12) id_consommation = peewee.ForeignKeyField(Consommation) id_foyer = peewee.ForeignKeyField(Foyer)
class Note(BaseModel): id = pw.AutoField() uuid = pw.UUIDField() title = pw.CharField(max_length=256) create_time = pw.TimestampField() update_time = pw.TimestampField() content = pw.TextField()
class Tag(IllusionDb): id = pw.AutoField() name = pw.CharField(index=True) @classmethod def get_tag_name(cls, tag_id): tag = cls.get(id=tag_id) return tag.name @classmethod def get_tag(cls, id=None, name=None): if id is not None: tag = cls.get(id=id) elif name is not None: tag = cls.get(name=name) else: raise ValueError("Either `id` or `name` should be provided") return tag @classmethod def get_or_create(cls, name): try: tag = cls.get(name=name) except: # TagDoesNotExist: tag = cls.create(name=name) return tag
class SubUserFlair(pw.Model): id = pw.AutoField() user = pw.ForeignKeyField( backref="subuserflair_set", column_name="uid", field="uid", model=migrator.orm["user"], ) sub = pw.ForeignKeyField( backref="subuserflair_set", column_name="sid", field="sid", model=migrator.orm["sub"], ) flair = pw.CharField(max_length=25) flair_choice = pw.ForeignKeyField( backref="subuserflair_set", column_name="flair_choice_id", field="id", model=migrator.orm["sub_user_flair_choice"], null=True, ) class Meta: table_name = "sub_user_flair"
class ArticleContent(base_model.BaseModel): content_id = peewee.AutoField(primary_key=True) article_id = peewee.BigIntegerField() content = peewee.TextField() class Meta: db_table = "app_article_content" @classmethod def get_content_by_article_id(cls, article_id): try: return ArticleContent.get(ArticleContent.article_id == article_id) except User.DoesNotExist: return None @classmethod def create_content(cls, data): cls.create(**data) @classmethod def update_content_by_article_id(cls, article_id, data): cls.update(**data).where(cls.article_id == article_id).execute() @classmethod def delete_content_by_article_id(cls, article_id): cls.delete().where(cls.article_id == article_id).execute()
class JudgmentElement(BaseModel): id = pw.AutoField() case = pw.ForeignKeyField(Case, backref='judgement_elements') content = pw.CharField() parent_element = pw.IntegerField(null=True) is_paragraph = pw.BooleanField() section_name = pw.CharField(null=True)
class UserRoles(pw.Model): id = pw.AutoField() role = pw.ForeignKeyField(backref='users', column_name='role_id', field='id', model=migrator.orm['role']) user = pw.ForeignKeyField(backref='roles', column_name='user_id', field='id', model=migrator.orm['users']) class Meta: table_name = "userroles"
class Playlist(peewee.Model): PlaylistId = peewee.AutoField() Name = peewee.CharField(index=True) Path = peewee.CharField() class Meta: database = database_context
class Owner(pw.Model): id = pw.AutoField() name = pw.CharField(max_length=256, unique=True) tel = pw.DecimalField(auto_round=False, decimal_places=0, max_digits=10, rounding=ROUND_HALF_EVEN) class Meta: table_name = "owner"
class TestSet(BaseModel): """This will be a prediction set. Attributes: id: set id. classifier: The classifier this set is intended for. name: User given name of the set. inference_completed: Whether the training or the inference has completed this set. error_encountered: Whether error was encontered during inference. """ @classmethod def create(cls, name: str, classifier: Classifier, notify_at_email: str) -> "TestSet": # type: ignore[override] return super(TestSet, cls).create(name=name, classifier=classifier, notify_at_email=notify_at_email) # TODO: The primary key here should be composite of classifier and id field. # Right now, we have checks in app.py to make sure a certain classifier id/test set # id combo exists, but that's not good design at all. id_: int = pw.AutoField(primary_key=True) # type: ignore classifier: Classifier = pw.ForeignKeyField( Classifier, backref="test_sets") # type: ignore name: str = pw.CharField() # type: ignore notify_at_email: str = pw.TextField() # type: ignore inference_began: bool = pw.BooleanField(default=False) # type: ignore error_encountered: bool = pw.BooleanField(default=False) # type: ignore inference_completed: bool = pw.BooleanField(default=False) # type: ignore
class Plan(pw.Model): id = pw.AutoField() name = pw.TextField() memory = pw.IntegerField() class Meta: table_name = "plan"
class CredentialBag(BaseModel): id = peewee.AutoField(primary_key=True) username = peewee.CharField(max_length=100) password = peewee.CharField(max_length=100) def __str__(self): return "{}:{}".format(self.username, self.password)
class Customer(BaseModel): id = pw.AutoField(primary_key=True) customer_number = pw.CharField(column_name="customernumber", max_length=30) firstname = pw.CharField(max_length=100) surname = pw.CharField(max_length=100) username = pw.CharField(max_length=30) dob = pw.DateField()
class Event(pw.Model): id = pw.AutoField() year = pw.IntegerField(unique=True) published = pw.BooleanField() class Meta: table_name = "event"
class User(peewee.Model): id = peewee.AutoField() email = peewee.CharField() password = peewee.CharField() class Meta: database = databaseConnection
class Products (Database): """ The Product Class will define the database Product table. We'll store the minimum required informations. If an attribute can be empty, it will be mentionned. Attributes : ------------ :code (p.BitField(primary_key = True)): The product's barcode. Can be used as primary key. :name (p.CharField(100)): The product's name. :brand_name (p. CharField(100)): The brand that owne the product. As it's not that important, can be empty. :description (p.TextField()): Descriptionof the product. Can be empty :nutriscore (p.CharField(1)): The French nutrition grade. Must be in between 'A' and 'E'. :url (p.TextField()): The URL to the OpenFoodFacts product page. Methods : --------- """ id = p.AutoField(primary_key=True, unique=True) name = p.CharField(50) code = p.BitField() brand_name = p.CharField(50) description = p.TextField(null = True) nutriscore = p.CharField(1) url = p.TextField()
class NoteType(pw.Model): id = pw.AutoField() title = pw.TextField() description = pw.TextField(null=True) class Meta: table_name = "notetype"