afimb / gtfslib-python

An open source library in python for reading GTFS files and computing various stats and indicators about Public Transport networks
GNU General Public License v3.0
44 stars 6 forks source link

Normalization of negative stop_seq can cause unique constraint failure #26

Open laurentg opened 8 years ago

laurentg commented 8 years ago

The stop_seq field is part of the primary key of table stop_times. As we remap stop_seq in an increasing order, remapping negative values can lead to unique constraint failure as we move indexes to larger values (for example -1 is remapped to 0 before 0 is remapped to 1).

To solve this, we need to analyze the graph of remapping and start with the non-conflicting indexes first, as processing in a decreasing order for negative values can also fail if we have non-consecutive indexes: for example the following sequence: { -2, -1, 0, 4, 6 } => { 0, 1, 2, 3, 4 } (Here the first remap 6 to 4 will fail).