Skip to content

Commit 2eb5822

Browse files
mmathieumCopilot
andauthored
Index Service IDs (#18)
Co-authored-by: Copilot <[email protected]>
1 parent e383322 commit 2eb5822

23 files changed

+371
-295
lines changed

src/main/java/org/mtransit/parser/DefaultAgencyTools.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.mtransit.parser.mt.data.MRoute;
3636
import org.mtransit.parser.mt.data.MRouteSNToIDConverter;
3737
import org.mtransit.parser.mt.data.MServiceDate;
38+
import org.mtransit.parser.mt.data.MServiceId;
39+
import org.mtransit.parser.mt.data.MServiceIds;
3840
import org.mtransit.parser.mt.data.MSpec;
3941
import org.mtransit.parser.mt.data.MDirection;
4042

@@ -151,6 +153,8 @@ public void start(@NotNull String[] args) {
151153
MTLog.log("Generating data...");
152154
MTLog.logDebug("Args [%d]: %s.", args.length, Arrays.asList(args));
153155
final List<MServiceDate> lastServiceDates = MReader.loadServiceDates(args[2]);
156+
final List<MServiceId> lastServiceIds = MReader.loadServiceIds(args[2]);
157+
MServiceIds.addAll(lastServiceIds);
154158
this.serviceIdInts = extractUsefulServiceIdInts(args, this, true, lastServiceDates);
155159
final String inputUrl = args.length >= 5 ? args[4] : null;
156160
if (excludingAll()) {
@@ -1317,7 +1321,7 @@ public static HashSet<Integer> extractUsefulServiceIdInts(
13171321
MTLog.log("* Generated on %s | NEXT Schedules from %s to %s.", usefulPeriod.getTodayStringInt(), usefulPeriod.getStartDate(), usefulPeriod.getEndDate());
13181322
MTLog.log("------------------------------");
13191323
}
1320-
HashSet<Integer> serviceIds = getPeriodServiceIds(usefulPeriod.getStartDate(), usefulPeriod.getEndDate(), gCalendars, gCalendarDates);
1324+
final HashSet<Integer> serviceIds = getPeriodServiceIds(usefulPeriod.getStartDate(), usefulPeriod.getEndDate(), gCalendars, gCalendarDates);
13211325
improveUsefulPeriod(usefulPeriod, c, gCalendars, gCalendarDates);
13221326
MTLog.log("Extracting useful service IDs... DONE");
13231327
//noinspection UnusedAssignment // FIXME
@@ -1448,7 +1452,8 @@ && diffLowerThan(DATE_FORMAT, c, pPrevious.getStartDate(), pPrevious.getEndDate(
14481452
private static boolean refreshStartEndDatesFromCalendarDates(
14491453
Period p,
14501454
HashSet<Integer> serviceIds,
1451-
List<GCalendarDate> gCalendarDates) {
1455+
List<GCalendarDate> gCalendarDates
1456+
) {
14521457
boolean newDates = false;
14531458
for (GCalendarDate gCalendarDate : gCalendarDates) {
14541459
if (gCalendarDate.isServiceIdInts(serviceIds)) {

src/main/java/org/mtransit/parser/db/DumpDbUtils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.mtransit.parser.db
22

3+
import org.mtransit.commons.FeatureFlags
34
import org.mtransit.commons.GTFSCommons
45
import org.mtransit.parser.FileUtils
56
import java.io.File
@@ -30,12 +31,18 @@ object DumpDbUtils {
3031
SQLUtils.executeUpdate(statement, GTFSCommons.T_STOP_SQL_DROP)
3132
SQLUtils.executeUpdate(statement, GTFSCommons.T_DIRECTION_SQL_DROP)
3233
SQLUtils.executeUpdate(statement, GTFSCommons.T_ROUTE_SQL_DROP)
34+
if (FeatureFlags.F_EXPORT_SERVICE_ID_INTS) {
35+
SQLUtils.executeUpdate(statement, GTFSCommons.T_SERVICE_IDS_SQL_DROP)
36+
}
3337
SQLUtils.executeUpdate(statement, GTFSCommons.T_SERVICE_DATES_SQL_DROP)
3438
// CREATE
3539
SQLUtils.executeUpdate(statement, GTFSCommons.T_ROUTE_SQL_CREATE)
3640
SQLUtils.executeUpdate(statement, GTFSCommons.T_DIRECTION_SQL_CREATE)
3741
SQLUtils.executeUpdate(statement, GTFSCommons.T_STOP_SQL_CREATE)
3842
SQLUtils.executeUpdate(statement, GTFSCommons.T_DIRECTION_STOPS_SQL_CREATE)
43+
if (FeatureFlags.F_EXPORT_SERVICE_ID_INTS) {
44+
SQLUtils.executeUpdate(statement, GTFSCommons.T_SERVICE_IDS_SQL_CREATE)
45+
}
3946
SQLUtils.executeUpdate(statement, GTFSCommons.T_SERVICE_DATES_SQL_CREATE)
4047
}
4148
}

src/main/java/org/mtransit/parser/gtfs/data/GAgency.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ data class GAgency(
3838
agencyEmail,
3939
)
4040

41-
@Discouraged(message = "Not memory efficient")
4241
@Suppress("unused")
43-
val agencyId = _agencyId
42+
@get:Discouraged(message = "Not memory efficient")
43+
val agencyId: AgencyId get() = _agencyId
4444

4545
private val _agencyId: AgencyId
46-
get() {
47-
return GIDs.getString(agencyIdInt)
48-
}
46+
get() = GIDs.getString(agencyIdInt)
4947

5048
@Suppress("unused")
5149
fun isDifferentAgency(otherAgencyIdInt: Int): Boolean = agencyIdInt != otherAgencyIdInt

src/main/java/org/mtransit/parser/gtfs/data/GCalendar.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.mtransit.parser.gtfs.data
33
import androidx.annotation.Discouraged
44
import org.mtransit.parser.MTLog
55
import org.mtransit.parser.db.SQLUtils.escape
6-
import org.mtransit.parser.gtfs.GAgencyTools
76
import java.util.Calendar
87

98
// https://developers.google.com/transit/gtfs/reference#calendar_fields
@@ -68,26 +67,19 @@ data class GCalendar(
6867
endDate
6968
)
7069

71-
@Discouraged(message = "Not memory efficient")
7270
@Suppress("unused")
73-
val serviceId = _serviceId
71+
@get:Discouraged(message = "Not memory efficient")
72+
val serviceId: String get() = _serviceId
7473

7574
private val _serviceId: String
76-
get() {
77-
return GIDs.getString(serviceIdInt)
78-
}
75+
get() = GIDs.getString(serviceIdInt)
7976

8077
val escapedServiceId: String
8178
get() = _serviceId.escape()
8279

8380
val escapedServiceIdInt: Int
8481
get() = escapedServiceId.toGIDInt()
8582

86-
@Suppress("unused")
87-
fun getCleanServiceId(agencyTools: GAgencyTools): String {
88-
return agencyTools.cleanServiceId(_serviceId)
89-
}
90-
9183
val dates: List<GCalendarDate> by lazy {
9284
initAllDates(
9385
serviceIdInt,
@@ -264,7 +256,7 @@ data class GCalendar(
264256
sunday: Boolean,
265257
startDate: Int,
266258
endDate: Int,
267-
exceptionType: GCalendarDatesExceptionType = GCalendarDatesExceptionType.SERVICE_ADDED,
259+
exceptionType: GCalendarDatesExceptionType = GCalendarDatesExceptionType.SERVICE_DEFAULT,
268260
) = buildList {
269261
try {
270262
val dateFormat = GFieldTypes.makeDateFormat()

src/main/java/org/mtransit/parser/gtfs/data/GCalendarDate.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,19 @@ data class GCalendarDate(
4040
GCalendarDatesExceptionType.parse(exceptionTypeInt)
4141
)
4242

43-
@Discouraged(message = "Not memory efficient")
4443
@Suppress("unused")
45-
val serviceId = _serviceId
44+
@get:Discouraged(message = "Not memory efficient")
45+
val serviceId: String get() = _serviceId
4646

4747
private val _serviceId: String
48-
get() {
49-
return GIDs.getString(serviceIdInt)
50-
}
48+
get() = GIDs.getString(serviceIdInt)
5149

5250
val escapedServiceId: String
5351
get() = _serviceId.escape()
5452

5553
val escapedServiceIdInt: Int
5654
get() = escapedServiceId.toGIDInt()
5755

58-
@Suppress("unused")
59-
fun getCleanServiceId(agencyTools: GAgencyTools): String {
60-
return agencyTools.cleanServiceId(_serviceId)
61-
}
62-
6356
val uID by lazy { getNewUID(date, serviceIdInt) }
6457

6558
@Suppress("unused")

src/main/java/org/mtransit/parser/gtfs/data/GDirection.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ data class GDirection(
2525
destination = destination,
2626
)
2727

28-
@Discouraged(message = "Not memory efficient")
2928
@Suppress("unused")
30-
val routeId = _routeId
29+
@get:Discouraged(message = "Not memory efficient")
30+
val routeId: String get() = _routeId
3131

3232
private val _routeId: String
33-
get() {
34-
return GIDs.getString(routeIdInt)
35-
}
33+
get() = GIDs.getString(routeIdInt)
3634

3735
@Suppress("unused")
3836
fun toStringPlus(): String {

src/main/java/org/mtransit/parser/gtfs/data/GFrequency.kt

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,34 @@ data class GFrequency(
3131
exactTimes,
3232
)
3333

34-
@Discouraged(message = "Not memory efficient")
3534
@Suppress("unused")
36-
val tripId = _tripId
35+
@get:Discouraged(message = "Not memory efficient")
36+
val tripId: String get() = _tripId
3737

3838
@Suppress("unused")
3939
private val _tripId: String
40-
get() {
41-
return GIDs.getString(tripIdInt)
42-
}
40+
get() = GIDs.getString(tripIdInt)
4341

4442
val startTime: Int = _startTime
4543

4644
@Suppress("unused")
4745
val startTimeDate: Date
48-
get() {
49-
return GTime.toDate(_startTime)
50-
}
46+
get() = GTime.toDate(_startTime)
5147

5248
val startTimeMs: Long
53-
get() {
54-
return GTime.toMs(_startTime)
55-
}
49+
get() = GTime.toMs(_startTime)
5650

5751
val endTime: Int = _endTime
5852

5953
@Suppress("unused")
6054
val endTimeDate: Date
61-
get() {
62-
return GTime.toDate(_endTime)
63-
}
55+
get() = GTime.toDate(_endTime)
6456

6557
val endTimeMs: Long
66-
get() {
67-
return GTime.toMs(_endTime)
68-
}
58+
get() = GTime.toMs(_endTime)
6959

7060
val headwayMs: Long
71-
get() {
72-
return TimeUnit.SECONDS.toMillis(headwaySecs.toLong())
73-
}
61+
get() = TimeUnit.SECONDS.toMillis(headwaySecs.toLong())
7462

7563
@Suppress("unused")
7664
fun toStringPlus(): String {

src/main/java/org/mtransit/parser/gtfs/data/GRoute.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,30 @@ data class GRoute(
6767
@Suppress("unused")
6868
fun isDifferentAgency(otherAgencyId: String): Boolean = isDifferentAgency(GIDs.getInt(otherAgencyId))
6969

70-
@Discouraged(message = "Not memory efficient")
7170
@Suppress("unused")
72-
val agencyIdOrDefault: AgencyId = _agencyId
71+
@get:Discouraged(message = "Not memory efficient")
72+
val agencyIdOrDefault: AgencyId get() = _agencyId
7373

74-
@Discouraged(message = "Not memory efficient")
7574
@Suppress("unused")
76-
val agencyId: AgencyId = _agencyId
75+
@get:Discouraged(message = "Not memory efficient")
76+
val agencyId: AgencyId get() = _agencyId
7777

7878
private val _agencyId: AgencyId
7979
get() = GIDs.getString(agencyIdInt)
8080

81-
@Discouraged(message = "Not memory efficient")
8281
@Suppress("unused")
83-
val routeId = _routeId
82+
@get:Discouraged(message = "Not memory efficient")
83+
val routeId: RouteId get() = _routeId
8484

8585
private val _routeId: RouteId
86-
get() {
87-
return GIDs.getString(routeIdInt)
88-
}
86+
get() = GIDs.getString(routeIdInt)
8987

90-
@Discouraged(message = "Not memory efficient")
9188
@Suppress("unused")
92-
val originalRouteId = _originalRouteId
89+
@get:Discouraged(message = "Not memory efficient")
90+
val originalRouteId: String get() = _originalRouteId
9391

9492
private val _originalRouteId: String
95-
get() {
96-
return GIDs.getString(originalRouteIdInt)
97-
}
93+
get() = GIDs.getString(originalRouteIdInt)
9894

9995
@Suppress("unused")
10096
val shortestRouteName = routeShortName.ifEmpty { routeLongName }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package org.mtransit.parser.gtfs.data
22

3-
fun GSpec.getRoute(gTrip: GTrip): GRoute? {
4-
return this.getRoute(gTrip.routeIdInt)
5-
}
3+
fun GSpec.getRoute(gTrip: GTrip) = this.getRoute(gTrip.routeIdInt)

src/main/java/org/mtransit/parser/gtfs/data/GStop.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,19 @@ data class GStop(
4242
GWheelchairBoardingType.parse(wheelchairBoarding),
4343
)
4444

45-
@Discouraged(message = "Not memory efficient")
4645
@Suppress("unused")
47-
val stopId = _stopId
46+
@get:Discouraged(message = "Not memory efficient")
47+
val stopId: StopId get() = _stopId
4848

4949
private val _stopId: StopId
50-
get() {
51-
return GIDs.getString(stopIdInt)
52-
}
50+
get() = GIDs.getString(stopIdInt)
5351

54-
@Discouraged(message = "Not memory efficient")
5552
@Suppress("unused")
56-
val parentStationId = _parentStationId
53+
@get:Discouraged(message = "Not memory efficient")
54+
val parentStationId: StopId? get() = _parentStationId
5755

5856
private val _parentStationId: StopId?
59-
get() {
60-
return parentStationIdInt?.let { GIDs.getString(it) }
61-
}
57+
get() = parentStationIdInt?.let { GIDs.getString(it) }
6258

6359
@JvmOverloads
6460
@Suppress("unused")

0 commit comments

Comments
 (0)