Esempio n. 1
0
def get_all_diagnostics(org_id):
    '''
    Returns the obd data for all assets.

    Note that this function can take a long time to execute, due
    to the fact that each asset requires its own call and response
    from the MAP server. This code is not used in these applications.

    '''
    asset_response = fms_client.search_asset()
    asset_dev_serials = {asset.deviceSerial: asset.assetId
                         for asset in asset_response.assetVOs}

    device_response = device_client.get_devices(org_id)

    # This is slightly backward, but it makes sure that only devices
    # currently connected to assets become part of the response
    asset_dev_ids = {asset_dev_serials[device.serial]: device.deviceId
                     for device in device_response.deviceVOs
                     if device.serial in asset_dev_serials}

    diagnostics = [
        {'asset': asset,
         'obd': fms_client.get_diagnostic_data(
             device_id=asset_dev_ids[asset]).diagnosticDataVOs}
        for asset in asset_dev_ids]

    return diagnostics
Esempio n. 2
0
def get_unused_device_serials(org_id):

    '''
    The aim of this function is to find the serials of all currently
    unused devices.

    To do this, we first retrieve a list of all devices and place
    their serials into a set.

    We then retrieve the list of all assets, extract their associated
    devices' serial numbers and place them into a second set.

    We then obtain the desired result by subtrating the second set from
    the first.

    '''

    devices = device_client.get_devices(org_id)
    assets = fms_client.search_asset()

    all_serials = set()
    taken_serials = set()

    for asset in assets.assetVOs:
        taken_serials.add(asset.deviceSerial)

    for device in devices.deviceVOs:
        all_serials.add(device.serial)

    untaken_serials = all_serials - taken_serials

    return sorted(list(untaken_serials))
Esempio n. 3
0
def get_assets():
    """
    Get assets associated with the account.

    Returns a dictionary of with keys name, description of all
    assets associated with an account.

    """
    response = fms_client.search_asset()

    return {asset.assetId: {'name': asset.name,
                            'description': asset.description}
            for asset in response.assetVOs}
Esempio n. 4
0
def get_detailed_assets():
    '''
    Retrieves detailed information about a given asset.

    Returns a dictionary possibly containing but not limited to:
        -Asset's last location
        *The general area of the asset (s.a. "Near Edina, MN")
        *Whether an asset has a >Geofence
                                >Speed Limit
                                >Rash Driving limitations
        -Asset's type, ID#
        -Information about the device

    '''

    response = fms_client.search_asset()

    assets_list = []

    for asset in response.assetVOs:
        a_dict = {'assetId': asset.assetId,
                  'Name': asset.name,
                  'Description': asset.description,
                  'ID_Number': asset.identificationNumber,
                  'Last_Updated': asset.lastUpdated,
                  'Org_ID': asset.organizationId,
                  'status': asset.status,
                  'device_serial': asset.deviceSerial,
                  }
        if asset.assetLastLocationVO is not None:
            a_dict['Last Location'] = {
                'Coordinates': (asset.assetLastLocationVO.latitude,
                                asset.assetLastLocationVO.longitude),
                'Near': asset.assetLastLocationVO.lastLocation,
                'Updated': asset.assetLastLocationVO.locationUpdate,
            }
        else:
            a_dict['Last Location'] = {'Coordinates': (None, None),
                                       'Near': None,
                                       'Updated': None
                                       }

        assets_list.append(a_dict)

    return assets_list