paddington-eurostar/tfl_fare.py
Edward Betts 35097fda4f Add Circle line fare to Transfer column and Total
Add tfl_fare.py with circle_line_fare() which returns £3.10 (peak) or
£3.00 (off-peak) based on TfL Zone 1 pricing. Peak applies Monday–Friday
(excluding England public holidays) 06:30–09:30 and 16:00–19:00.

Annotate each circle service with its fare in trip_planner.py, display
it alongside the Circle line times in the Transfer column, and include
it in the journey Total.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 16:47:34 +01:00

30 lines
957 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""TfL single fare calculations for journeys within Zone 1."""
from datetime import datetime, time
import holidays
CIRCLE_LINE_PEAK = 3.10
CIRCLE_LINE_OFF_PEAK = 3.00
_ENGLAND_HOLIDAYS = holidays.country_holidays("GB", subdiv="ENG")
_AM_PEAK_START = time(6, 30)
_AM_PEAK_END = time(9, 30)
_PM_PEAK_START = time(16, 0)
_PM_PEAK_END = time(19, 0)
def circle_line_fare(depart_dt: datetime) -> float:
"""Return the TfL Circle line single fare for a given departure datetime.
Peak (£3.10): MondayFriday (excluding public holidays),
06:3009:30 and 16:0019:00.
Off-peak (£3.00): all other times, weekends, and public holidays.
"""
if depart_dt.date() in _ENGLAND_HOLIDAYS or depart_dt.weekday() >= 5:
return CIRCLE_LINE_OFF_PEAK
t = depart_dt.time()
if _AM_PEAK_START <= t < _AM_PEAK_END or _PM_PEAK_START <= t < _PM_PEAK_END:
return CIRCLE_LINE_PEAK
return CIRCLE_LINE_OFF_PEAK