def FindUnitTypes(): """ returns a mapping of all the unit names to the unit types raises an exception if there is more than one option -- this will check the unit database for duplicated names """ unit_types = {} for unit_type in ConvertDataUnits.keys(): if unit_type == "Oil Concentration" or unit_type == "Concentration In Water": continue # skipping Oil Concentration, 'cause this is really length -- lots of duplicate units! # skipping Concentration in water, cause this has lots of duplicate units for PrimaryName, data in ConvertDataUnits[unit_type].items(): # strip out whitespace and capitalization #Pname = Simplify(PrimaryName) Pname = PrimaryName # add the primary name: unit_types[Pname] = unit_type # now the synonyms: for n in data[1]: if unit_type == "Volume" and n == 'oz': continue # skip, "oz" is only mass if unit_types.has_key(n): raise ValueError("Duplicate name in units table: %s" % n) unit_types[n] = unit_type return unit_types
def GetUnitTypes(): """ returns a list of all the unit types available a unit type is something like "mass", "velocity", etc. """ return ConvertDataUnits.keys()
def FindUnitTypes(): """ returns a mapping of all the unit names to the unit types raises an exception if there is more than one option -- this will check the unit database for duplicated names Usually not called from user code. """ unit_types = {} for unit_type in ConvertDataUnits.keys(): if unit_type == "Oil Concentration" or unit_type == "Concentration In Water": continue # skipping Oil Concentration, 'cause this is really length -- lots of duplicate units! # skipping Concentration in water, cause this has lots of duplicate units for PrimaryName, data in ConvertDataUnits[unit_type].items(): # strip out whitespace and capitalization #Pname = Simplify(PrimaryName) Pname = PrimaryName # add the primary name: unit_types[Pname] = unit_type # now the synonyms: for n in data[1]: if unit_type == "Volume" and n == 'oz': continue # skip, "oz" is only mass if unit_types.has_key(n): raise ValueError("Duplicate name in units table: %s"%n) unit_types[n] = unit_type return unit_types
def GetUnitTypes(): return ConvertDataUnits.keys()