Skip to content

Update TITLE-I endpoints to use data from 2014 to 2023. #326

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update API endpoints to make start and end years configurable. [#321](https://github.com/policy-design-lab/pdl-api/issues/321)
- Update ARC PLC data. [#324](https://github.com/policy-design-lab/pdl-api/issues/324)
- Update ARC PLC base acres rules. [#327](https://github.com/policy-design-lab/pdl-api/issues/327)
- Update Title I endpoints to include data from 2014 to 2023. [#192](https://github.com/policy-design-lab/pdl-api/issues/192)

## [0.22.0] - 2025-02-26

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.9-slim

ENV POETRY_VIRTUALENVS_CREATE false
ENV POETRY_VIRTUALENVS_CREATE=false

RUN apt update \
&& apt upgrade -y \
Expand Down Expand Up @@ -29,7 +29,7 @@ ENV DB_HOST=localhost \
ALL_PROGRAMS_START_YEAR=2018 \
ALL_PROGRAMS_END_YEAR=2022 \
TITLE_I_START_YEAR=2014 \
TITLE_I_END_YEAR=2021 \
TITLE_I_END_YEAR=2023 \
TITLE_II_START_YEAR=2014 \
TITLE_II_END_YEAR=2023 \
CROP_INSURANCE_START_YEAR=2014 \
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class to list all configuration settings required for preprocessing and formatti
ALL_PROGRAMS_END_YEAR = int(os.getenv('ALL_PROGRAMS_END_YEAR', '2022')) # Landing Page endpoint

TITLE_I_START_YEAR = int(os.getenv('TITLE_I_START_YEAR', '2014'))
TITLE_I_END_YEAR = int(os.getenv('TITLE_I_END_YEAR', '2021'))
TITLE_I_END_YEAR = int(os.getenv('TITLE_I_END_YEAR', '2023'))

TITLE_II_START_YEAR = int(os.getenv('TITLE_II_START_YEAR', '2014'))
TITLE_II_END_YEAR = int(os.getenv('TITLE_II_END_YEAR', '2023'))
Expand Down
40 changes: 30 additions & 10 deletions app/controllers/pdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,21 @@ def titles_title_i_summary_search():
min_year, max_year = cfg.TITLE_I_START_YEAR, cfg.TITLE_I_END_YEAR
start_year = request.args.get('start_year', type=int, default=min_year)
end_year = request.args.get('end_year', type=int, default=max_year)
title_id = 100

title_id = get_title_id(TITLE_I_NAME)
if title_id is None:
msg = {
"reason": "No record for the given title name " + TITLE_I_NAME,
"error": "Not found: " + request.url,
}
logging.error("Title I: " + json.dumps(msg))
return rs_handlers.not_found(msg)

if start_year and end_year and start_year > end_year:
start_year, end_year = min_year, max_year # Return all data if invalid range

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand All @@ -234,13 +242,21 @@ def titles_title_i_state_distribution_search():
min_year, max_year = cfg.TITLE_I_START_YEAR, cfg.TITLE_I_END_YEAR
start_year = request.args.get('start_year', type=int, default=min_year)
end_year = request.args.get('end_year', type=int, default=max_year)
title_id = 100

title_id = get_title_id(TITLE_I_NAME)
if title_id is None:
msg = {
"reason": "No record for the given title name " + TITLE_I_NAME,
"error": "Not found: " + request.url,
}
logging.error("Title I: " + json.dumps(msg))
return rs_handlers.not_found(msg)

if start_year and end_year and start_year > end_year:
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -283,7 +299,7 @@ def titles_title_i_subtitles_subtitle_a_state_distribution_search():
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -311,7 +327,7 @@ def titles_title_i_subtitles_subtitle_a_summary_search():
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -339,7 +355,7 @@ def titles_title_i_subtitles_subtitle_d_state_distribution_search():
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -367,7 +383,7 @@ def titles_title_i_subtitles_subtitle_d_summary_search():
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -395,7 +411,7 @@ def titles_title_i_subtitles_subtitle_e_state_distribution_search():
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -423,7 +439,7 @@ def titles_title_i_subtitles_subtitle_e_summary_search():
start_year, end_year = min_year, max_year # Reset to full range if invalid

if start_year is None:
start_year = min_year # Default to earliest available year
start_year = min_year # Default to the earliest available year

if end_year is None:
end_year = max_year # Default to latest available year
Expand Down Expand Up @@ -1764,6 +1780,8 @@ def generate_title_i_total_summary_response(title_id, start_year, end_year):
'totalPaymentInDollars': round(info['totalPaymentInDollars'], 2),
'totalCounts': info['totalCounts'],
'averageRecipientCount': round(average_recipient_count, 2),
'startYear': start_year,
'endYear': end_year,
'subtitles': subtitle_list
}
final_summary.append(title_entry)
Expand Down Expand Up @@ -2080,6 +2098,8 @@ def generate_title_i_summary_response(subtitle_id, start_year, end_year):
subtitle_response_dict = dict()
for row in subtitle_result:
subtitle_response_dict = dict(zip(column_names, row))
subtitle_response_dict["startYear"] = start_year
subtitle_response_dict["endYear"] = end_year
subtitle_response_dict["programs"] = []

# Find all programs under the subtitle
Expand Down