ooiservices/app/main/alertsalarms_tools.py
def process_toc_information_reference_designators(toc):
    """
    Get list of unique reference designators in /sensor/inv/toc; sorted ascending.
    If error log exception and return []. Includes all stream methods.
    Response output:
    {
      "reference_designators": [
        "CE01ISSP",                             # platform code
        "CE01ISSP-SP001",                       # platform code + mooring code
        "CE01ISSP-SP001-05-VELPTJ000",          # platform code + mooring code + instrument code
        "CE01ISSP-SP001-07-SPKIRJ000",
        "CE01ISSP-SP001-08-FLORTJ000",
        "CE01ISSP-SP001-09-CTDPFJ000",
        "CE01ISSP-SP001-10-PARADJ000",
        "CE01ISSP-XX001",
        "CE01ISSP-XX001-01-CTDPFJ999",
        "CE01ISSP-XX001-01CTDPFJ999",
        "CE01ISSP-XX099",
        "CE01ISSP-XX099-01-CTDPFJ999",
        "CE02SHBP",
        "CE02SHBP-LJ01D",
        . . .
        ]
    }
    """
    result = []
    rds = []
    try:
        if toc is None or not toc:
            message = 'toc is None or empty.'
            raise Exception(message)

        for item in toc:
            if item['reference_designator'] not in rds:
                rds.append(item['reference_designator'])                # format 'CP02PMCO-SBS01-00-RTE000000'

            platform_code = item['platform_code']                       # format 'CP02PMCO'
            if platform_code not in result:
                result.append(platform_code)

            mooring_code = item['mooring_code']                         # format 'SBS01', used with platform code
            instrument_code = item['instrument_code']

            _platform_code = "-".join([platform_code, mooring_code])    # format CP02PMCO-SBS01
            if _platform_code not in result:
                result.append(_platform_code)
            _instrument_code = "-".join([platform_code, mooring_code, instrument_code ])  #'CP02PMCO-SBS01-00-RTE000000'
            if _instrument_code not in result:
                result.append(_instrument_code)

        if rds:
            rds.sort()
        if result:
            result.sort()

        # Reviewing data from toc to see what we have and don't have...
        # Which items in result were not provided in rds?
        ommitted_reference_designators = []
        for item in result:
            if item not in rds:
                if item not in ommitted_reference_designators:
                    ommitted_reference_designators.append(item)
        if ommitted_reference_designators:
            ommitted_reference_designators.sort()

        """
        In brief, the 'reference_designators' provided in the /sensor/toc response, are less than the
        hierarchical structure (ui toc) count which would be generated to support those instruments.
        Namely, the difference being the list of omitted_reference_designators (47) shown above.
        """
        return result, rds, ommitted_reference_designators

    except Exception as err:
        current_app.logger.info(err.message)
        return [], [], []

    Get list of unique reference designators in /sensor/inv/toc; sorted ascending.
    If error log exception and return []. Includes all stream methods.
    Response output:
    {
      "reference_designators": [
        "CE01ISSP",                             # platform code
        "CE01ISSP-SP001",                       # platform code + mooring code
        "CE01ISSP-SP001-05-VELPTJ000",          # platform code + mooring code + instrument code
        "CE01ISSP-SP001-07-SPKIRJ000",
        "CE01ISSP-SP001-08-FLORTJ000",
        "CE01ISSP-SP001-09-CTDPFJ000",
        "CE01ISSP-SP001-10-PARADJ000",
        "CE01ISSP-XX001",
        "CE01ISSP-XX001-01-CTDPFJ999",
        "CE01ISSP-XX001-01CTDPFJ999",
        "CE01ISSP-XX099",
        "CE01ISSP-XX099-01-CTDPFJ999",
        "CE02SHBP",
        "CE02SHBP-LJ01D",
        . . .
        ]
    }
    
