def _process_stops_in_seg_data(ride_seg, xml_stops, index): """ Process the segment, extracting the stops and getting the bounds of the stops. @param ride_seg: L{Segment} to process @type ride_seg: L{Segment} @param xml_stops: C{list} of C{Element}s for stops in rideset @type xml_stops: C{list} of C{Element} @param index: next index to use for a stop @type index: C{int} @return: (stops for segment, bounds, updated index) @rtype: (C{list} of L{Stop},L{Box},C{int}) """ seg_stops = [] bounds = Box() for waypoint, dist in _stop_pts_dist(ride_seg.waypoints): if waypoint.stop is not None: stop_list = waypoint.stop.split() for stop_item in stop_list: xml_stop = get_from_id(xml_stops, stop_item.strip()) new_stop = _parse_stop_xml(xml_stop) new_stop.description = " ".join(new_stop.description.split()) new_stop.distance = ride_seg.start_dist + dist new_stop.off_route = new_stop.calculate_distance(waypoint) new_stop.index = index index += 1 seg_stops.append(new_stop) bounds.expand_to_point(new_stop.lat, new_stop.lon) return seg_stops, bounds, index
def process_ride_turns(ride_segs, xml_ride, xml_turns): """ Process the turn references for the given ride and generate a list of L{Turn} objects for it. @param ride_segs: C{list} of L{Segment} objects for the ride @type ride_segs: C{list} of L{Segment} objects @param xml_ride: C{Element} root of ride data tree @type xml_ride: C{Element} @param xml_turns: C{list} of C{Element} turn objects @type xml_turns: C{list} of C{Element}s @return: C{list} of L{Turn} @rtype: C{list} of L{Turn} """ ride_turns = [_parse_turn_xml(get_from_id(xml_turns, xml_turn.attrib['id'])) for xml_turn in xml_ride.findall('turn_ref')] # sanity check if len(ride_segs) != len(ride_turns): raise Exception('turn and seg counts do not match') # process segs for index, (turn, seg) in enumerate(zip(ride_turns, ride_segs)): turn.comments = " ".join(turn.comments.split()) turn.distance = seg.start_dist turn.lat = seg.lat turn.lon = seg.lon turn.index = index return ride_turns
def _process_pois_in_seg_data(ride_seg, xml_pois, index): """ Process the segment, extracting the POIs and getting the bounds of the POIs. @param ride_seg: L{Segment} to process @type ride_seg: L{Segment} @param xml_pois: C{list} of C{Element}s for POIs in rideset @type xml_pois: C{list} of C{Element} @param index: next index to use for a POI @type index: C{int} @return: (POIs for segment, bounds, updated index) @rtype: (C{list} of L{Poi},L{Box},C{int}) """ seg_pois = [] bounds = Box() for waypoint, dist in _poi_pts_dist(ride_seg.waypoints): if waypoint.poi is not None: poi_list = waypoint.poi.split() for poi_item in poi_list: xml_poi = get_from_id(xml_pois, poi_item.strip()) new_poi = _parse_poi_xml(xml_poi) new_poi.description = " ".join(new_poi.description.split()) new_poi.distance = ride_seg.start_dist + dist new_poi.off_route = new_poi.calculate_distance(waypoint) new_poi.index = index index += 1 seg_pois.append(new_poi) bounds.expand_to_point(new_poi.lat, new_poi.lon) return seg_pois, bounds, index
def _get_ride_segs(xml_ride, xml_segs): """ Process the ride, creating L{Segment} objects for each of its segment references. @param xml_ride: C{Element} for a ride @type xml_ride: C{Element} @param xml_segs: C{list} of C{Element} segment objects for this rideset @type xml_segs: C{list} of C{Element}s @return: C{list} of L{Segment} objects @rtype: C{list} of L{Segment} """ return [_parse_segment_xml(get_from_id(xml_segs, seg.attrib['id'])) for seg in xml_ride.findall('segment_ref')]
def process_ride_parking(xml_ride, xml_parking_places): """ Process the parking place reference for the give ride and generate a full L{Parking} object for it. @param xml_ride: root of C{Element} tree for this ride @type xml_ride: C{Element} @param xml_parking_places: C{list} of C{Element} trees for parking places @type xml_parking_places: C{list} of C{Element} trees @return: L{Parking} object for the ride @rtype: L{Parking} """ xml_ride_parking = xml_ride.find('parking_ref') xml_parking = get_from_id(xml_parking_places, xml_ride_parking.attrib['id']) ret = _parse_parking_xml(xml_parking) ret.description = " ".join(ret.description.split()) return ret