2020-06-14 22:42:15 +02:00
|
|
|
# math
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
Mathematical functions that generally only operate on a list of numbers (integers, decimals, bytes) and tables.
|
|
|
|
Currently the following functions are implemented:
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-20 01:20:25 +02:00
|
|
|
* `math avg`: Finds the average of a list of numbers or tables
|
2020-07-18 06:11:19 +02:00
|
|
|
* [`math eval`](math-eval.md): Evaluates a list of math expressions into numbers
|
2020-06-19 04:02:01 +02:00
|
|
|
* `math max`: Finds the maximum within a list of numbers or tables
|
2020-06-20 07:28:03 +02:00
|
|
|
* `math median`: Finds the median of a list of numbers or tables
|
2020-08-30 05:32:38 +02:00
|
|
|
* `math min`: Finds the minimum within a list of numbers or tables
|
|
|
|
* `math mode`: Finds the most frequent element(s) within a list of numbers or tables
|
|
|
|
* `math stddev`: Finds the standard deviation of a list of numbers or tables
|
2020-06-19 04:02:01 +02:00
|
|
|
* `math sum`: Finds the sum of a list of numbers or tables
|
2020-08-27 07:58:01 +02:00
|
|
|
* `math product`: Finds the product of a list of numbers or tables
|
2020-08-30 05:32:38 +02:00
|
|
|
* `math variance`: Finds the variance of a list of numbers or tables
|
2020-06-14 22:42:15 +02:00
|
|
|
|
|
|
|
However, the mathematical functions like `min` and `max` are more permissive and also work on `Dates`.
|
|
|
|
|
|
|
|
## Examples
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
To get the average of the file sizes in a directory, simply pipe the size column from the ls command to the average command.
|
|
|
|
|
|
|
|
### List of Numbers (Integers, Decimals, Bytes)
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
```shell
|
|
|
|
> ls
|
2020-06-19 04:02:01 +02:00
|
|
|
# │ name │ type │ size │ modified
|
2020-06-14 22:42:15 +02:00
|
|
|
────┼────────────────────┼──────┼──────────┼─────────────
|
2020-06-19 04:02:01 +02:00
|
|
|
0 │ CODE_OF_CONDUCT.md │ File │ 3.4 KB │ 4 days ago
|
|
|
|
1 │ CONTRIBUTING.md │ File │ 1.3 KB │ 4 days ago
|
|
|
|
2 │ Cargo.lock │ File │ 106.3 KB │ 6 mins ago
|
|
|
|
3 │ Cargo.toml │ File │ 4.6 KB │ 3 days ago
|
|
|
|
4 │ LICENSE │ File │ 1.1 KB │ 4 days ago
|
|
|
|
5 │ Makefile.toml │ File │ 449 B │ 4 days ago
|
|
|
|
6 │ README.md │ File │ 16.0 KB │ 6 mins ago
|
|
|
|
7 │ TODO.md │ File │ 0 B │ 6 mins ago
|
|
|
|
8 │ assets │ Dir │ 128 B │ 4 days ago
|
|
|
|
9 │ build.rs │ File │ 78 B │ 4 days ago
|
|
|
|
10 │ crates │ Dir │ 672 B │ 3 days ago
|
|
|
|
11 │ debian │ Dir │ 352 B │ 4 days ago
|
|
|
|
12 │ docker │ Dir │ 288 B │ 4 days ago
|
|
|
|
13 │ docs │ Dir │ 160 B │ 4 days ago
|
|
|
|
14 │ features.toml │ File │ 632 B │ 4 days ago
|
|
|
|
15 │ images │ Dir │ 160 B │ 4 days ago
|
|
|
|
16 │ justfile │ File │ 234 B │ 3 days ago
|
|
|
|
17 │ rustfmt.toml │ File │ 16 B │ 4 days ago
|
|
|
|
18 │ src │ Dir │ 128 B │ 4 days ago
|
|
|
|
19 │ target │ Dir │ 192 B │ 8 hours ago
|
|
|
|
20 │ tests │ Dir │ 192 B │ 4 days ago
|
|
|
|
```
|
2020-06-14 22:42:15 +02:00
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
2020-06-20 01:20:25 +02:00
|
|
|
> ls | get size | math avg
|
2020-06-14 22:42:15 +02:00
|
|
|
───┬────────
|
2020-06-20 07:28:03 +02:00
|
|
|
# │
|
|
|
|
───┼────────
|
2020-06-19 04:02:01 +02:00
|
|
|
0 │ 7.2 KB
|
2020-06-14 22:42:15 +02:00
|
|
|
───┴────────
|
2020-06-19 04:02:01 +02:00
|
|
|
```
|
2020-06-14 22:42:15 +02:00
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
2020-06-14 22:42:15 +02:00
|
|
|
> ls | get size | math min
|
|
|
|
───┬─────
|
2020-06-20 07:28:03 +02:00
|
|
|
# │
|
|
|
|
───┼─────
|
2020-06-19 04:02:01 +02:00
|
|
|
0 │ 0 B
|
2020-06-14 22:42:15 +02:00
|
|
|
───┴─────
|
2020-06-19 04:02:01 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
2020-06-23 20:21:47 +02:00
|
|
|
> ls | get size | math max
|
2020-06-14 22:42:15 +02:00
|
|
|
───┬──────────
|
2020-06-20 07:28:03 +02:00
|
|
|
# │
|
|
|
|
───┼──────────
|
|
|
|
0 │ 113.6 KB
|
2020-06-19 04:02:01 +02:00
|
|
|
───┴──────────
|
|
|
|
```
|
|
|
|
|
2020-06-20 07:28:03 +02:00
|
|
|
```shell
|
|
|
|
> ls | get size | math median
|
|
|
|
───┬───────
|
|
|
|
# │
|
|
|
|
───┼───────
|
|
|
|
0 │ 320 B
|
|
|
|
───┴───────
|
|
|
|
```
|
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
|
|
|
> ls | get size | math sum
|
|
|
|
───┬──────────
|
2020-06-20 07:28:03 +02:00
|
|
|
# │
|
|
|
|
───┼──────────
|
|
|
|
0 │ 143.6 KB
|
2020-06-14 22:42:15 +02:00
|
|
|
───┴──────────
|
2020-06-19 04:02:01 +02:00
|
|
|
```
|
|
|
|
|
2020-08-30 05:32:38 +02:00
|
|
|
```shell
|
|
|
|
> echo [3 3 9 12 12 15] | math mode
|
|
|
|
───┬────
|
|
|
|
0 │ 3
|
|
|
|
1 │ 12
|
|
|
|
───┴────
|
|
|
|
```
|
|
|
|
|
2020-08-27 07:58:01 +02:00
|
|
|
```shell
|
|
|
|
> echo [2 3 3 4] | math product
|
|
|
|
72
|
|
|
|
```
|
|
|
|
|
2020-08-30 05:32:38 +02:00
|
|
|
```shell
|
|
|
|
> echo [1 4 6 10 50] | math stddev
|
|
|
|
18.1372
|
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
|
|
|
> echo [1 4 6 10 50] | math variance
|
|
|
|
328.96
|
|
|
|
```
|
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
### Dates
|
2020-06-14 22:42:15 +02:00
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
2020-06-14 22:42:15 +02:00
|
|
|
> ls | get modified | math min
|
|
|
|
2020-06-09 17:25:51.798743222 UTC
|
2020-06-19 04:02:01 +02:00
|
|
|
```
|
2020-06-14 22:42:15 +02:00
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
2020-06-14 22:42:15 +02:00
|
|
|
> ls | get modified | math max
|
|
|
|
2020-06-14 05:49:59.637449186 UT
|
|
|
|
```
|
|
|
|
|
|
|
|
### Operations on tables
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
```shell
|
2020-06-19 04:02:01 +02:00
|
|
|
> pwd | split row / | size
|
2020-06-14 22:42:15 +02:00
|
|
|
───┬───────┬───────┬───────┬────────────
|
2020-09-01 04:51:35 +02:00
|
|
|
# │ lines │ words │ chars │ bytes
|
2020-06-14 22:42:15 +02:00
|
|
|
───┼───────┼───────┼───────┼────────────
|
2020-06-19 04:02:01 +02:00
|
|
|
0 │ 0 │ 1 │ 5 │ 5
|
2020-06-20 07:28:03 +02:00
|
|
|
1 │ 0 │ 1 │ 11 │ 11
|
|
|
|
2 │ 0 │ 1 │ 11 │ 11
|
|
|
|
3 │ 0 │ 1 │ 4 │ 4
|
|
|
|
4 │ 0 │ 2 │ 12 │ 12
|
|
|
|
5 │ 0 │ 1 │ 7 │ 7
|
2020-06-14 22:42:15 +02:00
|
|
|
───┴───────┴───────┴───────┴────────────
|
2020-06-19 04:02:01 +02:00
|
|
|
```
|
2020-06-14 22:42:15 +02:00
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
2020-06-14 22:42:15 +02:00
|
|
|
> pwd | split row / | size | math max
|
2020-06-20 07:28:03 +02:00
|
|
|
────────────┬────
|
2020-06-19 04:02:01 +02:00
|
|
|
lines │ 0
|
2020-06-20 07:28:03 +02:00
|
|
|
words │ 2
|
|
|
|
chars │ 12
|
2020-09-01 04:51:35 +02:00
|
|
|
bytes │ 12
|
2020-06-20 07:28:03 +02:00
|
|
|
────────────┴────
|
2020-06-19 04:02:01 +02:00
|
|
|
```
|
2020-06-14 22:42:15 +02:00
|
|
|
|
2020-06-19 04:02:01 +02:00
|
|
|
```shell
|
2020-06-20 01:20:25 +02:00
|
|
|
> pwd | split row / | size | math avg
|
2020-06-14 22:42:15 +02:00
|
|
|
────────────┬────────
|
2020-06-19 04:02:01 +02:00
|
|
|
lines │ 0.0000
|
2020-06-20 07:28:03 +02:00
|
|
|
words │ 1.1666
|
|
|
|
chars │ 8.3333
|
2020-09-01 04:51:35 +02:00
|
|
|
bytes │ 8.3333
|
2020-06-14 22:42:15 +02:00
|
|
|
────────────┴────────
|
|
|
|
```
|
|
|
|
|
2020-06-19 20:00:18 +02:00
|
|
|
To get the sum of the characters that make up your present working directory.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
> pwd | split row / | size | get chars | math sum
|
|
|
|
50
|
|
|
|
```
|
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
## Errors
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
`math` functions are aggregation functions so empty lists are invalid
|
2020-06-19 04:02:01 +02:00
|
|
|
|
2020-06-14 22:42:15 +02:00
|
|
|
```shell
|
2020-06-20 01:20:25 +02:00
|
|
|
> echo [] | math avg
|
2020-06-14 22:42:15 +02:00
|
|
|
error: Error: Unexpected: Cannot perform aggregate math operation on empty data
|
|
|
|
```
|