Skip to content

Segment Trip Metrics#122

Draft
devinmatte wants to merge 2 commits intomainfrom
segment-trip-metrics
Draft

Segment Trip Metrics#122
devinmatte wants to merge 2 commits intomainfrom
segment-trip-metrics

Conversation

@devinmatte
Copy link
Copy Markdown
Member

In order to build up transitmatters/t-performance-dash#1045, we need a median travel time for each station pair for the map

This stores the median travel time per day per time in DynamoDB

@devinmatte devinmatte requested review from a team, austinjpaul and idreyn as code owners March 4, 2025 02:00
FullStopPair = namedtuple("FullStopPair", ["fr", "to", "fr_order", "to_order", "direction"])


# TODO: We're using SlowZones data for now, we may want our own dataset or to rename the SlowZones dataset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
# TODO: We're using SlowZones data for now, we may want our own dataset or to rename the SlowZones dataset
# TODO(<owner>): We're using SlowZones data for now, we may want our own dataset or to rename the SlowZones dataset
comments must have ownership (...read more)

When using TODO or FIXME, specify who write the annotation. It's a best practice to remind you who created the annotation and have potential context and information about this issue.

View in Datadog  Leave us feedback  Documentation

tts.set_index("date", inplace=True)

tts = (tts["50%"]).dropna()
tts = tts.rename("travel_time")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

variable name is the same as a function parameter (...read more)

A function parameter should only be read and not be modified. If your intent is to modify the value of the parameter, return the value in the function and handle the new value in the caller of the function.

View in Datadog  Leave us feedback  Documentation


tts = (tts["50%"]).dropna()
tts = tts.rename("travel_time")
tts = tts.to_frame()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

variable name is the same as a function parameter (...read more)

A function parameter should only be read and not be modified. If your intent is to modify the value of the parameter, return the value in the function and handle the new value in the caller of the function.

View in Datadog  Leave us feedback  Documentation

return tts

tts.columns = tts.columns.str.strip()
tts = tts.rename(columns={"service_date": "date"})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

variable name is the same as a function parameter (...read more)

A function parameter should only be read and not be modified. If your intent is to modify the value of the parameter, return the value in the function and handle the new value in the caller of the function.

View in Datadog  Leave us feedback  Documentation

tts["date"] = pd.to_datetime(tts["date"]).dt.date
tts.set_index("date", inplace=True)

tts = (tts["50%"]).dropna()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

variable name is the same as a function parameter (...read more)

A function parameter should only be read and not be modified. If your intent is to modify the value of the parameter, return the value in the function and handle the new value in the caller of the function.

View in Datadog  Leave us feedback  Documentation



def download(key: str | pathlib.Path):
key = str(key) # in case it's a pathlib.Path
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

variable name is the same as a function parameter (...read more)

A function parameter should only be read and not be modified. If your intent is to modify the value of the parameter, return the value in the function and handle the new value in the caller of the function.

View in Datadog  Leave us feedback  Documentation

url = f"https://dashboard-api.labs.transitmatters.org/api/aggregate/traveltimes?from_stop={fr}&to_stop={to}&start_date={ago}&end_date={today}"
if verbose:
print(url)
resp = requests.get(url)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Vulnerability

Suggested change
resp = requests.get(url)
resp = requests.get(url, timeout=5)
timeout not defined (...read more)

Access to remote resources should always use a timeout and appropriately handle the timeout and recovery. When using requests.get, requests.put, requests.patch, etc. - we should always use a timeout as an argument.

Learn More

View in Datadog  Leave us feedback  Documentation

@devinmatte devinmatte marked this pull request as draft October 9, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant