Last active
June 13, 2019 00:12
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
$csvfile = "/Users/nwb/Desktop/data/FY15__FY16__FY17__FY18.csv" | |
# $csvfile = "/Users/nwb/Desktop/data/FY14-15__FY15-16.csv" | |
$jsonfile = "/Users/nwb/Desktop/data/sacbudget_v3.json" | |
$template = [PSCustomObject]@{ | |
name = "Sacramento Budget 2017/18"; | |
} | |
Import-Csv $csvfile | | |
Where-Object "account_type" -eq "Expenses" | | |
ForEach-Object { | |
"hello" + $_ | |
} | | |
ConvertTo-Json | | |
Out-File $jsonfile | |
# $csv = Import-Csv $csvfile | |
# $csv[0].psobject.properties.name # DEBUG: List all the headers. | |
# $csv1 = $csv | Where-Object "account_type" -eq "Expenses" | |
# $csv | Where-Object "account_type" -eq "Revenues" | |
# $csv | Where-Object "account_type" -eq "Expenses" | |
# Tests: | |
# Import-Csv $csvfile | Format-BudgetGraph | |
# Import-Csv $csvfile | Format-BudgetGraph | Out-Host -Paging | |
# Import-Csv $csvfile | Format-BudgetGraph | ConvertTo-Json | TestParsingOutputsSameJsonFile | |
function global:Format-BudgetGraph { | |
process { | |
if ($_.account_type -eq "Expense") { | |
return $_ | |
} | |
} | |
<# | |
.SYNOPSIS | |
Takes each line of the budget data and converts it to the format needed for the Department Budgets graph. | |
.DESCRIPTION | |
Adds a file name extension to a supplied name. | |
Takes any strings for the file name or extension. | |
.PARAMETER CsvLine | |
A line from the csv file with the following headers: | |
budget_year,account_type,department,division,org_code,org_description,fund_code,fund,account_category,account_code,account_description,amount | |
.INPUTS | |
None. You cannot pipe objects to Add-Extension. | |
.OUTPUTS | |
System.String. Add-Extension returns a string with the extension | |
or file name. | |
.EXAMPLE | |
PS> extension -name "File" | |
File.txt | |
#> | |
} | |
function global:TestParsingOutputsSameJsonFile { | |
<# | |
.Description | |
Get the first line | |
#> | |
process { | |
$originalJsonFile = "/Users/nwb/Desktop/data/sacbudget_v2.json" | |
# Compare-Object Format-BudgetGraph($CsvLine) Get-Content -Path $originalJsonFile | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment