ooiservices/app/uframe/vocab.py
def _compile_vocab():
    """ Get list of vocab items from uframe. Return dict (with reference designator as key), None or exception.
    Update cache 'vocab_dict' is successful. This function called from tasks for scheduled cache updates.

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

    Sample response dictionary (when VOCAB_PLUS enabled):
    {
        "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"
        },

        len(uframe vocab): (974):
        len(results): 974
        len(results_plus): 281
    """
    print '\n -- Compile vocabulary...'
    results = {}        # vocabulary generated from uframe vocab
    results_plus = {}   # additional vocabulary gleaned from uframe vocab
    try:

        # Get vocabulary from uframe.
        vocabs = get_vocab_from_uframe()

        """
        # If uframe vocabulary not available, return empty dicts.
        if not vocabs or vocabs is None:
            message = 'Vocabulary returned from uframe is empty; check uframe vocabulary configuration.'
            current_app.logger.info(message)
            raise Exception(message)
        """

        vocabulary, codes = preprocess_vocab_data(vocabs)

        # Process each vocab item into one or more dictionaries; return dict
        for vocab in vocabulary:

            # Process each vocab item
            rd = vocab['refdes']
            if rd not in results:

                len_rd = len(rd)

                # uframe currently provides only reference designators for instruments.
                if len_rd != 27:
                    message = 'Uframe vocab reference designator %s is not an instrument.' % rd
                    current_app.logger.info(message)
                    continue

                # Process uframe vocab consisting of instrument reference designators only.
                if len_rd == 27:

                    display_name, name, id = make_display_name(vocab)
                    if display_name is not None and name is not None:
                        results[rd] = {'long_name': display_name, 'name': name, 'id': id}

                    # Add additional information to resulting vocabulary (lighten dependency on db)
                    if VOCAB_PLUS:

                        # Process array; note id set to 0
                        array_code = rd[:2]
                        long_name = vocab['tocL1']
                        name = vocab['tocL1']
                        id = 0
                        results_plus[array_code] = {'long_name': long_name, 'name': name, 'id': 0}

                        # Process subsite (mooring); note id set to 0
                        subsite, node, _ = rd.split('-',2)
                        if subsite not in results:
                            long_name = ' '.join([ vocab['tocL1'], vocab['tocL2']])
                            name = vocab['tocL2']
                            if long_name is not None and name is not None:
                                results_plus[subsite] = {'long_name': long_name, 'name': name, 'id': 0}

                        # Process platform (subsite & node); note id set to 0
                        platform = '-'.join([subsite, node])
                        if platform not in results:
                            long_name = ' '.join([vocab['tocL1'], vocab['tocL2']])
                            long_name += ' - ' + vocab['tocL3']
                            name = vocab['tocL3']
                            if long_name is not None and name is not None:
                                results_plus[platform] = {'long_name': long_name, 'name': name, 'id': 0}

            else:
                message = 'Reference designator %s duplicate in uframe vocab response.' % rd
                current_app.logger.info(message)

        # If additional array and platform entries desired in response, use VOCAB_PLUS
        if VOCAB_PLUS:
            results.update(results_plus)

        return results, codes

    except Exception as err:
        message = str(err)
        current_app.logger.info(message)
        raise
 Get list of vocab items from uframe. Return dict (with reference designator as key), None or exception.
    Update cache 'vocab_dict' is successful. This function called from tasks for scheduled cache updates.

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

    Sample response dictionary (when VOCAB_PLUS enabled):
    {
        "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"
        },

        len(uframe vocab): (974):
        len(results): 974
        len(results_plus): 281
    
Get list of vocab items from uframe. Return dict (with reference designator as key), None or exception.
Update cache 'vocab_dict' is successful. This function called from tasks for scheduled cache updates.






