Created
May 11, 2023 03:13
-
-
Save dharmatech/9da03b42c6d6479f902e7daa285c6bc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $base = 'https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v1/accounting/dts' | |
| $rest_url = '/dts_table_2?filter=record_date:gte:{0},transaction_catg:eq:{1}&fields=record_date,transaction_type,transaction_catg,transaction_today_amt&page[number]=1&page[size]=300' | |
| $date = '2023-01-01' | |
| # ---------------------------------------------------------------------- | |
| # https://www.opm.gov/policy-data-oversight/pay-leave/federal-holidays/#url=2023 | |
| $holidays = @( | |
| Get-Date "Monday, January 02" -Format 'yyyy-MM-dd' # New Year’s Day | |
| Get-Date "Monday, January 16" -Format 'yyyy-MM-dd' # Birthday of Martin Luther King, Jr. | |
| Get-Date "Monday, February 20" -Format 'yyyy-MM-dd' # Washington’s Birthday | |
| Get-Date "Monday, May 29" -Format 'yyyy-MM-dd' # Memorial Day | |
| Get-Date "Monday, June 19" -Format 'yyyy-MM-dd' # Juneteenth National Independence Day | |
| Get-Date "Tuesday, July 04" -Format 'yyyy-MM-dd' # Independence Day | |
| Get-Date "Monday, September 04" -Format 'yyyy-MM-dd' # Labor Day | |
| Get-Date "Monday, October 09" -Format 'yyyy-MM-dd' # Columbus Day | |
| Get-Date "Friday, November 10" -Format 'yyyy-MM-dd' # Veterans Day | |
| Get-Date "Thursday, November 23" -Format 'yyyy-MM-dd' # Thanksgiving Day | |
| Get-Date "Monday, December 25" -Format 'yyyy-MM-dd' # Christmas Day | |
| ) | |
| # ---------------------------------------------------------------------- | |
| $start_date = '2023-05-05' | |
| $end_date = '2023-07-01' | |
| # SSA - Benefits Payments | |
| # Rule: | |
| # Each month on the 3rd of the month, and then the second, third, and fourth Wed of the month 24-26b of SSA benefits go out. | |
| # If the 3rd falls on a Saturday or Sunday, payment goes out the Friday before | |
| $result_ssa = Invoke-RestMethod -Method Get -Uri ($base + $rest_url -f $date, 'SSA - Benefits Payments') | |
| $reference_start_date = '2023-04-01' | |
| $reference_end_date = '2023-04-30' | |
| $avg_big = $result_ssa.data | | |
| ? record_date -GE $reference_start_date | | |
| ? record_date -LE $reference_end_date | | |
| ? { [decimal]$_.transaction_today_amt -gt 10000 } | | |
| ? transaction_type -EQ 'Withdrawals' | | |
| Measure-Object -Property transaction_today_amt -Average | | |
| ForEach-Object Average | |
| $avg_small = $result_ssa.data | | |
| ? record_date -GE $reference_start_date | | |
| ? record_date -LE $reference_end_date | | |
| ? { [decimal]$_.transaction_today_amt -lt 10000 } | | |
| ? transaction_type -EQ 'Withdrawals' | | |
| Measure-Object -Property transaction_today_amt -Average | | |
| ForEach-Object Average | |
| $eval_date = $start_date | |
| $rows = while ($eval_date -le '2023-07-01') | |
| { | |
| if ( | |
| (Get-Date $eval_date).Day -eq 3 -and | |
| (Get-Date $eval_date).DayOfWeek -notin 'Saturday', 'Sunday' -and | |
| $eval_date -notin $holidays | |
| ) | |
| { | |
| [PSCustomObject]@{ date = $eval_date; transaction_type = 'Withdrawals'; transaction_catg = 'SSA - Benefits Payments'; val = $avg_big } | |
| } | |
| elseif ( | |
| (Get-Date $eval_date).Day -in 1, 2 -and | |
| (Get-Date $eval_date).DayOfWeek -eq 'Friday' -and | |
| $eval_date -notin $holidays | |
| ) | |
| { | |
| [PSCustomObject]@{ date = $eval_date; transaction_type = 'Withdrawals'; transaction_catg = 'SSA - Benefits Payments'; val = $avg_big } | |
| } | |
| elseif ( | |
| (Get-Date $eval_date).DayOfWeek -eq 'Wednesday' -and | |
| (Get-Date $eval_date).Day -in 8..28 -and | |
| $eval_date -notin $holidays | |
| ) | |
| { | |
| [PSCustomObject]@{ date = $eval_date; transaction_type = 'Withdrawals'; transaction_catg = 'SSA - Benefits Payments'; val = $avg_big } | |
| } | |
| elseif ( | |
| (Get-Date $eval_date).DayOfWeek -eq 'Tuesday' -and | |
| (Get-Date $eval_date).Day -in 7..27 -and | |
| (Get-Date (Get-Date $eval_date).AddDays(1) -Format 'yyyy-MM-dd') -in $holidays | |
| ) | |
| { | |
| [PSCustomObject]@{ date = $eval_date; transaction_type = 'Withdrawals'; transaction_catg = 'SSA - Benefits Payments'; val = $avg_big } | |
| } | |
| else | |
| { | |
| if ( | |
| (Get-Date $eval_date).DayOfWeek -notin 'Saturday', 'Sunday' -and | |
| $eval_date -notin $holidays | |
| ) | |
| { | |
| [PSCustomObject]@{ date = $eval_date; transaction_type = 'Withdrawals'; transaction_catg = 'SSA - Benefits Payments'; val = $avg_small } | |
| } | |
| } | |
| $eval_date = Get-Date (Get-Date $eval_date).AddDays(1) -Format 'yyyy-MM-dd' | |
| } | |
| $rows | Select-Object *, @{ Label = 'day_of_week'; Expression = { (Get-Date $_.date).DayOfWeek } } | ft * | |
| # ---------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment