From 4ecc95174ef3d901be7cd38942c47a7714357ffd Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Tue, 13 Aug 2024 09:59:36 +0100 Subject: [PATCH] feat: add JSONProducer Outputs a representation of the Features extrated by the pipeline Intent is to write a FE that takes the output so that a pipeline can be 're-run' Output JSON could also be used with external tools --- pipeline/video_producers.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pipeline/video_producers.py b/pipeline/video_producers.py index d078cee..45c09e8 100644 --- a/pipeline/video_producers.py +++ b/pipeline/video_producers.py @@ -1,6 +1,7 @@ """Classes for producing videos""" from abc import ABC +import json import logging import os import subprocess @@ -139,3 +140,15 @@ class VisualisationProducer(Producer): # save the plot plt.savefig("/tmp/visualisation.png") plt.close() + +class JSONProducer(Producer): + """Produce JSON output""" + def __init__(self, features): + if not features: + raise ValueError("No features provided") + self.features = features + + def produce(self): + # FIXME: config option for output path + with open("/tmp/features.json", "w") as jsonfile: + jsonfile.write(json.dumps(self.features, cls=PipelineJSONEncoder, indent=4))