From 3b360eaf530416c83d5c1ddc6b65a777e5901f58 Mon Sep 17 00:00:00 2001 From: ferugit Date: Fri, 10 Mar 2023 14:28:11 +0100 Subject: [PATCH] add a json reporter --- src/keyword_spotting/reporter.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/keyword_spotting/reporter.py diff --git a/src/keyword_spotting/reporter.py b/src/keyword_spotting/reporter.py new file mode 100644 index 0000000..39af19e --- /dev/null +++ b/src/keyword_spotting/reporter.py @@ -0,0 +1,19 @@ +import os +import json + +class Reporter: + def __init__(self, experiment_path, filename): + self.experiment_path = experiment_path + self.file_name = filename + self.output_file = os.path.join(experiment_path, self.file_name) + self.data = {} + + def __del__(self): + with open(self.output_file , 'w', encoding='utf-8') as f: + json.dump(self.data, f, ensure_ascii=False, indent=4) + + def report(self, key, data): + self.data[key] = data + + def load(self, filepath): + self.data = json.load(open(filepath, 'r')) \ No newline at end of file