From f8a05efc31a67979f6863b6eb2d12dce605f8bbc Mon Sep 17 00:00:00 2001 From: d3m1g0d Date: Mon, 4 Mar 2019 16:57:19 +0100 Subject: [PATCH] Started work on storage backend --- backend/storage.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 backend/storage.py diff --git a/backend/storage.py b/backend/storage.py new file mode 100644 index 0000000..18122bb --- /dev/null +++ b/backend/storage.py @@ -0,0 +1,28 @@ +# storage.py - storage backend for TeraHz +# Copyright Kristjan KomloĊĦi 2019 +# This code is licensed under the 3-clause BSD license + +import file +import json +import pandas as pd + +class measurementStorage(): + def __init__(self, directory): + self.storageDirectory = directory + + def storeJSON(self, JSON): + # JSON sanity check, shouldn't be needed, but just in case... + if 'metadata' not in JSON or 'timestamp' not in JSON['metadata']: + raise Exception('Invalid JSON passed to storage backend: no timestamp') + + if 'spectral' not in JSON or [x for x in 'ABCDEFGHIJKLMNOPQR'] not in JSON['spectral']: + raise Exception('Invalid JSON passed to storage backend: no spectral data') + + if 'uv' not in JSON or ['a', 'b', 'i'] not in JSON['uv']: + raise Exception('Invalid JSON passed to storage backend: no UVA/B/I data') + + if 'lux' not in JSON: + raise Exception('Invalid JSON passed to storage backend: no illuminance data') + + filename = JSON['metadata']['timestamp'] + '.thz' + with file.open()