Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] NeTEx IDFM - Use VehicleJourneyStopAssignment for TN vehiclejourneys #600

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
431 changes: 406 additions & 25 deletions src/netex_idf/offers.rs

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/netex_idf/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
collections.feed_infos = feed_infos;

let path = netex_idf_path.as_ref();
stops::from_path(&path.join(STOPS_FILENAME), &mut collections)?;
let virtual_stop_points = stops::from_path(&path.join(STOPS_FILENAME), &mut collections)?;
let lines_netex_idf = lines::from_path(&path.join(LINES_FILENAME), &mut collections)?;
for offer_folder in WalkDir::new(path)
.min_depth(1)
Expand All @@ -59,7 +59,12 @@ where
{
info!("Reading offer in folder {:?}", offer_folder.path());
skip_error_and_log!(
offers::read_offer_folder(offer_folder.path(), &mut collections, &lines_netex_idf),
offers::read_offer_folder(
offer_folder.path(),
&mut collections,
&lines_netex_idf,
&virtual_stop_points
),
LogLevel::Warn
);
}
Expand Down
67 changes: 48 additions & 19 deletions src/netex_idf/stops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ use skip_error::skip_error_and_log;
use std::{collections::HashMap, fs::File, io::Read};
use typed_index_collection::CollectionWithId;

type VirtualStopPoint = StopPoint;
type Stops = (
CollectionWithId<StopArea>,
CollectionWithId<StopPoint>,
CollectionWithId<Equipment>,
CollectionWithId<VirtualStopPoint>,
);

impl From<StopArea> for StopPoint {
fn from(stop_area: StopArea) -> Self {
StopPoint {
id: stop_area.id.clone(),
name: stop_area.name,
visible: stop_area.visible,
coord: stop_area.coord,
stop_area_id: stop_area.id.clone(),
stop_type: StopType::Point,
..Default::default()
}
}
}

pub fn extract_quay_id(raw_id: &str) -> Result<&str> {
raw_id
.split(':')
Expand Down Expand Up @@ -97,29 +119,40 @@ fn load_stop_areas<'a>(
stop_places: Vec<&'a Element>,
map_stopplace_stoparea: &mut HashMap<String, String>,
proj: &Proj,
) -> Result<CollectionWithId<StopArea>> {
) -> Result<(
CollectionWithId<StopArea>,
CollectionWithId<VirtualStopPoint>,
)> {
let mut stop_areas = CollectionWithId::default();
let mut virtual_stop_points = CollectionWithId::default();

let has_parent_site_ref = |sp: &Element| sp.try_only_child("ParentSiteRef").is_ok();

for stop_place in stop_places.iter().filter(|sp| !has_parent_site_ref(sp)) {
stop_areas.push(load_stop_area(stop_place, proj)?)?;
let loaded_stop_area = load_stop_area(stop_place, proj)?;
if loaded_stop_area.id.contains("monomodalStopPlace:") {
virtual_stop_points.push(StopPoint::from(loaded_stop_area.clone()))?;
}
stop_areas.push(loaded_stop_area)?;
}

for stop_place in stop_places.iter().filter(|sp| has_parent_site_ref(sp)) {
let parent_site_ref: String = stop_place
.try_only_child("ParentSiteRef")?
.try_attribute_with("ref", extract_multimodal_stop_place_id)?;

let stop_place_id = stop_place.try_attribute_with("id", extract_monomodal_stop_place_id)?;
let loaded_stop_area = load_stop_area(stop_place, proj)?;
let mut virtual_stop_point = StopPoint::from(loaded_stop_area.clone());
if stop_areas.get(&parent_site_ref).is_some() {
map_stopplace_stoparea.insert(stop_place_id, parent_site_ref.clone());
virtual_stop_point.stop_area_id = parent_site_ref.clone();
map_stopplace_stoparea.insert(stop_place_id, parent_site_ref);
} else {
stop_areas.push(load_stop_area(stop_place, proj)?)?;
stop_areas.push(loaded_stop_area)?;
map_stopplace_stoparea.insert(stop_place_id.clone(), stop_place_id);
}
virtual_stop_points.push(virtual_stop_point)?;
}
Ok(stop_areas)
Ok((stop_areas, virtual_stop_points))
}

fn load_coords(elem: &Element) -> Result<(f64, f64)> {
Expand Down Expand Up @@ -275,13 +308,7 @@ fn load_stop_points<'a>(
Ok((stop_points, CollectionWithId::new(equipments)?))
}

fn load_stops(
frames: &Frames,
) -> Result<(
CollectionWithId<StopArea>,
CollectionWithId<StopPoint>,
CollectionWithId<Equipment>,
)> {
fn load_stops(frames: &Frames) -> Result<Stops> {
let member_children = || {
frames
.get(&FrameType::General)
Expand All @@ -298,8 +325,7 @@ fn load_stops(
.ok_or_else(|| format_err!("Proj cannot build a converter from '{}' to '{}'", from, to))?;

let mut map_stopplace_stoparea = HashMap::default();

let mut stop_areas = load_stop_areas(
let (mut stop_areas, virtual_stop_points) = load_stop_areas(
member_children()
.filter(|e| e.name() == "StopPlace")
.collect(),
Expand All @@ -314,10 +340,13 @@ fn load_stops(
&proj,
)?;

Ok((stop_areas, stop_points, equipments))
Ok((stop_areas, stop_points, equipments, virtual_stop_points))
}

pub fn from_path(path: &std::path::Path, collections: &mut Collections) -> Result<()> {
pub fn from_path(
path: &std::path::Path,
collections: &mut Collections,
) -> Result<CollectionWithId<VirtualStopPoint>> {
info!("Reading {:?}", path);

let mut file = File::open(&path).with_context(|_| format!("Error reading {:?}", path))?;
Expand All @@ -332,13 +361,13 @@ pub fn from_path(path: &std::path::Path, collections: &mut Collections) -> Resul
.try_only_child("frames")?,
)?;

let (stop_areas, stop_points, equipments) = load_stops(&frames)?;
let (stop_areas, stop_points, equipments, virtual_stop_points) = load_stops(&frames)?;

collections.stop_areas.try_merge(stop_areas)?;
collections.stop_points.try_merge(stop_points)?;
collections.equipments.try_merge(equipments)?;

Ok(())
Ok(virtual_stop_points)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ impl Approx {
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)]
pub struct StopArea {
pub id: String,
pub name: String,
Expand Down
62 changes: 61 additions & 1 deletion tests/fixtures/netexidf2ntfs/input/netex/OFFRE_TP/offre_tp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@
</StopPointInJourneyPattern>
</pointsInSequence>
</ServiceJourneyPattern>
<ServiceJourneyPattern dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:JourneyPattern:local-26-C00114-3:LOC" version="any">
<RouteRef ref="stif:Route:local-26-C00114-2:LOC" version="any"/>
<pointsInSequence>
<StopPointInJourneyPattern id="stif:JourneyPattern:local-26-C00114-24:LOC" order="1" version="any">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-23:LOC" version="any"/>
<ForAlighting>true</ForAlighting>
<ForBoarding>true</ForBoarding>
</StopPointInJourneyPattern>
<StopPointInJourneyPattern id="stif:JourneyPattern:local-26-C00114-25:LOC" order="2" version="any">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-24:LOC" version="any"/>
<ForAlighting>true</ForAlighting>
<ForBoarding>true</ForBoarding>
</StopPointInJourneyPattern>
<StopPointInJourneyPattern id="stif:JourneyPattern:local-26-C00114-26:LOC" order="3" version="any">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-25:LOC" version="any"/>
<ForAlighting>true</ForAlighting>
<ForBoarding>true</ForBoarding>
</StopPointInJourneyPattern>
</pointsInSequence>
</ServiceJourneyPattern>
<PassengerStopAssignment dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:PassengerStopAssignment:local-26-C00114-10:LOC" version="any" order="0">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-10:LOC" version="any" />
<QuayRef ref="FR::Quay:50144192:FR1">version="any"</QuayRef>
Expand Down Expand Up @@ -93,6 +113,18 @@
<PassengerStopAssignment dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:PassengerStopAssignment:local-26-C00114-22:LOC" version="any" order="0">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-22:LOC" version="any" />
<QuayRef ref="FR::Quay:50144192:FR1">version="any"</QuayRef>
</PassengerStopAssignment>
<PassengerStopAssignment dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:PassengerStopAssignment:local-26-C00114-23:LOC" version="any" order="0">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-23:LOC" version="any" />
<StopPlaceRef ref="FR::monomodalStopPlace:57250:FR1" version="any" />
</PassengerStopAssignment>
<PassengerStopAssignment dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:PassengerStopAssignment:local-26-C00114-24:LOC" version="any" order="0">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-24:LOC" version="any" />
<StopPlaceRef ref="FR::monomodalStopPlace:sp_with_parent_not_found:FR1" version="any" />
</PassengerStopAssignment>
<PassengerStopAssignment dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:PassengerStopAssignment:local-26-C00114-25:LOC" version="any" order="0">
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-25:LOC" version="any" />
<QuayRef ref="FR::Quay:50114580:FR1" version="any" />
</PassengerStopAssignment>
<RoutingConstraintZone dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:RoutingConstraintZone:local-26-C00114:LOC" version="any">
<Name>ITL 1</Name>
Expand Down Expand Up @@ -190,9 +222,37 @@
</TimetabledPassingTime>
</passingTimes>
</ServiceJourney>
<ServiceJourney dataSourceRef="DATASOURCEREF_EDITION_BOIV" id="stif:VehicleJourney:local-26-C00114-3:LOC" version="any">
<dayTypes>
<DayTypeRef ref="stif:TimeTable:local-28-2:LOC">version="1"</DayTypeRef>
</dayTypes>
<JourneyPatternRef ref="stif:JourneyPattern:local-26-C00114-3:LOC" version="any"/>
<passingTimes>
<TimetabledPassingTime version="any">
<ArrivalTime>06:30:00</ArrivalTime>
<DepartureTime>06:30:00</DepartureTime>
<DepartureDayOffset>0</DepartureDayOffset>
</TimetabledPassingTime>
<TimetabledPassingTime version="any">
<ArrivalTime>07:05:00</ArrivalTime>
<DepartureTime>07:05:00</DepartureTime>
<DepartureDayOffset>0</DepartureDayOffset>
</TimetabledPassingTime>
<TimetabledPassingTime version="any">
<ArrivalTime>07:15:00</ArrivalTime>
<DepartureTime>07:15:00</DepartureTime>
<DepartureDayOffset>0</DepartureDayOffset>
</TimetabledPassingTime>
</passingTimes>
</ServiceJourney>
<VehicleJourneyStopAssignment dataSourceRef="STIF" id="stif:VehicleJourneyStopAssignment:local-26-C00114-1:LOC" version="any">
<QuayRef ref="FR::Quay:50068421:FR1">version="any"</QuayRef>
<ScheduledStopPointRef ref="stif:ScheduledStopPoint:local-26-C00114-24:LOC" version="any"/>
<VehicleJourneyRef ref="stif:VehicleJourney:local-26-C00114-3:LOC" version="any"/>
</VehicleJourneyStopAssignment>
</members>
</GeneralFrame>
</frames>
</frames>
</CompositeFrame>
</dataObjects>
</PublicationDelivery>
2 changes: 2 additions & 0 deletions tests/fixtures/netexidf2ntfs/output/object_codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ line,prefix:C00114,Netex_PrivateCode,011011019
route,prefix:stif:local-26-C00114-1,Netex_ServiceJourneyPattern,stif:JourneyPattern:local-26-C00114-1:LOC
route,prefix:stif:local-26-C00114-1,source,stif:Route:local-26-C00114-1:LOC
route,prefix:stif:local-26-C00114-2,Netex_ServiceJourneyPattern,stif:JourneyPattern:local-26-C00114-2:LOC
route,prefix:stif:local-26-C00114-2,Netex_ServiceJourneyPattern,stif:JourneyPattern:local-26-C00114-3:LOC
route,prefix:stif:local-26-C00114-2,source,stif:Route:local-26-C00114-2:LOC
trip,prefix:stif:local-26-C00114-1,source,stif:VehicleJourney:local-26-C00114-1:LOC
trip,prefix:stif:local-26-C00114-2,source,stif:VehicleJourney:local-26-C00114-2:LOC
trip,prefix:stif:local-26-C00114-3,source,stif:VehicleJourney:local-26-C00114-3:LOC
trip,prefix:stif:only_one_exception,source,stif:VehicleJourney:only_one_exception:LOC
stop_area,prefix:monomodalStopPlace:sp_with_parent_not_found,source,FR::monomodalStopPlace:sp_with_parent_not_found:FR1
stop_area,prefix:stop_area_1,source,FR::multimodalStopPlace:stop_area_1:FR1
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/netexidf2ntfs/output/stop_times.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ prefix:50114580,prefix:stif:local-26-C00114-1,3,07:00:00,07:00:00,0,0,1,0,0,,,,0
prefix:50013706,prefix:stif:local-26-C00114-2,0,06:30:00,06:30:00,0,0,0,0,0,,,,0
prefix:with_zder_but_no_stopplace,prefix:stif:local-26-C00114-2,1,07:00:00,07:00:00,0,0,0,0,0,,,,0
prefix:50144192,prefix:stif:local-26-C00114-2,2,07:05:00,07:05:00,0,0,0,0,0,,,,0
prefix:monomodalStopPlace:57250,prefix:stif:local-26-C00114-3,0,06:30:00,06:30:00,0,0,0,0,0,,,,0
prefix:50068421,prefix:stif:local-26-C00114-3,1,07:05:00,07:05:00,0,0,0,0,0,,,,0
prefix:50114580,prefix:stif:local-26-C00114-3,2,07:15:00,07:15:00,0,0,0,0,0,,,,0
prefix:50013706,prefix:stif:only_one_exception,0,06:30:00,06:30:00,0,0,0,0,0,,,,0
prefix:50144192,prefix:stif:only_one_exception,2,07:05:00,07:05:00,0,0,0,0,0,,,,0
prefix:with_zder_but_no_stopplace,prefix:stif:only_one_exception,1,07:00:00,07:00:00,0,0,0,0,0,,,,0
1 change: 1 addition & 0 deletions tests/fixtures/netexidf2ntfs/output/stops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ prefix:stop_area_1,Maison du citoyen,,1,,2.476489952100393,48.846575715368985,1,
prefix:stop_area_2,Roger Genty,,1,,2.767274238725237,48.34061261273478,1,,,,,,
prefix:monomodalStopPlace:sp_with_parent_not_found,Avenue de la Gare,,1,,2.696063645783932,49.0339040919032,1,,,,,,
prefix:Navitia:with_zder_not_found,République,,1,,2.3633222823037054,48.86766535188487,1,,Europe/Paris,,,,
prefix:monomodalStopPlace:57250,Maison du citoyen,,1,,2.476489952100393,48.846575715368985,0,prefix:stop_area_1,,,,,
prefix:Navitia:with_zder_but_no_stopplace,DIDEROT,,1,,2.287023483401608,48.818795173318996,1,,Europe/Paris,,,,
prefix:50114580,BIBLIOTHEQUE NATIONALE,,1,1,2.337949003337833,48.8679593749302,0,prefix:Navitia:50114580,Europe/Paris,,prefix:3,,
1 change: 1 addition & 0 deletions tests/fixtures/netexidf2ntfs/output/trips.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
trip_id,route_id,physical_mode_id,dataset_id,service_id,trip_headsign,trip_short_name,block_id,company_id,trip_property_id,geometry_id,journey_pattern_id
prefix:stif:local-26-C00114-1,prefix:stif:local-26-C00114-1,RapidTransit,prefix:IDF,prefix:1,BIBLIOTHEQUE NATIONALE,BIBLIOTHEQUE NATIONALE,,prefix:011,prefix:FR1:AccessibilityAssessment:C00114:,,
prefix:stif:local-26-C00114-2,prefix:stif:local-26-C00114-2,RapidTransit,prefix:IDF,prefix:1,MAISON DU CITOYEN,,,prefix:011,prefix:FR1:AccessibilityAssessment:C00114:,,
prefix:stif:local-26-C00114-3,prefix:stif:local-26-C00114-2,RapidTransit,prefix:IDF,prefix:1,BIBLIOTHEQUE NATIONALE,,,prefix:011,prefix:FR1:AccessibilityAssessment:C00114:,,
prefix:stif:only_one_exception,prefix:stif:local-26-C00114-2,RapidTransit,prefix:IDF,prefix:3,MAISON DU CITOYEN,,,prefix:011,prefix:FR1:AccessibilityAssessment:C00114:,,