class AlgorithmResult(Model): algorithm = ForeignKey(Algorithm, on_delete=CASCADE) user = ForeignKey(User, on_delete=CASCADE) media = ManyToManyField(EntityMediaBase) started = DateTimeField() stopped = DateTimeField() result = EnumField(JobResult) message = CharField(max_length=128) setup_log = FileField(null=True, blank=True) algorithm_log = FileField(null=True, blank=True) teardown_log = FileField(null=True, blank=True) def __str__(self): return f"{self.algorithm.name}, {self.result}, started {self.started}"
class EntityMediaBase(EntityBase): name = CharField(max_length=256) uploader = ForeignKey(User, on_delete=PROTECT) upload_datetime = DateTimeField() md5 = SlugField(max_length=32) """ md5 hash of the originally uploaded file. """ file = FileField() last_edit_start = DateTimeField(null=True, blank=True) """ Start datetime of a session in which the media's annotations were edited. """ last_edit_end = DateTimeField(null=True, blank=True) """ End datetime of a session in which the media's annotations were edited.
class Algorithm(Model): name = CharField(max_length=128) project = ForeignKey(Project, on_delete=CASCADE) user = ForeignKey(User, on_delete=PROTECT) description = CharField(max_length=1024, null=True, blank=True) manifest = FileField(upload_to=ProjectBasedFileLocation, null=True, blank=True) cluster = ForeignKey(JobCluster, null=True, blank=True, on_delete=SET_NULL) files_per_job = PositiveIntegerField( default=1, validators=[MinValueValidator(1),] ) max_concurrent = PositiveIntegerField( default=1, validators=[MinValueValidator(1),] ) def __str__(self): return self.name
class Media(Model): """ Fields: original: Originally uploaded file. Users cannot interact with it except by downloading it. .. deprecated :: Use media_files object segment_info: File for segment files to support MSE playback. .. deprecated :: Use meda_files instead media_files: Dictionary to contain a map of all files for this media. The schema looks like this: .. code-block :: map = {"archival": [ VIDEO_DEF, VIDEO_DEF,... ], "streaming": [ VIDEO_DEF, VIDEO_DEF, ... ], <"audio": [AUDIO_DEF]>} video_def = {"path": <path_to_disk>, "codec": <human readable codec>, "resolution": [<vertical pixel count, e.g. 720>, width] audio_def = {"path": <path_to_disk>, "codec": <human readable codec>} ################### # Optional Fields # ################### # Path to the segments.json file for streaming files. # not expected/required for archival. Required for # MSE playback with seek support for streaming files. segment_info = <path_to_json> # If supplied will use this instead of currently # connected host. e.g. https://example.com "host": <host url> # If specified will be used for HTTP authorization # in the request for media. I.e. "bearer <token>" "http_auth": <http auth header> # Example mime: 'video/mp4; codecs="avc1.64001e"' # Only relevant for straming files, will assume # example above if not present. "codec_mime": <mime for MSE decode> "codec_description": <description other than codec>} """ project = ForeignKey(Project, on_delete=SET_NULL, null=True, blank=True, db_column='project') meta = ForeignKey(MediaType, on_delete=SET_NULL, null=True, blank=True, db_column='meta') """ Meta points to the defintion of the attribute field. That is a handful of AttributeTypes are associated to a given MediaType that is pointed to by this value. That set describes the `attribute` field of this structure. """ attributes = JSONField(null=True, blank=True) """ Values of user defined attributes. """ gid = CharField(max_length=36, null=True, blank=True) """ Group ID for the upload that created this media. Note we intentionally do not use UUIDField because this field is provided by the uploader and not guaranteed to be an actual UUID. """ uid = CharField(max_length=36, null=True, blank=True) """ Unique ID for the upload that created this media. Note we intentionally do not use UUIDField because this field is provided by the uploader and not guaranteed to be an actual UUID. """ created_datetime = DateTimeField(auto_now_add=True, null=True, blank=True) created_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, related_name='media_created_by', db_column='created_by') modified_datetime = DateTimeField(auto_now=True, null=True, blank=True) modified_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, related_name='media_modified_by', db_column='modified_by') name = CharField(max_length=256) md5 = SlugField(max_length=32) """ md5 hash of the originally uploaded file. """ file = FileField(null=True, blank=True) last_edit_start = DateTimeField(null=True, blank=True) """ Start datetime of a session in which the media's annotations were edited. """ last_edit_end = DateTimeField(null=True, blank=True) """ End datetime of a session in which the media's annotations were edited. """ original = FilePathField(path=settings.RAW_ROOT, null=True, blank=True) thumbnail = ImageField(null=True, blank=True) thumbnail_gif = ImageField(null=True, blank=True) num_frames = IntegerField(null=True, blank=True) fps = FloatField(null=True, blank=True) codec = CharField(null=True, blank=True, max_length=256) width = IntegerField(null=True) height = IntegerField(null=True) segment_info = FilePathField(path=settings.MEDIA_ROOT, null=True, blank=True) media_files = JSONField(null=True, blank=True) def update_media_files(self, media_files): """ Updates media files by merging a new key into existing JSON object. """ # Handle null existing value. if self.media_files is None: self.media_files = {} # Append to existing definitions. new_streaming = media_files.get('streaming', []) old_streaming = self.media_files.get('streaming', []) streaming = new_streaming + old_streaming new_archival = media_files.get('archival', []) old_archival = self.media_files.get('archival', []) archival = new_archival + old_archival new_audio = media_files.get('audio', []) old_audio = self.media_files.get('audio', []) audio = new_audio + old_audio for fp in new_streaming: path = fp['path'] seg_path = fp['segment_info'] Resource.add_resource(path) Resource.add_resource(seg_path) for fp in new_archival: Resource.add_resource(fp['path']) for fp in new_audio: Resource.add_resource(fp['path']) # Only fill in a key if it has at least one definition. self.media_files = {} if streaming: streaming.sort(key=lambda x: x['resolution'][0], reverse=True) self.media_files['streaming'] = streaming if archival: self.media_files['archival'] = archival if audio: self.media_files['audio'] = audio # Handle roi, layout, and quality for x in ['layout', 'ids', 'quality']: if x in media_files: self.media_files[x] = media_files[x]
class Media(Model): """ Fields: original: Originally uploaded file. Users cannot interact with it except by downloading it. .. deprecated :: Use media_files object segment_info: File for segment files to support MSE playback. .. deprecated :: Use meda_files instead media_files: Dictionary to contain a map of all files for this media. The schema looks like this: .. code-block :: map = {"archival": [ VIDEO_DEF, VIDEO_DEF,... ], "streaming": [ VIDEO_DEF, VIDEO_DEF, ... ], <"audio": [AUDIO_DEF]>} video_def = {"path": <path_to_disk>, "codec": <human readable codec>, "resolution": [<vertical pixel count, e.g. 720>, width] audio_def = {"path": <path_to_disk>, "codec": <human readable codec>} ################### # Optional Fields # ################### # Path to the segments.json file for streaming files. # not expected/required for archival. Required for # MSE playback with seek support for streaming files. segment_info = <path_to_json> # If supplied will use this instead of currently # connected host. e.g. https://example.com "host": <host url> # If specified will be used for HTTP authorization # in the request for media. I.e. "bearer <token>" "http_auth": <http auth header> # Example mime: 'video/mp4; codecs="avc1.64001e"' # Only relevant for straming files, will assume # example above if not present. "codec_mime": <mime for MSE decode> "codec_description": <description other than codec>} """ project = ForeignKey(Project, on_delete=SET_NULL, null=True, blank=True, db_column='project', related_name='media_project') meta = ForeignKey(MediaType, on_delete=SET_NULL, null=True, blank=True, db_column='meta') """ Meta points to the defintion of the attribute field. That is a handful of AttributeTypes are associated to a given MediaType that is pointed to by this value. That set describes the `attribute` field of this structure. """ attributes = JSONField(null=True, blank=True) """ Values of user defined attributes. """ gid = CharField(max_length=36, null=True, blank=True) """ Group ID for the upload that created this media. Note we intentionally do not use UUIDField because this field is provided by the uploader and not guaranteed to be an actual UUID. """ uid = CharField(max_length=36, null=True, blank=True) """ Unique ID for the upload that created this media. Note we intentionally do not use UUIDField because this field is provided by the uploader and not guaranteed to be an actual UUID. """ created_datetime = DateTimeField(auto_now_add=True, null=True, blank=True) created_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, related_name='media_created_by', db_column='created_by') modified_datetime = DateTimeField(auto_now=True, null=True, blank=True) modified_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, related_name='media_modified_by', db_column='modified_by') name = CharField(max_length=256) md5 = SlugField(max_length=32) """ md5 hash of the originally uploaded file. """ file = FileField(null=True, blank=True) last_edit_start = DateTimeField(null=True, blank=True) """ Start datetime of a session in which the media's annotations were edited. """ last_edit_end = DateTimeField(null=True, blank=True) """ End datetime of a session in which the media's annotations were edited. """ original = FilePathField(path=settings.RAW_ROOT, null=True, blank=True) thumbnail = ImageField(null=True, blank=True) thumbnail_gif = ImageField(null=True, blank=True) num_frames = IntegerField(null=True, blank=True) fps = FloatField(null=True, blank=True) codec = CharField(null=True, blank=True, max_length=256) width = IntegerField(null=True) height = IntegerField(null=True) segment_info = FilePathField(path=settings.MEDIA_ROOT, null=True, blank=True) media_files = JSONField(null=True, blank=True) recycled_from = ForeignKey(Project, on_delete=SET_NULL, null=True, blank=True, related_name='recycled_from')