-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from BAMresearch/unittest-mixture-metadata-ext…
…raction Unittest mixture metadata extraction
- Loading branch information
Showing
10 changed files
with
222 additions
and
167 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import unittest | ||
import rdflib | ||
import datetime | ||
import os | ||
import yaml | ||
from pathlib import Path | ||
|
||
from lebedigital.mapping.emodul_mapping import generate_knowledge_graph, get_date_time_value | ||
|
||
class TestMappingScript(unittest.TestCase): | ||
|
||
def query_and_test_result(self, typeOfQuery, predicate, prop, g): | ||
print(f"""Query for {typeOfQuery}:""") | ||
q = f""" | ||
SELECT ?o WHERE {{ | ||
{predicate} {prop} ?o . | ||
}} | ||
""" | ||
print(q) | ||
result = g.query(q) | ||
return result | ||
|
||
|
||
def print_next(self): | ||
print("Pass") | ||
print("###################Next Query#####################################") | ||
|
||
|
||
def print_first(self): | ||
print("###################First Query####################################") | ||
|
||
|
||
def test_generate_knowledge_graph(self): | ||
metadataPath = 'testMetaData.yaml' | ||
filename = "knowledgeGraph.ttl" | ||
print("Start testing:") | ||
# Generate a testMetadata file | ||
print("Generate metadata file for test:") | ||
target_data = {'experimentName': 'BA-Losert MI E-Modul 28d v. 04.08.14 Probe 4', | ||
'software_specification': 'MTS793|MPT|DEU|1|2|,|.|:|49|1|1|A', | ||
'operator_timestamp': '13:25:39', | ||
'operator_date': '01.09.2014', | ||
'tester_name': 'Kh', | ||
'specimen_name': 'BA-Losert E-Modul 28d v. 04.08.14 Probe 4', | ||
'remark': 'Kraftgeregelt 3,9 kN/s', | ||
'weight': 5342.0, | ||
'weight_unit': 'g', | ||
'diameter': 98.6, | ||
'length': 300.3, | ||
'length_unit': 'mm', | ||
'mix_file': '2014_08_05 Rezeptur_MI.xlsx'} | ||
|
||
with open(metadataPath, 'w') as yamlFile: | ||
yaml.dump(target_data, yamlFile) | ||
print("Generate knowledgeGraph:") | ||
generate_knowledge_graph(metadataPath, filename) | ||
|
||
g = rdflib.Graph() | ||
result = g.parse(filename, format='ttl') | ||
print("Query knowledgeGraph:") | ||
|
||
self.print_first() | ||
|
||
result = self.query_and_test_result('diameter', 'ns1:informationbearingentity1', | ||
'ns7:has_decimal_value', g) | ||
for row in result: | ||
self.assertEqual(target_data['diameter'], float(row.o)) | ||
|
||
self.print_next() | ||
|
||
result = self.query_and_test_result('length', 'ns1:informationbearingentity2', | ||
'ns7:has_decimal_value', g) | ||
for row in result: | ||
self.assertEqual(target_data['length'], float(row.o)) | ||
|
||
self.print_next() | ||
|
||
result = self.query_and_test_result('weight', 'ns1:informationbearingentity3', | ||
'ns7:has_decimal_value', g) | ||
for row in result: | ||
self.assertEqual(target_data['weight'], float(row.o)) | ||
|
||
self.print_next() | ||
|
||
time = get_date_time_value(target_data) | ||
result = self.query_and_test_result('operator_time', 'ns1:informationbearingentity6', | ||
'ns1:has_datetime_value', g) | ||
for row in result: | ||
self.assertEqual(time, datetime.datetime.strptime(str(row.o).replace('T', ' '), "%Y-%m-%d %H:%M:%S")) | ||
|
||
self.print_next() | ||
|
||
result = self.query_and_test_result('operatorName', 'ns1:informationbearingentity7', | ||
'ns7:has_text_value', g) | ||
for row in result: | ||
self.assertEqual(target_data['tester_name'], str(row.o)) | ||
|
||
self.print_next() | ||
result = self.query_and_test_result('rawFileName', 'ns1:informationbearingentity4', | ||
'ns7:has_text_value', g) | ||
for row in result: | ||
self.assertEqual(target_data['experimentName'], str(row.o)) | ||
|
||
self.print_next() | ||
result = self.query_and_test_result('rawFileName', 'ns1:informationbearingentity5', | ||
'ns7:has_text_value', g) | ||
rawPath = os.path.join(Path(__file__).parents[2], 'usecases', | ||
'MinimumWorkingExample', 'Data', 'E-modul', target_data['experimentName']) | ||
|
||
for row in result: | ||
self.assertEqual(rawPath, str(row.o)) | ||
|
||
print('Pass all tests') | ||
|
||
print("Deleting test files:") | ||
os.remove(filename) | ||
os.remove(metadataPath) | ||
|
||
print("End testing") | ||
|
||
# test_generate_knowledge_graph() |
49 changes: 49 additions & 0 deletions
49
tests/raw_data_processing/mixture/test_mixture_metadata_extraction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
from lebedigital.raw_data_processing.mixture.mixture_metadata_extraction import extract_metadata_mixture | ||
|
||
|
||
def test_mixture_metadata_extraction(): | ||
"""Testing the mixture metadata extraction on a single example""" | ||
|
||
# setting up the test example input | ||
input_path = '../usecases/MinimumWorkingExample/Data/Mischungen/2014_08_05 Rezeptur_MI.xlsx' | ||
|
||
# make sure that the path exists | ||
assert(os.path.exists(input_path)) | ||
|
||
target_data = {'operator_date': '2014-06-30', | ||
'tester_name': 'Werner', | ||
'specimen_name': 'BA-Losert MI', | ||
'cement--QuantityInMix': 330.0, | ||
'cement--BulkDensity': 3.123, | ||
'cement--Volume': 105.7, | ||
'cement--Annotation': 'CEM I 42.5 R', | ||
'water_total--QuantityInMix': 175.0, | ||
'water_total--BulkDensity': 1.0, | ||
'water_total--Volume': 175.0, | ||
'water_cement_ratio': 0.5303030303030303, | ||
'water_effective--QuantityInMix': float('nan'), | ||
'water_effective--BulkDensity': float('nan'), | ||
'water_effective--Volume': float('nan'), | ||
'air_content--QuantityInMix': 0.0, | ||
'air_content--BulkDensity': 0.0, | ||
'air_content--Volume': 20.0, | ||
'addition1--QuantityInMix': 273.0, | ||
'addition1--BulkDensity': 2.74, | ||
'addition1--Volume': 99.6, | ||
'addition1--Annotation': 'Medenbach - Kalksteinmehl', | ||
'admixture--QuantityInMix': 5.61, | ||
'admixture--BulkDensity': 1.05, | ||
'admixture--Volume': 5.3, | ||
'admixture--Annotation': 'FM 595 BASF', | ||
'aggregate--QuantityInMix': 1564.0, | ||
'aggregate--BulkDensity': float('nan'), | ||
'aggregate--Volume': 594.4000000000001} | ||
|
||
# run extraction and getting a dictionary with metadata | ||
test_data = extract_metadata_mixture(input_path, None) | ||
|
||
# test each value | ||
# conversion to string is required as float.nan != float.nan | ||
for key in target_data.keys(): | ||
assert(str(test_data[key]) == str(target_data[key])) |
32 changes: 32 additions & 0 deletions
32
tests/raw_data_processing/youngs_modulus_data/test_metadata_extraction_emodul.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
|
||
from lebedigital.raw_data_processing.youngs_modulus_data \ | ||
.emodul_metadata_extraction import extract_metadata_emodulus | ||
class TestMetaDataExtractionEmodul(unittest.TestCase): | ||
def test_metadata_extraction_emodul(self): | ||
"""Tesing the metadata extraction on a single example""" | ||
|
||
# setting up the test example | ||
input = '../usecases/MinimumWorkingExample/Data/E-modul/BA-Losert MI E-Modul 28d v. 04.08.14 Probe 4' | ||
mix_file = 'mix.dat' | ||
specimen_file = 'specimen.dat' | ||
|
||
target_data = {'experimentName': 'BA-Losert MI E-Modul 28d v. 04.08.14 Probe 4', | ||
'software_specification': 'MTS793|MPT|DEU|1|2|,|.|:|49|1|1|A', | ||
'operator_timestamp': '13:25:39', | ||
'operator_date': '01.09.2014', | ||
'tester_name': 'Kh', | ||
'specimen_name': 'BA-Losert E-Modul 28d v. 04.08.14 Probe 4', | ||
'remark': 'Kraftgeregelt 3,9 kN/s', | ||
'weight': 5342.0, | ||
'weight_unit': 'g', | ||
'diameter': 98.6, | ||
'length': 300.3, | ||
'length_unit': 'mm', | ||
'mix_file': '2014_08_05 Rezeptur_MI.xlsx'} | ||
|
||
# run extraction and getting a dictionary with metadata | ||
test_data = extract_metadata_emodulus(input, specimen_file, mix_file) | ||
|
||
# checking if result is correct | ||
self.assertEqual(test_data, target_data) |
20 changes: 20 additions & 0 deletions
20
tests/raw_data_processing/youngs_modulus_data/test_processed_data_from_rawdata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import unittest | ||
import os | ||
|
||
from lebedigital.raw_data_processing.youngs_modulus_data.emodul_generate_processed_data import \ | ||
processed_data_from_rawdata | ||
|
||
class TestProcessedDataFromRawData(unittest.TestCase): | ||
|
||
def test_emodul_generate_processed_data(self): | ||
""" | ||
Testing the processed data generation on a single experiment | ||
""" | ||
|
||
rawdata_location = '../usecases/MinimumWorkingExample/Data/E-modul/BA-Losert MI E-Modul 28d v. 04.08.14 Probe 4' | ||
processeddat_location = './BA-Losert MI E-Modul 28d v. 04.08.14 Probe 4' + '.csv' | ||
|
||
processed_data_from_rawdata(locationOfRawData=rawdata_location, locationOfProcessedData=processeddat_location) | ||
|
||
self.assertTrue(os.path.exists('./BA-Losert MI E-Modul 28d v. 04.08.14 Probe 4.csv')) | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.