Skip to content
Draft
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
117 changes: 25 additions & 92 deletions src/main/java/org/mtransit/parser/db/DBUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ object DBUtils {
@JvmStatic
fun insertStopTime(gStopTime: GStopTime, preparedStatement: PreparedStatement) {
try {
var idx = 1
var idx = 0
with(preparedStatement) {
setInt(idx++, gStopTime.tripIdInt)
setInt(idx++, gStopTime.stopIdInt)
setInt(idx++, gStopTime.stopSequence)
setInt(idx++, gStopTime.arrivalTime)
setInt(idx++, gStopTime.departureTime)
setString(idx++, gStopTime.stopHeadsign?.quotesEscape())
setInt(idx++, gStopTime.pickupType.id)
setInt(idx++, gStopTime.dropOffType.id)
setInt(idx++, gStopTime.timePoint.id)
setInt(++idx, gStopTime.tripIdInt)
setInt(++idx, gStopTime.stopIdInt)
setInt(++idx, gStopTime.stopSequence)
setInt(++idx, gStopTime.arrivalTime)
setInt(++idx, gStopTime.departureTime)
setString(++idx, gStopTime.stopHeadsign?.quotesEscape())
setInt(++idx, gStopTime.pickupType.id)
setInt(++idx, gStopTime.dropOffType.id)
setInt(++idx, gStopTime.timePoint.id)
addBatch()
}
insertRowCount++
Expand Down Expand Up @@ -416,6 +416,7 @@ object DBUtils {
}
}

@Suppress("AssignedValueIsNeverRead")
@JvmStatic
fun selectSchedules(
serviceIdInt: Int? = null,
Expand All @@ -434,21 +435,11 @@ object DBUtils {
// SERVICE ID
serviceIdInt?.let {
@Suppress("KotlinConstantConditions")
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.SERVICE_ID} = $serviceIdInt"
}
serviceIdInts?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.SERVICE_ID} IN ${
serviceIdInts
.distinct()
Expand All @@ -458,26 +449,15 @@ object DBUtils {
postfix = ")"
) { "$it" }
}"
whereAdded = true
}
// DIRECTION ID
directionId?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.DIRECTION_ID} = $directionId"

}
directionIds?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.DIRECTION_ID} IN ${
directionIds
.distinct()
Expand All @@ -487,26 +467,15 @@ object DBUtils {
postfix = ")"
) { "$it" }
}"
whereAdded = true
}
// STOP ID
stopIdInt?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.STOP_ID} = $stopIdInt"

}
stopIdInts?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.STOP_ID} IN ${
stopIdInts
.distinct()
Expand All @@ -516,25 +485,14 @@ object DBUtils {
postfix = ")"
) { "$it" }
}"
whereAdded = true
}
// ARRIVAL & DEPARTURE
arrival?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.ARRIVAL} = $arrival"
}
departure?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.DEPARTURE} = $departure"
}
query += " ORDER BY " +
Expand Down Expand Up @@ -574,7 +532,7 @@ object DBUtils {
}
}

@Suppress("unused")
@Suppress("unused", "AssignedValueIsNeverRead")
@JvmStatic
fun deleteSchedules(
serviceIdInt: Int? = null,
Expand All @@ -587,52 +545,27 @@ object DBUtils {
var whereAdded = false
serviceIdInt?.let {
@Suppress("KotlinConstantConditions")
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.SERVICE_ID} = $serviceIdInt"
}
directionId?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.DIRECTION_ID} = $directionId"

}
// STOP ID
stopIdInt?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.STOP_ID} = $stopIdInt"

}
// ARRIVAL & DEPARTURE
arrival?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.ARRIVAL} = $arrival"
}
departure?.let {
query += if (whereAdded) {
" AND"
} else {
" WHERE"
}
whereAdded = true
query += if (whereAdded) " AND" else " WHERE"; whereAdded = true
query += " ${MSchedule.DEPARTURE} = $departure"
}
deleteCount++
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/mtransit/parser/mt/GenerateMObjectsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.mtransit.parser.mt.data.MServiceDate;
import org.mtransit.parser.mt.data.MSpec;
import org.mtransit.parser.mt.data.MStop;
import org.mtransit.parser.mt.data.MTrip;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -92,6 +93,7 @@ private MSpec doCall() {
HashMap<Long, MRoute> mRoutes = new HashMap<>();
HashMap<Long, MDirection> mDirections = new HashMap<>();
HashMap<String, MDirectionStop> allMDirectionStops = new HashMap<>();
HashMap<Integer, MTrip> mTrips = new HashMap<>();
HashMap<Integer, MStop> mStops = new HashMap<>();
HashSet<Integer> directionStopIds = new HashSet<>(); // the list of stop IDs used by directions
HashSet<Integer> serviceIdInts = new HashSet<>();
Expand Down Expand Up @@ -136,6 +138,7 @@ private MSpec doCall() {
mAgencies,
mRoutes,
mDirections,
mTrips,
mStops,
allMDirectionStops,
directionStopIds,
Expand Down Expand Up @@ -168,6 +171,8 @@ private MSpec doCall() {
Collections.sort(mAgenciesList);
ArrayList<MStop> mStopsList = new ArrayList<>(mStops.values());
Collections.sort(mStopsList);
ArrayList<MTrip> mTripsList = new ArrayList<>(mTrips.values());
Collections.sort(mTripsList);
ArrayList<MRoute> mRoutesList = new ArrayList<>(mRoutes.values());
Collections.sort(mRoutesList);
ArrayList<MDirection> mDirectionsList = new ArrayList<>(mDirections.values());
Expand All @@ -176,7 +181,7 @@ private MSpec doCall() {
Collections.sort(mDirectionStopsList);
setDirectionStopNoPickup(mDirectionStopsList, mSchedules.values());
ArrayList<MServiceDate> mServiceDatesList = new ArrayList<>(mServiceDates);
Collections.sort(mServiceDatesList);
mServiceDatesList.sort(MServiceDate.getCOMPARATOR_BY_CALENDAR_DATE());
ArrayList<MFrequency> mFrequenciesList = new ArrayList<>(mFrequencies.values());
Collections.sort(mFrequenciesList);
TreeMap<Long, List<MFrequency>> mRouteFrequencies = new TreeMap<>();
Expand Down Expand Up @@ -257,12 +262,13 @@ private MSpec doCall() {
throw new MTLog.Fatal(e, "Error while parsing dates '%s %s'!", lastCalendarDate, lastDeparture);
}
}
MSpec mRouteSpec = new MSpec(
final MSpec mRouteSpec = new MSpec(
mAgenciesList,
mStopsList,
mRoutesList,
mDirectionsList,
mDirectionStopsList,
mTripsList,
mServiceDatesList,
mRouteFrequencies,
firstTimestamp,
Expand All @@ -279,6 +285,7 @@ private void parseRDS(HashMap<String, MSchedule> mSchedules,
HashMap<Integer, MAgency> mAgencies,
HashMap<Long, MRoute> mRoutes,
HashMap<Long, MDirection> mDirections,
HashMap<Integer, MTrip> mTrips,
HashMap<Integer, MStop> mStops,
HashMap<String, MDirectionStop> allMDirectionStops,
HashSet<Integer> directionStopIds,
Expand Down Expand Up @@ -341,6 +348,7 @@ private void parseRDS(HashMap<String, MSchedule> mSchedules,
mSchedules,
mFrequencies,
mDirections,
mTrips,
mStops,
serviceIdInts,
mRoute,
Expand Down Expand Up @@ -450,6 +458,7 @@ private void fixRouteLongName(HashMap<Long, MRoute> mRoutes, HashMap<Long, MDire
private void parseGTrips(HashMap<String, MSchedule> mSchedules,
HashMap<String, MFrequency> mFrequencies,
HashMap<Long, MDirection> mDirections,
HashMap<Integer, MTrip> mTrips,
HashMap<Integer, MStop> mStops,
HashSet<Integer> serviceIdInts,
MRoute mRoute,
Expand Down Expand Up @@ -603,6 +612,7 @@ private void parseGTrips(HashMap<String, MSchedule> mSchedules,
continue;
}
mDirections.put(mDirection.getId(), mDirection);
mTrips.put(gTrip.getTripIdInt(), MTrip.from(routeId, mDirection.getId(), gTrip));
}
if (g++ % 10 == 0) { // LOG
MTLog.logPOINT(); // LOG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ object MDataChangedManager {
}
@Suppress("LocalVariableName")
val DATE_FORMAT = GFieldTypes.makeDateFormat()
removedCalendarsServiceDates.sortedDescending().forEach { removedServiceDate ->
removedCalendarsServiceDates.sortedWith(MServiceDate.COMPARATOR_BY_CALENDAR_DATE).reversed().forEach { removedServiceDate ->
if (ALL_CALENDARS_IN_CALENDAR_DATES) {
return
}
Expand Down
Loading