Get list of unique reference designators in /sensor/inv/toc; sorted ascending.
If error log exception and return []. Includes all stream methods.
Get list of unique reference designators in / sensor / inv / toc ; sorted ascending . If error log exception and return [] . Includes all stream methods .
def process_toc_information_reference_designators(toc):
    result = []
    rds = []
    try:
        if toc is None or not toc:
            message = 'toc is None or empty.'
            raise Exception(message)
        for item in toc:
            if item['reference_designator'] not in rds:
                rds.append(item['reference_designator'])                
            platform_code = item['platform_code']                       
            if platform_code not in result:
                result.append(platform_code)
            mooring_code = item['mooring_code']                         
            instrument_code = item['instrument_code']
            _platform_code = "-".join([platform_code, mooring_code])    
            if _platform_code not in result:
                result.append(_platform_code)
            _instrument_code = "-".join([platform_code, mooring_code, instrument_code ])  
            if _instrument_code not in result:
                result.append(_instrument_code)
        if rds:
            rds.sort()
        if result:
            result.sort()
        ommitted_reference_designators = []
        for item in result:
            if item not in rds:
                if item not in ommitted_reference_designators:
                    ommitted_reference_designators.append(item)
        if ommitted_reference_designators:
            ommitted_reference_designators.sort()
        return result, rds, ommitted_reference_designators
    except Exception as err:
        current_app.logger.info(err.message)
        return [], [], []
def process_toc_information_reference_designators ( toc ) : result = [ ] rds = [ ] try : if toc is None or not toc : message = 'toc is None or empty.' raise Exception ( message ) for item in toc : if item [ 'reference_designator' ] not in rds : rds . append ( item [ 'reference_designator' ] ) platform_code = item [ 'platform_code' ] if platform_code not in result : result . append ( platform_code ) mooring_code = item [ 'mooring_code' ] instrument_code = item [ 'instrument_code' ] _platform_code = "-" . join ( [ platform_code , mooring_code ] ) if _platform_code not in result : result . append ( _platform_code ) _instrument_code = "-" . join ( [ platform_code , mooring_code , instrument_code ] ) if _instrument_code not in result : result . append ( _instrument_code ) if rds : rds . sort ( ) if result : result . sort ( ) ommitted_reference_designators = [ ] for item in result : if item not in rds : if item not in ommitted_reference_designators : ommitted_reference_designators . append ( item ) if ommitted_reference_designators : ommitted_reference_designators . sort ( ) """
        In brief, the 'reference_designators' provided in the /sensor/toc response, are less than the
        hierarchical structure (ui toc) count which would be generated to support those instruments.
        Namely, the difference being the list of omitted_reference_designators (47) shown above.
        """ return result , rds , ommitted_reference_designators except Exception as err : current_app . logger . info ( err . message ) return [ ] , [ ] , [ ]
Get list of unique reference designators in /sensor/inv/toc; sorted ascending.
Get list of unique reference designators in / sensor / inv / toc ; sorted ascending .
"""
    Get list of unique reference designators in /sensor/inv/toc; sorted ascending.
    If error log exception and return []. Includes all stream methods.
    Response output:
    {
      "reference_designators": [
        "CE01ISSP",                             # platform code
        "CE01ISSP-SP001",                       # platform code + mooring code
        "CE01ISSP-SP001-05-VELPTJ000",          # platform code + mooring code + instrument code
        "CE01ISSP-SP001-07-SPKIRJ000",
        "CE01ISSP-SP001-08-FLORTJ000",
        "CE01ISSP-SP001-09-CTDPFJ000",
        "CE01ISSP-SP001-10-PARADJ000",
        "CE01ISSP-XX001",
        "CE01ISSP-XX001-01-CTDPFJ999",
        "CE01ISSP-XX001-01CTDPFJ999",
        "CE01ISSP-XX099",
        "CE01ISSP-XX099-01-CTDPFJ999",
        "CE02SHBP",
        "CE02SHBP-LJ01D",
        . . .
        ]
    }
    """ # format 'CP02PMCO-SBS01-00-RTE000000' # format 'CP02PMCO' # format 'SBS01', used with platform code # format CP02PMCO-SBS01 #'CP02PMCO-SBS01-00-RTE000000' # Reviewing data from toc to see what we have and don't have... # Which items in result were not provided in rds? """
        In brief, the 'reference_designators' provided in the /sensor/toc response, are less than the
        hierarchical structure (ui toc) count which would be generated to support those instruments.
        Namely, the difference being the list of omitted_reference_designators (47) shown above.
        """
toc