Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/mtransit/parser/DefaultAgencyTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ public Integer getAgencyRouteType() {

@Nullable
public Integer getAgencyExtendedRouteType() {
if (Configs.getAgencyConfig() != null) {
return Configs.getAgencyConfig().getExtendedTargetRouteTypeId();
}
return null; // optional
}

Expand Down Expand Up @@ -1105,6 +1108,9 @@ public boolean forceStopTimeFirstNoDropOffType() {

@Override
public boolean excludeStopTime(@NotNull GStopTime gStopTime) {
if (Configs.getRouteConfig().excludeStopTime(gStopTime)) {
return EXCLUDE;
}
// https://gtfs.org/schedule/best-practices/#stop_timestxt
return GPickupType.NO_PICKUP == gStopTime.getPickupType() //
&& GDropOffType.NO_DROP_OFF == gStopTime.getDropOffType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ data class AgencyConfig(
*/
@SerialName("target_route_type_id")
val targetRouteTypeId: Int, // REQUIRED
@SerialName("extended_target_route_type_id")
val extendedTargetRouteTypeId: Int? = null, // OPTIONAL
// STRINGS
/**
* (Optional) Default string cleaner enabled/disabled (based on language/country/field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.mtransit.commons.CleanUtils
import org.mtransit.parser.gtfs.data.GRoute
import org.mtransit.parser.gtfs.data.GStopTime
import org.mtransit.parser.gtfs.data.GTrip

@Serializable
Expand Down Expand Up @@ -104,6 +105,8 @@ data class RouteConfig(
@SerialName("stop_headsign_cleanup_regex")
val stopHeadsignCleanupRegex: String? = null, // optional
// STOP TIMES
@SerialName("stop_time_excludes")
val stopTimeExcludes: List<StopTimeFilter> = emptyList(), // optional
@SerialName("allow_invalid_stop_times")
val allowInvalidStopTimes: Boolean = false, // OPT-IN feature
@SerialName("allow_invalid_stop_times_until")
Expand Down Expand Up @@ -182,6 +185,14 @@ data class RouteConfig(
val ignoreCase: Boolean = false,
)

@Serializable
data class StopTimeFilter(
@SerialName("stop_time_headsign_regex")
val stopTimeHeadsignRegex: String? = null,
@SerialName("ignore_case")
val ignoreCase: Boolean = false,
)

fun keepRoutes(gRoute: GRoute) =
this.keepRoutes.any {
//noinspection DiscouragedApi
Expand Down Expand Up @@ -252,15 +263,36 @@ data class RouteConfig(
}

fun excludeTrip(gTrip: GTrip): Boolean {
val gTripHeadsign = gTrip.tripHeadsign ?: return false // EXCLUDE
this._tripExcludes.forEach {
val gTripHeadsign = gTrip.tripHeadsign ?: return@forEach
if (it.matches(gTripHeadsign)) {
return true // EXCLUDE
}
}
return false // KEEP
}

private val _stopTimeExcludes: List<Regex> by lazy {
this.stopTimeExcludes.mapNotNull {
if (it.stopTimeHeadsignRegex.isNullOrEmpty()) return@mapNotNull null
val regexOptions = mutableSetOf<RegexOption>()
if (it.ignoreCase) {
regexOptions.add(RegexOption.IGNORE_CASE)
}
it.stopTimeHeadsignRegex.toRegex(regexOptions)
}
}

fun excludeStopTime(gStopTime: GStopTime): Boolean {
val gStopTimeHeadsign = gStopTime.stopHeadsign ?: return false // KEEP
this._stopTimeExcludes.forEach {
if (it.matches(gStopTimeHeadsign)) {
return true // EXCLUDE
}
}
return false // KEEP
}

fun cleanDirectionHeadsign(directionHeadsign: String) =
cleanString(directionHeadsign, this.directionHeadsignCleaners)

Expand Down