Skip to content

Commit b6944a9

Browse files
committed
Add modifiche per gestione campi extra per cafe
1 parent bdb76ee commit b6944a9

18 files changed

+520
-127
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
*.iml
99
.idea/
1010
target/
11-
12-
lambda$*.json
11+
.classpath
12+
.project
13+
.settings/
14+
lambda$*.json

src/main/java/com/conveyal/gtfs/PatternFinder.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package com.conveyal.gtfs;
23

34
import com.conveyal.gtfs.error.NewGTFSError;
@@ -11,7 +12,6 @@
1112
import com.conveyal.gtfs.model.Trip;
1213
import com.conveyal.gtfs.validator.service.GeoUtils;
1314
import com.google.common.collect.HashMultimap;
14-
import com.google.common.collect.LinkedHashMultimap;
1515
import com.google.common.collect.Multimap;
1616
import org.locationtech.jts.geom.Coordinate;
1717
import org.locationtech.jts.geom.CoordinateList;
@@ -24,11 +24,11 @@
2424
import java.util.HashMap;
2525
import java.util.HashSet;
2626
import java.util.Iterator;
27-
import java.util.LinkedHashMap;
2827
import java.util.List;
2928
import java.util.Locale;
3029
import java.util.Map;
3130
import java.util.Set;
31+
import java.util.TreeMap;
3232
import java.util.stream.Collectors;
3333

3434
import static com.conveyal.gtfs.util.Util.human;
@@ -46,7 +46,8 @@ public class PatternFinder {
4646
private static final Logger LOG = LoggerFactory.getLogger(PatternFinder.class);
4747

4848
// 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();
5051

5152
private int nTripsProcessed = 0;
5253

@@ -88,8 +89,9 @@ public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopB
8889
// Make pattern ID one-based to avoid any JS type confusion between an ID of zero vs. null value.
8990
int nextPatternId = 1;
9091
// 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<>();
9395
// TODO assign patterns sequential small integer IDs (may include route)
9496
for (TripPatternKey key : tripsForPattern.keySet()) {
9597
Collection<Trip> trips = tripsForPattern.get(key);
@@ -99,6 +101,7 @@ public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopB
99101
// FIXME: Should associated shapes be a single entry?
100102
pattern.associatedShapes = new HashSet<>();
101103
trips.stream().forEach(trip -> pattern.associatedShapes.add(trip.shape_id));
104+
/* 5t disabilitiamo temporaneamente
102105
if (pattern.associatedShapes.size() > 1 && errorStorage != null) {
103106
// Store an error if there is more than one shape per pattern. Note: error storage is null if called via
104107
// MapDB implementation.
@@ -107,7 +110,7 @@ public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopB
107110
pattern,
108111
NewGTFSErrorType.MULTIPLE_SHAPES_FOR_PATTERN)
109112
.setBadValue(pattern.associatedShapes.toString()));
110-
}
113+
}*/
111114
patterns.put(key, pattern);
112115
}
113116
// Name patterns before storing in SQL database.
@@ -167,19 +170,21 @@ public static void renamePatterns(Collection<Pattern> patterns, Map<String, Stop
167170
intersection.retainAll(info.toStops.get(toName));
168171

169172
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);
171174
continue;
172175
}
173176

174177
// check for unique via stop
178+
/* 5t moved below
175179
pattern.orderedStops.stream().map(stopById::get).forEach(stop -> {
176180
Set<Pattern> viaIntersection = new HashSet<>(intersection);
177181
viaIntersection.retainAll(info.vias.get(stop.stop_name));
178182
179183
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);
181185
}
182186
});
187+
*/
183188

184189
if (pattern.name == null) {
185190
// no unique via, one pattern is subset of other.
@@ -188,26 +193,39 @@ public static void renamePatterns(Collection<Pattern> patterns, Map<String, Stop
188193
Pattern p0 = it.next();
189194
Pattern p1 = it.next();
190195
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);
193198
} 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);
196201
}
197202
}
198203
}
199204

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+
200217
if (pattern.name == null) {
201218
// 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));
203220
}
204221
}
205222

223+
// 5t removed trips and stops count from pattern name
206224
// attach a stop and trip count to each
207-
for (Pattern pattern : info.patternsOnRoute) {
225+
/*for (Pattern pattern : info.patternsOnRoute) {
208226
pattern.name = String.format(Locale.US, "%s stops %s (%s trips)",
209227
pattern.orderedStops.size(), pattern.name, pattern.associatedTrips.size());
210-
}
228+
}*/
211229
}
212230
}
213231

src/main/java/com/conveyal/gtfs/TripPatternKey.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* stops on two different routes makes two different patterns.
1717
* These objects are not intended for use outside the grouping process.
1818
*/
19-
public class TripPatternKey {
19+
public class TripPatternKey implements Comparable<TripPatternKey>{
2020

2121
public String routeId;
2222
public List<String> stops = new ArrayList<>();
@@ -83,4 +83,11 @@ public int hashCode() {
8383
return result;
8484
}
8585

86+
87+
@Override
88+
public int compareTo(TripPatternKey tpk) {
89+
return this.routeId.compareTo(tpk.routeId) <= 0 ? -1 : 1 ;
90+
}
91+
92+
8693
}

0 commit comments

Comments
 (0)