예제 #1
0
def parse_trip(trip):
    """
    Parse a trip from a a dict representation.

    Parameters
    ----------
    trip  : dict
            The trip as a dict.

    Returns
    -------
    tuple
        A namedtuple containing trip info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return Trip(
            trip['id'],
            parse_location(trip['beginLocation']),
            parse_location(trip['endLocation']),
            isodate.parse_datetime(trip['beginDate']),
            isodate.parse_datetime(trip['endDate'])
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #2
0
def parse_trip_stat(trip_stat):
    """
    Parse a trip stat from a a dict representation.

    Parameters
    ----------
    trip_stat  : dict
                 The trip stat as a dict.

    Returns
    -------
    tuple
        A namedtuple containing trip stat info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return TripStat(
            trip_stat['type'],
            trip_stat['value']
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #3
0
def parse_location(location):
    """
    Parse a Location from a a dict representation.

    Parameters
    ----------
    location  : dict
                The signal as a dict.

    Returns
    -------
    tuple
        A namedtuple containing location info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return Location(
            location['latitude'],
            location['longitude'],
            location['altitude'],
            location['nbSat'],
            location['heading'],
            location['hacc'],
            isodate.parse_datetime(location['date'])
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #4
0
def parse_mileage(mileage):
    """
    Parse a MileageStat from a a dict representation.

    Parameters
    ----------
    mileage  :  dict
                The mileage as a dict.

    Returns
    -------
    tuple
        A namedtuple containing mileage stat info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return MileageStat(
            isodate.parse_datetime(mileage['beginDate']),
            isodate.parse_datetime(mileage['endDate']),
            mileage['type'],
            mileage['value'],
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #5
0
def parse_signal(signal):
    """
    Parse a Signal from a a dict representation.

    Parameters
    ----------
    signal  :   dict
                The signal as a dict.

    Returns
    -------
    tuple
        A namedtuple containing signal info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return Signal(
            signal['name'],
            signal['value'],
            isodate.parse_datetime(signal['date'])
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #6
0
def parse_user(user):
    """
    Parse a User from a dict representation.

    Parameters
    ----------
    user  : dict
            The user as a dict.

    Returns
    -------
    tuple
        A namedtuple containing user info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    print("user=",user)
    try:
        return User(
            user['createdAt'],
            user['email'],
            user['firstName'],
            user['gender'],
            user['id'],
            user['lastName'],
            user['updatedAt']
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #7
0
def parse_token(token):
    """
    Parse a Token from a dict representation.

    Parameters
    ----------
    token : dict
            The token as a dict.

    Returns
    -------
    tuple
        A namedtuple containing token info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return Token(
            token['access_token'],
            token['refresh_token'],
            token['expires_in'],
            token['expires_at']
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #8
0
def parse_status(status):
    """
    Parse a Status from a a dict representation.

    Parameters
    ----------
    status  :   dict
                The status as a dict.

    Returns
    -------
    tuple
        A namedtuple containing status info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        accelerometer = None
        if 'accelerometer' in status:
            accelerometer_dict = status['accelerometer']
            if accelerometer_dict:
                accelerometer = Accelerometer(accelerometer_dict['x'], accelerometer_dict['y'],
                                              accelerometer_dict['z'],
                                              isodate.parse_datetime(accelerometer_dict['date']))
        location = None
        if 'location' in status:
            location_dict = status['location']
            if location_dict:
                location = parse_location(location_dict)
        return Status(
            location,
            accelerometer,
            [parse_signal(signal) for signal in status['signals']]
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)
예제 #9
0
def parse_car(car):
    """
    Parse a Car from a dict representation.

    Parameters
    ----------
    car  :  dict
            The car as a json dict.

    Returns
    -------
    tuple
        A namedtuple containing car info.
        The error is None if everything went fine.

    Raises
    ------
    ValueError
        If the dict does not contains the correct data.

    """
    try:
        return Car(
            car['brand'],
            car['createdAt'],
            car['firstEntryIntoService'],
            car['fleetId'],
            car['id'],
            car['kType'],
            car['licensePlate'],
            car['model'],
            car['name'],
            car['updatedAt'],
            car['userId']
        )
    except ValueError as err:
        raise xee_exceptions.ParseException(err)