storeTemp() and loadTemp()
This commit is contained in:
+11
-16
@@ -5,24 +5,19 @@
|
|||||||
import file
|
import file
|
||||||
import json
|
import json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
class measurementStorage():
|
class measurementStorage():
|
||||||
def __init__(self, directory):
|
def __init__(self, directory):
|
||||||
self.storageDirectory = directory
|
self.storagePath = Path(directory)
|
||||||
|
if not self.storagePath.exists():
|
||||||
|
raise Exception('Storage directory does not exist')
|
||||||
|
|
||||||
def storeJSON(self, JSON):
|
def storeTemp(self, jsonObject):
|
||||||
# JSON sanity check, shouldn't be needed, but just in case...
|
with self.storagepath / 'temp.thz' as tempfile:
|
||||||
if 'metadata' not in JSON or 'timestamp' not in JSON['metadata']:
|
json.dump(jsonObject, tempfile)
|
||||||
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']:
|
def loadTemp(self):
|
||||||
raise Exception('Invalid JSON passed to storage backend: no spectral data')
|
with self.storagePath / 'temp.thz' as tempfile:
|
||||||
|
return json.load(tempfile)
|
||||||
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()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user