소스 검색

feat: add JSONEncoder class

Handles serialisation of custom classes via to_json() method if present
main
Rob Hallam 2 달 전
부모
커밋
8d188cab19
1개의 변경된 파일11개의 추가작업 그리고 0개의 파일을 삭제
  1. +11
    -0
      pipeline/video_producers.py

+ 11
- 0
pipeline/video_producers.py 파일 보기

@@ -10,6 +10,10 @@ import tempfile
# for visualisations:
import matplotlib.pyplot as plt

# for encoding as JSON
from pipeline.utils import Feature


class Producer(ABC):
"""Generic producer interface."""
def __init__(self, features):
@@ -141,6 +145,13 @@ class VisualisationProducer(Producer):
plt.savefig("/tmp/visualisation.png")
plt.close()

class PipelineJSONEncoder(json.JSONEncoder):
def default(self, obj):
if hasattr(obj, 'to_json'):
return obj.to_json()
else:
return json.JSONEncoder.default(self, obj)

class JSONProducer(Producer):
"""Produce JSON output"""
def __init__(self, features):


불러오는 중...
취소
저장