1
+
1
2
package com .conveyal .gtfs ;
2
3
3
4
import com .conveyal .gtfs .error .NewGTFSError ;
11
12
import com .conveyal .gtfs .model .Trip ;
12
13
import com .conveyal .gtfs .validator .service .GeoUtils ;
13
14
import com .google .common .collect .HashMultimap ;
14
- import com .google .common .collect .LinkedHashMultimap ;
15
15
import com .google .common .collect .Multimap ;
16
16
import org .locationtech .jts .geom .Coordinate ;
17
17
import org .locationtech .jts .geom .CoordinateList ;
24
24
import java .util .HashMap ;
25
25
import java .util .HashSet ;
26
26
import java .util .Iterator ;
27
- import java .util .LinkedHashMap ;
28
27
import java .util .List ;
29
28
import java .util .Locale ;
30
29
import java .util .Map ;
31
30
import java .util .Set ;
31
+ import java .util .TreeMap ;
32
32
import java .util .stream .Collectors ;
33
33
34
34
import static com .conveyal .gtfs .util .Util .human ;
@@ -46,7 +46,8 @@ public class PatternFinder {
46
46
private static final Logger LOG = LoggerFactory .getLogger (PatternFinder .class );
47
47
48
48
// A multi-map that groups trips together by their sequence of stops
49
- private Multimap <TripPatternKey , Trip > tripsForPattern = LinkedHashMultimap .create ();
49
+ // 5t private Multimap<TripPatternKey, Trip> tripsForPattern = LinkedHashMultimap.create();
50
+ private Multimap <TripPatternKey , Trip > tripsForPattern = HashMultimap .create ();
50
51
51
52
private int nTripsProcessed = 0 ;
52
53
@@ -88,8 +89,9 @@ public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopB
88
89
// Make pattern ID one-based to avoid any JS type confusion between an ID of zero vs. null value.
89
90
int nextPatternId = 1 ;
90
91
// Create an in-memory list of Patterns because we will later rename them before inserting them into storage.
91
- // Use a LinkedHashMap so we can retrieve the entrySets later in the order of insertion.
92
- Map <TripPatternKey , Pattern > patterns = new LinkedHashMap <>();
92
+ // 5t ordiniamo i pattern raggrupparti per route_id
93
+ // Map<TripPatternKey, Pattern> patterns = new LinkedHashMap<>();
94
+ Map <TripPatternKey , Pattern > patterns = new TreeMap <>();
93
95
// TODO assign patterns sequential small integer IDs (may include route)
94
96
for (TripPatternKey key : tripsForPattern .keySet ()) {
95
97
Collection <Trip > trips = tripsForPattern .get (key );
@@ -99,6 +101,7 @@ public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopB
99
101
// FIXME: Should associated shapes be a single entry?
100
102
pattern .associatedShapes = new HashSet <>();
101
103
trips .stream ().forEach (trip -> pattern .associatedShapes .add (trip .shape_id ));
104
+ /* 5t disabilitiamo temporaneamente
102
105
if (pattern.associatedShapes.size() > 1 && errorStorage != null) {
103
106
// Store an error if there is more than one shape per pattern. Note: error storage is null if called via
104
107
// MapDB implementation.
@@ -107,7 +110,7 @@ public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopB
107
110
pattern,
108
111
NewGTFSErrorType.MULTIPLE_SHAPES_FOR_PATTERN)
109
112
.setBadValue(pattern.associatedShapes.toString()));
110
- }
113
+ }*/
111
114
patterns .put (key , pattern );
112
115
}
113
116
// Name patterns before storing in SQL database.
@@ -167,19 +170,21 @@ public static void renamePatterns(Collection<Pattern> patterns, Map<String, Stop
167
170
intersection .retainAll (info .toStops .get (toName ));
168
171
169
172
if (intersection .size () == 1 ) {
170
- pattern .name = String .format (Locale .US , "from %s to %s" , fromName , toName );
173
+ pattern .name = String .format (Locale .US , "%s >> %s" , fromName , toName );
171
174
continue ;
172
175
}
173
176
174
177
// check for unique via stop
178
+ /* 5t moved below
175
179
pattern.orderedStops.stream().map(stopById::get).forEach(stop -> {
176
180
Set<Pattern> viaIntersection = new HashSet<>(intersection);
177
181
viaIntersection.retainAll(info.vias.get(stop.stop_name));
178
182
179
183
if (viaIntersection.size() == 1) {
180
- pattern .name = String .format (Locale .US , "from %s to %s via %s" , fromName , toName , stop .stop_name );
184
+ pattern.name = String.format(Locale.US, "%s >> %s via %s", fromName, toName, stop.stop_name);
181
185
}
182
186
});
187
+ */
183
188
184
189
if (pattern .name == null ) {
185
190
// no unique via, one pattern is subset of other.
@@ -188,26 +193,39 @@ public static void renamePatterns(Collection<Pattern> patterns, Map<String, Stop
188
193
Pattern p0 = it .next ();
189
194
Pattern p1 = it .next ();
190
195
if (p0 .orderedStops .size () > p1 .orderedStops .size ()) {
191
- p1 .name = String .format (Locale .US , "from %s to %s express" , fromName , toName );
192
- p0 .name = String .format (Locale .US , "from %s to %s local" , fromName , toName );
196
+ p1 .name = String .format (Locale .US , "%s >> %s express" , fromName , toName );
197
+ p0 .name = String .format (Locale .US , "%s >> %s local" , fromName , toName );
193
198
} else if (p1 .orderedStops .size () > p0 .orderedStops .size ()){
194
- p0 .name = String .format (Locale .US , "from %s to %s express" , fromName , toName );
195
- p1 .name = String .format (Locale .US , "from %s to %s local" , fromName , toName );
199
+ p0 .name = String .format (Locale .US , "%s >> %s express" , fromName , toName );
200
+ p1 .name = String .format (Locale .US , "%s >> %s local" , fromName , toName );
196
201
}
197
202
}
198
203
}
199
204
205
+ // check for unique via stop
206
+ for (String stopId : pattern .orderedStops ) {
207
+ Set <Pattern > viaIntersection = new HashSet <>(intersection );
208
+ Stop stop = stopById .get (stopId );
209
+ viaIntersection .retainAll (info .vias .get (stop .stop_name ));
210
+
211
+ if (viaIntersection .size () == 1 ) {
212
+ if (pattern .name == null )
213
+ pattern .name = String .format (Locale .US , "%s >> %s via %s" , fromName , toName , stop .stop_name );
214
+ }
215
+ }
216
+
200
217
if (pattern .name == null ) {
201
218
// give up
202
- pattern .name = String .format (Locale .US , "from %s to %s like trip %s" , fromName , toName , pattern .associatedTrips .get (0 ));
219
+ pattern .name = String .format (Locale .US , "%s >> %s like trip %s" , fromName , toName , pattern .associatedTrips .get (0 ));
203
220
}
204
221
}
205
222
223
+ // 5t removed trips and stops count from pattern name
206
224
// attach a stop and trip count to each
207
- for (Pattern pattern : info .patternsOnRoute ) {
225
+ /* for (Pattern pattern : info.patternsOnRoute) {
208
226
pattern.name = String.format(Locale.US, "%s stops %s (%s trips)",
209
227
pattern.orderedStops.size(), pattern.name, pattern.associatedTrips.size());
210
- }
228
+ }*/
211
229
}
212
230
}
213
231
0 commit comments