annacrombie / plot

plot on the command line
MIT License
113 stars 9 forks source link

Data pipes #18

Closed annacrombie closed 3 years ago

annacrombie commented 3 years ago

This pr totally refactors the input system. It simplifies the actual reading of numbers and makes data processing more flexible.

Pipelines

With this pr, you specify a pipeline for each input. Currently, this is with the option '-p'.

example:

the equivalent of seq 1 100 | plot -a 5 would become seq 1 100 | plot -p avg:5

or you could get a simple moving average with this:

seq 1 100 | plot -p sma:5

furthermore, these data processors or data procs, can be composed

seq 1 100 | plot -p "avg:5|sma:2"

They can also be set per input. Using -p before any input sets the default pipeline which is copied to each input.

@kuro > ~/src/c/plot build/plot -p avg:40 -i gas_prices -i gas_prices -p sma:9
      12.29 ┤  ╭╮
      11.82 ┤  ││
      11.36 ┤  ││
      10.90 ┤  ││
      10.44 ┤ ╭╯│
       9.98 ┤ │ │
       9.52 ┤ │ │
       9.06 ┤╭╯ │
       8.60 ┤│  │
       8.14 ┼───╮╮
       7.68 ┼╯  ╰╮
       7.22 ┤    ╰╮
       6.76 ┤    ╰╰╮
       6.30 ┤     ││
       5.84 ┤     ╰╰╮    ╭╮
       5.38 ┤      ││    ││
       4.92 ┤      │╰╮   ││                       ╭─╮
       4.46 ┤      ╰╮╰─╮╭╯╰╭──╮╭╮╭─╮              │ ╰─╮
       3.99 ┤       │╭╮╰───╯ ╰╰───╮╰╮        ╭─╭───────╮╮                        ╭╮
       3.53 ┤       ╰╯│╭╯     ╰╯  ╰──╮     ╭╭──╯──╯    ╰─╮           ╭╮          ││
       3.07 ┤         ╰╯             ╰──────╯            ╰─╮       ╭╮╭──────────────╮
       2.61 ┤                         ╰╮╭╯                ╰╰─────────╯       ╰╯     ╰───╮
       2.15 ┤                          ╰╯                     ╰─╮╭╯                  ╰╯ ╰╮
       1.69 ┤                                                   ╰╯                       ╰───

data source original: https://datahub.io/core/natural-gas

The pipelines for the above look like

in1 -> avg:40 -> output
in1 -> avg:40 -> sma:9 -> output

implemented data procs:

Other changes

TODO

annacrombie commented 3 years ago

@AdrianDC @holmanb would you like to take a look at this before I merge it?

holmanb commented 3 years ago

I've only read the description so far, but it sounds promising. I'll take a looks at the implementation and make comments if I have any.