refactor: optimisation around stoptimes
- moved stoptime related functionality into new core:data:stoptime module
- will feature all the different realtime stoptime sources to be
integrated later
- create proper database schema for future migrations
- deduplicate trips into stoppingpatterns, since many trips share the
exact same stopping pattern
- stoptimes are now linked to stoppingpatterns instead
- stoppingpattern ids are generated from a hash composed of all stoptimes
- stoptimes now use deltas for arrival time to save space
This commit is contained in:
parent
f1770744db
commit
102c028407
39 changed files with 396 additions and 223 deletions
|
|
@ -151,7 +151,7 @@ fun Application.module() {
|
|||
)
|
||||
.executeAsList()
|
||||
.map { it.asModel().atDate(date) }
|
||||
.sortedBy { it.departureTime }
|
||||
.sortedBy { it.time.departure }
|
||||
}
|
||||
call.respond(times)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import moe.lava.banksia.core.model.Service
|
|||
import moe.lava.banksia.core.model.ServiceException
|
||||
import moe.lava.banksia.core.model.Shape
|
||||
import moe.lava.banksia.core.model.Stop
|
||||
import moe.lava.banksia.core.model.StopTime
|
||||
import moe.lava.banksia.core.model.Trip
|
||||
import moe.lava.banksia.core.sqld.DatabaseManager
|
||||
import moe.lava.banksia.core.sqld.mappers.asDb
|
||||
|
|
@ -30,7 +29,6 @@ class GtfsImporter(
|
|||
is GtfsData.ServiceExceptionChunk -> database.addServiceExceptions(chunk.exceptions)
|
||||
is GtfsData.ShapeChunk -> database.addShapes(chunk.shapes)
|
||||
is GtfsData.StopChunk -> database.addStops(chunk.stops)
|
||||
is GtfsData.StopTimeChunk -> database.addStopTimes(chunk.stopTimes)
|
||||
is GtfsData.TripChunk -> database.addTrips(chunk.trips)
|
||||
}
|
||||
}
|
||||
|
|
@ -101,21 +99,15 @@ class GtfsImporter(
|
|||
log.info("done")
|
||||
}
|
||||
|
||||
private fun Database.addStopTimes(stopTimes: List<StopTime>) {
|
||||
log.info("inserting ${stopTimes.size} stoptimes...")
|
||||
stopTimeQueries.transaction {
|
||||
stopTimes.forEach {
|
||||
stopTimeQueries.insert(it.asDb())
|
||||
}
|
||||
}
|
||||
log.info("done")
|
||||
}
|
||||
|
||||
private fun Database.addTrips(trips: List<Trip>) {
|
||||
private fun Database.addTrips(trips: List<Trip.Undated>) {
|
||||
log.info("inserting ${trips.size} trips...")
|
||||
tripQueries.transaction {
|
||||
trips.forEach {
|
||||
tripQueries.insert(it.asDb())
|
||||
transaction {
|
||||
trips.forEach { trip ->
|
||||
stoppingPatternQueries.insert(trip.pattern.asDb())
|
||||
trip.pattern.stoptimes.forEach { stoptime ->
|
||||
stopTimeQueries.insert(stoptime.asDb())
|
||||
}
|
||||
tripQueries.insert(trip.asDb())
|
||||
}
|
||||
}
|
||||
log.info("done")
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="trace">
|
||||
<root level="debug">
|
||||
<appender-ref ref="FILE"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue