Explorar el Código

refactor!: viz+json producer: add simple config option for output

BREAKING CHANGE: default is now to save to current working directory instead of tmp
main
Rob Hallam hace 3 meses
padre
commit
f160a83967
Se han modificado 1 ficheros con 13 adiciones y 6 borrados
  1. +13
    -6
      pipeline/producers.py

+ 13
- 6
pipeline/producers.py Ver fichero

@@ -24,7 +24,6 @@ class Producer(ABC):
class VideoProducer(Producer):
"""Video producer interface."""


class FfmpegVideoProducer(VideoProducer):
"""Produce videos using ffmpeg"""
# TODO: consider output filename options
@@ -105,11 +104,16 @@ class FfmpegVideoProducer(VideoProducer):

class VisualisationProducer(Producer):
"""Visualisation producer -- illustrate the features we have extracted"""
def __init__(self, features):
DEFAULT_OUTPUT_FILEPATH = "visualisation.png"
def __init__(self, features, output_filepath=DEFAULT_OUTPUT_FILEPATH):
if not features:
raise ValueError("No features provided")
self.features = features

if not output_filepath:
raise ValueError("No output filepath provided")
self.output_filepath = output_filepath # TODO: sanity check this

def produce(self):
"""Produce visualisation"""
# basic idea: use matplotlib to plot:
@@ -150,7 +154,7 @@ class VisualisationProducer(Producer):
ax.set_yticks([])
# ax.tick_params(axis='y', labelrotation=90, ha='right')
# save the plot
plt.savefig("/tmp/visualisation.png")
plt.savefig(self.output_filepath)
plt.close()

class PipelineJSONEncoder(json.JSONEncoder):
@@ -162,12 +166,15 @@ class PipelineJSONEncoder(json.JSONEncoder):

class JSONProducer(Producer):
"""Produce JSON output"""
def __init__(self, features):
DEFAULT_OUTPUT_FILEPATH = "features.json"
def __init__(self, features, output_filepath=DEFAULT_OUTPUT_FILEPATH):
if not features:
raise ValueError("No features provided")
self.features = features
if not output_filepath:
raise ValueError("No output filepath provided")
self.output_filepath = output_filepath

def produce(self):
# FIXME: config option for output path
with open("/tmp/features.json", "w") as jsonfile:
with open(self.output_filepath, "w") as jsonfile:
jsonfile.write(json.dumps(self.features, cls=PipelineJSONEncoder, indent=4))

Cargando…
Cancelar
Guardar