From f94ffa73ce14ca949d029d1fe8105d8887441b42 Mon Sep 17 00:00:00 2001
From: Zhichao Zhang <zhichao.zhang@stud.tu-darmstadt.de>
Date: Mon, 5 Sep 2022 21:07:02 +0200
Subject: [PATCH] move keyvalue class into archive

---
 {pykkn => .archive}/dataset_keyvalue.py | 96 ++++++++++++++-----------
 1 file changed, 55 insertions(+), 41 deletions(-)
 rename {pykkn => .archive}/dataset_keyvalue.py (75%)

diff --git a/pykkn/dataset_keyvalue.py b/.archive/dataset_keyvalue.py
similarity index 75%
rename from pykkn/dataset_keyvalue.py
rename to .archive/dataset_keyvalue.py
index 138191a..c5f3b6b 100644
--- a/pykkn/dataset_keyvalue.py
+++ b/.archive/dataset_keyvalue.py
@@ -1,17 +1,17 @@
 import numpy as np
-
-from dataset import Dataset
-from instrument import Instrument
-from model import Model
-from parameter import Parameter
-from pipeline import Pipeline
-from run import Run
-from storage import Storage
+from pykkn.dataset import Dataset
+from pykkn.instrument import Instrument
+from pykkn.model import Model
+from pykkn.parameter import Parameter
+from pykkn.pipeline import Pipeline
+from pykkn.run import Run
+from pykkn.storage import Storage
 
 
 class Dataset_KeyValue(Storage):
 
-    """Dataset_KeyValue class is used as a converter between a dictionary formated in an HDF5 storable way to a hdf file
+    """Dataset_KeyValue class is used as a converter between a
+    dictionary formated in an HDF5 storable way to a HDF file
 
 
     Parameters
@@ -58,46 +58,48 @@ class Dataset_KeyValue(Storage):
 
         Parameter:
         1. see if dictname = parameter;
-        2. if last group = parameter, go into dict and create parameter for each (e. g.: gain, offset )
+        2. if last group = parameter, go into dict and create parameter
+        for each (e. g.: gain, offset )
         3. Go into the parameters and add the attributes
 
         Data is similar to parameter, just that we add data instead
 
-        XXXXXXXXXX  data kann also have attributes  ----> How would attributes look in a JSON-> Dict?
+        XXXXXXXXXX  data kann also have attributes  ---->
+        How would attributes look in a JSON-> Dict?
 
 
 
 
         _Group : str
-            parameter to be used by the recursive function; describes the last "wrapper class" (pipeline,instruments,model)
+            parameter to be used by the recursive function; describes
+            the last "wrapper class" (pipeline,instruments,model)
 
         _last_group : str
             parameter to be used by the recursive function
 
         Dict : list, tuple, dict
             nested key value pairs -->
