pebble-caltrain
pebble-caltrain copied to clipboard
Holidays aren't handled correctly
The current methods for looking up trains do not prefer trains whose calendar starts today, resulting in holidays getting incorrect trains. The new schedule has a holiday on Washington's Birthday, February 16, 2015. If you set your date to this, the trains you get are the regular weekday trains, since the trains for the holiday are at the end of the trips list.
I think the best way to fix this would be to do a search through the calendars (since that list is much much shorter than the trips list), looking for the calendar whose start date is closest to the current date. Then use that calendar when searching for trains (maybe have a trips file indexed by calendar, and then use that subset of trips in place of the full trips list? could probably then dump the full list, so your resource usage won't increase noticeably. Side benefit of reducing runtime memory usage, since you no longer need the full trips list in memory)
Also going to have to start parsing calendar_dates.txt, because that's the one that has exceptions for the regular holidays, such as Thanksgiving, Christmas, and New Year's.
It may be necessary to do calendar-based loading anyway, because the app is running low on memory, and crashing in at least one instance as a result (which is what I was debugging when I found this issue). If you launch the app, then wait for it to load the closest station, back out and go to San Jose Diridon, then select a direction, the second malloc() in get_future_trains fails and returns NULL, resulting in a crash. Interestingly, this only happens if you let the autoload happen, as opening the app immediately after the crash, which pulls up Diridon immediately due to the persistence, and selecting a direction does not crash. From my debug statements, it's trying to load 509 trips, and does two malloc()s for this * sizeof(TrainTime), resulting in trying to allocate just short of 6 KB of RAM for all the trips. Granted, dropping the schedule that just got obsoleted would cut this in half and temporarily solve the problem, but it'll just crop back up at the next schedule change, when the new schedule is preseeded.
I'll see if I can't throw something together to implement this after work today, unless you want to work on it.