Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin to newer version of poetry, and cleanup package pinning #804

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository for the TransitMatters Data Dashboard. Client code is wri
- node 18.x and npm 9.x required
- With `nvm` installed, use `nvm install && nvm use`
- verify with `node -v`
- Python 3.10 with recent poetry
- Python 3.10 with recent poetry (1.5.0 or later)
- Verify with `python --version && poetry --version`
- `poetry self update` to update poetry

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"generate-oss-list": "generate-attribution --outputDir common/constants/licenses",
"lint": "npm run lint-frontend && npm run lint-backend",
"lint-frontend": "tsc --noEmit && eslint . && next lint",
"lint-backend": "cd server && poetry run flake8",
"lint-backend": "cd server && poetry run flake8 && poetry run black . --check",
"test": "react-scripts test",
"eject": "react-scripts eject",
"postinstall": "cd server && poetry install",
Expand Down
14 changes: 3 additions & 11 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def healthcheck():
"API Key Present": (lambda: len(secrets.MBTA_V2_API_KEY) > 0),
"S3 Headway Fetching": (
lambda: "2020-11-07 10:33:40"
in json.dumps(
data_funcs.headways(date(year=2020, month=11, day=7), ["70061"])
)
in json.dumps(data_funcs.headways(date(year=2020, month=11, day=7), ["70061"]))
),
"Performance API Check": (
lambda: MbtaPerformanceAPI.get_api_data(
Expand Down Expand Up @@ -112,9 +110,7 @@ def traveltime_route(user_date):
@app.route("/api/alerts/{user_date}", cors=cors_config)
def alerts_route(user_date):
date = parse_user_date(user_date)
return json.dumps(
data_funcs.alerts(date, mutlidict_to_dict(app.current_request.query_params))
)
return json.dumps(data_funcs.alerts(date, mutlidict_to_dict(app.current_request.query_params)))


@app.route("/api/aggregate/traveltimes", cors=cors_config)
Expand Down Expand Up @@ -163,11 +159,7 @@ def dwells_aggregate_route():
def get_git_id():
# Only do this on localhost
if TM_FRONTEND_HOST == "localhost":
git_id = str(
subprocess.check_output(
["git", "describe", "--always", "--dirty", "--abbrev=10"]
)
)[2:-3]
git_id = str(subprocess.check_output(["git", "describe", "--always", "--dirty", "--abbrev=10"]))[2:-3]
return json.dumps({"git_id": git_id})
else:
raise ConflictError("Cannot get git id from serverless host")
Expand Down
2 changes: 1 addition & 1 deletion server/chalicelib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"line-red": ["line-red-a", "line-red-b"],
"line-green": ["line-green-b", "line-green-c", "line-green-d", "line-green-e"],
"line-blue": ["line-blue"],
"line-orange": ["line-orange"]
"line-orange": ["line-orange"],
}
5 changes: 4 additions & 1 deletion server/chalicelib/dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def query_daily_trips_on_route(table_name, route, start_date, end_date):
def query_daily_trips_on_line(table_name, line, start_date, end_date):
route_keys = constants.LINE_TO_ROUTE_MAP[line]
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
futures = [executor.submit(query_daily_trips_on_route, table_name, route_key, start_date, end_date) for route_key in route_keys]
futures = [
executor.submit(query_daily_trips_on_route, table_name, route_key, start_date, end_date)
for route_key in route_keys
]
results = []
for future in concurrent.futures.as_completed(futures):
result = future.result()
Expand Down
5 changes: 1 addition & 4 deletions server/chalicelib/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
MBTA_V2_API_KEY = os.environ.get("MBTA_V2_API_KEY", "")
MBTA_V3_API_KEY = os.environ.get("MBTA_V3_API_KEY", "")

HEALTHCHECK_HIDE_SECRETS = [
MBTA_V2_API_KEY,
MBTA_V3_API_KEY
]
HEALTHCHECK_HIDE_SECRETS = [MBTA_V2_API_KEY, MBTA_V3_API_KEY]
18 changes: 9 additions & 9 deletions server/chalicelib/service_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ def get_service_levels(


def get_weekly_scheduled_service(scheduled_service_arr, start_date, end_date):
df = pd.DataFrame({'value': scheduled_service_arr}, index=pd.date_range(start_date, end_date))
weekly_df = df.resample('W-SUN').median()
df = pd.DataFrame({"value": scheduled_service_arr}, index=pd.date_range(start_date, end_date))
weekly_df = df.resample("W-SUN").median()
# Drop the first week if it is incomplete
if datetime.fromisoformat(start_date.isoformat()).weekday() != 6:
weekly_df = weekly_df[1:]
return weekly_df['value'].tolist()
return weekly_df["value"].tolist()


def get_monthly_scheduled_service(scheduled_service_arr, start_date, end_date):
df = pd.DataFrame({'value': scheduled_service_arr}, index=pd.date_range(start_date, end_date))
monthly_df = df.resample('M').median()
df = pd.DataFrame({"value": scheduled_service_arr}, index=pd.date_range(start_date, end_date))
monthly_df = df.resample("M").median()
# Drop the first month if it is incomplete
if datetime.fromisoformat(start_date.isoformat()).day != 1:
monthly_df = monthly_df[1:]
return monthly_df['value'].tolist()
return monthly_df["value"].tolist()


def get_scheduled_service(
Expand All @@ -105,11 +105,11 @@ def get_scheduled_service(
scheduled_service_count = None
scheduled_service_arr.append(scheduled_service_count)
counts = []
if agg == 'daily':
if agg == "daily":
counts = scheduled_service_arr
if agg == 'weekly':
if agg == "weekly":
counts = get_weekly_scheduled_service(scheduled_service_arr, start_date, end_date)
if agg == 'monthly':
if agg == "monthly":
counts = get_monthly_scheduled_service(scheduled_service_arr, start_date, end_date)

return {
Expand Down
17 changes: 12 additions & 5 deletions server/chalicelib/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ def aggregate_actual_trips(actual_trips, agg, start_date):
# Create a DataFrame from the flattened data
df = pd.DataFrame(flat_data)
# Set miles_covered to NaN for each date with any entry having miles_covered as nan
df.loc[df.groupby('date')['miles_covered'].transform(lambda x: (np.isnan(x)).any()), ['count', 'total_time', 'miles_covered']] = np.nan
df.loc[
df.groupby("date")["miles_covered"].transform(lambda x: (np.isnan(x)).any()),
["count", "total_time", "miles_covered"],
] = np.nan
# Group each branch into one entry. Keep NaN entries as NaN
df_grouped = df.groupby('date').agg({'miles_covered': 'sum', 'total_time': 'sum', 'count': 'sum', 'line': 'first'}).reset_index()
df_grouped = (
df.groupby("date")
.agg({"miles_covered": "sum", "total_time": "sum", "count": "sum", "line": "first"})
.reset_index()
)
# set index to use datetime object.
df_grouped.set_index(pd.to_datetime(df_grouped['date']), inplace=True)
return df_grouped.to_dict(orient='records')
df_grouped.set_index(pd.to_datetime(df_grouped["date"]), inplace=True)
return df_grouped.to_dict(orient="records")


def trip_metrics_by_line(params):
Expand Down Expand Up @@ -53,7 +60,7 @@ def trip_metrics_by_line(params):


def is_invalid_range(start_date, end_date, max_delta):
'''Check if number of requested entries is more than maximum for the table'''
"""Check if number of requested entries is more than maximum for the table"""
start_datetime = datetime.strptime(start_date, DATE_FORMAT_BACKEND)
end_datetime = datetime.strptime(end_date, DATE_FORMAT_BACKEND)
return start_datetime + timedelta(days=max_delta) < end_datetime
Loading
Loading