Skip to content

Commit

Permalink
Merge pull request #638 from patochectp/add_odt_comment_on_frequency_v2
Browse files Browse the repository at this point in the history
[feature] add odt comment on frequencies
  • Loading branch information
ArnaudOggy authored Jun 1, 2020
2 parents ef56e99 + e5da566 commit 08d5f69
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 85 deletions.
20 changes: 18 additions & 2 deletions src/add_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ fn add_prefix_on_vehicle_journey_ids(
.collect()
}

fn add_prefix_on_vehicle_journey_ids_and_values(
vehicle_journey_ids: &HashMap<(String, u32), String>,
prefix: &str,
) -> HashMap<(String, u32), String> {
vehicle_journey_ids
.iter()
.map(|((trip_id, sequence), value)| {
(
(format!("{}{}", prefix, trip_id), *sequence),
format!("{}{}", prefix, value.to_string()),
)
})
.collect()
}

impl AddPrefix for Collections {
fn add_prefix(&mut self, prefix: &str) {
self.contributors.add_prefix(&prefix);
Expand Down Expand Up @@ -104,9 +119,10 @@ impl AddPrefix for Collections {
self.grid_rel_calendar_line.add_prefix(&prefix);
self.stop_time_headsigns =
add_prefix_on_vehicle_journey_ids(&self.stop_time_headsigns, &prefix);
self.stop_time_ids = add_prefix_on_vehicle_journey_ids(&self.stop_time_ids, &prefix);
self.stop_time_ids =
add_prefix_on_vehicle_journey_ids_and_values(&self.stop_time_ids, &prefix);
self.stop_time_comments =
add_prefix_on_vehicle_journey_ids(&self.stop_time_comments, &prefix);
add_prefix_on_vehicle_journey_ids_and_values(&self.stop_time_comments, &prefix);
}
}

Expand Down
62 changes: 53 additions & 9 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ where
collections,
message,
company_idx,
collections.vehicle_journeys[vj_idx].id.clone(),
vj_idx,
stop_time,
);
}
Expand Down Expand Up @@ -615,7 +615,7 @@ fn manage_odt_comment_from_stop_time(
collections: &mut Collections,
on_demand_transport_comment: &str,
company_idx: Idx<objects::Company>,
vj_id: String,
vj_idx: Idx<objects::VehicleJourney>,
stop_time: &StopTime,
) {
let comment_id = format!("ODT:{}", collections.companies[company_idx].id);
Expand All @@ -640,13 +640,21 @@ fn manage_odt_comment_from_stop_time(
};
collections.comments.push(comment).unwrap()
});
collections
.stop_time_comments
.insert((vj_id.to_string(), stop_time.stop_sequence), comment_id);
collections.stop_time_comments.insert(
(
collections.vehicle_journeys[vj_idx].id.to_string(),
stop_time.stop_sequence,
),
comment_id,
);
let stop_time_id = format!("{}-{}", stop_time.trip_id, stop_time.stop_sequence);
collections
.stop_time_ids
.insert((vj_id, stop_time.stop_sequence), stop_time_id);
collections.stop_time_ids.insert(
(
collections.vehicle_journeys[vj_idx].id.to_string(),
stop_time.stop_sequence,
),
stop_time_id,
);
}

#[derive(Default)]
Expand Down Expand Up @@ -1277,17 +1285,53 @@ where
.collect();
start_time = start_time + Time::new(0, 0, frequency.headway_secs);
let generated_vj = VehicleJourney {
id: generated_trip_id,
id: generated_trip_id.clone(),
service_id,
stop_times,
..corresponding_vj.clone()
};
new_vehicle_journeys.push(generated_vj);
let stop_time_comments: HashMap<(String, u32), String> = corresponding_vj
.stop_times
.iter()
.filter(|stop_time| {
stop_time.pickup_type == 2 || stop_time.drop_off_type == 2
})
.filter_map(|stop_time| {
collections
.stop_time_comments
.get(&(frequency.trip_id.clone(), stop_time.sequence))
.map(|comment_id| {
(
(generated_trip_id.clone(), stop_time.sequence),
comment_id.to_string(),
)
})
})
.collect();
let stop_time_ids: HashMap<(String, u32), String> = stop_time_comments
.keys()
.map(|(trip_id, sequence)| {
(
(trip_id.to_string(), *sequence),
format!("{}-{}", trip_id, sequence),
)
})
.collect();
collections.stop_time_comments.extend(stop_time_comments);
collections.stop_time_ids.extend(stop_time_ids);
}
}
let mut vehicle_journeys = collections.vehicle_journeys.take();
let trip_ids_to_remove: Vec<_> = gtfs_frequencies.iter().map(|f| &f.trip_id).collect();
vehicle_journeys.retain(|vj| !trip_ids_to_remove.contains(&&vj.id));
collections
.stop_time_ids
.retain(|(vj_id, _), _| !trip_ids_to_remove.contains(&&vj_id));
collections
.stop_time_comments
.retain(|(vj_id, _), _| !trip_ids_to_remove.contains(&&vj_id));

