Skip to content

Commit 699eaf4

Browse files
authored
313 feature update title 2 data to use years 2014 2023 (#314)
* Update title-2 data response to use years 2014 to 2023. * Update CHANGELOG. * Make start and end year for Title-II endpoints a global variable and add those values in the summary endpoint response.
1 parent 80206ed commit 699eaf4

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [unreleased]
7+
## Unreleased
88

99
### Added
1010
- Add year query parameter to Title-I program and top-level endpoints. [#300](https://github.com/policy-design-lab/pdl-api/issues/300)
1111
- Add year query parameter to SNAP endpoints. [#303](https://github.com/policy-design-lab/pdl-api/issues/303)
1212
- Add year query parameter to Crop Insurance endpoints. [#302](https://github.com/policy-design-lab/pdl-api/issues/302)
1313

14+
### Changed
15+
- Update Title II endpoints to include data from 2014 to 2023. [#313](https://github.com/policy-design-lab/pdl-api/issues/313)
16+
1417
## [0.22.0] - 2025-02-26
1518

1619
### Added

app/controllers/pdl.py

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
TITLE_IV_SNAP_PROGRAM_NAME = "Supplemental Nutrition Assistance Program (SNAP)"
9292
TITLE_XI_CROP_INSURANCE_PROGRAM_NAME = "Crop Insurance"
9393

94+
TITLE_II_START_YEAR = 2014
95+
TITLE_II_END_YEAR = 2023
96+
9497

9598
def search():
9699
out_json = jsonutils.create_test_message()
@@ -433,21 +436,34 @@ def titles_title_i_subtitles_subtitle_e_summary_search():
433436
endpoint_response = generate_title_i_summary_response(subtitle_id, start_year, end_year)
434437
return endpoint_response
435438

439+
436440
# /pdl/titles/title-ii/summary:
437441
def titles_title_ii_summary_search():
438-
start_year = 2018
439-
end_year = 2022
440-
title_id = 101
441-
endpoint_response = generate_title_ii_total_summary_response(title_id, start_year, end_year)
442+
title_id = get_title_id(TITLE_II_NAME)
443+
if title_id is None:
444+
msg = {
445+
"reason": "No record for the given title name " + TITLE_II_NAME,
446+
"error": "Not found: " + request.url,
447+
}
448+
logging.error("Title II: " + json.dumps(msg))
449+
return rs_handlers.not_found(msg)
450+
451+
endpoint_response = generate_title_ii_total_summary_response(title_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
442452
return endpoint_response
443453

444454

445455
# /pdl/titles/title-ii/state-distribution:
446456
def titles_title_ii_state_distribution_search():
447-
start_year = 2018
448-
end_year = 2022
449-
title_id = 101
450-
endpoint_response = generate_title_ii_total_state_distribution_response(title_id, start_year, end_year)
457+
title_id = get_title_id(TITLE_II_NAME)
458+
if title_id is None:
459+
msg = {
460+
"reason": "No record for the given title name " + TITLE_II_NAME,
461+
"error": "Not found: " + request.url,
462+
}
463+
logging.error("Title II: " + json.dumps(msg))
464+
return rs_handlers.not_found(msg)
465+
466+
endpoint_response = generate_title_ii_total_state_distribution_response(title_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
451467
return endpoint_response
452468

453469
# /pdl/titles/title-ii/programs/eqip/map
@@ -476,9 +492,7 @@ def titles_title_ii_programs_eqip_state_distribution_search(practice_code=None):
476492
logging.error("EQIP: " + json.dumps(msg))
477493
return rs_handlers.not_found(msg)
478494

479-
start_year = 2018
480-
end_year = 2022
481-
endpoint_response = generate_title_ii_state_distribution_response(program_id, start_year, end_year, practice_code=practice_code)
495+
endpoint_response = generate_title_ii_state_distribution_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR, practice_code=practice_code)
482496
return endpoint_response
483497

484498

@@ -492,9 +506,8 @@ def titles_title_ii_programs_eqip_summary_search():
492506
}
493507
logging.error("EQIP: " + json.dumps(msg))
494508
return rs_handlers.not_found(msg)
495-
start_year = 2018
496-
end_year = 2022
497-
endpoint_response = generate_title_ii_summary_response(program_id, start_year, end_year)
509+
510+
endpoint_response = generate_title_ii_summary_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
498511
return endpoint_response
499512

500513

@@ -508,9 +521,8 @@ def titles_title_ii_programs_eqip_practice_names_search():
508521
}
509522
logging.error("EQIP: " + json.dumps(msg))
510523
return rs_handlers.not_found(msg)
511-
start_year = 2018
512-
end_year = 2022
513-
endpoint_response = generate_title_ii_practice_names_response(program_id, start_year, end_year)
524+
525+
endpoint_response = generate_title_ii_practice_names_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
514526
return endpoint_response
515527

516528

@@ -599,9 +611,8 @@ def titles_title_ii_programs_csp_state_distribution_search(practice_code=None):
599611
}
600612
logging.error("CSP: " + json.dumps(msg))
601613
return rs_handlers.not_found(msg)
602-
start_year = 2018
603-
end_year = 2022
604-
endpoint_response = generate_title_ii_state_distribution_response(program_id, start_year, end_year, practice_code=practice_code)
614+
615+
endpoint_response = generate_title_ii_state_distribution_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR, practice_code=practice_code)
605616
return endpoint_response
606617

607618

@@ -615,9 +626,8 @@ def titles_title_ii_programs_csp_summary_search():
615626
}
616627
logging.error("CSP: " + json.dumps(msg))
617628
return rs_handlers.not_found(msg)
618-
start_year = 2018
619-
end_year = 2022
620-
endpoint_response = generate_title_ii_summary_response(program_id, start_year, end_year)
629+
630+
endpoint_response = generate_title_ii_summary_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
621631
return endpoint_response
622632

623633

@@ -631,9 +641,8 @@ def titles_title_ii_programs_csp_practice_names_search():
631641
}
632642
logging.error("EQIP: " + json.dumps(msg))
633643
return rs_handlers.not_found(msg)
634-
start_year = 2018
635-
end_year = 2022
636-
endpoint_response = generate_title_ii_practice_names_response(program_id, start_year, end_year)
644+
645+
endpoint_response = generate_title_ii_practice_names_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
637646
return endpoint_response
638647

