-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61a0a99
commit 5e3f8ff
Showing
2 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
core/data/src/main/kotlin/xyz/ksharma/krail/data/gtfs_static/parser/CalendarParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package xyz.ksharma.krail.data.gtfs_static.parser | ||
|
||
import timber.log.Timber | ||
import xyz.ksharma.krail.model.gtfs_static.Calendar | ||
import java.io.BufferedReader | ||
import java.io.FileReader | ||
import java.io.IOException | ||
import java.nio.file.Path | ||
|
||
object CalendarParser { | ||
|
||
internal fun Path.parseCalendar(): List<Calendar> { | ||
val calendarList = mutableListOf<Calendar>() | ||
|
||
try { | ||
BufferedReader(FileReader(this.toString())).use { reader -> | ||
val headersList = reader.readLine().split(",").trimQuotes() | ||
// todo use headers instead of hard code later. | ||
//Log.d(TAG, "headersList: $headersList") | ||
|
||
while (true) { | ||
val line = reader.readLine() ?: break | ||
val fieldsList = line.split(",").trimQuotes() | ||
|
||
calendarList.add( | ||
Calendar( | ||
serviceId = fieldsList[0], | ||
monday = fieldsList[1], | ||
tuesday = fieldsList[2], | ||
wednesday = fieldsList[3], | ||
thursday = fieldsList[4], | ||
friday = fieldsList[5], | ||
saturday = fieldsList[6], | ||
sunday = fieldsList[7], | ||
startDate = fieldsList[8], | ||
endDate = fieldsList[9], | ||
) | ||
) | ||
} | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
Timber.e(e, "parseCalendar: ") | ||
} catch (e: IllegalArgumentException) { | ||
e.printStackTrace() | ||
Timber.e(e, "parseCalendar: ") | ||
} | ||
|
||
return calendarList | ||
} | ||
|
||
private fun Int.toWheelchairBoarding() = when (this) { | ||
0 -> xyz.ksharma.krail.model.gtfs_realtime.proto.Stop.WheelchairBoarding.UNKNOWN | ||
1 -> xyz.ksharma.krail.model.gtfs_realtime.proto.Stop.WheelchairBoarding.AVAILABLE | ||
2 -> xyz.ksharma.krail.model.gtfs_realtime.proto.Stop.WheelchairBoarding.NOT_AVAILABLE | ||
else -> null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters