ooiservices/app/uframe/vocab.py
def build_display_name(rd):
    """ Get display name for reference designator using the codes dictionary.

        "CE01ISSM": {
          "id": 0,
          "long_name": "Endurance OR Inshore Surface Mooring",
          "name": "OR Inshore Surface Mooring"
        },
        "CE01ISSM-MFC31": {
          "id": 0,
          "long_name": "Endurance OR Inshore Surface Mooring Multi-Function Node",
          "name": "Multi-Function Node"
        },
        "CE01ISSM-MFC31-00-CPMENG000": {
          "id": 1,
          "long_name": "Endurance OR Inshore Surface Mooring Multi-Function Node Buoy Controller Engineering",
          "name": "Buoy Controller Engineering"
        },

    {
      "@class" : ".VocabRecord",
      "refdes" : "CE01ISSM-MFC31-00-CPMENG000",
      "vocabId" : 1,
      "instrument" : "Buoy Controller Engineering",
      "tocL1" : "Endurance",
      "tocL2" : "OR Inshore Surface Mooring",
      "tocL3" : "Multi-Function Node"
    }

    Test cases:
        RS01SUM2-MJ01B-06-MASSPA101
        RS03INT1-MJ03C-06-MASSPA301
        GI03FLMA-RIS01-00-SIOENG000

    """
    try:
        # Get 'vocab_dict' if cached, if not cached build cache, set and continue
        dict_cached = cache.get('vocab_codes')
        if dict_cached:
            vocab_codes = dict_cached
        else:
            vocab_dict, vocab_codes = _compile_vocab()
            cache.set('vocab_dict', vocab_dict, timeout=CACHE_TIMEOUT)
            cache.set('vocab_codes', vocab_codes, timeout=CACHE_TIMEOUT)

        # Verify 'vocab_codes' has content, otherwise error
        if not vocab_codes:
            message = 'Vocabulary processing failed to obtain vocab_codes dictionary, unable to process.'
            current_app.logger.info(message)
            return None

        # Process reference designator using 'vocab_dict' and 'vocab_codes'
        len_rd = len(rd)
        if len_rd < 8:
            return None

        # Prepare prefix processing for Endurance array vocab (tocL2)
        prefix = ''
        array_code = rd[:2]

        # For endurance array, check subsite and apply prefix as required.
        if array_code == 'CE':
            key = rd[0:3]
            if key == 'CE01' or key == 'CE02' or key == 'CE04':
                prefix = 'OR '
            elif key == 'CE06' or key == 'CE07' or key == 'CE09':
                prefix = 'WA '

        # Build display name for instrument
        if len_rd == 27:
            subsite, node, instr = rd.split('-', 2)  # subsite = 'CE01ISSM', node = 'MFC31'
            port, instrument = instr.split('-')
            instr_class = instrument[0:5]
            line4 = None
            if instr_class in vocab_codes['classes']:
                line4 = vocab_codes['classes'][instr_class]

            if line4 is None:
                return None

            result = line4

        # Build display name for platform
        elif len_rd == 14:
            subsite, node = rd.split('-')  # subsite = 'CE01ISSM', node = 'MFC31'
            node_code = node[0:2]
            line3 = None
            if node_code in vocab_codes['nodes']:
                line3 = vocab_codes['nodes'][node_code]

            if line3 is None:
                return None

            result = line3

        # Build display name for mooring
        elif len_rd == 8:
            subsite = rd
            subsite_code = subsite[4:8]

            line1 = None
            if array_code in vocab_codes['arrays']:
                line1 = vocab_codes['arrays'][array_code]

            line2 = None
            if subsite_code in vocab_codes['subsites']:
                line2 = vocab_codes['subsites'][subsite_code]

            if line1 is None or line2 is None:
                return None

            if prefix:
                line2 = prefix + line2

            result = ' '.join([line1, line2])

        else:
            return None

        #print '\n\t ***** debug -- build_display_name -- result: ', result
        return result
    except Exception as err:
        message = 'Exception in build display name for %s; %s' % (rd, str(err))
        current_app.logger.info(message)
        return None
 Get display name for reference designator using the codes dictionary.

        "CE01ISSM": {
          "id": 0,
          "long_name": "Endurance OR Inshore Surface Mooring",
          "name": "OR Inshore Surface Mooring"
        },
        "CE01ISSM-MFC31": {
          "id": 0,
          "long_name": "Endurance OR Inshore Surface Mooring Multi-Function Node",
          "name": "Multi-Function Node"
        },
        "CE01ISSM-MFC31-00-CPMENG000": {
          "id": 1,
          "long_name": "Endurance OR Inshore Surface Mooring Multi-Function Node Buoy Controller Engineering",
          "name": "Buoy Controller Engineering"
        },

    {
      "@class" : ".VocabRecord",
      "refdes" : "CE01ISSM-MFC31-00-CPMENG000",
      "vocabId" : 1,
      "instrument" : "Buoy Controller Engineering",
      "tocL1" : "Endurance",
      "tocL2" : "OR Inshore Surface Mooring",
      "tocL3" : "Multi-Function Node"
    }

    Test cases:
        RS01SUM2-MJ01B-06-MASSPA101
        RS03INT1-MJ03C-06-MASSPA301
        GI03FLMA-RIS01-00-SIOENG000

    
Get display name for reference designator using the codes dictionary.




Get display name for reference designator using the codes dictionary .
def build_display_name(rd):
    try:
        dict_cached = cache.get('vocab_codes')
        if dict_cached:
            vocab_codes = dict_cached
        else:
            vocab_dict, vocab_codes = _compile_vocab()
            cache.set('vocab_dict', vocab_dict, timeout=CACHE_TIMEOUT)
            cache.set('vocab_codes', vocab_codes, timeout=CACHE_TIMEOUT)
        if not vocab_codes:
            message = 'Vocabulary processing failed to obtain vocab_codes dictionary, unable to process.'
            current_app.logger.info(message)
            return None
        len_rd = len(rd)
        if len_rd < 8:
            return None
        prefix = ''
        array_code = rd[:2]
        if array_code == 'CE':
            key = rd[0:3]
            if key == 'CE01' or key == 'CE02' or key == 'CE04':
                prefix = 'OR '
            elif key == 'CE06' or key == 'CE07' or key == 'CE09':
                prefix = 'WA '
        if len_rd == 27:
            subsite, node, instr = rd.split('-', 2)  
            port, instrument = instr.split('-')
            instr_class = instrument[0:5]
            line4 = None
            if instr_class in vocab_codes['classes']:
                line4 = vocab_codes['classes'][instr_class]
            if line4 is None:
                return None
            result = line4
        elif len_rd == 14:
            subsite, node = rd.split('-')  
            node_code = node[0:2]
            line3 = None
            if node_code in vocab_codes['nodes']:
                line3 = vocab_codes['nodes'][node_code]
            if line3 is None:
                return None
            result = line3
        elif len_rd == 8:
            subsite = rd
            subsite_code = subsite[4:8]
            line1 = None
            if array_code in vocab_codes['arrays']:
                line1 = vocab_codes['arrays'][array_code]
            line2 = None
            if subsite_code in vocab_codes['subsites']:
                line2 = vocab_codes['subsites'][subsite_code]
            if line1 is None or line2 is None:
                return None
            if prefix:
                line2 = prefix + line2
            result = ' '.join([line1, line2])
        else:
            return None
        return result
    except Exception as err:
        message = 'Exception in build display name for %s; %s' % (rd, str(err))
        current_app.logger.info(message)
        return None
def build_display_name ( rd ) : try : dict_cached = cache . get ( 'vocab_codes' ) if dict_cached : vocab_codes = dict_cached else : vocab_dict , vocab_codes = _compile_vocab ( ) cache . set ( 'vocab_dict' , vocab_dict , timeout = CACHE_TIMEOUT ) cache . set ( 'vocab_codes' , vocab_codes , timeout = CACHE_TIMEOUT ) if not vocab_codes : message = 'Vocabulary processing failed to obtain vocab_codes dictionary, unable to process.' current_app . logger . info ( message ) return None len_rd = len ( rd ) if len_rd < 8 : return None prefix = '' array_code = rd [ : 2 ] if array_code == 'CE' : key = rd [ 0 : 3 ] if key == 'CE01' or key == 'CE02' or key == 'CE04' : prefix = 'OR ' elif key == 'CE06' or key == 'CE07' or key == 'CE09' : prefix = 'WA ' if len_rd == 27 : subsite , node , instr = rd . split ( '-' , 2 ) port , instrument = instr . split ( '-' ) instr_class = instrument [ 0 : 5 ] line4 = None if instr_class in vocab_codes [ 'classes' ] : line4 = vocab_codes [ 'classes' ] [ instr_class ] if line4 is None : return None result = line4 elif len_rd == 14 : subsite , node = rd . split ( '-' ) node_code = node [ 0 : 2 ] line3 = None if node_code in vocab_codes [ 'nodes' ] : line3 = vocab_codes [ 'nodes' ] [ node_code ] if line3 is None : return None result = line3 elif len_rd == 8 : subsite = rd subsite_code = subsite [ 4 : 8 ] line1 = None if array_code in vocab_codes [ 'arrays' ] : line1 = vocab_codes [ 'arrays' ] [ array_code ] line2 = None if subsite_code in vocab_codes [ 'subsites' ] : line2 = vocab_codes [ 'subsites' ] [ subsite_code ] if line1 is None or line2 is None : return None if prefix : line2 = prefix + line2 result = ' ' . join ( [ line1 , line2 ] ) else : return None return result except Exception as err : message = 'Exception in build display name for %s; %s' % ( rd , str ( err ) ) current_app . logger . info ( message ) return None
Get display name for reference designator using the codes dictionary.
Get display name for reference designator using the codes dictionary .
""" Get display name for reference designator using the codes dictionary.

        "CE01ISSM": {
          "id": 0,
          "long_name": "Endurance OR Inshore Surface Mooring",
          "name": "OR Inshore Surface Mooring"
        },
        "CE01ISSM-MFC31": {
          "id": 0,
          "long_name": "Endurance OR Inshore Surface Mooring Multi-Function Node",
          "name": "Multi-Function Node"
        },
        "CE01ISSM-MFC31-00-CPMENG000": {
          "id": 1,
          "long_name": "Endurance OR Inshore Surface Mooring Multi-Function Node Buoy Controller Engineering",
          "name": "Buoy Controller Engineering"
        },

    {
      "@class" : ".VocabRecord",
      "refdes" : "CE01ISSM-MFC31-00-CPMENG000",
      "vocabId" : 1,
      "instrument" : "Buoy Controller Engineering",
      "tocL1" : "Endurance",
      "tocL2" : "OR Inshore Surface Mooring",
      "tocL3" : "Multi-Function Node"
    }

    Test cases:
        RS01SUM2-MJ01B-06-MASSPA101
        RS03INT1-MJ03C-06-MASSPA301
        GI03FLMA-RIS01-00-SIOENG000

    """ # Get 'vocab_dict' if cached, if not cached build cache, set and continue # Verify 'vocab_codes' has content, otherwise error # Process reference designator using 'vocab_dict' and 'vocab_codes' # Prepare prefix processing for Endurance array vocab (tocL2) # For endurance array, check subsite and apply prefix as required. # Build display name for instrument # subsite = 'CE01ISSM', node = 'MFC31' # Build display name for platform # subsite = 'CE01ISSM', node = 'MFC31' # Build display name for mooring #print '\n\t ***** debug -- build_display_name -- result: ', result
rd