vehicle_journeys.append(&mut new_vehicle_journeys);
collections.vehicle_journeys = CollectionWithId::new(vehicle_journeys)?;
Ok(())
Expand Down
40 changes: 20 additions & 20 deletions tests/fixtures/gtfs2ntfs/frequencies/input/stop_times.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
trip_id,stop_sequence,stop_id,arrival_time,departure_time
trip:1,0,stop:11,9:00:00,9:02:00
trip:1,1,stop:12,9:15:00,9:18:00
trip:1,2,stop:13,9:30:00,9:30:00
trip:1,3,stop:14,9:40:00,9:40:00
trip:2,0,stop:21,10:40:00,10:40:00
trip:2,1,stop:22,10:45:00,10:45:00
trip:3,0,stop:31,23:50:00,23:50:00
trip:3,1,stop:32,24:03:00,24:05:00
trip:3,2,stop:33,24:10:00,24:15:00
trip:4,0,stop:11,07:23:00,07:23:00
trip:4,1,stop:22,07:32:00,07:32:00
trip:4,2,stop:33,07:40:00,07:42:00
trip:5,0,stop:51,13:23:00,13:23:00
trip:5,1,stop:52,14:10:00,14:10:00
trip:5,2,stop:53,14:40:00,14:40:00
trip:russian,0,stop:71,14:00:00,14:00:00
trip:russian,1,stop:72,16:00:00,16:00:00
trip:after_midnight,0,stop:61,14:40:00,14:40:00
trip:after_midnight,1,stop:61,15:20:00,15:20:00
trip_id,stop_sequence,stop_id,arrival_time,departure_time,pickup_type,drop_off_type
trip:1,0,stop:11,9:00:00,9:02:00,0,0
trip:1,1,stop:12,9:15:00,9:18:00,0,0
trip:1,2,stop:13,9:30:00,9:30:00,2,0
trip:1,3,stop:14,9:40:00,9:40:00,0,2
trip:2,0,stop:21,10:40:00,10:40:00,0,0
trip:2,1,stop:22,10:45:00,10:45:00,0,0
trip:3,0,stop:31,23:50:00,23:50:00,0,0
trip:3,1,stop:32,24:03:00,24:05:00,0,0
trip:3,2,stop:33,24:10:00,24:15:00,0,0
trip:4,0,stop:11,07:23:00,07:23:00,0,0
trip:4,1,stop:22,07:32:00,07:32:00,0,0
trip:4,2,stop:33,07:40:00,07:42:00,0,0
trip:5,0,stop:51,13:23:00,13:23:00,0,0
trip:5,1,stop:52,14:10:00,14:10:00,0,0
trip:5,2,stop:53,14:40:00,14:40:00,0,0
trip:russian,0,stop:71,14:00:00,14:00:00,0,0
trip:russian,1,stop:72,16:00:00,16:00:00,0,0
trip:after_midnight,0,stop:61,14:40:00,14:40:00,0,0
trip:after_midnight,1,stop:61,15:20:00,15:20:00,0,0
56 changes: 28 additions & 28 deletions tests/fixtures/gtfs2ntfs/frequencies/output/stop_times.txt
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
stop_id,trip_id,stop_sequence,arrival_time,departure_time,boarding_duration,alighting_duration,pickup_type,drop_off_type,datetime_estimated,local_zone_id,stop_headsign,stop_time_id,stop_time_precision
stop:11,trip:1-0,0,07:00:00,07:02:00,0,0,0,0,1,,,,0
stop:12,trip:1-0,1,07:15:00,07:18:00,0,0,0,0,1,,,,0
stop:13,trip:1-0,2,07:30:00,07:30:00,0,0,0,0,1,,,,0
stop:14,trip:1-0,3,07:40:00,07:40:00,0,0,0,0,1,,,,0
stop:13,trip:1-0,2,07:30:00,07:30:00,0,0,2,0,1,,,,0
stop:14,trip:1-0,3,07:40:00,07:40:00,0,0,0,2,1,,,,0
stop:11,trip:1-1,0,07:30:00,07:32:00,0,0,0,0,1,,,,0
stop:12,trip:1-1,1,07:45:00,07:48:00,0,0,0,0,1,,,,0
stop:13,trip:1-1,2,08:00:00,08:00:00,0,0,0,0,1,,,,0
stop:14,trip:1-1,3,08:10:00,08:10:00,0,0,0,0,1,,,,0
stop:13,trip:1-1,2,08:00:00,08:00:00,0,0,2,0,1,,,,0
stop:14,trip:1-1,3,08:10:00,08:10:00,0,0,0,2,1,,,,0
stop:11,trip:1-2,0,17:00:00,17:02:00,0,0,0,0,1,,,,0
stop:12,trip:1-2,1,17:15:00,17:18:00,0,0,0,0,1,,,,0
stop:13,trip:1-2,2,17:30:00,17:30:00,0,0,0,0,1,,,,0
stop:14,trip:1-2,3,17:40:00,17:40:00,0,0,0,0,1,,,,0
stop:13,trip:1-2,2,17:30:00,17:30:00,0,0,2,0,1,,,,0
stop:14,trip:1-2,3,17:40:00,17:40:00,0,0,0,2,1,,,,0
stop:11,trip:1-3,0,17:05:00,17:07:00,0,0,0,0,1,,,,0
stop:12,trip:1-3,1,17:20:00,17:23:00,0,0,0,0,1,,,,0
stop:13,trip:1-3,2,17:35:00,17:35:00,0,0,0,0,1,,,,0
stop:14,trip:1-3,3,17:45:00,17:45:00,0,0,0,0,1,,,,0
stop:13,trip:1-3,2,17:35:00,17:35:00,0,0,2,0,1,,,,0
stop:14,trip:1-3,3,17:45:00,17:45:00,0,0,0,2,1,,,,0
stop:11,trip:1-4,0,17:10:00,17:12:00,0,0,0,0,1,,,,0
stop:12,trip:1-4,1,17:25:00,17:28:00,0,0,0,0,1,,,,0
stop:13,trip:1-4,2,17:40:00,17:40:00,0,0,0,0,1,,,,0
stop:14,trip:1-4,3,17:50:00,17:50:00,0,0,0,0,1,,,,0
stop:13,trip:1-4,2,17:40:00,17:40:00,0,0,2,0,1,,,,0
stop:14,trip:1-4,3,17:50:00,17:50:00,0,0,0,2,1,,,,0
stop:11,trip:1-5,0,17:15:00,17:17:00,0,0,0,0,1,,,,0
stop:12,trip:1-5,1,17:30:00,17:33:00,0,0,0,0,1,,,,0
stop:13,trip:1-5,2,17:45:00,17:45:00,0,0,0,0,1,,,,0
stop:14,trip:1-5,3,17:55:00,17:55:00,0,0,0,0,1,,,,0
stop:13,trip:1-5,2,17:45:00,17:45:00,0,0,2,0,1,,,,0
stop:14,trip:1-5,3,17:55:00,17:55:00,0,0,0,2,1,,,,0
stop:11,trip:1-6,0,17:20:00,17:22:00,0,0,0,0,1,,,,0
stop:12,trip:1-6,1,17:35:00,17:38:00,0,0,0,0,1,,,,0
stop:13,trip:1-6,2,17:50:00,17:50:00,0,0,0,0,1,,,,0
stop:14,trip:1-6,3,18:00:00,18:00:00,0,0,0,0,1,,,,0
stop:13,trip:1-6,2,17:50:00,17:50:00,0,0,2,0,1,,,,0
stop:14,trip:1-6,3,18:00:00,18:00:00,0,0,0,2,1,,,,0
stop:11,trip:1-7,0,17:25:00,17:27:00,0,0,0,0,1,,,,0
stop:12,trip:1-7,1,17:40:00,17:43:00,0,0,0,0,1,,,,0
stop:13,trip:1-7,2,17:55:00,17:55:00,0,0,0,0,1,,,,0
stop:14,trip:1-7,3,18:05:00,18:05:00,0,0,0,0,1,,,,0
stop:13,trip:1-7,2,17:55:00,17:55:00,0,0,2,0,1,,,,0
stop:14,trip:1-7,3,18:05:00,18:05:00,0,0,0,2,1,,,,0
stop:11,trip:1-8,0,17:30:00,17:32:00,0,0,0,0,1,,,,0
stop:12,trip:1-8,1,17:45:00,17:48:00,0,0,0,0,1,,,,0
stop:13,trip:1-8,2,18:00:00,18:00:00,0,0,0,0,1,,,,0
stop:14,trip:1-8,3,18:10:00,18:10:00,0,0,0,0,1,,,,0
stop:13,trip:1-8,2,18:00:00,18:00:00,0,0,2,0,1,,,,0
stop:14,trip:1-8,3,18:10:00,18:10:00,0,0,0,2,1,,,,0
stop:11,trip:1-9,0,17:35:00,17:37:00,0,0,0,0,1,,,,0
stop:12,trip:1-9,1,17:50:00,17:53:00,0,0,0,0,1,,,,0
stop:13,trip:1-9,2,18:05:00,18:05:00,0,0,0,0,1,,,,0
stop:14,trip:1-9,3,18:15:00,18:15:00,0,0,0,0,1,,,,0
stop:13,trip:1-9,2,18:05:00,18:05:00,0,0,2,0,1,,,,0
stop:14,trip:1-9,3,18:15:00,18:15:00,0,0,0,2,1,,,,0
stop:11,trip:1-10,0,17:40:00,17:42:00,0,0,0,0,1,,,,0
stop:12,trip:1-10,1,17:55:00,17:58:00,0,0,0,0,1,,,,0
stop:13,trip:1-10,2,18:10:00,18:10:00,0,0,0,0,1,,,,0
stop:14,trip:1-10,3,18:20:00,18:20:00,0,0,0,0,1,,,,0
stop:13,trip:1-10,2,18:10:00,18:10:00,0,0,2,0,1,,,,0
stop:14,trip:1-10,3,18:20:00,18:20:00,0,0,0,2,1,,,,0
stop:11,trip:1-11,0,17:45:00,17:47:00,0,0,0,0,1,,,,0
stop:12,trip:1-11,1,18:00:00,18:03:00,0,0,0,0,1,,,,0
stop:13,trip:1-11,2,18:15:00,18:15:00,0,0,0,0,1,,,,0
stop:14,trip:1-11,3,18:25:00,18:25:00,0,0,0,0,1,,,,0
stop:13,trip:1-11,2,18:15:00,18:15:00,0,0,2,0,1,,,,0
stop:14,trip:1-11,3,18:25:00,18:25:00,0,0,0,2,1,,,,0
stop:11,trip:1-12,0,17:50:00,17:52:00,0,0,0,0,1,,,,0
stop:12,trip:1-12,1,18:05:00,18:08:00,0,0,0,0,1,,,,0
stop:13,trip:1-12,2,18:20:00,18:20:00,0,0,0,0,1,,,,0
stop:14,trip:1-12,3,18:30:00,18:30:00,0,0,0,0,1,,,,0
stop:13,trip:1-12,2,18:20:00,18:20:00,0,0,2,0,1,,,,0
stop:14,trip:1-12,3,18:30:00,18:30:00,0,0,0,2,1,,,,0
stop:11,trip:1-13,0,17:55:00,17:57:00,0,0,0,0,1,,,,0
stop:12,trip:1-13,1,18:10:00,18:13:00,0,0,0,0,1,,,,0
stop:13,trip:1-13,2,18:25:00,18:25:00,0,0,0,0,1,,,,0
stop:14,trip:1-13,3,18:35:00,18:35:00,0,0,0,0,1,,,,0
stop:13,trip:1-13,2,18:25:00,18:25:00,0,0,2,0,1,,,,0
stop:14,trip:1-13,3,18:35:00,18:35:00,0,0,0,2,1,,,,0
stop:21,trip:2-0,0,14:05:00,14:05:00,0,0,0,0,0,,,,0
stop:22,trip:2-0,1,14:10:00,14:10:00,0,0,0,0,0,,,,0
stop:21,trip:2-1,0,14:15:00,14:15:00,0,0,0,0,0,,,,0
Expand Down
9 changes: 0 additions & 9 deletions tests/fixtures/gtfs2ntfs/odt_comment/comment_links.txt

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fixtures/gtfs2ntfs/odt_comment/comments.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
object_id,object_type,comment_id
test:trip:1-8-3,stop_time,test:ODT:1
test:trip:1-1-2,stop_time,test:ODT:1
test:trip:1-5-2,stop_time,test:ODT:1
test:trip:1-2-2,stop_time,test:ODT:1
test:trip:1-2-3,stop_time,test:ODT:1
test:trip:1-9-3,stop_time,test:ODT:1
test:trip:1-12-2,stop_time,test:ODT:1
test:trip:1-0-2,stop_time,test:ODT:1
test:trip:1-1-3,stop_time,test:ODT:1
test:trip:1-6-3,stop_time,test:ODT:1
test:trip:1-3-2,stop_time,test:ODT:1
test:trip:1-8-2,stop_time,test:ODT:1
test:trip:1-4-3,stop_time,test:ODT:1
test:trip:1-4-2,stop_time,test:ODT:1
test:trip:1-7-3,stop_time,test:ODT:1
test:trip:1-11-3,stop_time,test:ODT:1
test:trip:1-6-2,stop_time,test:ODT:1
test:trip:1-13-2,stop_time,test:ODT:1
test:trip:1-3-3,stop_time,test:ODT:1
test:trip:1-10-3,stop_time,test:ODT:1
test:trip:1-11-2,stop_time,test:ODT:1
test:trip:1-0-3,stop_time,test:ODT:1
test:trip:1-10-2,stop_time,test:ODT:1
test:trip:1-7-2,stop_time,test:ODT:1
test:trip:1-9-2,stop_time,test:ODT:1
test:trip:1-12-3,stop_time,test:ODT:1
test:trip:1-13-3,stop_time,test:ODT:1
test:trip:1-5-3,stop_time,test:ODT:1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
comment_id,comment_type,comment_label,comment_name,comment_url
test:ODT:1,on_demand_transport,,Service à réservation mon agence ,
Loading

0 comments on commit 08d5f69

Please sign in to comment.