plotty 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +117 -7
- data/lib/plotty/command.rb +3 -1
- data/lib/plotty/graph.rb +19 -15
- data/lib/plotty/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee59e3e02d9e99451d65a0c0580e7fa29561d8f
|
4
|
+
data.tar.gz: 9926f065f4c1ae3f8efc8bfaf53ee245d4700af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a531dc811cf328e24334a1faf577bb13dd41809d6677a8ac980f9d9fec31843f392064edabab399b9c1cd54060d2e787bf50d5b570e6146dcbb276649067934b
|
7
|
+
data.tar.gz: b148af4b818bb1cd3f10a88cb1f250a20d96af8aa5e4e83f2c00e47a1030c56dd10a32ec02872a522d4155b9cc65e6073e7ca61fd36d6dedf0073b1ecd499bbe
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,22 +14,132 @@ gem 'plotty'
|
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
17
|
+
$ bundle
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
|
21
|
+
$ gem install plotty
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
`plotty` allows you to graph data from commands, e.g.
|
26
26
|
|
27
|
-
|
27
|
+
plotty -x 1:10 -y '\d+' -- 'echo 1' 'echo $x' 'expr $x \* $x'
|
28
|
+
|
29
|
+
This will graph the results xecuting the 3 commands after the split with `$x = 1, 2, 3, ... 10`. The y value is computed by the first match of the given regular expression.
|
30
|
+
|
31
|
+
### X Axis
|
32
|
+
|
33
|
+
The `-x` argument can take sequences of the following format:
|
34
|
+
|
35
|
+
| Value | Meaning |
|
36
|
+
| ----------|------------------------------------------------------------------|
|
37
|
+
| `1:10` | Enumerate from 1 to 10. |
|
38
|
+
| `1:2:10` | Enumerate from 1 to 10 with steps of size 2. |
|
39
|
+
| `1:*2:64` | Enumerate from 1 to 64 by multiplying the value by 2 each time. |
|
40
|
+
|
41
|
+
### Y Axis
|
42
|
+
|
43
|
+
The `-y` argument is a regular expression which is used to extract the y value from the `stdout` of the command. If a capture is specified, the first one is used.
|
44
|
+
|
45
|
+
### Use libcaca
|
46
|
+
|
47
|
+
Add the following to your `~/.gnuplot`
|
48
|
+
|
49
|
+
set terminal caca driver ncurses
|
50
|
+
|
51
|
+
If you are on arch, install [gnuplot-caca](https://aur.archlinux.org/packages/gnuplot-caca).
|
52
|
+
|
53
|
+
## Examples
|
54
|
+
|
55
|
+
### Trivial Math
|
56
|
+
|
57
|
+
```
|
58
|
+
plotty -x 1:1:20 -y '\d+' -e "set terminal dumb; set key outside" -- 'echo 1' 'echo $x'
|
59
|
+
|
60
|
+
20 +------------------------------------------------------+
|
61
|
+
| + + + + + + + + +### | echo 1 *******
|
62
|
+
18 |-+ ## +-| echo $x #######
|
63
|
+
| ### |
|
64
|
+
16 |-+ ### +-|
|
65
|
+
| ### |
|
66
|
+
14 |-+ ## +-|
|
67
|
+
| ### |
|
68
|
+
12 |-+ ### +-|
|
69
|
+
| ### |
|
70
|
+
10 |-+ ## +-|
|
71
|
+
| ### |
|
72
|
+
8 |-+ ### +-|
|
73
|
+
| ### |
|
74
|
+
6 |-+ ## +-|
|
75
|
+
| ### |
|
76
|
+
4 |-+ ### +-|
|
77
|
+
| ### |
|
78
|
+
2 |-+ ## +-|
|
79
|
+
| ##**************************************************|
|
80
|
+
0 +------------------------------------------------------+
|
81
|
+
0 2 4 6 8 10 12 14 16 18 20
|
82
|
+
```
|
83
|
+
|
84
|
+
```
|
85
|
+
plotty -x 1:1:100 -y '\d+' -e "set terminal dumb; set key outside" -- 'echo $x' 'expr $x \* $x'
|
86
|
+
|
87
|
+
100 +-----------------------------------------------+
|
88
|
+
| + + + + + + + + #| echo $x *******
|
89
|
+
90 |-+ ##-| expr $x \* $x #######
|
90
|
+
| # |
|
91
|
+
80 |-+ ## +-|
|
92
|
+
| ## |
|
93
|
+
70 |-+ ## +-|
|
94
|
+
| # |
|
95
|
+
60 |-+ ## +-|
|
96
|
+
| ## |
|
97
|
+
50 |-+ # +-|
|
98
|
+
| ## |
|
99
|
+
40 |-+ ## +-|
|
100
|
+
| ## |
|
101
|
+
30 |-+ ### +-|
|
102
|
+
| ### |
|
103
|
+
20 |-+ ## +-|
|
104
|
+
| #### |
|
105
|
+
10 |-+ ###### *************|
|
106
|
+
| #####*************************** + + |
|
107
|
+
0 +-----------------------------------------------+
|
108
|
+
1 2 3 4 5 6 7 8 9 10
|
109
|
+
```
|
110
|
+
|
111
|
+
### Web Server Benchmark
|
28
112
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
113
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
114
|
|
33
115
|
## Contributing
|
34
116
|
|
35
|
-
|
117
|
+
1. Fork it
|
118
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
119
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
120
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
121
|
+
5. Create new Pull Request
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
Released under the MIT license.
|
126
|
+
|
127
|
+
Copyright, 2012, 2014, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
128
|
+
|
129
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
130
|
+
of this software and associated documentation files (the "Software"), to deal
|
131
|
+
in the Software without restriction, including without limitation the rights
|
132
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
133
|
+
copies of the Software, and to permit persons to whom the Software is
|
134
|
+
furnished to do so, subject to the following conditions:
|
135
|
+
|
136
|
+
The above copyright notice and this permission notice shall be included in
|
137
|
+
all copies or substantial portions of the Software.
|
138
|
+
|
139
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
140
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
141
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
142
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
143
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
144
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
145
|
+
THE SOFTWARE.
|
data/lib/plotty/command.rb
CHANGED
@@ -35,6 +35,8 @@ module Plotty
|
|
35
35
|
option "-x <axis>", "Specify the x axis explicitly", default: "1:10"
|
36
36
|
option "-y <axis>", "Specify the y axis explicitly"
|
37
37
|
|
38
|
+
option "-e/--script <script>", "Prepend this script to the gnuplot command."
|
39
|
+
|
38
40
|
option '-h/--help', "Print out help information."
|
39
41
|
option '-v/--version', "Print out the application version."
|
40
42
|
end
|
@@ -42,7 +44,7 @@ module Plotty
|
|
42
44
|
split :command
|
43
45
|
|
44
46
|
def plot_graph
|
45
|
-
Graph.parse(options[:x], options[:y], @command).plot!
|
47
|
+
Graph.parse(options[:x], options[:y], @command).plot!(options[:script])
|
46
48
|
end
|
47
49
|
|
48
50
|
def invoke(program_name: File.basename($0))
|
data/lib/plotty/graph.rb
CHANGED
@@ -49,7 +49,7 @@ module Plotty
|
|
49
49
|
Scalar.new($1.to_i, $3.to_i, $2.to_i)
|
50
50
|
when /^(.*?):(.*?):(.*?)$/
|
51
51
|
Linear.new($1.to_i, $3.to_i, $2.to_i)
|
52
|
-
when
|
52
|
+
when /^(.*?):(.*?)$/
|
53
53
|
Linear.new($1.to_i, $2.to_i, 1)
|
54
54
|
end
|
55
55
|
end
|
@@ -61,6 +61,10 @@ module Plotty
|
|
61
61
|
@command = command
|
62
62
|
end
|
63
63
|
|
64
|
+
def title
|
65
|
+
@command
|
66
|
+
end
|
67
|
+
|
64
68
|
def call(value)
|
65
69
|
r, w = IO.pipe
|
66
70
|
|
@@ -90,10 +94,10 @@ module Plotty
|
|
90
94
|
@y = y
|
91
95
|
end
|
92
96
|
|
93
|
-
def self.parse(x, y,
|
97
|
+
def self.parse(x, y, commands)
|
94
98
|
self.new(
|
95
99
|
Sequence.parse(x),
|
96
|
-
Function.new(y, command
|
100
|
+
commands.collect{|command| Function.new(y, command)},
|
97
101
|
)
|
98
102
|
end
|
99
103
|
|
@@ -101,21 +105,21 @@ module Plotty
|
|
101
105
|
TTY::Screen.size.reverse
|
102
106
|
end
|
103
107
|
|
104
|
-
def plot!
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
108
|
+
def plot!(script = nil)
|
109
|
+
File.open("data.txt", "w") do |file|
|
110
|
+
@x.each do |x|
|
111
|
+
values = @y.collect do |function|
|
112
|
+
function.call(x)
|
113
|
+
end
|
114
|
+
|
115
|
+
puts "#{x}: #{values.inspect}"
|
116
|
+
file.puts "#{x} #{values.join(' ')}"
|
117
|
+
end
|
114
118
|
end
|
115
119
|
|
116
|
-
|
120
|
+
plots = @y.collect.with_index{|function, index| "'data.txt' using 1:#{index+2} with lines title #{function.title.dump}"}
|
117
121
|
|
118
|
-
|
122
|
+
system("gnuplot", "-e", "#{script}; plot #{plots.join(', ')}")
|
119
123
|
end
|
120
124
|
end
|
121
125
|
end
|
data/lib/plotty/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plotty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: samovar
|