ooiservices/app/uframe/assetController.py
def associate_events(id):
    """ Get all associated events for an asset (by id).
    When an individual asset is requested from GET(id) all the events for that
    asset need to be associated.  This is represented in a list of URIs, one
    for it's services endpoint and one for it's direct endpoint in uframe.
    """
    uframe_url = current_app.config['UFRAME_ASSETS_URL'] + '/assets/%s/events' % (id)
    result = []
    payload = requests.get(uframe_url)
    if payload.status_code != 200:
        return [{"error": "server responded with error code: %s" %
                payload.status_code}]

    json_data = payload.json()
    for row in json_data:
        try:

            d = {}
            # set up some static keys
            d['locationLonLat'] = []

            d['eventId'] = row['eventId']
            d['eventClass'] = row['@class']
            d['notes'] = len(row['notes'])
            d['startDate'] = row['startDate']
            d['endDate'] = row['endDate']
            d['tense'] = row['tense']
            if d['eventClass'] == '.CalibrationEvent':
                d['calibrationCoefficient'] = row['calibrationCoefficient']
                lon = 0.0
                lat = 0.0
                for cal_coef in d['calibrationCoefficient']:
                    if cal_coef['name'] == 'CC_lon':
                        lon = cal_coef['values']
                    if cal_coef['name'] == 'CC_lat':
                        lat = cal_coef['values']
                if lon is not None and lat is not None:
                    d['locationLonLat'] = convert_lat_lon(lat, lon)
            if d['evetClass'] == '.DeploymentEvent':
                d['deploymentDepth'] = row['deploymentDepth']
                if row['locationLonLat']:
                    d['locationLonLat'] = convert_lat_lon(
                        row['locationLonLat'][1],
                        row['locationLonLat'][0])
                d['deploymentNumber'] = row['deploymentNumber']
        except KeyError:
            pass
        result.append(d)

    try:
        if request.args.get('sort') and request.args.get('sort') != "":
            sort_by = request.args.get('sort')
        else:
            sort_by = 'eventId'
        result = sorted(result, key=itemgetter(sort_by))
    except (TypeError, KeyError) as e:
        raise

    return result
 Get all associated events for an asset (by id).
    When an individual asset is requested from GET(id) all the events for that
    asset need to be associated.  This is represented in a list of URIs, one
    for it's services endpoint and one for it's direct endpoint in uframe.
    
Get all associated events for an asset (by id).
When an individual asset is requested from GET(id) all the events for that
asset need to be associated.  This is represented in a list of URIs, one
for it's services endpoint and one for it's direct endpoint in uframe.
Get all associated events for an asset ( by id ) . When an individual asset is requested from GET ( id ) all the events for that asset need to be associated . This is represented in a list of URIs one for it ' s services endpoint and one for it ' s direct endpoint in uframe .
def associate_events(id):
    uframe_url = current_app.config['UFRAME_ASSETS_URL'] + '/assets/%s/events' % (id)
    result = []
    payload = requests.get(uframe_url)
    if payload.status_code != 200:
        return [{"error": "server responded with error code: %s" %
                payload.status_code}]
    json_data = payload.json()
    for row in json_data:
        try:
            d = {}
            d['locationLonLat'] = []
            d['eventId'] = row['eventId']
            d['eventClass'] = row['@class']
            d['notes'] = len(row['notes'])
            d['startDate'] = row['startDate']
            d['endDate'] = row['endDate']
            d['tense'] = row['tense']
            if d['eventClass'] == '.CalibrationEvent':
                d['calibrationCoefficient'] = row['calibrationCoefficient']
                lon = 0.0
                lat = 0.0
                for cal_coef in d['calibrationCoefficient']:
                    if cal_coef['name'] == 'CC_lon':
                        lon = cal_coef['values']
                    if cal_coef['name'] == 'CC_lat':
                        lat = cal_coef['values']
                if lon is not None and lat is not None:
                    d['locationLonLat'] = convert_lat_lon(lat, lon)
            if d['evetClass'] == '.DeploymentEvent':
                d['deploymentDepth'] = row['deploymentDepth']
                if row['locationLonLat']:
                    d['locationLonLat'] = convert_lat_lon(
                        row['locationLonLat'][1],
                        row['locationLonLat'][0])
                d['deploymentNumber'] = row['deploymentNumber']
        except KeyError:
            pass
        result.append(d)
    try:
        if request.args.get('sort') and request.args.get('sort') != "":
            sort_by = request.args.get('sort')
        else:
            sort_by = 'eventId'
        result = sorted(result, key=itemgetter(sort_by))
    except (TypeError, KeyError) as e:
        raise
    return result
def associate_events ( id ) : uframe_url = current_app . config [ 'UFRAME_ASSETS_URL' ] + '/assets/%s/events' % ( id ) result = [ ] payload = requests . get ( uframe_url ) if payload . status_code != 200 : return [ { "error" : "server responded with error code: %s" % payload . status_code } ] json_data = payload . json ( ) for row in json_data : try : d = { } d [ 'locationLonLat' ] = [ ] d [ 'eventId' ] = row [ 'eventId' ] d [ 'eventClass' ] = row [ '@class' ] d [ 'notes' ] = len ( row [ 'notes' ] ) d [ 'startDate' ] = row [ 'startDate' ] d [ 'endDate' ] = row [ 'endDate' ] d [ 'tense' ] = row [ 'tense' ] if d [ 'eventClass' ] == '.CalibrationEvent' : d [ 'calibrationCoefficient' ] = row [ 'calibrationCoefficient' ] lon = 0.0 lat = 0.0 for cal_coef in d [ 'calibrationCoefficient' ] : if cal_coef [ 'name' ] == 'CC_lon' : lon = cal_coef [ 'values' ] if cal_coef [ 'name' ] == 'CC_lat' : lat = cal_coef [ 'values' ] if lon is not None and lat is not None : d [ 'locationLonLat' ] = convert_lat_lon ( lat , lon ) if d [ 'evetClass' ] == '.DeploymentEvent' : d [ 'deploymentDepth' ] = row [ 'deploymentDepth' ] if row [ 'locationLonLat' ] : d [ 'locationLonLat' ] = convert_lat_lon ( row [ 'locationLonLat' ] [ 1 ] , row [ 'locationLonLat' ] [ 0 ] ) d [ 'deploymentNumber' ] = row [ 'deploymentNumber' ] except KeyError : pass result . append ( d ) try : if request . args . get ( 'sort' ) and request . args . get ( 'sort' ) != "" : sort_by = request . args . get ( 'sort' ) else : sort_by = 'eventId' result = sorted ( result , key = itemgetter ( sort_by ) ) except ( TypeError , KeyError ) as e : raise return result
Get all associated events for an asset (by id).
Get all associated events for an asset ( by id ) .
""" Get all associated events for an asset (by id).
    When an individual asset is requested from GET(id) all the events for that
    asset need to be associated.  This is represented in a list of URIs, one
    for it's services endpoint and one for it's direct endpoint in uframe.
    """ # set up some static keys
id