Просмотр исходного кода

feat: add to_json() to Source, Interval & Feature

This lets us serialise properly
main
Rob Hallam 3 месяцев назад
Родитель
Сommit
6b83118b91
1 измененных файлов: 22 добавлений и 0 удалений
  1. +22
    -0
      pipeline/utils.py

+ 22
- 0
pipeline/utils.py Просмотреть файл

@@ -92,6 +92,13 @@ class Source():
self._duration = 0.0 or float(subprocess.check_output(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", file]))
return self._duration

def to_json(self):
"""Return a dict representation of the source for JSON encoding

@see video_producers.py:PipelineJSONEncoder
"""
return dict(source=self.source, path=self.path, provider=self.provider)



class Interval():
@@ -113,6 +120,7 @@ class Interval():
# TODO: have default duration for intervals set by config
# TODO: consider if we want to permit adjusting intervals (eg, start time, end time, duration) [probably yes]
# NOTE: if we have more ways of defining, we could consider multipledispatch?
# TODO: consider if we want to keep a reference to the media file (source) in the interval

DEFAULT_DURATION = 5 # seconds
DEFAUT_PRECISION = 3 # decimal places
@@ -171,6 +179,13 @@ class Interval():
return self.end < other.end
return self.start < other.start

def to_json(self):
"""Return a dict representation of the interval for JSON encoding

@see video_producers.py:PipelineJSONEncoder
"""
return dict(start=self.start, end=self.end, duration=self.duration)

# --------------------------------------------------------------
# TODO: handle bad cases, eg negative duration, start > end, etc
# --------------------------------------------------------------
@@ -261,3 +276,10 @@ class Feature():
return self.score < other.score
return self.source < other.source
return self.interval < other.interval
def to_json(self):
"""Return a dict representation of the feature for JSON encoding

@see video_producers.py:PipelineJSONEncoder
"""
return dict(interval=self.interval.to_json(), source=self.source.to_json(),
feature_extractor=self.feature_extractor, score=self.score)

Загрузка…
Отмена
Сохранить