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
23 changes: 6 additions & 17 deletions src/main/java/org/mtransit/parser/mt/GenerateMObjectsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mtransit.commons.CollectionUtils;
import org.mtransit.commons.FeatureFlags;
import org.mtransit.commons.StringUtils;
import org.mtransit.parser.Constants;
import org.mtransit.parser.MTLog;
Expand Down Expand Up @@ -144,28 +143,23 @@ private MSpec doCall() {
serviceIdInts,
routeGTFS
);
final HashSet<Long> gCalendarDateServiceRemoved = new HashSet<>();
for (GCalendarDate gCalendarDate : routeGTFS.getAllCalendarDates()) {
if (!serviceIdInts.contains(gCalendarDate.getServiceIdInt())) {
continue;
}
switch (gCalendarDate.getExceptionType()) {
case SERVICE_REMOVED: // keep list of removed service for calendars processing
if (FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE) {
mServiceDates.add(new MServiceDate(
gCalendarDate.getServiceIdInt(),
gCalendarDate.getDate(),
MCalendarExceptionType.REMOVED
));
} else {
gCalendarDateServiceRemoved.add(gCalendarDate.getUID());
}
mServiceDates.add(new MServiceDate(
gCalendarDate.getServiceIdInt(),
gCalendarDate.getDate(),
MCalendarExceptionType.REMOVED
));
break;
case SERVICE_ADDED:
mServiceDates.add(new MServiceDate(
gCalendarDate.getServiceIdInt(),
gCalendarDate.getDate(),
FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE ? MCalendarExceptionType.ADDED : MCalendarExceptionType.DEFAULT
MCalendarExceptionType.ADDED
));
break;
case SERVICE_DEFAULT:
Expand All @@ -186,11 +180,6 @@ private MSpec doCall() {
continue;
}
for (GCalendarDate gCalendarDate : gCalendar.getDates()) {
if (!FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE) {
if (gCalendarDateServiceRemoved.contains(gCalendarDate.getUID())) {
continue; // service REMOVED at this date
}
}
mServiceDates.add(new MServiceDate(
gCalendarDate.getServiceIdInt(),
gCalendarDate.getDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ object MDataChangedManager {
//noinspection DiscouragedApi
val originalServiceIdInt = newGCalendarDates.firstOrNull { it.serviceId.escape() == removedServiceDate.serviceId }?.serviceIdInt
val missingCalendarDate = removedServiceDate.toCalendarDate(overrideServiceIdInt = originalServiceIdInt)
MTLog.log("> Optimising data changed by adding ${missingCalendarDate?.toStringPlus()}...")
MTLog.log("> Optimising data changed by adding ${missingCalendarDate.toStringPlus()}...")
newGCalendarDates.add(missingCalendarDate)
dataChanged = true
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/mtransit/parser/mt/data/MRoute.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mtransit.parser.mt.data

import org.mtransit.commons.FeatureFlags
import org.mtransit.commons.GTFSCommons
import org.mtransit.parser.Constants
import org.mtransit.parser.db.SQLUtils.quotes
Expand All @@ -14,7 +13,7 @@ data class MRoute(
var longName: String,
private val color: String?,
private val originalIdHash: Int,
private val type: Int?,
private val type: Int,
) : Comparable<MRoute> {

constructor(
Expand All @@ -23,7 +22,7 @@ data class MRoute(
longName: String,
color: String?,
originalId: String,
type: Int?,
type: Int,
agencyTools: GAgencyTools? = null,
) : this(
id,
Expand All @@ -42,9 +41,7 @@ data class MRoute(
add(longName.quotesEscape()) // long name
add((color?.uppercase() ?: Constants.EMPTY).quotes()) // color
add(originalIdHash.toString()) // original ID hash
if (FeatureFlags.F_EXPORT_ORIGINAL_ROUTE_TYPE) {
type?.let { add(it.toString()) } // route type
}
add(type.toString())
}.joinToString(Constants.COLUMN_SEPARATOR_)

override fun compareTo(other: MRoute): Int {
Expand Down
37 changes: 10 additions & 27 deletions src/main/java/org/mtransit/parser/mt/data/MServiceDate.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mtransit.parser.mt.data

import androidx.annotation.Discouraged
import org.mtransit.commons.FeatureFlags
import org.mtransit.parser.Constants
import org.mtransit.parser.db.SQLUtils.quotesEscape
import org.mtransit.parser.db.SQLUtils.unquotes
Expand Down Expand Up @@ -44,9 +43,7 @@ data class MServiceDate(
fun toFile(agencyTools: GAgencyTools) = buildList {
add(agencyTools.cleanServiceId(_serviceId).quotesEscape()) // service ID
add(calendarDate.toString()) // calendar date
if (FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE) {
add(exceptionType.toString()) // exception type
}
add(exceptionType.toString())
}.joinToString(Constants.COLUMN_SEPARATOR_)

@Suppress("unused")
Expand All @@ -56,27 +53,17 @@ data class MServiceDate(
"+(exception:$exceptionType)"
}

fun toCalendarDate(overrideServiceIdInt: Int? = null): GCalendarDate? {
if (!FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE
&& this.exceptionType == MCalendarExceptionType.REMOVED.id
) {
return null // removed
}
return GCalendarDate(
fun toCalendarDate(overrideServiceIdInt: Int? = null) =
GCalendarDate(
serviceIdInt = overrideServiceIdInt ?: this.serviceIdInt,
date = calendarDate,
exceptionType = if (FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE) {
when (this.exceptionType) {
MCalendarExceptionType.ADDED.id -> GCalendarDatesExceptionType.SERVICE_ADDED
MCalendarExceptionType.REMOVED.id -> GCalendarDatesExceptionType.SERVICE_REMOVED
MCalendarExceptionType.DEFAULT.id -> GCalendarDatesExceptionType.SERVICE_DEFAULT
else -> GCalendarDatesExceptionType.SERVICE_ADDED // default
}
} else {
GCalendarDatesExceptionType.SERVICE_ADDED // default
exceptionType = when (this.exceptionType) {
MCalendarExceptionType.ADDED.id -> GCalendarDatesExceptionType.SERVICE_ADDED
MCalendarExceptionType.REMOVED.id -> GCalendarDatesExceptionType.SERVICE_REMOVED
MCalendarExceptionType.DEFAULT.id -> GCalendarDatesExceptionType.SERVICE_DEFAULT
else -> GCalendarDatesExceptionType.SERVICE_ADDED // default
}
Comment thread
mmathieum marked this conversation as resolved.
)
}

companion object {
@Suppress("unused")
Expand All @@ -86,16 +73,12 @@ data class MServiceDate(
}

fun fromFileLine(line: String) = line.split(Constants.COLUMN_SEPARATOR)
.takeIf { it.size == if (FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE) 3 else 2 }
.takeIf { it.size == 3 }
?.let { columns ->
MServiceDate(
serviceIdInt = GIDs.getInt(columns[0].unquotes()), // service ID
calendarDate = columns[1].toInt(), // calendar date
exceptionType = if (FeatureFlags.F_EXPORT_SERVICE_EXCEPTION_TYPE) {
columns[2].toInt() // exception type
} else {
MCalendarExceptionType.DEFAULT.id
}
exceptionType = columns[2].toInt()
)
}

Expand Down
Loading