Something went wrong. Try again.
Created 2w ago
12 kB 213 lines Created 2w ago Nushell
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214let now = (date now) | collect {|current_date| { current_date: $current_date month: (($current_date | format date '%m') | into int) year: (($current_date | format date '%Y') | into int) date: (($current_date | format date '%d') | into int)} }def main [--view(-v), --math(-m), --test(-t)] { let list = (ls $'paystubs/**/($now.year)/*.nuon').name | sort-by { path parse | get stem } -r if $view { open ($list | input list) } else if $test { ($list | input list) | collect {|file| open employers.nuon | where $it.abbreviation == ($file | path split).1 } } else if $math { let annual_workdays = open annual_workdays.nuon $list | each {|| open } | collect {|| each {|item| { date: ($item.info.issued.0 | format date '%m') gross_income: $item.summary.current_period.6 taxable_income: $item.summary.current_period.8 net_pay: $item.summary.current_period.10 units: $item.earnings.units.0 } } | sort-by date | group-by date --prune } | values } | collect {|| each {|month| { sum_gross_income: ($month.gross_income | math sum) sum_taxable_income: ($month.taxable_income | math sum) sum_net_pay: ($month.net_pay | math sum) sum_units: ($month.units | math sum) } } | collect {|sums| let next_year = $'('Next year' | date from-human | format date '%Y')-01-01' let current_month = $'($now.year)-($now.month)-01' | detect type let next_month = ( $'($now.year)-('Next month' | format date '%m')-01' | detect type ) | collect {|time| if ($time | format date '%m') == '01' and $now.month == 12 { $next_year | detect type } else { $time } } let month_progress_percent = ( (($now.current_date - $current_month) / 1sec) / (($next_month - $current_month) / 1sec) ) * 100 let remaining_months_multiplier = 13 - ( $now.month + ($month_progress_percent / 100) | math round -p 2 ) let workdays = ( $annual_workdays | where Year == $now.year | reject December | transpose -d -r | values ).0
{ current_statistics: ([ [Metric, 'Net Pay', 'Gross Income', 'Taxable Income', WorkDays, WorkHours, 'WorkDays (8hrs)', 'WorkDays (24hrs)', 'WorkHours %']; ['avg (per month)', ($sums.sum_net_pay | math avg), ($sums.sum_gross_income | math avg), ($sums.sum_taxable_income | math avg), ($workdays | math avg), ($sums.sum_units | math avg), (($sums.sum_units | math avg) / 8), (($sums.sum_units | math avg) / 24), ((($sums.sum_units | math avg) / (24 * 365)) * 100)] ['median (per month)', ($sums.sum_net_pay | math median), ($sums.sum_gross_income | math median), ($sums.sum_taxable_income | math median), ($workdays | math median), ($sums.sum_units | math median), (($sums.sum_units | math median) / 8), (($sums.sum_units | math median) / 24), ((($sums.sum_units | math median) / (24 * 365)) * 100)] [sum, ($sums.sum_net_pay | math sum), ($sums.sum_gross_income | math sum), ($sums.sum_taxable_income | math sum), ($workdays | math sum), ($sums.sum_units | math sum), (($sums.sum_units | math sum) / 8), (($sums.sum_units | math sum) / 24), ((($sums.sum_units | math sum) / (24 * 365)) * 100)] ] | table -i false) predicted_statistics: ([ [Metric, 'Net Pay', 'Gross Income', 'Taxable Income', WorkDays, WorkHours, 'WorkDays (8hrs)', 'WorkDays (24hrs)', 'WorkHours %']; ['avg (per month)', ( ((($sums.sum_net_pay | math avg) * $remaining_months_multiplier) + ($sums.sum_net_pay | math sum)) / 12 ), ( ((($sums.sum_gross_income | math avg) * $remaining_months_multiplier) + ($sums.sum_gross_income | math sum)) / 12 ),
( ((($sums.sum_taxable_income | math avg) * $remaining_months_multiplier) + ($sums.sum_taxable_income | math sum)) / 12 ) , ( ((($workdays | math avg) * $remaining_months_multiplier) + ($workdays | math sum)) / 12 ), ( ((($sums.sum_units | math avg) * $remaining_months_multiplier) + ($sums.sum_units | math sum)) / 12 ), ( (((($sums.sum_units | math avg) / 8) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 8)) / 12 ), ( (((($sums.sum_units | math avg) / 24) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 24)) / 12 ), ( (( ((($sums.sum_units | math avg) * $remaining_months_multiplier) + ($sums.sum_units | math sum)) / (24 * 365) * 100 ) | math round -p 2) / 12 )] ['median (per month)', ( ((($sums.sum_net_pay | math median) * $remaining_months_multiplier) + ($sums.sum_net_pay | math sum)) / 12 ), ( ((($sums.sum_gross_income | math median) * $remaining_months_multiplier) + ($sums.sum_gross_income | math sum)) / 12 ),
( ((($sums.sum_taxable_income | math median) * $remaining_months_multiplier) + ($sums.sum_taxable_income | math sum)) / 12 ) , ( ((($workdays | math median) * $remaining_months_multiplier) + ($workdays | math sum)) / 12 ), ( ((($sums.sum_units | math median) * $remaining_months_multiplier) + ($sums.sum_units | math sum)) / 12 ), ( (((($sums.sum_units | math median) / 8) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 8)) / 12 ), ( (((($sums.sum_units | math median) / 24) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 24)) / 12 ), ( (( ((($sums.sum_units | math median) * $remaining_months_multiplier) + ($sums.sum_units | math sum)) / (24 * 365) * 100 ) | math round -p 2) / 12 )] ['avg (remaining)', ( ($sums.sum_net_pay | math avg) * $remaining_months_multiplier ), ( ($sums.sum_gross_income | math avg) * $remaining_months_multiplier ), ( ($sums.sum_taxable_income | math avg) * $remaining_months_multiplier ),
(($workdays | math avg) * $remaining_months_multiplier), ( ($sums.sum_units | math avg) * $remaining_months_multiplier ), ( (($sums.sum_units | math avg) / 8) * $remaining_months_multiplier ), ( (($sums.sum_units | math avg) / 24) * $remaining_months_multiplier ), ( (($sums.sum_units | math avg) * $remaining_months_multiplier) / (24 * 365) * 100 )] ['median (remaining)', ( ($sums.sum_net_pay | math median) * $remaining_months_multiplier ), ( ($sums.sum_gross_income | math median) * $remaining_months_multiplier ), ( ($sums.sum_taxable_income | math median) * $remaining_months_multiplier ),
(($workdays | math median) * $remaining_months_multiplier), ( ($sums.sum_units | math median) * $remaining_months_multiplier ), ( (($sums.sum_units | math median) / 8) * $remaining_months_multiplier ), ( (($sums.sum_units | math median) / 24) * $remaining_months_multiplier ), ( ( ($sums.sum_units | math median) * $remaining_months_multiplier) / (24 * 365) * 100 )] ['avg (sum)', ( (($sums.sum_net_pay | math avg) * $remaining_months_multiplier) + ($sums.sum_net_pay | math sum) ), ( (($sums.sum_gross_income | math avg) * $remaining_months_multiplier) + ($sums.sum_gross_income | math sum) ), ( (($sums.sum_taxable_income | math avg) * $remaining_months_multiplier) + ($sums.sum_taxable_income | math sum) ),
( (($workdays | math avg) * $remaining_months_multiplier) + ($workdays | math sum) ), ( (($sums.sum_units | math avg) * $remaining_months_multiplier) + ($sums.sum_units | math sum) ), ( ((($sums.sum_units | math avg) / 8) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 8) ), ( ((($sums.sum_units | math avg) / 24) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 24) ), ( ( ((($sums.sum_units | math avg) * $remaining_months_multiplier) + ($sums.sum_units | math sum)) / (24 * 365) * 100 ) | math round -p 2 )] ['median (sum)', ( (($sums.sum_net_pay | math median) * $remaining_months_multiplier) + ($sums.sum_net_pay | math sum) ), ( (($sums.sum_gross_income | math median) * $remaining_months_multiplier) + ($sums.sum_gross_income | math sum) ), ( (($sums.sum_taxable_income | math median) * $remaining_months_multiplier) + ($sums.sum_taxable_income | math sum) ), ( (($workdays | math median) * $remaining_months_multiplier) + ($workdays | math sum) ), ( (($sums.sum_units | math median) * $remaining_months_multiplier) + ($sums.sum_units | math sum) ), ( ((($sums.sum_units | math median) / 8) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 8) ), ( ((($sums.sum_units | math median) / 24) * $remaining_months_multiplier) + (($sums.sum_units | math sum) / 24) ), ( ( ((($sums.sum_units | math median) * $remaining_months_multiplier) + ($sums.sum_units | math sum)) / (24 * 365) * 100
) | math round -p 2 )] ] | table -i false) } } }}