class CameraRecording(BaseModel): task_name = CharField(default="") image_path = CharField() video_path = CharField(null=True) settings = JSONField(default=dict) camera = ForeignKeyField(Camera, on_delete="CASCADE", backref='recordings') camera_snapshot = JSONField(default=dict) print = ForeignKeyField(Print, on_delete="SET NULL", related_name="recordings", null=True, default=None, backref='recordings') status = CharField(null=True) reason = CharField(null=True) layerkeep_id = IntegerField(null=True) @property def serialize(self): return { 'id': self.id, 'settings': self.settings, 'image_path': self.image_path, 'video_path': self.video_path } def __repr__(self): return "{}, {}, {}".format(self.id, self.settings, self.image_path, self.video_path) class Meta: table_name = "camera_recordings"
class Message(Model): """Archived message.""" class Meta: # These are copies of our messages and so they are stored under a more descriptive table name. table_name = 'history' # Snowflake assigned by Discord. id = BigIntegerField(primary_key=True) # Link to jump to message. link = TextField() # Author of message. author = BigIntegerField() # Cached information about the author. # See `author_to_cacheable` for contents. _cached_author_info = JSONField() # Channel in which the message was posted. channel = BigIntegerField() # Cached information about the channel. # See `channel_to_cacheable` for contents. _cached_channel_info = JSONField() # Content of message. content = TextField() # Reactions to message. # See `reaction_to_cacheable` for contents. reactions = JSONField() # Timestamp when message was posted. timestamp = DateTimeField()
class ServiceAttachment(BaseModel): settings = JSONField(default=dict) listeners = JSONField(default=dict) parent = ForeignKeyField(Service, on_delete="CASCADE", column_name='parent_id', index=True, null=False, backref="service_attachments") attachment = ForeignKeyField(Service, on_delete="CASCADE", column_name='attachment_id', index=True, null=False, backref="attached_to") @property def serialize(self): return { 'id': self.id, 'settings': self.settings, 'listeners': self.listeners, 'parent_id': self.parent_id, 'attachment_id': self.attachment_id } def __repr__(self): return "{}, {}, {}, {}".format(self.id, self.settings, self.listeners, self.parent_id) class Meta: table_name = "service_attachments"
class Job(TimestampModel): id = AutoField() url = CharField() cities = JSONField(null=True, json_dumps=friendly_json_dumps) opts = JSONField(null=True, json_dumps=friendly_json_dumps) class Meta: database = db
class Conversation(Model): business = ForeignKeyField(Business, backref='conversation') customer = ForeignKeyField(Customer, null=True, backref='conversation') call_sid = CharField(max_length=100, primary_key=True, index=True) call_country = CharField(max_length=10, default='') call_zip = CharField(max_length=10, default='') call_state = CharField(max_length=10, index=True, default='') call_city = CharField(max_length=100, index=True, default='') call_number = CharField(max_length=20, default='') context = JSONField(null=True) history = JSONField(default={}) last_update = DateTimeField(default=datetime.datetime.now) class Meta: database = db @classmethod def get_or_new(cls, form, call_sid=None): conv = Conversation.get_or_none(call_sid=call_sid) if conv: return conv, False, "" buss = Business.get_using_form(form) cust = Customer.get_using_form(form, business=buss) context = {'conversation_id': '', 'system': {}} if buss: context['business'] = buss.name if cust: context['name'] = cust.name context['identified'] = 'true' else: context['identified'] = 'false' conv = Conversation.create(call_sid=call_sid, call_country=form['CallerCountry'], call_zip=form['CallerZip'], call_state=form['CallerState'], call_city=form['CallerCity'], call_number=form['Caller'], business=buss, customer=cust, context=context) return conv, True, "" else: return None, False, "Line is not setup to accept call for any business." def identity_affirmed(self): return (self.context and ('identified' in self.context and self.context['identified'] == 'true') and ('identity_affirmed' in self.context and self.context['identity_affirmed'] == 'true')) def store_context(self): if 'context' not in self.history: self.history['context'] = [] self.history['context'].append(self.context) def log_json(self): app.logger.info(pformat(model_to_dict(self)))
class AnalysisModel(BaseModel): """Data on analyses of multiple datasets.""" name = TextField() # analysis_hash = TextField(default=utils.get_git_revision_hash) analysis_hash = TextField(default='') date = DateField(default=datetime.datetime.now) datasets = JSONField() filters = JSONField( json_dumps=lambda x: json.dumps(x, cls=utils.JSONSetEncoder), null=True)
class House(TimestampModel): job_id = ForeignKeyField(Job, backref='houses') house_id = CharField() list_meta = JSONField(null=True, json_dumps=friendly_json_dumps) detail_meta = JSONField(null=True, json_dumps=friendly_json_dumps) rough_gps = JSONField(null=True, json_dumps=friendly_json_dumps) class Meta: database = db indexes = ((('job_id', 'house_id'), True), )
class TestSuite(BaseModel): name = CharField(null=False) coverage = IntegerField() tests_total = IntegerField() fail_tests_total = IntegerField() fail_tests = JSONField() coverage_tests = JSONField() fail_coverage_tests = JSONField() fail_coverage_tests_total = IntegerField() mutant = ForeignKeyField(Mutant, backref='test_suites')
class LogbookChange(Model): class Meta: database = db logbook = ForeignKeyField(Logbook, related_name="changes") changed = JSONField() timestamp = UTCDateTimeField(default=datetime.utcnow) change_authors = JSONField(null=True) change_comment = TextField(null=True) change_ip = CharField(null=True) def get_old_value(self, attr): """Get the value of the attribute at the time of this revision. That is, *before* the change happened.""" # First check if the attribute was changed in this revision, # in that case we return that. if attr in self.changed: return self.changed[attr] # Otherwise, check for the next revision where this attribute # changed; the value from there must be the current value # at this revision. try: change = (LogbookChange.select().where( (LogbookChange.logbook == self.logbook) & (LogbookChange.changed.extract(attr) != None) & (LogbookChange.id > self.id)).order_by( LogbookChange.id).get()) return change.changed[attr] except DoesNotExist: # No later revisions changed the attribute either, so we can just # take the value from the current logbook return getattr(self.logbook, attr) def get_new_value(self, attr): """Get the value of the attribute at the time of this revision. That is, *before* the change happened.""" # check for the next revision where this attribute # changed; the value from there must be the current value # at this revision. try: change = (LogbookChange.select().where( (LogbookChange.logbook == self.logbook) & (LogbookChange.changed.extract(attr) != None) & (LogbookChange.id > self.id)).order_by( LogbookChange.id).get()) return change.changed[attr] except DoesNotExist: # No later revisions changed the attribute, so we can just # take the value from the current logbook return getattr(self.logbook, attr)
class RipperVideoInfo(TableBase): """Ripper Video Info Table""" iso_file = TextField(default="") uuid = CharField(max_length=16) label = TextField() disc_type = CharField(max_length=6) disc_data = JSONField() rip_data = JSONField() rip_data_locked = BooleanField(default=0) rip_data_downloaded = BooleanField(default=0)
class PluginModel(sql.Model): id = sql.PrimaryKeyField() user = sql.ForeignKeyField(UserModel, 'id', 'plugins') plugin = sql.TextField(null=False) size = sql.IntegerField(null=False) params = JSONField(null=False, default={}) data = JSONField(null=False, default={}) class Meta: database = db
class Article(BaseModel): url = CharField(unique=True) title = CharField() description = CharField() date = DateField() text = TextField() rubrics = JSONField() themes = JSONField() difficulty = IntegerField() internal_links = JSONField() external_links = JSONField() author = CharField() @classmethod def by_url(cls, url): return cls.get_or_create(defaults={'url': url}, url=url)[0] @staticmethod def is_parsed(url): try: art = Article.get(Article.url == url) except Article.DoesNotExist: return False else: return art.title is not None @staticmethod def iter_unparsed_urls(): for art in Article.select().where(Article.url != None, Article.title == None).select(): yield art.url @staticmethod def parsed_num(): return Article.select().where(Article.title != None).count() @staticmethod def unparsed_num(): return Article.select().where(Article.title == None).count() class ScrapyItem(scrapy.Item): data = scrapy.Field() def __repr__(self): req_fields = ['url', 'title', 'description', 'author', 'internal_links'] return pformat({f: self['data'][f] for f in req_fields}) def to_scrapy_item(self): return self.ScrapyItem(data=model_to_dict(self)) def save(self, force_insert=False, only=None): super(Article, self).save(force_insert, only) ArticleIndex.index_article(self)
class User(BaseModel): uid = IntegerField(unique=True) state = IntegerField(default=0) first_name = CharField() tasks = JSONField(default={}) current_filters = JSONField(default={}) @staticmethod def set_state(user, state): User.update(state=state).where(User.uid == user.id).execute() @staticmethod def get_state(user): return User.get(uid=user.id).state @staticmethod def get_users_tasks(user, *args): usr = User.get(User.uid == user.id) tasks = [Task.get(task_id) for task_id in usr.tasks] tasks = list(filter(lambda task: task.deadline, tasks)) if Filter.ALL in args: return sorted(tasks, key=lambda task: task.deadline) if not (Filter.PRIVATE in args and Filter.SHARED in args): if Filter.PRIVATE in args: tasks = filter(lambda task: task.is_private, tasks) elif Filter.SHARED in args: tasks = filter(lambda task: not task.is_private, tasks) else: return [] if not (Filter.DONE in args and Filter.UNDONE in args): if Filter.DONE in args: tasks = filter(lambda task: usr.id in task.done_by, tasks) elif Filter.UNDONE in args: tasks = filter(lambda task: usr.id not in task.done_by, tasks) else: return [] return sorted(tasks, key=lambda task: task.deadline) @staticmethod def get_users_none_deadline_task(user): usr = User.get(User.uid == user.id) tasks = [Task.get(task_id) for task_id in usr.tasks] tasks = list(filter(lambda task: not task.deadline, tasks)) return tasks[0]
class NlpTrialConfig(Model): """ Trial config for NLP. epoch_num is fixed at 50. Attributes ---------- arch: dict aka recepie in NAS-NLP-Benchmark repo (https://github.com/fmsnew/nas-bench-nlp-release). an arch has multiple Node, Node_input_n and Node_op. ``Node`` can be ``node_n`` or ``h_new_n`` or ``f/i/o/j(_act)`` etc. (n is an int number and need not to be consecutive) ``Node_input_n`` can be ``Node`` or ``x`` etc. ``Node_op`` can be ``linear`` or ``activation_sigm`` or ``activation_tanh`` or ``elementwise_prod`` or ``elementwise_sum`` or ``activation_leaky_relu`` ... e.g., {"h_new_0_input_0":"node_3","h_new_0_input_1":"x","h_new_0_op":"linear","node_2_input_0":"x", "node_2_input_1":"h_prev_0","node_2_op":"linear","node_3_input_0":"node_2","node_3_op":"activation_leaky_relu"} dataset: str Dataset used. Could be ``ptb`` or ``wikitext-2``. """ arch = JSONField(json_dumps=json_dumps, index=True) dataset = CharField(max_length=15, index=True, choices=['ptb', 'wikitext-2']) class Meta: database = db
class PokemonTable(BaseModel): id = IntegerField(primary_key=True) name = TextField(index=True) legendary = BooleanField() mythical = BooleanField() shiny = BooleanField() alolan = BooleanField() galarian = BooleanField() types = JSONField() released = BooleanField(index=True) attack = IntegerField() defense = IntegerField() stamina = IntegerField() @classmethod def reload_default(cls): if not KyogreDB._db: return try: cls.delete().execute() except: pass with open('data/pkmn_data.json', 'r') as f: pkmn_data = json.load(f) with KyogreDB._db.atomic(): for chunk in chunked(pkmn_data, 50): cls.insert_many(chunk).execute()
class NVQueue(Model): # Use integer timestamp as default row ID id = PrimaryKeyField() item = JSONField() class Meta: database = qdb
class Camera(BaseModel): name = CharField(unique=True) endpoint = CharField(unique=True) # baud_rate = CharField() service = ForeignKeyField(Service, null=True, default=None, on_delete="SET NULL", backref="camera") settings = JSONField(default=dict) # service_id = IntegerField(null=True) @property def serialize(self): return { 'id': self.id, 'name': self.name, 'endpoint': self.endpoint, 'settings': self.settings } def __repr__(self): return "\\{{}, {}, {}\\}".format(self.id, self.name, self.endpoint) class Meta: table_name = "cameras"
class Case(BaseModel): itemid = pw.CharField(primary_key=True) docname = pw.CharField() doctypebranch = pw.CharField() ecli = pw.CharField(unique=True) importance = pw.IntegerField() applicability = pw.CharField() appno = pw.CharField() decisiondate = pw.DateTimeField(null=True) introductiondate = pw.DateTimeField(null=True) judgementdate = pw.DateTimeField(null=True) kpdate = pw.DateTimeField(null=True) languageisocode = pw.CharField() originatingbody_name = pw.CharField() originatingbody_type = pw.CharField() rank = pw.CharField() respondent = pw.CharField() respondentOrderEng = pw.CharField() separateopinion = pw.BooleanField() sharepointid = pw.IntegerField() typedescription = pw.IntegerField() judgment = JSONField(null=True)
class Attachment(Model): """Store information about an attachment, e.g. an arbitrary file associated with an entry. The file itself is not stored in the database though, only a path to where it's expected to be. """ class Meta: database = db order_by = ("id", ) entry = ForeignKeyField(Entry, null=True, related_name="attachments") filename = CharField(null=True) timestamp = UTCDateTimeField(default=datetime.utcnow) path = CharField() # path within the upload folder content_type = CharField(null=True) embedded = BooleanField(default=False) # i.e. an image in the content metadata = JSONField(null=True) # may contain image size, etc archived = BooleanField(default=False) @property def link(self): return url_for("get_attachment", path=self.path) @property def thumbnail_link(self): return url_for("get_attachment", path=self.path) + ".thumbnail"
class Nb101TrialConfig(Model): """ Trial config for NAS-Bench-101. Attributes ---------- arch : dict A dict with keys ``op1``, ``op2``, ... and ``input1``, ``input2``, ... Vertices are enumerate from 0. Since node 0 is input node, it is skipped in this dict. Each ``op`` is one of :const:`nni.nas.benchmark.nasbench101.CONV3X3_BN_RELU`, :const:`nni.nas.benchmark.nasbench101.CONV1X1_BN_RELU`, and :const:`nni.nas.benchmark.nasbench101.MAXPOOL3X3`. Each ``input`` is a list of previous nodes. For example ``input5`` can be ``[0, 1, 3]``. num_vertices : int Number of vertices (nodes) in one cell. Should be less than or equal to 7 in default setup. hash : str Graph-invariant MD5 string for this architecture. num_epochs : int Number of epochs planned for this trial. Should be one of 4, 12, 36, 108 in default setup. """ arch = JSONField(json_dumps=json_dumps, index=True) num_vertices = IntegerField(index=True) hash = CharField(max_length=64, index=True) num_epochs = IntegerField(index=True) class Meta: database = db
class Thing(Model): # This table is not meant to represent a complete relationship of submissions/comments on reddit # Its behaviour is more of a log to track submissions and comments # that have had replies attempted and prevent replying twice # It also acts as a job queue of sorts, for the model text generator daemon # timestamp representation of when this record was entered into the database created_utc = TimestampField(default=time.time, utc=True) # the praw *name* of the original comment or submission, # where t3_ prefix = submission, t1_ prefix = comment source_name = TextField() # json object of the model parameters, passed into the generator daemon function text_generation_parameters = JSONField(null=True) # Count text generation attempts. In normal operation this will only be 0 or 1 text_generation_attempts = IntegerField(default=0) # text generated by model and returned to the job generated_text = TextField(null=True) # the subreddit used by new_submission job type subreddit = TextField(null=True) # attempts to post the generated_text back to reddit reddit_post_attempts = IntegerField(default=0) # The 'name' of the object posted back to reddit posted_name = TextField(null=True) class Meta: database = db
class Reply(Model): roll = IntegerField(null=False, unique=True) replies = JSONField(null=False, default=ReplyModel.replies_model) class Meta: database = db
class PrintSlice(BaseModel): name = CharField() generated_name = CharField() path = CharField(unique=True) source = CharField(default="local") description = CharField(null=True) properties = JSONField(default=dict) layerkeep_id = IntegerField(null=True) @property def serialize(self): return { 'id': self.id, 'name': self.name, 'path': self.path, 'description': self.description, 'source': self.source, 'properties': self.properties, 'layerkeep_id': self.layerkeep_id } def __repr__(self): return "{}, {}, {}".format(self.id, self.name, self.path) class Meta: table_name = "print_slices"
class Player(pw.Model): tag = pw.CharField() firstTime = pw.DateTimeField() json = JSONField() class Meta: database = db
class NodeConfig(Model): node_id = TextField(primary_key=True) config = JSONField(null=True) access_key = DateTimeField(null=True) class Meta: database = cdb
class QueueCheck(BaseModel): item = TextField(unique=True) function = TextField(default="") complete = BooleanField(default=True) error = TextField(default="") meta = JSONField(default="") created_date = DateField(default=datetime.datetime.now())
class Edge(_BaseModel): """Edge ORM class. See: https://github.com/commonsense/conceptnet5/wiki/Edges. Everything except relation, start, and end nodes is stored in :attr:`etc` field that is plain :class:`dict`. """ relation = ForeignKeyField(Relation, backref='edges') start = ForeignKeyField(Concept, backref='edges_out') end = ForeignKeyField(Concept, backref='edges_in') etc = JSONField() def __str__(self): return self.uri @classmethod def get(cls, *query, **filters): if isinstance(filters.get('relation'), str): filters['relation'] = Relation.get(name=filters['relation']) if isinstance(filters.get('start'), str): filters['start'] = Concept.get(uri=filters['start']) if isinstance(filters.get('end'), str): filters['end'] = Concept.get(uri=filters['end']) return super().get(*query, **filters) @property def uri(self) -> str: return f'/a/[{self.relation.uri}/,{self.start.uri}/,{self.end.uri}/]'
class QuestTable(BaseModel): name = TextField(unique=True) reward_pool = JSONField() @classmethod def reload_default(cls): if not KyogreDB._db: return try: cls.delete().execute() except: pass with open('data/quest_data.json', 'r') as f: quest_data = json.load(f) with KyogreDB._db.atomic(): for quest in quest_data: try: name = quest['name'] pool = quest['reward_pool'] QuestTable.create(name=name, reward_pool=pool) parseRewardPool(pool) except Exception as e: import pdb pdb.set_trace() print(e)
class RaidTable(BaseModel): trainer_report = ForeignKeyField(TrainerReportRelation, backref='raids') level = TextField(index=True) type = TextField(index=True) next_event_time = DateTimeField(index=True) channel = BigIntegerField(index=True) trainer_dict = JSONField()
class RipperAudioInfo(TableBase): """Ripper Audio Info Table""" iso_file = TextField(null=True, default="") musicbrainz_disc_id = (CharField(max_length=28), ) track_count = SmallIntegerField() release_id = CharField(max_length=36) disc_data = JSONField()