Skip to content

Commit

Permalink
Adding commuter rail ridership to the landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte committed Jul 24, 2024
1 parent f71e8f8 commit f454de7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ingestor/chalicelib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ def get_route_metadata(line: str, date: date, include_terminals: bool, route: st
"line-blue": "line-Blue",
"line-green": "line-Green",
}
COMMUTER_RAIL_LINES = [
"CR-Fairmount",
"CR-Fitchburg",
"CR-Worcester",
"CR-Franklin",
"CR-Greenbush",
"CR-Haverhill",
"CR-Kingston",
"CR-Lowell",
"CR-Middleborough",
"CR-Needham",
"CR-Newburyport",
"CR-Providence",
]

DATE_FORMAT = "%Y-%m-%dT%H:%M:%S"
DATE_FORMAT_BACKEND = "%Y-%m-%d"
GLX_EXTENSION_DATE = datetime.strptime("2023-03-19", DATE_FORMAT_BACKEND).date()
Expand All @@ -261,6 +276,10 @@ def get_route_metadata(line: str, date: date, include_terminals: bool, route: st
DD_URL_SINGLE_TT = "https://dashboard-api.labs.transitmatters.org/api/traveltimes/{date}?{parameters}"


def commuter_rail_ridership_key(line: str):
return f"line-{line[3:]}"


def get_monthly_table_update_start():
"""Get 1st of current month"""
yesterday = datetime.today() - timedelta(days=1)
Expand Down
17 changes: 17 additions & 0 deletions ingestor/chalicelib/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ def get_ridership_data():
for line in constants.LINES:
data = query_landing_ridership_data(constants.RIDERSHIP_KEYS[line])
ridership_object[line] = data

ridership_object["line-commuter-rail"] = [None] * 10
for line in constants.COMMUTER_RAIL_LINES:
data = query_landing_ridership_data(constants.commuter_rail_ridership_key(line))
for index, week in enumerate(data):
if ridership_object["line-commuter-rail"][index] is None:
ridership_object["line-commuter-rail"][index] = week
continue
else:
data = {
"lineId": "line-commuter-rail",
"count": ridership_object["line-commuter-rail"][index]["count"] + week["count"],
"timestamp": week["timestamp"],
"date": week["date"],
}
ridership_object["line-commuter-rail"][index] = data

return ridership_object


Expand Down

0 comments on commit f454de7

Please sign in to comment.