class SessionPulseStudent(Document): session = LazyReferenceField(Session) attentiveness = DecimalField() engagement = DecimalField() student = LazyReferenceField(Student) datetime_modified = DateTimeField(default=datetime.now()) datetime_sequence = DateTimeField(default=datetime.now()) version = StringField()
class LearningSession(Document): """ Represents a single learning session """ uuid = UUIDField(primary_key=True) course = LazyReferenceField(Course) user = LazyReferenceField(User) start_time = DateTimeField() end_time = DateTimeField()
class ClusterElement(Document): cluster = LazyReferenceField("Cluster", required=True) object = LazyReferenceField("Object", required=True) ref_object = LazyReferenceField("Object") type = EnumField(ClusterType, default=ClusterType.FACE, required=True) created_at = DateTimeField(default=datetime.utcnow, required=True) meta = {"collection": "cluster_elements"}
class FinancialInstrumentHolders(Document): uid = StringField(primary_key=True) """holder + symbol + date 计算得到的 uid """ symbol = LazyReferenceField(FinancialInstrumentSymbol, default=None) t = DateTimeField() """date reported""" holder = LazyReferenceField(GlobalEntity, default=None) shares = FloatField() value = FloatField() percentage_out = FloatField() meta = {"indexes": ["#symbol", "#holder", "-t"]}
class Answer(Document): """ Represents an answer a student gave to a question """ uuid = UUIDField(primary_key=True) course = LazyReferenceField(Course) time = DateTimeField() question = LazyReferenceField(Question) user = LazyReferenceField(User) answer = DynamicField() level = FloatField() score = FloatField()
class CourseStudentEntry(Document): """ Represents the course statistics for a given student in a given course. There should be only one such entry per student per course """ uuid = UUIDField(primary_key=True) course = LazyReferenceField(Course) user = LazyReferenceField(User) level = FloatField() as_of = DateTimeField() last_session = LazyReferenceField(LearningSession)
class CourseStudentSnapshot(Document): """ Represents a snapshot of a student's ability level in a given course. Many such snapshots will be created as the user advances through the course """ uuid = UUIDField(primary_key=True) user = LazyReferenceField(User) course = LazyReferenceField(Course) as_of = DateTimeField() level = FloatField() session = LazyReferenceField(LearningSession)
class FinancialInstrumentRecommendInYahoo(Document): uid = StringField(primary_key=True) """t+symbol+firm 获得""" symbol = LazyReferenceField(FinancialInstrumentSymbol, default=None) firm = LazyReferenceField(GlobalEntity, default=None) t = DateTimeField() to_grade = StringField() from_grade = StringField() action = StringField() meta = { "indexes": ["#symbol", "#firm", "#to_grade", "#from_grade", "#action", "-t"] }
class Process(Document): camera = LazyReferenceField("Camera") user = LazyReferenceField("User", required=True) uuid = IntField(required=True) name = StringField(required=True) url = StringField() file_root = StringField(required=True) started_at = DateTimeField(required=True) config = EmbeddedDocumentField(Config, required=True) created_at = DateTimeField(default=datetime.datetime.utcnow, required=True) meta = {"collection": "processes"}
class Comment(CommentBase): """ A part of a discussion. """ author = LazyReferenceField('User', required=True) body = StringField(max_lenth=4096, required=True) meta = { 'allow_inheritance': True, } def delete(self, *args, **kwargs): """ Delete a comment. We must override mongo's delete() in order to preserve the comment tree. """ logger.debug("Deleting comment {}".format(self.id)) # replace all childrens' parent with a deleted comment deleted = DeletedComment(replies=copy.deepcopy(self.replies), timestamp=self.timestamp) del self.replies deleted.save() logger.debug('placeholder comment: {}'.format(deleted)) # get this parent's children. if self.parent is not None: for (i, reply) in enumerate(self.parent.replies): logger.debug("Is {} == {}".format(reply.id, self.id)) if reply == self: logger.debug('deleting comment {}'.format(self.id)) self.parent.replies[i] = deleted self.parent.save() # continue with mongo's delete super(Comment, self).delete(*args, **kwargs)
class SearchingPhrase(Document): """ 适用于 普通的 keyword search 组合,也适用于特定网站中 Advance Search 的 特定语法 """ searching_phrase = StringField(primary_key=True) batch_action_uuid = StringField() related_symbols = ListField( LazyReferenceField('FinancialInstrumentSymbol'), default=None) """适用于有几个 kw 来自于 symbol """ # --- twitter advance search 的一些条件 # 这些字段暂时都可以不需要 # kws_from_symbol = ListField(LazyReferenceField('FinancialInstrumentSymbol'), default=None) # twitter_user = ListField(LazyReferenceField(UserInTwitter), default=None) # 来自于 twitter 的一个或者多个用户 # min_retweet = IntField() # min_tweet_like = IntField() # min_tweet_reply = IntField() meta = { "indexes": [ "$searching_phrase", # text index "#batch_action_uuid", # "-min_retweet", # "-min_tweet_like", # "-min_tweet_reply", ] }
class Protocol(EntityBase): """ Contiene la informacion del protocolo al cual se le realizaran las nanopublicaciones """ meta = {"collection": "protocols", "strict": False} # uri de identificacion del protocolo uri = StringField(primary_key=True) # titulo del protocolo title = StringField(required=True, max_length=250) # numero maximo de nanopublicaciones para el protocolo max_nanopubs = IntField(default=10) # nanopublicationes nanopublications = LazyReferenceField("Nanopublication", reverse_delete_rule=CASCADE) # site data site_data = {} @staticmethod def fromAnnotation(annotation: Annotation, settings: dict = None): """ transforma la anotacion (generalmente una anotacionn marcada con 'step') pasada a una un Protocolo Annotation -> Protocol """ return Protocol( uri=clean_url_with_settings(annotation.url, settings=settings), title=annotation.title[0], ) def to_json_map(self): base = super().to_json_map() base["site_data"] = self.site_data return base
class Logger(Document): process_id = LazyReferenceField("Process", required=True) data = EmbeddedDocumentField(Threads) created_at = DateTimeField(default=datetime.datetime.utcnow, required=True) meta = {"collection": "loggers"}
class PulseProcessing(Document): session = LazyReferenceField(Session) camera = LazyReferenceField(Camera) frame_type = StringField() frame_number = IntField() person_id = StringField( unique=True, required=True ) # is a hash of session, camera, frame_number by pipeline image_url = URLField() person_detection_event = EmbeddedDocumentField(PersonDetectionEvent) face_detection_event = EmbeddedDocumentField(FaceDetectionEvent) face_embedding_event = EmbeddedDocumentField(FaceEmbeddingEvent) face_recognition_event = EmbeddedDocumentField(FaceRecognitionEvent) gaze_detection_event = EmbeddedDocumentField(GazeDetectionEvent) action_recognition_event = EmbeddedDocumentField(ActionRecognitionEvent) detected_at = DateTimeField()
class File(MongoModel, Document): brewtils_model = brewtils.models.File owner_id = StringField(required=False) owner_type = StringField(required=False) request = LazyReferenceField(Request, required=False, reverse_delete_rule=NULLIFY) job = LazyReferenceField(Job, required=False, reverse_delete_rule=NULLIFY) updated_at = DateTimeField(default=datetime.datetime.utcnow, required=True) file_name = StringField(required=True) file_size = IntField(required=True) chunks = DictField(required=False) chunk_size = IntField(required=True) # This was originally used instead of request and job. See #833 # We could probably have kept using this if a GenericLazyReferenceField could have # a reverse_delete_rule. Alas! owner = DummyField()
class FileChunk(MongoModel, Document): brewtils_model = brewtils.models.FileChunk file_id = StringField(required=True) offset = IntField(required=True) data = StringField(required=True) # Delete Rule (2) = CASCADE; This causes this document to be deleted when the owner doc is. owner = LazyReferenceField(File, required=False, reverse_delete_rule=CASCADE)
class RawFile(Document): file = FileField() created_at = DateTimeField(default=datetime.datetime.utcnow, required=True) request = LazyReferenceField(Request, required=False, reverse_delete_rule=CASCADE) meta = {"queryset_class": FileFieldHandlingQuerySet}
class FinancialInstrumentDividends(Document): uid = StringField(primary_key=True) """symbol + date 计算得到的 uid""" symbol = LazyReferenceField(FinancialInstrumentSymbol, default=None) t = DateTimeField() divident = FloatField() split = FloatField() meta = {"indexes": ["#symbol", "-t"]}
class ClusteringFace(EmbeddedDocument): object = LazyReferenceField("Object", required=True) face_id = LongField(required=True) url = StringField(required=True) head_pose = ListField(IntField(required=True), default=[]) width = IntField(min_value=0, required=True) height = IntField(min_value=0, required=True) sharpness = FloatField(min_value=0, required=True)
class BillLog(Document): """ 账单信息 Time series """ date_in = DateTimeField(required=True) date_out = DateTimeField(required=True) addition_info = StringField(max_length=10000, default='') # 暂时没法直到具体车位, 所以暂时设置为 optional parking_info = ReferenceField(Parking) # 懒加载, 到时候我们要根据 pk 搜索日志, 所以必须要用这个为了效率 vehicle = LazyReferenceField(Vehicle, required=True) # 非会员用户或者储值卡(top-up)用户 fee = DecimalField(min_value=0., precision=3) # 如果使用了(储值卡/记次卡)才需要用到 member_card member_card = ReferenceField(MemberCard) indoor = LazyReferenceField(Door, require=True) outdoor = LazyReferenceField(Door, require=True) admin_info = StringField(max_length=50, required=True)
class Question(Document): """ Represents a question """ uuid = UUIDField(primary_key=True) course = LazyReferenceField(Course) level = FloatField(default=0.) question = StringField() answers = EmbeddedDocumentListField(AnswerChoice) multiple = BooleanField() def _to_uuid(self, answer): return answer if isinstance(answer, UUID) else UUID(answer) def _answers_to_set(self, answers): if isinstance(answers, str): answers = [answers] return set(self._to_uuid(answer) for answer in answers) def _score_multiple(self, answer): """ Scores a response to this question using Coursera-style scoring (the fraction of checkboxes checked correctly) """ actual_answers = set(answer) return 0. if not any(self.answers) else sum( float((answer.uuid in actual_answers) == (answer.checked or False)) for answer in self.answers) / len(self.answers) def _score_single(self, answer): """ Scores a response based on classic multiple choice model with a single correct answer, awarding 1.0 for a correct answer and 0.0 for an incorrect one :param answer: a single answer or a collection containing a single answer """ actual = self._answers_to_set(answer) if len(actual) == 1: reference = set( answer.uuid for answer in self.answers if answer.checked) result = actual == reference else: result = 0. return result def score(self, answer): """ Scores the answer to a question :param answer: a collection of uuids of selected answers (or a single answer) """ return ( self._score_multiple(answer) if self.multiple else self._score_single(answer))
class MonkeyFinding(Finding): # We put additional info into a lazy reference field, because this info should be only # pulled when explicitly needed due to performance details = LazyReferenceField(MonkeyFindingDetails, required=True) @staticmethod def save_finding(test: str, status: str, detail_ref: MonkeyFindingDetails) -> MonkeyFinding: finding = MonkeyFinding(test=test, status=status, details=detail_ref) finding.save() return finding
class SessionIntervention(Document): session = LazyReferenceField(Session) datetime_created = DateTimeField(default=datetime.now()) datetime_sequence = DateTimeField(default=datetime.now()) version = StringField() intervention_reason = StringField() # engagement, attention etc. intervention_period_start = DateTimeField() intervention_period_end = DateTimeField() intervention_reason_value = DecimalField() intervention_reason_threshold = DecimalField() meta = {'allow_inheritance': True}
class AccountCreateRequestLog(Document): """ 记录由web端传递过来的相关的数据 """ # platform = StringField(max_length=32) # 平台的id account_source = LazyReferenceField('AccountSource') # 所属平台 number = IntField() # 一次请求应创建指定个数的account status = StringField(choices=('new', 'doing', 'done', 'error')) # 请求的状态 date = FloatField() # 创建请求的时间(时间戳) error_msg = StringField() # 错误请求的详细信息
class TriggeredWebPagesCrawlWorkflow(Document): """ Trigger 的一次抓取数据的 workflow 的内容 eg : 在 2020/06/21 时, laigen 触发了一次获取 AAPL 的相关舆情数据的一次 workflow (一个 document ) 在 2020/06/22 时,laigen 又触发了一次获取 AAPL 的相关舆情数据的 workflow (另一个 document) """ uuid = StringField(primary_key=True) """ uuid 由 HASH[ ( fin_instrument | named_entity | txt_paragraph ) + workflow_name + (para_begin|para_end) + submit_account + ctime ] 构成 """ main_entity_type = IntField() """value is EntityType""" fin_instrument = LazyReferenceField(FinancialInstrumentSymbol, default=None) """ 适用于 main_entity_type == EntityType.Equity 的情况 """ named_entity = LazyReferenceField(GlobalEntity, default=None) """ 适用于 main_entity_type == EntityType.NamedEntity 的情况""" txt_paragraph = StringField() """ 适用于 main_entity_type == EntityType.Paragraph 的情况""" workflow = LazyReferenceField(PredefinedWorkflow, default=None) """ 执行哪一项预定义的 workflow 内容 """ para_begin = DateTimeField() para_end = DateTimeField() # ---- 以下是一些与 workflow 溯源相关的信息 ---- submit_account = StringField() """由哪个账号提交的workflow""" submit_type = IntField() """提交方式, see WorkflowSubmitType """ submit_time = DateTimeField() """提交任务的时间""" # ---- some result ------- finish_or_error_flag = IntField() """ see : WorkflowStatusFlag """ error_msg = StringField() # ---- relate batch action --------- action_batch = LazyReferenceField(RPABatchAction, default=None)
class Theme(Document): name = StringField() videos = ListField(LazyReferenceField("Video")) @property def rating(self): up = 0 down = 0 for video in self.videos: video = video.fetch() up += video.thumbs_up down += video.thumbs_down return up - (down / 2)
class Region(Document): """ 区域信息 """ name = StringField(max_length=100, required=True) # DCMMC: TODO: 这个在模型的 json 里面暂时还没有... id_in_map = StringField(max_length=100, required=True, unique=True) floor = ReferenceField('Floor', require=True) # 车位 # {parkingNo: LazyRefField} 的字典 parkings = MapField(field=LazyReferenceField('Parking')) addition_info = StringField(max_length=10000, default='')
class Detection(Document): object = LazyReferenceField("Object", required=True) frame_index = IntField(required=True, min_value=0) head_bbox = ListField(FloatField(min_value=0, required=True), default=[]) head_confidence = IntField(min_value=0) face_bbox = ListField(FloatField(min_value=0, required=True), default=[]) face_confidence = IntField(min_value=0) body_bbox = ListField(FloatField(min_value=0, required=True), default=[]) body_confidence = IntField(min_value=0) head_pose = ListField(IntField(required=True), default=[]) meta = {"collection": "detections"}
class UserInTwitter(Document): user_id = StringField(primary_key=True) name = StringField() intro = StringField() intro_ana = EmbeddedDocumentField(AzureTextAna) follower = IntField() following = IntField() arr_following = ListField(LazyReferenceField('self'), default=None) batch_action_uuid = StringField() mtime = DateTimeField() meta = { "indexes": ["$intro", "#batch_action_uuid", "-follower", "-following"] }
class Object(Document): process = LazyReferenceField("Process", required=True) identity = LazyReferenceField("Identity") uuid = LongField(unique=True, required=True, min_value=0) track_id = IntField(required=True, min_value=0) avatars = ListField(StringField(required=True), required=True) confidence_rate = IntField() similarity_distance = FloatField() age = IntField(min_value=0) gender = StringField() from_frame = IntField(required=True, min_value=0) to_frame = IntField(min_value=0) from_time = DateTimeField() to_time = DateTimeField() face_ids = ListField(ListField(EmbeddedDocumentField(Face)), default={}) body_ids = ListField(EmbeddedDocumentField(Body), default=[]) have_new_face = BooleanField(default=False, required=True) have_new_body = BooleanField(default=False, required=True) created_at = DateTimeField(default=datetime.datetime.utcnow, required=True) meta = {"collection": "objects"}