Created
May 17, 2023 02:08
-
-
Save dharmatech/0547ba37db0b897e493d8b0d6bde06cf 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},transaction_today_amt:gte:{2}&fields=record_date,transaction_type,transaction_catg,transaction_today_amt&page[number]=1&page[size]=900' | |
| $date = '2000-01-01' | |
| $category = 'Interest on Treasury Securities' | |
| $result = Invoke-RestMethod -Method Get -Uri ($base + $rest_url -f $date, $category, 1000) | |
| foreach ($row in $result.data) | |
| { | |
| $row.transaction_today_amt = [decimal] $row.transaction_today_amt | |
| } | |
| $result.data | Sort-Object transaction_today_amt -Descending | Select-Object -First 30 | |
| # $result.data | ft * | |
| # $result.data | ft record_date, transaction_type, transaction_catg, @{ Expression = 'transaction_today_amt'; Format = 'N0' } | |
| # ---------------------------------------------------------------------- | |
| $result.data | Where-Object transaction_today_amt -GT 1000 | ft * | |
| $items = $result.data | Where-Object transaction_today_amt -GT 1000 | |
| $json = @{ | |
| chart = @{ | |
| type = 'bar' | |
| data = @{ | |
| labels = $items | ForEach-Object record_date | |
| datasets = @( | |
| @{ data = $items.ForEach({ $_.transaction_today_amt / 1000 }); } | |
| ) | |
| } | |
| options = @{ | |
| title = @{ display = $true; text = 'TGA : Interest on Treasury Securities (Billions USD)' } | |
| scales = @{ | |
| yAxes = @( | |
| @{ | |
| ticks = @{ | |
| min = 0 | |
| # max = 60 | |
| } | |
| } | |
| ) | |
| } | |
| } | |
| } | |
| } | ConvertTo-Json -Depth 100 | |
| $quickchart_result = Invoke-RestMethod -Method Post -Uri 'https://quickchart.io/chart/create' -Body $json -ContentType 'application/json' | |
| $id = ([System.Uri] $quickchart_result.url).Segments[-1] | |
| Start-Process ('https://quickchart.io/chart-maker/view/{0}' -f $id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment