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
15 changes: 9 additions & 6 deletions src/main/java/org/mtransit/parser/DefaultAgencyTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void start(@NotNull String[] args) {
}
final long start = System.currentTimeMillis();
final GSpec gtfs = GReader.readGtfsZipFile(args[0], this, false, false);
MDataChangedManager.avoidCalendarDatesDataChanged(lastServiceDates, gtfs);
MDataChangedManager.avoidCalendarDatesDataChanged(lastServiceDates, gtfs, this);
gtfs.cleanupStops();
gtfs.cleanupExcludedData();
gtfs.cleanupStopTimesPickupDropOffTypes(this);
Expand Down Expand Up @@ -1381,7 +1381,7 @@ public static HashSet<Integer> extractUsefulServiceIdInts(
usefulPeriod.setTodayStringInt(OVERRIDE_DATE);
}
GSpec gtfs = GReader.readGtfsZipFile(args[0], agencyTools, !agencyFilter, agencyFilter);
MDataChangedManager.avoidCalendarDatesDataChanged(lastServiceDates, gtfs);
MDataChangedManager.avoidCalendarDatesDataChanged(lastServiceDates, gtfs, agencyTools);
if (agencyFilter) {
gtfs.cleanupExcludedServiceIds();
}
Expand Down Expand Up @@ -1928,10 +1928,13 @@ public static boolean diffLowerThan(@NotNull SimpleDateFormat dateFormat,
}
}

private static long diffInMs(@NotNull SimpleDateFormat dateFormat,
@NotNull Calendar calendar,
@Nullable Integer startDateInt,
@Nullable Integer endDateInt) {
@SuppressWarnings("WeakerAccess")
public static long diffInMs(
@NotNull SimpleDateFormat dateFormat,
@NotNull Calendar calendar,
@Nullable Integer startDateInt,
@Nullable Integer endDateInt
) {
try {
calendar.setTime(dateFormat.parse(String.valueOf(startDateInt)));
long startDateInMs = calendar.getTimeInMillis();
Expand Down
112 changes: 76 additions & 36 deletions src/main/java/org/mtransit/parser/mt/MDataChangedManager.kt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/org/mtransit/parser/mt/data/MFrequency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class MFrequency(
val uID by lazy { getNewUID(serviceIdInt, directionId, startTime, endTime) }

fun toFile(agencyTools: GAgencyTools) = buildList {
add(MServiceIds.convert(agencyTools.cleanServiceId(_serviceId)))
add(_serviceId.convertServiceId(agencyTools, quotesString = true))
add(directionId.toString())
add(startTime.toString())
add(endTime.toString())
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/mtransit/parser/mt/data/MSchedule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ data class MSchedule(
if (FeatureFlags.F_EXPORT_SCHEDULE_SORTED_BY_ROUTE_DIRECTION) {
// no route ID, just for logs
add(directionId.toString())
add(MServiceIds.convert(agencyTools.cleanServiceId(_serviceId)))
add(_serviceId.convertServiceId(agencyTools, quotesString = true))
} else {
add(MServiceIds.convert(agencyTools.cleanServiceId(_serviceId)))
add(_serviceId.convertServiceId(agencyTools, quotesString = true))
// no route ID, just for logs
add(directionId.toString())
}
Expand All @@ -125,7 +125,7 @@ data class MSchedule(
}
add(arrivalDiff?.toString().orEmpty())
}
add(MTripIds.convert(_tripId))
add(_tripId.convertTripId(quotesString = true))
}
if (headsignType == MDirection.HEADSIGN_TYPE_NO_PICKUP) {
add(MDirection.HEADSIGN_TYPE_NO_PICKUP.toString())
Expand All @@ -137,8 +137,10 @@ data class MSchedule(
} else {
add(headsignType.takeIf { it >= 0 }?.toString().orEmpty())
if (FeatureFlags.F_SCHEDULE_NO_QUOTES) {
@Suppress("SimplifyBooleanWithConstants")
add(headsignValue.orEmpty().toStringIds(FeatureFlags.F_EXPORT_STRINGS || FeatureFlags.F_EXPORT_SCHEDULE_STRINGS))
} else {
@Suppress("SimplifyBooleanWithConstants")
add(headsignValue.orEmpty().toStringIds(FeatureFlags.F_EXPORT_STRINGS || FeatureFlags.F_EXPORT_SCHEDULE_STRINGS).quotesEscape())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mtransit/parser/mt/data/MServiceDate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class MServiceDate(
fun toFile(agencyTools: GAgencyTools, lastServiceDate: MServiceDate? = null) = buildList {
@Suppress("SimplifyBooleanWithConstants")
if (!FeatureFlags.F_EXPORT_FLATTEN_SERVICE_DATES || lastServiceDate == null) { // new
add(MServiceIds.convert(agencyTools.cleanServiceId(_serviceId)))
add(_serviceId.convertServiceId(agencyTools, quotesString = true))
}
add(calendarDate.toString())
add(exceptionType.toString())
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/mtransit/parser/mt/data/MServiceIds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import androidx.collection.SparseArrayCompat
import androidx.collection.mutableScatterMapOf
import org.mtransit.commons.FeatureFlags
import org.mtransit.parser.MTLog
import org.mtransit.parser.db.SQLUtils.quotesEscapeId
import org.mtransit.parser.db.SQLUtils.escapeId
import org.mtransit.parser.db.SQLUtils.quotes
import org.mtransit.parser.gtfs.GAgencyTools

object MServiceIds {

Expand Down Expand Up @@ -58,15 +60,21 @@ object MServiceIds {
}
}.sorted()

@Suppress("unused")
@JvmStatic
fun containsAllIdInts(idInts: Iterable<Int>)
= idInts.all { idIntToId.containsKey(it) }

@JvmStatic
fun convert(serviceId: String) =
fun convert(agencyTools: GAgencyTools, serviceId: String, quotesString: Boolean = false) : String =
if (FeatureFlags.F_EXPORT_SERVICE_ID_INTS) {
getInt(serviceId).toString()
getInt(agencyTools.cleanServiceId(serviceId)).toString()
} else {
serviceId.quotesEscapeId()
agencyTools.cleanServiceId(serviceId).escapeId()
.let {
if (quotesString) it.quotes() else it
}
}
}

fun String.convertServiceId(agencyTools: GAgencyTools, quotesString: Boolean = false) = MServiceIds.convert(agencyTools, this, quotesString)
4 changes: 2 additions & 2 deletions src/main/java/org/mtransit/parser/mt/data/MTrip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ data class MTrip(
if (lastTrip == null) { // NEW
add(routeId.toString())
add(directionId.toString())
add(MServiceIds.convert(agencyTools.cleanServiceId(_serviceId)))
add(_serviceId.convertServiceId(agencyTools, quotesString = true))
}
add(MTripIds.convert(_tripId))
add(_tripId.convertTripId(quotesString = true))
}.joinToString(SQLUtils.COLUMN_SEPARATOR)

fun isSameRouteDirectionService(other: MTrip?) =
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/mtransit/parser/mt/data/MTripIds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import androidx.collection.SparseArrayCompat
import androidx.collection.mutableScatterMapOf
import org.mtransit.commons.FeatureFlags
import org.mtransit.parser.MTLog
import org.mtransit.parser.db.SQLUtils.quotesEscapeId
import org.mtransit.parser.db.SQLUtils.escapeId
import org.mtransit.parser.db.SQLUtils.quotes

object MTripIds {

Expand Down Expand Up @@ -59,10 +60,15 @@ object MTripIds {
}.sorted()

@JvmStatic
fun convert(tripId: String) =
fun convert(tripId: String, quotesString: Boolean = false) =
if (FeatureFlags.F_EXPORT_TRIP_ID_INTS) {
getInt(tripId).toString()
} else {
tripId.quotesEscapeId()
tripId.escapeId()
.let {
if (quotesString) it.quotes() else it
}
}
}

fun String.convertTripId(quotesString: Boolean = false) = MTripIds.convert(this, quotesString)