diff --git a/CHANGELOG.md b/CHANGELOG.md index bb40652..496664e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Dockerfile b/Dockerfile index ba0d58c..39d00c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 \ diff --git a/app/controllers/configs.py b/app/controllers/configs.py index 607ea46..468e945 100644 --- a/app/controllers/configs.py +++ b/app/controllers/configs.py @@ -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')) diff --git a/app/controllers/pdl.py b/app/controllers/pdl.py index d12471f..9c922d1 100644 --- a/app/controllers/pdl.py +++ b/app/controllers/pdl.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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