def _create_trip_from_stack(temp_trip_stack, origin_activity, destination_activity):
    """
    Aggregate information of trip elements in a structured dictionary

    Parameters
    ----------
    temp_trip_stack : list
                    list of dictionary like elements (either pandas series or python dictionary). Contains all elements
                    that will be aggregated into a trip
    origin_activity : dictionary like
                    Either dictionary or pandas series
    destination_activity : dictionary like
                    Either dictionary or pandas series

    Returns
    -------
    dictionary

    """

    # this function return and empty dict if no tripleg is in the stack
    first_trip_element = temp_trip_stack[0]
    last_trip_element = temp_trip_stack[-1]

    # all data has to be from the same user
    assert origin_activity['user_id'] == last_trip_element['user_id']

    # double check if trip requirements are fulfilled
    assert origin_activity['activity'] == True
    assert destination_activity['activity'] == True
    assert first_trip_element['activity'] == False

    trip_dict_entry = {'user_id': origin_activity['user_id'],
                       'started_at': first_trip_element['started_at'],
                       'finished_at': last_trip_element['finished_at'],
                       'origin_staypoint_id': origin_activity['id'],
                       'destination_staypoint_id': destination_activity['id'],
                       'tpls': [tripleg['id'] for tripleg in temp_trip_stack if tripleg['type'] == 'tripleg'],
                       'spts': [tripleg['id'] for tripleg in temp_trip_stack if tripleg['type'] == 'staypoint']}
    
    return trip_dict_entry