sdata 0.23.3__tar.gz → 0.24.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sdata-0.23.3/sdata.egg-info → sdata-0.24.0}/PKG-INFO +1 -1
- {sdata-0.23.3 → sdata-0.24.0}/sdata/__init__.py +1 -1
- {sdata-0.23.3 → sdata-0.24.0}/sdata/data.py +77 -2
- {sdata-0.23.3 → sdata-0.24.0}/sdata/image.py +4 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/metadata.py +16 -0
- {sdata-0.23.3 → sdata-0.24.0/sdata.egg-info}/PKG-INFO +1 -1
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_data.py +22 -0
- {sdata-0.23.3 → sdata-0.24.0}/LICENSE-MIT +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/MANIFEST.in +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/README.md +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/blob.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/attrdict/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/attrdict/default.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/attrdict/dictionary.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/attrdict/mapping.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/attrdict/merge.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/attrdict/mixins.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_common.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_dump.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_exceptions.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_exif.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_insert.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_load.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_remove.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_transplant.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/_webp.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/piexif/helper.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/collections/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/collections/rangebucketmap.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/collections/rangemap.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/collections/rangeset.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/range/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/range/cut.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/ranger/range/range.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/semver.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/simple_graph_db/LICENSE +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/simple_graph_db/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/simple_graph_db/database.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/simple_graph_db/schema.sql +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sobol_seq.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sortedcontainers/LICENSE +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sortedcontainers/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sortedcontainers/sorteddict.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sortedcontainers/sortedlist.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sortedcontainers/sortedset.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/sqlitedict.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/timeflake/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/timeflake/flake.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/contrib/timeflake/utils.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/doe.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/experiments/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/experiments/ks2.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/experiments/lapshear.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/experiments/material.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/db.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/hdf.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/isomme.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/pgp.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/pud.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/simple_signature.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/iolib/vault.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/suuid.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/timestamp.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/tools.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata/workbook.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata.egg-info/SOURCES.txt +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata.egg-info/dependency_links.txt +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata.egg-info/requires.txt +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/sdata.egg-info/top_level.txt +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/setup.cfg +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/setup.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/iolib/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/iolib/pud/__init__.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/iolib/pud/test_pud.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/iolib/test_hdf.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_attribute.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_blob.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_image.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_io.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_ks2.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_metadata.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_sqlite.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_suuid.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_table.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_testprogram.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_timeflake.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_timestamp.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_tools.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_vault.py +0 -0
- {sdata-0.23.3 → sdata-0.24.0}/tests/test_workbook.py +0 -0
|
@@ -24,6 +24,7 @@ import json
|
|
|
24
24
|
import hashlib
|
|
25
25
|
import base64
|
|
26
26
|
import requests
|
|
27
|
+
import re
|
|
27
28
|
from tabulate import tabulate
|
|
28
29
|
from sdata.contrib.sqlitedict import SqliteDict
|
|
29
30
|
|
|
@@ -46,6 +47,24 @@ except:
|
|
|
46
47
|
def uuid_from_str(name):
|
|
47
48
|
return uuid.uuid3(uuid.NAMESPACE_DNS, name)
|
|
48
49
|
|
|
50
|
+
def nameunit_from_colname(column_name):
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
#pattern = r"^(.*?)\s*\[(.+)\]$"
|
|
55
|
+
pattern = r"^(.*?)\s*\[([^\]]+)\]$"
|
|
56
|
+
|
|
57
|
+
# Anwenden des Regex
|
|
58
|
+
match = re.match(pattern, column_name)
|
|
59
|
+
|
|
60
|
+
if match:
|
|
61
|
+
name = match.group(1) # Der Name der Spalte
|
|
62
|
+
unit = match.group(2) # Die Einheit
|
|
63
|
+
else:
|
|
64
|
+
name = column_name
|
|
65
|
+
unit = "-"
|
|
66
|
+
return name.strip(), unit.strip()
|
|
67
|
+
|
|
49
68
|
class Data(object):
|
|
50
69
|
"""Base sdata object"""
|
|
51
70
|
ATTR_NAMES = []
|
|
@@ -61,6 +80,7 @@ class Data(object):
|
|
|
61
80
|
SDATA_CLASS = "!sdata_class"
|
|
62
81
|
SDATA_PROJECT = "!sdata_project"
|
|
63
82
|
SDATA_URL = "!sdata_url"
|
|
83
|
+
SDATA_COLUMN = "!sdata_column"
|
|
64
84
|
|
|
65
85
|
SDATA_ATTRIBUTES = [SDATA_VERSION, SDATA_NAME, SDATA_UUID, SDATA_SUUID, SDATA_CLASS, SDATA_PARENT, SDATA_PROJECT,
|
|
66
86
|
SDATA_CTIME, SDATA_MTIME, SDATA_URL]
|
|
@@ -166,6 +186,10 @@ class Data(object):
|
|
|
166
186
|
if "sname" in kwargs:
|
|
167
187
|
self.sname = kwargs.get("sname")
|
|
168
188
|
|
|
189
|
+
|
|
190
|
+
if "parent" in kwargs:
|
|
191
|
+
self.metadata.add(self.SDATA_PARENT, kwargs.get("parent"))
|
|
192
|
+
|
|
169
193
|
def gen_suuid(self):
|
|
170
194
|
self.suuid = sdata.SUUID(self.__class__.__name__, self.name, huuid=self.uuid).idstr
|
|
171
195
|
self.sname = sdata.SUUID(self.__class__.__name__, self.name, huuid=self.uuid).sname
|
|
@@ -212,6 +236,10 @@ class Data(object):
|
|
|
212
236
|
self._set_uuid(suuid.huuid)
|
|
213
237
|
return self
|
|
214
238
|
|
|
239
|
+
@property
|
|
240
|
+
def m(self):
|
|
241
|
+
return self.metadata
|
|
242
|
+
|
|
215
243
|
def update_mtime(self):
|
|
216
244
|
"""update modification time
|
|
217
245
|
|
|
@@ -520,6 +548,49 @@ class Data(object):
|
|
|
520
548
|
data.to_folder(exportpath, dtype=dtype)
|
|
521
549
|
return path
|
|
522
550
|
|
|
551
|
+
def set_column_metadata(self):
|
|
552
|
+
"""convert 'Force [N]' -> 'Force', 'N'
|
|
553
|
+
|
|
554
|
+
add Attribute for each column
|
|
555
|
+
|
|
556
|
+
sdata_column_0: value="Force", unit="N"
|
|
557
|
+
sdata_column_1
|
|
558
|
+
...
|
|
559
|
+
sdata_column_n
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
"""
|
|
563
|
+
if self.df is None:
|
|
564
|
+
return
|
|
565
|
+
for i, col in enumerate(self.df.columns):
|
|
566
|
+
name, unit = nameunit_from_colname(col)
|
|
567
|
+
scolname = f"{self.SDATA_COLUMN}_{i}"
|
|
568
|
+
self.metadata.add(scolname, value=name, unit=unit, label=col)
|
|
569
|
+
|
|
570
|
+
def set_columnnames_from_metadata(self):
|
|
571
|
+
"""Use '!sdata_column_*' to reformat columns names
|
|
572
|
+
|
|
573
|
+
'!sdata_column_0', value='Force', unit='N' -> 'Force [N]'
|
|
574
|
+
|
|
575
|
+
> f'{name} [{unit}]'
|
|
576
|
+
|
|
577
|
+
"""
|
|
578
|
+
if self.df is None:
|
|
579
|
+
return
|
|
580
|
+
|
|
581
|
+
cols = []
|
|
582
|
+
for i, col in enumerate(self.df.columns):
|
|
583
|
+
scolname = f"{self.SDATA_COLUMN}_{i}"
|
|
584
|
+
attr = self.metadata.get(scolname)
|
|
585
|
+
if attr is None:
|
|
586
|
+
name, unit = nameunit_from_colname(col)
|
|
587
|
+
else:
|
|
588
|
+
name = attr.value
|
|
589
|
+
unit = attr.unit
|
|
590
|
+
new_colname = f'{name} [{unit}]'
|
|
591
|
+
cols.append(new_colname)
|
|
592
|
+
self.df.columns = cols
|
|
593
|
+
|
|
523
594
|
@classmethod
|
|
524
595
|
def from_folder(cls, path):
|
|
525
596
|
"""sdata object instance
|
|
@@ -1018,15 +1089,19 @@ class Data(object):
|
|
|
1018
1089
|
:param sep: separator (default=";")
|
|
1019
1090
|
:return: sdata.Data
|
|
1020
1091
|
"""
|
|
1092
|
+
if s is None and filepath is None:
|
|
1093
|
+
logging.error("specify string if filepath")
|
|
1094
|
+
return
|
|
1021
1095
|
data = cls()
|
|
1022
1096
|
df = None
|
|
1023
1097
|
try:
|
|
1024
1098
|
if filepath:
|
|
1025
1099
|
df = pd.read_csv(filepath, sep=";", comment="#", index_col=0)
|
|
1026
1100
|
sio = open(filepath, "r")
|
|
1101
|
+
sio.seek(0)
|
|
1027
1102
|
elif s is not None:
|
|
1028
1103
|
sio = StringIO(s)
|
|
1029
|
-
pd.read_csv(sio, sep=";", comment="#")
|
|
1104
|
+
df = pd.read_csv(sio, sep=";", comment="#")
|
|
1030
1105
|
sio.seek(0)
|
|
1031
1106
|
else:
|
|
1032
1107
|
logger.error("data.from_csv: no csv data available")
|
|
@@ -1274,7 +1349,7 @@ class Data(object):
|
|
|
1274
1349
|
:return: Data
|
|
1275
1350
|
"""
|
|
1276
1351
|
data = copy.deepcopy(self)
|
|
1277
|
-
data.metadata.add(self.SDATA_PARENT, self.
|
|
1352
|
+
data.metadata.add(self.SDATA_PARENT, self.suuid)
|
|
1278
1353
|
data.metadata.add(self.SDATA_UUID, self.gen_uuid())
|
|
1279
1354
|
data.metadata.add(self.SDATA_MTIME, now_utc_str(), dtype="str")
|
|
1280
1355
|
if "uuid" in kwargs:
|
|
@@ -455,6 +455,22 @@ class Metadata(object):
|
|
|
455
455
|
"""create dataframe for user attributes"""
|
|
456
456
|
return self._to_dataframe(self.user_attributes)
|
|
457
457
|
|
|
458
|
+
@property
|
|
459
|
+
def dft(self):
|
|
460
|
+
"""create transposed dataframe for sdata attributes"""
|
|
461
|
+
mt = self.df[["value"]].transpose(copy=True)
|
|
462
|
+
mt.index = [self.get("!sdata_sname").value]
|
|
463
|
+
return mt
|
|
464
|
+
|
|
465
|
+
def get_dft(self, index_name=None):
|
|
466
|
+
"""create transposed dataframe for sdata attributes"""
|
|
467
|
+
if index_name is None:
|
|
468
|
+
index_name = "!sdata_sname"
|
|
469
|
+
mt = self.df[["value"]].transpose(copy=True)
|
|
470
|
+
mt.index = [self.get(index_name).value]
|
|
471
|
+
return mt
|
|
472
|
+
|
|
473
|
+
|
|
458
474
|
@property
|
|
459
475
|
def sdf(self):
|
|
460
476
|
"""create dataframe for sdata attributes"""
|
|
@@ -25,6 +25,28 @@ def test_data():
|
|
|
25
25
|
|
|
26
26
|
assert data2.uuid == uuidobj.hex
|
|
27
27
|
|
|
28
|
+
def test_column_units():
|
|
29
|
+
columns = ["Länge [mm]", "Breite [cm]", "wtf", "Spannung[MPa]"]
|
|
30
|
+
df = pd.DataFrame(columns=columns)
|
|
31
|
+
d = sdata.Data(table=df)
|
|
32
|
+
d.set_column_metadata()
|
|
33
|
+
print(d.sdf)
|
|
34
|
+
c0 = d.m.get("!sdata_column_0")
|
|
35
|
+
|
|
36
|
+
assert "!sdata_column_3" in d.m.keys()
|
|
37
|
+
assert c0
|
|
38
|
+
print(c0.value, c0.unit)
|
|
39
|
+
assert c0.value == "Länge"
|
|
40
|
+
assert c0.unit == "mm"
|
|
41
|
+
|
|
42
|
+
c3 = d.m.get("!sdata_column_3")
|
|
43
|
+
print(c3.value, c3.unit)
|
|
44
|
+
assert c3.value == "Spannung"
|
|
45
|
+
assert c3.unit == "MPa"
|
|
46
|
+
c4 = d.m.get("!sdata_column_4")
|
|
47
|
+
assert c4 is None
|
|
48
|
+
|
|
49
|
+
|
|
28
50
|
def test_group():
|
|
29
51
|
|
|
30
52
|
data1 = sdata.Data(name="data1", uuid="38b26864e7794f5182d38459bab8584f")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|