Get list of vocab items from uframe . Return dict ( with reference designator as key ) None or exception . Update cache ' vocab_dict ' is successful . This function called from tasks for scheduled cache updates .
def _compile_vocab():
    print '\n -- Compile vocabulary...'
    results = {}        
    results_plus = {}   
    try:
        vocabs = get_vocab_from_uframe()
        vocabulary, codes = preprocess_vocab_data(vocabs)
        for vocab in vocabulary:
            rd = vocab['refdes']
            if rd not in results:
                len_rd = len(rd)
                if len_rd != 27:
                    message = 'Uframe vocab reference designator %s is not an instrument.' % rd
                    current_app.logger.info(message)
                    continue
                if len_rd == 27:
                    display_name, name, id = make_display_name(vocab)
                    if display_name is not None and name is not None:
                        results[rd] = {'long_name': display_name, 'name': name, 'id': id}
                    if VOCAB_PLUS:
                        array_code = rd[:2]
                        long_name = vocab['tocL1']
                        name = vocab['tocL1']
                        id = 0
                        results_plus[array_code] = {'long_name': long_name, 'name': name, 'id': 0}
                        subsite, node, _ = rd.split('-',2)
                        if subsite not in results:
                            long_name = ' '.join([ vocab['tocL1'], vocab['tocL2']])
                            name = vocab['tocL2']
                            if long_name is not None and name is not None:
                                results_plus[subsite] = {'long_name': long_name, 'name': name, 'id': 0}
                        platform = '-'.join([subsite, node])
                        if platform not in results:
                            long_name = ' '.join([vocab['tocL1'], vocab['tocL2']])
                            long_name += ' - ' + vocab['tocL3']
                            name = vocab['tocL3']
                            if long_name is not None and name is not None:
                                results_plus[platform] = {'long_name': long_name, 'name': name, 'id': 0}
            else:
                message = 'Reference designator %s duplicate in uframe vocab response.' % rd
                current_app.logger.info(message)
        if VOCAB_PLUS:
            results.update(results_plus)
        return results, codes
    except Exception as err:
        message = str(err)
        current_app.logger.info(message)
        raise
def _compile_vocab ( ) : print '\n -- Compile vocabulary...' results = { } results_plus = { } try : vocabs = get_vocab_from_uframe ( ) """
        # If uframe vocabulary not available, return empty dicts.
        if not vocabs or vocabs is None:
            message = 'Vocabulary returned from uframe is empty; check uframe vocabulary configuration.'
            current_app.logger.info(message)
            raise Exception(message)
        """ vocabulary , codes = preprocess_vocab_data ( vocabs ) for vocab in vocabulary : rd = vocab [ 'refdes' ] if rd not in results : len_rd = len ( rd ) if len_rd != 27 : message = 'Uframe vocab reference designator %s is not an instrument.' % rd current_app . logger . info ( message ) continue if len_rd == 27 : display_name , name , id = make_display_name ( vocab ) if display_name is not None and name is not None : results [ rd ] = { 'long_name' : display_name , 'name' : name , 'id' : id } if VOCAB_PLUS : array_code = rd [ : 2 ] long_name = vocab [ 'tocL1' ] name = vocab [ 'tocL1' ] id = 0 results_plus [ array_code ] = { 'long_name' : long_name , 'name' : name , 'id' : 0 } subsite , node , _ = rd . split ( '-' , 2 ) if subsite not in results : long_name = ' ' . join ( [ vocab [ 'tocL1' ] , vocab [ 'tocL2' ] ] ) name = vocab [ 'tocL2' ] if long_name is not None and name is not None : results_plus [ subsite ] = { 'long_name' : long_name , 'name' : name , 'id' : 0 } platform = '-' . join ( [ subsite , node ] ) if platform not in results : long_name = ' ' . join ( [ vocab [ 'tocL1' ] , vocab [ 'tocL2' ] ] ) long_name += ' - ' + vocab [ 'tocL3' ] name = vocab [ 'tocL3' ] if long_name is not None and name is not None : results_plus [ platform ] = { 'long_name' : long_name , 'name' : name , 'id' : 0 } else : message = 'Reference designator %s duplicate in uframe vocab response.' % rd current_app . logger . info ( message ) if VOCAB_PLUS : results . update ( results_plus ) return results , codes except Exception as err : message = str ( err ) current_app . logger . info ( message ) raise
Get list of vocab items from uframe.
Get list of vocab items from uframe .
""" Get list of vocab items from uframe. Return dict (with reference designator as key), None or exception.
    Update cache 'vocab_dict' is successful. This function called from tasks for scheduled cache updates.

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

    Sample response dictionary (when VOCAB_PLUS enabled):
    {
        "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"
        },

        len(uframe vocab): (974):
        len(results): 974
        len(results_plus): 281
    """ # vocabulary generated from uframe vocab # additional vocabulary gleaned from uframe vocab # Get vocabulary from uframe. """
        # If uframe vocabulary not available, return empty dicts.
        if not vocabs or vocabs is None:
            message = 'Vocabulary returned from uframe is empty; check uframe vocabulary configuration.'
            current_app.logger.info(message)
            raise Exception(message)
        """ # Process each vocab item into one or more dictionaries; return dict # Process each vocab item # uframe currently provides only reference designators for instruments. # Process uframe vocab consisting of instrument reference designators only. # Add additional information to resulting vocabulary (lighten dependency on db) # Process array; note id set to 0 # Process subsite (mooring); note id set to 0 # Process platform (subsite & node); note id set to 0 # If additional array and platform entries desired in response, use VOCAB_PLUS