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
|
|
@ -1,14 +1,43 @@
|
|||
package moe.lava.banksia.core.model
|
||||
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StopTime(
|
||||
val tripId: String,
|
||||
data class StopTime<T: TimeType>(
|
||||
val patternId: Long,
|
||||
val stopId: String,
|
||||
val arrivalTime: FutureTime,
|
||||
val departureTime: FutureTime,
|
||||
val headsign: String?,
|
||||
val time: T,
|
||||
val pickupType: Int,
|
||||
val dropOffType: Int,
|
||||
) {
|
||||
typealias Dated = StopTime<TimeType.Dated>
|
||||
typealias Undated = StopTime<TimeType.Undated>
|
||||
}
|
||||
|
||||
@Serializable
|
||||
sealed class TimeType {
|
||||
@Serializable
|
||||
data class Undated(
|
||||
val arrival: FutureTime,
|
||||
val departure: FutureTime,
|
||||
) : TimeType()
|
||||
|
||||
@Serializable
|
||||
data class Dated(
|
||||
val arrival: LocalDateTime,
|
||||
val departure: LocalDateTime,
|
||||
) : TimeType()
|
||||
}
|
||||
|
||||
fun StopTime<TimeType.Undated>.atDate(date: LocalDate) = StopTime(
|
||||
patternId = patternId,
|
||||
stopId = stopId,
|
||||
time = TimeType.Dated(
|
||||
arrival = time.arrival.atDate(date),
|
||||
departure = time.departure.atDate(date),
|
||||
),
|
||||
pickupType = pickupType,
|
||||
dropOffType = dropOffType,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
package moe.lava.banksia.core.model
|
||||
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StopTimeDated(
|
||||
val tripId: String,
|
||||
val stopId: String,
|
||||
val arrivalTime: LocalDateTime,
|
||||
val departureTime: LocalDateTime,
|
||||
val headsign: String?,
|
||||
val pickupType: Int,
|
||||
val dropOffType: Int,
|
||||
)
|
||||
|
||||
fun StopTime.atDate(date: LocalDate) = StopTimeDated(
|
||||
tripId = tripId,
|
||||
stopId = stopId,
|
||||
arrivalTime = arrivalTime.atDate(date),
|
||||
departureTime = departureTime.atDate(date),
|
||||
headsign = headsign,
|
||||
pickupType = pickupType,
|
||||
dropOffType = dropOffType,
|
||||
)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package moe.lava.banksia.core.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StoppingPattern<T: TimeType>(
|
||||
val id: Long,
|
||||
val routeId: String,
|
||||
val shapeId: String,
|
||||
val headsign: String,
|
||||
val wheelchairAccessible: Boolean,
|
||||
val stoptimes: List<StopTime<T>>,
|
||||
) {
|
||||
typealias Dated = StoppingPattern<TimeType.Dated>
|
||||
typealias Undated = StoppingPattern<TimeType.Undated>
|
||||
}
|
||||
|
|
@ -3,13 +3,13 @@ package moe.lava.banksia.core.model
|
|||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Trip(
|
||||
data class Trip<T: TimeType>(
|
||||
val id: String,
|
||||
val routeId: String,
|
||||
val pattern: StoppingPattern<T>,
|
||||
val service: Service,
|
||||
val shapeId: String,
|
||||
val tripHeadsign: String,
|
||||
val directionId: String,
|
||||
val directionId: Int,
|
||||
val blockId: String?,
|
||||
val wheelchairAccessible: Boolean,
|
||||
)
|
||||
) {
|
||||
typealias Dated = Trip<TimeType.Dated>
|
||||
typealias Undated = Trip<TimeType.Undated>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue