Connect to Granta MI
Connect to Granta MI and specify the database and table containing the test results. Since this operation is likely to be performed as a batch operation, see the notebook on Storing Credentials Securely for more information how to connect to Granta MI securely in a batch Python script.Find test data to process
Before we start, we need to find the Test Data records we want to process by applying the following criteria:- The test record has test data which has not previously been compared to a specification.
- The test record is linked to a specification record.
Criteria 1: Test data that has not been compared to a specification
First, define the attributes that contain the relevant test data, and the name of the meta-attribute that contains specification comparison results (if they exist). A dictionary is used for test data attributes so they can be mapped to the corresponding specification attributes.ATTRIBUTES constant to get the previously unprocessed records for each
one. Use a dictionary with the record.record_guid as the key to ensure you only get unique records (a single
record may be missing multiple attributes, and we only want to process each record once).
record values from the dict and confirm the number of unprocessed records identified.
Criteria 2: Test data with linked specifications
To compare test data to specification values, each unprocessed record must also be linked to a specification record containing those values. Therefore, we need to filter theunprocessed_records list to include only those records
that have a link to a Specification Values record.
Use the test_data_table.bulk_link_fetch() method to improve performance by fetching links for all records in a
single operation. The link group name is stored in a constant, since we will need to refer to it later.
Compare test data to specification values
Now check each record in therecords_to_process list against its linked specification.
Pre-fetch the data
First, pre-fetch all the attributes in the Specification Values and Tensile Test Data tables that are required for the analysis. (This step is optional, but helps improve performance for large datasets.) Pre-fetching data using thebulk_fetch() operation generally requires three types of objects: a list of attributes,
a list of records, and the table to fetch the data from.
For the test data, we already have the test_data_table object and the list of records. However, we need to construct
the list of attributes. We want to export the following:
- The Specimen ID attribute, used for printing status information while performing the comparison
- The list of test data attributes defined as values in the
COMPARISON_ATTRIBUTESdictionary - The Specification Status meta-attribute
bulk_fetch() to fetch the data.
- Create a single flat list of all linked specification records. Use a
setas the intermediary container to only include unique records. - Extract the table name from one of the specification records and create a
specification_tableobject. - Use the
specification_tableobject to bulk fetch the data.
Comparison logic
Next, write a function that compares the test data attribute and the specification attribute and returns the result as a string. This function includes an initial check to ensure values exist for both attributes. If either attribute does not have a value, returnNone.
Compare the data
Finally, iterate over all records in therecords_to_process list and all attributes in the COMPARISON_ATTRIBUTES
constant. For each combination of record and attribute, call the function defined above and store the result in the
Specification Status meta-attribute. The comparison is skipped if the meta-attribute is already populated.