def testStandardFieldNameWithoutIncrement(self): test_unincremented_standard_field = StandardField( namespace_name='', standard_field_name='water_temperature_sensor' ) self.assertEqual( test_unincremented_standard_field.GetStandardFieldName(), 'water_temperature_sensor')
class StandardFieldTest(absltest.TestCase): def setUp(self): super().setUp() self.test_standard_field = StandardField( namespace_name='', standard_field_name='supply_air_flowrate_sensor', increment='_1_12') def testGetIncrement(self): expected_output = '_1_12' function_output = self.test_standard_field.GetIncrement() self.assertEqual(function_output, expected_output) def testGetNamespaceName(self): # testing with '' because it is the global namespace which, in practice, # all fields are defined under the global namespace expected_output = '' function_output = self.test_standard_field.GetNamespaceName() self.assertEqual(function_output, expected_output) def testGetStandardFieldName(self): expected_output = 'supply_air_flowrate_sensor' function_output = self.test_standard_field.GetStandardFieldName() self.assertEqual(function_output, expected_output) def testEqualityWithEntityTypeField(self): test_entity_type_field = EntityTypeField( namespace_name='', standard_field_name='supply_air_flowrate_sensor', is_optional=False, increment='_1_12') self.assertEqual(test_entity_type_field, self.test_standard_field) def testStandardFieldNameWithoutIncrement(self): test_unincremented_standard_field = StandardField( namespace_name='', standard_field_name='water_temperature_sensor' ) self.assertEqual( test_unincremented_standard_field.GetStandardFieldName(), 'water_temperature_sensor') def testIncorrectSFNRaisesValueError(self): # Standard field names cannot start with numbers incorrect_standard_field_name = '9lives_is_what_a_cat_has' with self.assertRaises(ValueError): StandardField( namespace_name='', standard_field_name=incorrect_standard_field_name, increment='_1' )
def IsFieldValid(self, field: StandardField) -> bool: """A method to validate a field name against the ontology.""" if not isinstance(field, StandardField): raise TypeError('Field argument must be a StandardField object.\n' + f'You provided a {type(field)} object.') namespace_name = field.GetNamespaceName() standard_field_name = field.GetStandardFieldName() validity = self.universe.field_universe.IsFieldDefined( namespace_name=namespace_name, fieldname=standard_field_name) return validity
def testStandardizeField(self): expected_output = StandardField( namespace_name='', standard_field_name='supply_air_flowrate_sensor') function_output = StandardizeField(self.test_entity_type_field) self.assertEqual(function_output, expected_output)
def testIncorrectSFNRaisesValueError(self): # Standard field names cannot start with numbers incorrect_standard_field_name = '9lives_is_what_a_cat_has' with self.assertRaises(ValueError): StandardField( namespace_name='', standard_field_name=incorrect_standard_field_name, increment='_1' )
def testGetEntityTypesFromFields(self): input_field_list = [ StandardField('', 'exhaust_air_damper_command'), StandardField('', 'exhaust_air_damper_status'), StandardField('', 'manufacturer_label'), StandardField('', 'model_label') ] etu = self.universe.entity_type_universe expected_output = [ Match(input_field_list, etu.GetEntityType('HVAC', 'DMP_EDM'), 100), Match(input_field_list, etu.GetEntityType('HVAC', 'SDC_EXT'), 25), Match(input_field_list, etu.GetEntityType('HVAC', 'CHWS_WDT'), 0) ] function_output = self.ontology.GetEntityTypesFromFields(input_field_list) for i in range(len(expected_output)): self.assertEqual(expected_output[i], function_output[i])
class StandardFieldTest(absltest.TestCase): def setUp(self): super(StandardFieldTest).setUp() self.test_standard_field = StandardField( namespace_name='', standard_field_name='supply_air_flowrate_sensor') def testGetNamespaceName(self): # testing with '' because it is the global namespace which, in practice, # all fields are defined under the global namespace expected_output = '' function_output = self.test_standard_field.GetNamespaceName() self.assertEqual(function_output, expected_output) def testGetStandardFieldName(self): expected_output = 'supply_air_flowrate_sensor' function_output = self.test_standard_field.GetStandardFieldName() self.assertEqual(function_output, expected_output)
def testFilterTypesWithGeneralTypeFromFields(self): input_general_type = 'CHWS' input_field_list = [ StandardField('', 'return_water_temperature_sensor'), StandardField('', 'flowrate_requirement'), StandardField('', 'differential_pressure_specification'), StandardField('', 'supply_water_temperature_sensor'), StandardField('', 'thermal_power_capacity') ] expected_entity_type = self.universe.entity_type_universe.GetEntityType( namespace_name='HVAC', typename='CHWS_WDT' ) expected_output = [Match(input_field_list, expected_entity_type, 100)] function_output = self.ontology.GetEntityTypesFromFields( input_field_list, general_type=input_general_type ) for i in range(len(expected_output)): self.assertEqual(expected_output[i], function_output[i])
def _InputFieldsFromUser() -> List[StandardField]: """Method to take in field inputs from the user. Returns: A list of StandardField objects corresponding to the input field names. """ standard_field_list = [] raw_fields = input('Enter your fields here as a comma separated list: ') raw_field_list = raw_fields.replace(' ', '').split(',') for field in raw_field_list: split_field = re.split(FIELD_INCREMENT_REGEX, field) standard_field = StandardField(standard_field_name=split_field[0], namespace_name='', increment=split_field[1]) standard_field_list.append(standard_field) return standard_field_list
def _InputFieldsFromUser(ontology) -> List[StandardField]: """Method to take in field inputs from the user. Args: ontology: Instance of OntologyWrapper class. Returns: A list of StandardField objects corresponding to the input field names. """ standard_field_list = [] raw_fields = input('Enter your fields here as a comma separated list: ') raw_field_list = raw_fields.replace(' ', '').split(',') for field in raw_field_list: standard_field = StandardField(standard_field_name=field, namespace_name='') if ontology.IsFieldValid(standard_field): standard_field_list.append(standard_field) return standard_field_list
def GetEntityTypeForStandardFieldList( self, raw_field_list: List[str], ontology: ontology_wrapper.OntologyWrapper) -> str: """Calls entity type matcher to determine an entity's type based on a list of fields. Args: raw_field_list: A list of standard field names to use as input with the entity type matcher. ontology: An OntologyWrapper instance for interfacing with DBO. Returns: A canonical entity type corresponding to the input fields. """ standard_field_list = [] for field in raw_field_list: standard_field = StandardField(standard_field_name=field, namespace_name='') if ontology.IsFieldValid(standard_field): standard_field_list.append(standard_field) matches = ontology.GetEntityTypesFromFields( field_list=standard_field_list) generated_type_name = matches[0].GetEntityType().typename return generated_type_name
def setUp(self): super().setUp() self.test_standard_field = StandardField( namespace_name='', standard_field_name='supply_air_flowrate_sensor', increment='_1_12')
def testEqualityWithStandardField(self): test_standard_field = StandardField( namespace_name='', standard_field_name='supply_air_flowrate_sensor') self.assertEqual(test_standard_field, self.test_entity_type_field)
def testInvalidField(self): invalid_test_field = StandardField('HVAC', 'exhaust_air_damper_command') function_output = self.ontology.IsFieldValid(invalid_test_field) self.assertFalse(function_output)
def testValidField(self): valid_test_field = StandardField('', 'zone_use_label') function_output = self.ontology.IsFieldValid(valid_test_field) self.assertTrue(function_output)
def setUp(self): super(StandardFieldTest).setUp() self.test_standard_field = StandardField( namespace_name='', standard_field_name='supply_air_flowrate_sensor')