639648

@@ -696,6 +705,7 @@ def titles_title_ii_programs_csp_ira_predicted_search():
696705

697706
return data_json
698707

708+
699709
# /pdl/titles/title-ii/programs/crp/state-distribution
700710
def titles_title_ii_programs_crp_state_distribution_search():
701711
program_id = get_program_id(TITLE_II_CRP_PROGRAM_NAME)
@@ -706,9 +716,8 @@ def titles_title_ii_programs_crp_state_distribution_search():
706716
}
707717
logging.error("CRP: " + json.dumps(msg))
708718
return rs_handlers.not_found(msg)
709-
start_year = 2018
710-
end_year = 2022
711-
endpoint_response = generate_title_ii_state_distribution_response(program_id, start_year, end_year)
719+
720+
endpoint_response = generate_title_ii_state_distribution_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
712721
return endpoint_response
713722

714723

@@ -722,9 +731,8 @@ def titles_title_ii_programs_crp_summary_search():
722731
}
723732
logging.error("CRP: " + json.dumps(msg))
724733
return rs_handlers.not_found(msg)
725-
start_year = 2018
726-
end_year = 2022
727-
endpoint_response = generate_title_ii_summary_response(program_id, start_year, end_year)
734+
735+
endpoint_response = generate_title_ii_summary_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
728736
return endpoint_response
729737

730738

@@ -738,9 +746,8 @@ def titles_title_ii_programs_acep_state_distribution_search():
738746
}
739747
logging.error("ACEP: " + json.dumps(msg))
740748
return rs_handlers.not_found(msg)
741-
start_year = 2018
742-
end_year = 2022
743-
endpoint_response = generate_title_ii_state_distribution_response(program_id, start_year, end_year)
749+
750+
endpoint_response = generate_title_ii_state_distribution_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
744751
return endpoint_response
745752

746753

@@ -754,9 +761,8 @@ def titles_title_ii_programs_acep_summary_search():
754761
}
755762
logging.error("ACEP: " + json.dumps(msg))
756763
return rs_handlers.not_found(msg)
757-
start_year = 2018
758-
end_year = 2022
759-
endpoint_response = generate_title_ii_summary_response(program_id, start_year, end_year)
764+
765+
endpoint_response = generate_title_ii_summary_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
760766
return endpoint_response
761767

762768

@@ -770,9 +776,8 @@ def titles_title_ii_programs_rcpp_state_distribution_search():
770776
}
771777
logging.error("RCPP: " + json.dumps(msg))
772778
return rs_handlers.not_found(msg)
773-
start_year = 2018
774-
end_year = 2022
775-
endpoint_response = generate_title_ii_state_distribution_response(program_id, start_year, end_year)
779+
780+
endpoint_response = generate_title_ii_state_distribution_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
776781
return endpoint_response
777782

778783

@@ -786,9 +791,8 @@ def titles_title_ii_programs_rcpp_summary_search():
786791
}
787792
logging.error("RCPP: " + json.dumps(msg))
788793
return rs_handlers.not_found(msg)
789-
start_year = 2018
790-
end_year = 2022
791-
endpoint_response = generate_title_ii_summary_response(program_id, start_year, end_year)
794+
795+
endpoint_response = generate_title_ii_summary_response(program_id, TITLE_II_START_YEAR, TITLE_II_END_YEAR)
792796
return endpoint_response
793797

794798
# /pdl/titles/title-ii/proposals/2024/house/eqip/predicted
@@ -1549,6 +1553,7 @@ def generate_title_i_total_summary_response(title_id, start_year, end_year):
15491553

15501554
return final_summary
15511555

1556+
15521557
def generate_title_ii_total_summary_response(title_id, start_year, end_year):
15531558
session = Session()
15541559

@@ -1600,6 +1605,8 @@ def generate_title_ii_total_summary_response(title_id, start_year, end_year):
16001605
title_entry = {
16011606
'titleName': title_name,
16021607
'totalPaymentInDollars': title_total_payment,
1608+
'startYear': start_year,
1609+
'endYear': end_year,
16031610
'programs': program_list
16041611
}
16051612

@@ -3127,7 +3134,7 @@ def generate_title_ii_summary_response(program_id, start_year, end_year):
31273134
# Sort the sub programs by total payment in descending order
31283135
sub_programs_list = sorted(sub_programs_list, key=lambda x: x['totalPaymentInDollars'], reverse=True)
31293136

3130-
response = {**total_values_dict, "statutes": statutes_list, "subPrograms": sub_programs_list}
3137+
response = {"startYear": start_year, "endYear": end_year, **total_values_dict, "statutes": statutes_list, "subPrograms": sub_programs_list}
31313138
return response
31323139

31333140

0 commit comments

Comments
 (0)