From bd3547dcab96e73e13a79349ec61bfea7d0c58d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Wed, 23 Jun 2021 13:28:52 +0200
Subject: [PATCH] up

---
 integrationtests/crawl.py                             |  4 ++--
 integrationtests/model.yml                            |  8 ++++++++
 integrationtests/test_crawler_with_cfoods.py          | 11 +++++++++++
 src/caosadvancedtools/scifolder/__init__.py           |  1 +
 src/caosadvancedtools/scifolder/result_table_cfood.py |  6 ++++--
 unittests/test.csv                                    |  2 +-
 6 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/integrationtests/crawl.py b/integrationtests/crawl.py
index 65600016..61f51c29 100755
--- a/integrationtests/crawl.py
+++ b/integrationtests/crawl.py
@@ -34,7 +34,7 @@ from caosadvancedtools.crawler import FileCrawler
 from caosadvancedtools.guard import INSERT, UPDATE
 from caosadvancedtools.scifolder import (AnalysisCFood, ExperimentCFood,
                                          PublicationCFood, SimulationCFood,
-                                         SoftwareCFood)
+                                         SoftwareCFood, ResultTableCFood)
 
 try:
     from sss_helper import get_argument_parser, print_success
@@ -89,7 +89,7 @@ if __name__ == "__main__":
                     interactive=False, hideKnown=False,
                     cfood_types=[ExperimentCFood, AnalysisCFood, SoftwareCFood,
                                  PublicationCFood, SimulationCFood,
-                                 ])
+                                 ResultTableCFood])
 
     if args.authorize_run:
         for run_id in args.authorize_run:
diff --git a/integrationtests/model.yml b/integrationtests/model.yml
index 0a4ad381..357adfc7 100644
--- a/integrationtests/model.yml
+++ b/integrationtests/model.yml
@@ -18,6 +18,14 @@ SoftwareVersion:
     binaries:
     sourceCode:
     Software:
+DepthTest:
+  obligatory_properties:
+    temperature:
+      datatype: DOUBLE 
+      description: 'temp'
+    depth:
+      datatype: DOUBLE 
+      description: 'temp'
 Person:
   obligatory_properties:
     firstName:
diff --git a/integrationtests/test_crawler_with_cfoods.py b/integrationtests/test_crawler_with_cfoods.py
index c39c3fc6..18aa4847 100755
--- a/integrationtests/test_crawler_with_cfoods.py
+++ b/integrationtests/test_crawler_with_cfoods.py
@@ -57,6 +57,17 @@ class CrawlerTest(unittest.TestCase):
                          datfile.description)
         assert os.path.basename(datfile.path) == "datafile.dat"
 
+        # There should be two DepthTest Properties
+        depthtests = exp.get_property("DepthTest")
+        assert len(depthtests) == 1
+        assert len(depthtests.value) == 2
+        depthtest = db.Record(id=depthtests.value[0])
+        depthtest.retrieve()
+        assert "DepthTest" in [p.name for p in project.get_parents()]
+        assert 234.4 == depthtest.get_property("temperature").value[0]
+        assert "簞C" == depthtest.get_property("temperature").unit
+        assert 3.0 == depthtest.get_property("depth").value[0]
+
         # Should have a responsible person
         self.assertIsNotNone(exp.get_property("responsible"))
         person = db.Record(id=exp.get_property("responsible").value[0])
diff --git a/src/caosadvancedtools/scifolder/__init__.py b/src/caosadvancedtools/scifolder/__init__.py
index d7d67937..cf753cfc 100644
--- a/src/caosadvancedtools/scifolder/__init__.py
+++ b/src/caosadvancedtools/scifolder/__init__.py
@@ -3,3 +3,4 @@ from .experiment_cfood import ExperimentCFood
 from .publication_cfood import PublicationCFood
 from .simulation_cfood import SimulationCFood
 from .software_cfood import SoftwareCFood
+from .result_table_cfood import ResultTableCFood
diff --git a/src/caosadvancedtools/scifolder/result_table_cfood.py b/src/caosadvancedtools/scifolder/result_table_cfood.py
index edd65b30..b6e5573d 100644
--- a/src/caosadvancedtools/scifolder/result_table_cfood.py
+++ b/src/caosadvancedtools/scifolder/result_table_cfood.py
@@ -17,6 +17,7 @@
 # along with this program. If not, see <https://www.gnu.org/licenses/>.
 
 import caosdb as db
+import re
 import pandas as pd
 from caosadvancedtools.cfood import (AbstractFileCFood, assure_has_description,
                                      assure_has_parent, assure_has_property,
@@ -63,7 +64,7 @@ class ResultTableCFood(AbstractFileCFood):
             rec.add_parent(self.match.group("recordtype"))
 
             for col in self.table.columns[:2]:
-                match = ResultTableCFood.match(col)
+                match = re.match(ResultTableCFood.property_name_re, col)
 
                 if match.group("unit"):
                     rec.add_property(match.group("pname"), row.loc[col], unit=match.group("unit"))
@@ -77,6 +78,7 @@ class ResultTableCFood(AbstractFileCFood):
     def update_identifiables(self):
         for ii, (idx, row) in enumerate(self.table.iterrows()):
             for col in row.index:
-                assure_property_is(self.recs[ii], col, row.loc[col], to_be_updated=self.to_be_updated)
+                match = re.match(ResultTableCFood.property_name_re, col)
+                assure_property_is(self.recs[ii], match.group("pname"), row.loc[col], to_be_updated=self.to_be_updated)
         assure_property_is(self.experiment, self.match.group("recordtype"),
                            self.recs, to_be_updated=self.to_be_updated)
diff --git a/unittests/test.csv b/unittests/test.csv
index f8ec95d3..b005ccf1 100644
--- a/unittests/test.csv
+++ b/unittests/test.csv
@@ -1,3 +1,3 @@
-demperature [蚓] ,depth [m]
+temperature [蚓] ,depth 
 234.4,3.0
 344.6,5.1
-- 
GitLab