Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Variable not working through def #163

Open
kurtlawrence opened this issue Aug 10, 2022 · 0 comments
Open

[BUG] Variable not working through def #163

kurtlawrence opened this issue Aug 10, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@kurtlawrence
Copy link
Member

Current Behaviour

This works:

    open wallet-lt.csv | filter timestamp { take 10 | >= $cutoff-date }
    | let {nth 0 get:Num fiat-value} $start 
          {last get:Num fiat-value} $end
    | Table $name
    | append-row { \$end | - $start }
    | append-row { \$end | / $start | - 1 }
    | let $t
    | open executions-lt.csv | filter timestamp { take 10 | >= $cutoff-date }
    | filter real = 'true'
    | append --ret-val { let #i.buy-fiat:Num $s | get sell-fiat | - $s }
    | grp coin
    | append --sum { get value | fold 0 {:Num + $row.ret-val } }
    | sort 'sum'
    | let $cs
    | \$t
    | append-row { \ $cs | if {empty} '' { last get:Str key } }
}

However, if we abstract the last line into a definition:

def def-if-empty (t:Table d e:Expr) { \ $t | if {empty} $d $e }

def summary-col (name:Str cutoff-date:Str) {
    open wallet-lt.csv | filter timestamp { take 10 | >= $cutoff-date }
    | let {nth 0 get:Num fiat-value} $start 
          {last get:Num fiat-value} $end
    | Table $name
    | append-row { \$end | - $start }
    | append-row { \$end | / $start | - 1 }
    | let $t
    | open executions-lt.csv | filter timestamp { take 10 | >= $cutoff-date }
    | filter real = 'true'
    | append --ret-val { let #i.buy-fiat:Num $s | get sell-fiat | - $s }
    | grp coin
    | append --sum { get value | fold 0 {:Num + $row.ret-val } }
    | sort 'sum'
    | let $cs
    | \$t
    | append-row def-if-empty $cs '' { last get:Str key }
}

There is a runtime error saying that the column key is not present.

This is either a locals issue or an input issue, but the last call is not being invoked on the correct table.

@kurtlawrence kurtlawrence added the bug Something isn't working label Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant