Exemple #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
Exemple #2
0
def get_diagnostics(org_id, asset_id):
    '''
    Returns a dictionary of the obd data for one asset.

    '''
    asset_response = fms_client.get_asset(asset_id)
    device_serial = asset_response.assetVO.deviceSerial

    response = fms_client.get_diagnostic_data(device_serial)

    if not 'diagnosticDataVOs' in response:
        return

    elif len(response.diagnosticDataVOs) == 0:
        diagnostics = {asset_id: [{
            'Absolute Throttle Position': None,
            'AirIntake Temperature': None,
            'Cruise Control Status': None,
            'Cumulative Fuel Used': None,
            'Date Created': None,
            'Device Serial': device_serial,
            'Diagnostic Data Id': None,
            'Dtc Errors': None,
            'Dtc Value': None,
            'Engine Coolant Temperature': None,
            'Engine Rpm': None,
            'Ignition State': None,
            'Instantaneous Fuel Rate': None,
            'Load Percentage': None,
            'Long Term Fuel Trim': None,
            'Mass Air Flow': None,
            'Odometer Reading': None,
            'Pto Information': None,
            'Record Type': None,
            'Short Term Fuel Trim': None,
            'Speed': None
        }]}
    else:
        # Diagnostics is a data stucture of the form:
        # {asset_id: [{key1: value1, key2: value2, ... }
        #             {key1: value1, key2: value2, ... }
        #             ...
        #            ]
        # }
        diagnostics = {
            asset_id: [
                {make_readable(record[0]): record[1] for record in OBDdata}
                for OBDdata in response.diagnosticDataVOs
            ]
        }

    return diagnostics