-            Dicti[key]: whole dictionary is called by the name Dicti, to get a single value Dicti[key] is called
+            Dicti[key]: whole dictionary is called by the name Dicti,
+            to get a single value Dicti[key] is called
             Dict structure => Dicti = {key : value, .. ,}
         """
 
-        #     (self, Dict, _last_group = None, _key = None, _nested_group):: Key is the key as string/object
+        #     (self, Dict, _last_group = None, _key = None, _nested_group)::
+        # Key is the key as string/object
         for key in Dict:
             """key : value
             key = our key as a string
             Dict[key] = value of key
             """
-            #### run
-
             if (
                 isinstance(Dict[key], (list, tuple, dict))
-                and _last_group == None
-                and _key == None
+                and _last_group is None
+                and _key is None
             ):  # first dict name is the name of the run (e.g. run_01)
                 key = Run(key)
                 key.add([self.nested_dict(Dict[key], "run_start")])
                 key.store()
 
-            #### param
             # TODO
             if (
                 isinstance(Dict[key], (list, tuple, dict))
@@ -117,7 +119,6 @@ class Dataset_KeyValue(Storage):
             elif _last_group == "parameters":  # add parameter attributes
                 _key.attrs[key] = Dict[key]  # gain.attrs["value"] = 10 ..
 
-            #### dataset
             # TODO
             if (
                 isinstance(Dict[key], (list, tuple, dict))
@@ -127,16 +128,19 @@ class Dataset_KeyValue(Storage):
                 return self.nested_dict(Dict[key], "data")
 
             elif (
-                isinstance(Dict[key], (list, tuple, dict)) and _last_group == "data"
+                isinstance(Dict[key], (list, tuple, dict))
+                and _last_group == "data"
             ):  # create data class
                 key = Dataset(key)  # 1000 = dataset("1000")
                 self.nested_dict(Dict, "data", _key=key)
                 self.nested_dict(Dict[key], _last_group, key)
-                # key.data = self.nested_dict(Dict[key], _last_group, key) --- and return Dict[key]
+                # key.data = self.nested_dict(Dict[key], _last_group, key)
+                # --- and return Dict[key]
                 return key
 
             elif (
-                not isinstance(Dict[key], (list, tuple, dict)) and _last_group == "data"
+                not isinstance(Dict[key], (list, tuple, dict))
+                and _last_group == "data"
             ):  # add the meta data
                 _key.attrs[key] = Dict[key]
             # TODO
@@ -145,9 +149,8 @@ class Dataset_KeyValue(Storage):
             ):  # and not isinstance?                   # add data to dataset
                 _key.data = Dict[key]  # Can we pass a array like this?
                 # Is array list or tuple
-                # is it possible to get lists or tuples as data (add them for safety?)
-
-            #### model
+                # is it possible to get lists or tuples as data
+                # (add them for safety?)
 
             if (
                 isinstance(Dict[key], (list, tuple, dict))
@@ -158,20 +161,22 @@ class Dataset_KeyValue(Storage):
 
             # inside the model dict
 
-            elif isinstance(Dict[key], (list, tuple, dict)) and _last_group == "model":
+            elif (isinstance(Dict[key], (list, tuple, dict))
+                    and _last_group == "model"):
                 key = Model(key)  # create model class
                 self.nested_dict(Dict, "data", _key=key)  # check for meta data
-                key.add([self.nested_dict(Dict[key], _last_group="")])  # add models
+                key.add([self.nested_dict(Dict[key], _last_group="")])
+                # add models
                 return key
 
             # meta data
 
             elif (
-                not isinstance(Dict[key], (list, tuple, dict)) and _last_group == "data"
+                not isinstance(Dict[key], (list, tuple, dict))
+                and _last_group == "data"
             ):  # add the meta data
                 _key.attrs[key] = Dict[key]
 
-            #### instrument
             # TODO
             if (
                 isinstance(Dict[key], (list, tuple, dict))
@@ -196,16 +201,19 @@ class Dataset_KeyValue(Storage):
             # meta data
 
             elif (
-                not isinstance(Dict[key], (list, tuple, dict)) and _last_group == "data"
+                not isinstance(Dict[key], (list, tuple, dict))
+                and _last_group == "data"
             ):  # add the meta data
                 _key.attrs[key] = Dict[key]
 
-            #### pipeline
+            # pipeline
             # TODO
             if (
-                isinstance(Dict[key], (list, tuple, dict)) and key == "pipeline"
+                isinstance(Dict[key], (list, tuple, dict))
+                    and key == "pipeline"
             ):  # check if pipeline
-                return self.nested_dict(Dict[key], "pipeline", _nested_group=None)
+                return self.nested_dict(Dict[key],
+                                        "pipeline", _nested_group=None)
 
             # inside the pipeline dict
 
@@ -218,19 +226,24 @@ class Dataset_KeyValue(Storage):
                 and key != "model"
                 and key != "parameters"
             ):
-                if _nested_group == None:
-                    return self.nested_dict(Dict[key], "pipeline", _nested_group=key)
-                elif _nested_group != None:
+                if _nested_group is None:
+                    return self.nested_dict(Dict[key],
+                                            "pipeline",
+                                            _nested_group=key)
+                elif _nested_group is not None:
                     return self.nested_dict(
-                        Dict[key], "pipeline", _nested_group=_nested_group + "/" + key
+                        Dict[key], "pipeline",
+                        _nested_group=_nested_group + "/" + key
                     )  # measured/capa1/raw
 
             # create the pipeline with nested name
 
             elif (
-                isinstance(Dict[key], (list, tuple, dict)) and _last_group == "pipeline"
+                isinstance(Dict[key], (list, tuple, dict))
+                and _last_group == "pipeline"
             ):
-                _nested_group = Pipeline(_nested_group)  # create instrument class
+                _nested_group = Pipeline(_nested_group)
+                # create instrument class
                 self.nested_dict(
                     Dict, "data", _key=_nested_group
                 )  # check for meta data
@@ -242,7 +255,8 @@ class Dataset_KeyValue(Storage):
             # meta data
 
             elif (
-                not isinstance(Dict[key], (list, tuple, dict)) and _last_group == "data"
+                not isinstance(Dict[key], (list, tuple, dict))
+                and _last_group == "data"
             ):  # add the meta data
                 _key.attrs[key] = Dict[key]
 
-- 
GitLab