plotty 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 016556c8fc016be7abc5fc5c5d61925aae7dbb33a82b9acd22213930e878ddcd
4
- data.tar.gz: 7c205e096b7c9089550ebbcaa90925c7bf1dc90787571b62e444eb78d0534938
3
+ metadata.gz: 803c07230307be6c48e3404effbc1cde3e2e2b616545e241b7c8f813a7fc9fdc
4
+ data.tar.gz: 1ccae425bc6678012a9106297b2a38f6e8461388a9f09f5fa91cf2cf1c27ee2c
5
5
  SHA512:
6
- metadata.gz: e2724ee565736c9040114287f65185d242364d5d3381841043da1b0b186530567c79ecb7af3fcbec9b212f4232d88dd3043b4aac2d9a68dd963ff1c63682b9f6
7
- data.tar.gz: 6ba6bd7a79bc85e4431be4bffb0ba2f49a6507677c91d349d82d074a3c128bd4c73ac6823876b54a5f07ec8903d864f6ca865aa428fd7ea7137911deb1ec43f7
6
+ metadata.gz: 8c499f3d39a37005968f220ae416dcbb6942c6daa5d2b57802b165bac9a083aae0448985a489cbb9b126d7a757b463cb10cb2c84f98c2b1fd3b04afed426a2a5
7
+ data.tar.gz: 6b0082b63fd500bf4c4bed18564e305e65e0d2202de778e4664de3bbd33c3da9d921dc4e3aa3b04d9e8a4d4b4634dea3b8c4297776f8a8e98fff90dd5ba4a72d
data/bin/plotty CHANGED
@@ -22,4 +22,4 @@
22
22
 
23
23
  require_relative '../lib/plotty/command'
24
24
 
25
- Plotty::Command.parse(ARGV).invoke
25
+ Plotty::Command::Top.call
@@ -24,16 +24,14 @@ require_relative 'graph'
24
24
 
25
25
  module Plotty
26
26
  module Command
27
- def self.parse(*args)
28
- Top.parse(*args)
29
- end
30
-
31
27
  class Top < Samovar::Command
32
28
  self.description = "Render graphs by executing commands."
33
29
 
34
30
  options do
31
+ option "-n/--name <string>", "The name of the output plot.", default: "plot"
32
+
35
33
  option "-x <axis>", "Specify the x axis explicitly", default: "1:10"
36
- option "-y <axis>", "Specify the y axis explicitly"
34
+ option "-y <axis>", "Regular expression for the y-axis value."
37
35
 
38
36
  option "-e/--script <script>", "Prepend this script to the gnuplot command."
39
37
 
@@ -41,13 +39,13 @@ module Plotty
41
39
  option '-v/--version', "Print out the application version."
42
40
  end
43
41
 
44
- split :command
42
+ split :command, "The command to execute."
45
43
 
46
44
  def plot_graph
47
- Graph.parse(options[:x], options[:y], @command).plot!(options[:script])
45
+ Graph.parse(options[:x], options[:y], @command).plot!(options[:script], options[:name])
48
46
  end
49
47
 
50
- def invoke(program_name: File.basename($0))
48
+ def call(program_name: File.basename($0))
51
49
  if @options[:version]
52
50
  puts "plotty v#{Teapot::VERSION}"
53
51
  elsif @options[:help] or @command.nil?
@@ -45,6 +45,8 @@ module Plotty
45
45
 
46
46
  def self.parse(command)
47
47
  case command
48
+ when /^(.*?),(.*?)$/
49
+ command.split(',').map(&:to_i)
48
50
  when /^(.*?):\*(.*?):(.*?)$/
49
51
  Scalar.new($1.to_i, $3.to_i, $2.to_i)
50
52
  when /^(.*?):(.*?):(.*?)$/
@@ -57,7 +59,7 @@ module Plotty
57
59
 
58
60
  Function = Struct.new(:pattern, :command, :title) do
59
61
  def self.parse(pattern, command)
60
- pattern = Regexp.new(pattern)
62
+ pattern = Regexp.new(pattern, Regexp::MULTILINE)
61
63
 
62
64
  if command =~ /^(\w+):(.*?)$/
63
65
  self.new(pattern, $2, $1)
@@ -69,7 +71,7 @@ module Plotty
69
71
  def call(value)
70
72
  r, w = IO.pipe
71
73
 
72
- # puts "Running #{@command} with x = #{value}..."
74
+ $stderr.puts "Running #{self.command} with x = #{value}..."
73
75
 
74
76
  pid = Process.spawn({'x' => value.to_s}, self.command, out: w, err: STDERR)
75
77
 
@@ -80,11 +82,13 @@ module Plotty
80
82
  Process.waitpid pid
81
83
 
82
84
  if match = self.pattern.match(buffer)
83
- result = match[1] || match[0]
85
+ $stderr.puts "\tresult = #{match.inspect}"
84
86
 
85
- # puts "\tresult = #{result}"
86
-
87
- return result
87
+ if match.captures.empty?
88
+ return [match[0]]
89
+ else
90
+ return match.captures
91
+ end
88
92
  end
89
93
  end
90
94
  end
@@ -106,8 +110,11 @@ module Plotty
106
110
  TTY::Screen.size.reverse
107
111
  end
108
112
 
109
- def generate_values
110
- File.open("data.txt", "w") do |file|
113
+ def generate_values(name)
114
+ path = name + ".csv"
115
+ values = nil
116
+
117
+ File.open(path, "w") do |file|
111
118
  file.sync = true
112
119
 
113
120
  @x.each do |x|
@@ -115,41 +122,50 @@ module Plotty
115
122
  function.call(x)
116
123
  end
117
124
 
118
- # puts "#{x}: #{values.inspect}"
119
- file.puts "#{x} #{values.join(' ')}"
125
+ file.puts "#{x}, #{values.flatten.join(', ')}"
120
126
  end
121
127
  end
128
+
129
+ return values.map(&:count)
122
130
  end
123
131
 
124
- def generate_plot(path = "plot.gp")
125
- File.open(path, "w") do |file|
126
- yield file if block_given?
127
-
128
- file.write("plot ")
129
- first = true
130
- @y.collect.with_index do |function, index|
131
- if first
132
- first = false
133
- else
134
- file.write ','
132
+ def generate_plot(name, offsets, force = false)
133
+ path = name + ".gp"
134
+
135
+ if !File.exist?(path) or force
136
+ File.open(path, "w") do |file|
137
+ file.puts('set datafile separator ","')
138
+
139
+ yield file if block_given?
140
+
141
+ file.write("plot ")
142
+ first = true
143
+ @y.collect.with_index do |function, index|
144
+ if first
145
+ first = false
146
+ else
147
+ file.write ','
148
+ end
149
+
150
+ file.write "'#{name}.txt' using 1:#{offsets[index]} with lines title #{function.title.dump}"
135
151
  end
136
152
 
137
- file.write "'data.txt' using 1:#{index+2} with lines title #{function.title.dump}"
153
+ file.puts
138
154
  end
139
-
140
- file.puts
141
-
142
- # file.puts "pause 1"
143
- # file.puts "reread"
144
155
  end
145
156
 
146
157
  return path
147
158
  end
148
159
 
149
- def plot!(script = nil)
150
- generate_values
160
+ def plot!(script = nil, name = "plot")
161
+ counts = generate_values(name)
162
+ offsets = [2]
163
+
164
+ counts.each do |count|
165
+ offsets << offsets.last + count
166
+ end
151
167
 
152
- path = generate_plot do |file|
168
+ path = generate_plot(name, offsets) do |file|
153
169
  file.puts script if script
154
170
  end
155
171
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Plotty
22
- VERSION = "0.4.0"
22
+ VERSION = "0.5.0"
23
23
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plotty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-17 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: samovar
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tty-screen
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.16'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.16'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,33 +80,24 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
- description:
83
+ description:
84
84
  email:
85
- - samuel.williams@oriontransfer.co.nz
86
85
  executables:
87
86
  - plotty
88
87
  extensions: []
89
88
  extra_rdoc_files: []
90
89
  files:
91
- - ".gitignore"
92
- - ".rspec"
93
- - ".travis.yml"
94
- - Gemfile
95
- - Gemfile.lock
96
- - README.md
97
- - Rakefile
98
90
  - bin/plotty
99
91
  - lib/plotty.rb
100
92
  - lib/plotty/command.rb
101
93
  - lib/plotty/graph.rb
102
94
  - lib/plotty/version.rb
103
- - plotty.gemspec
104
- - spec/plotty_spec.rb
105
- - spec/spec_helper.rb
106
95
  homepage: https://github.com/ioquatix/plotty
107
- licenses: []
108
- metadata: {}
109
- post_install_message:
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ funding_uri: https://github.com/sponsors/ioquatix/
100
+ post_install_message:
110
101
  rdoc_options: []
111
102
  require_paths:
112
103
  - lib
@@ -121,11 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
112
  - !ruby/object:Gem::Version
122
113
  version: '0'
123
114
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.7.6
126
- signing_key:
115
+ rubygems_version: 3.1.2
116
+ signing_key:
127
117
  specification_version: 4
128
118
  summary: Draw graphs from data gathered by executing commands
129
- test_files:
130
- - spec/plotty_spec.rb
131
- - spec/spec_helper.rb
119
+ test_files: []
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.16.0
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- group :develoment do
6
- gem 'pry'
7
- end
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- plotty (0.4.0)
5
- samovar
6
- tty-screen
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- coderay (1.1.2)
12
- diff-lcs (1.3)
13
- mapping (1.1.1)
14
- method_source (0.9.0)
15
- pry (0.11.3)
16
- coderay (~> 1.1.0)
17
- method_source (~> 0.9.0)
18
- rainbow (2.2.2)
19
- rake
20
- rake (10.5.0)
21
- rspec (3.7.0)
22
- rspec-core (~> 3.7.0)
23
- rspec-expectations (~> 3.7.0)
24
- rspec-mocks (~> 3.7.0)
25
- rspec-core (3.7.1)
26
- rspec-support (~> 3.7.0)
27
- rspec-expectations (3.7.0)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.7.0)
30
- rspec-mocks (3.7.0)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.7.0)
33
- rspec-support (3.7.1)
34
- samovar (1.8.0)
35
- mapping (~> 1.0)
36
- rainbow (~> 2.0)
37
- tty-screen (0.6.4)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- bundler (~> 1.16)
44
- plotty!
45
- pry
46
- rake (~> 10.0)
47
- rspec (~> 3.0)
48
-
49
- BUNDLED WITH
50
- 1.16.1
data/README.md DELETED
@@ -1,168 +0,0 @@
1
- # Plotty
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plotty`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'plotty'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install plotty
22
-
23
- ## Usage
24
-
25
- `plotty` allows you to graph data from commands, e.g.
26
-
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
112
-
113
- ```
114
- wrk -c $x -t $x -d 1 http://localhost:9292 *******
115
- wrk -c $x -t $x -d 1 http://localhost:9293 #######
116
- 800 +--------------------------------------------------------------------+
117
- | + + + + + |
118
- 700 |-+ ################################ +-|
119
- | #### |
120
- 600 |-+ ### +-|
121
- | #### |
122
- | ## |
123
- 500 |-+ ## +-|
124
- | ## |
125
- 400 |-+ # +-|
126
- | ## |
127
- 300 |-+ # +-|
128
- | # |
129
- 200 |-+ # +-|
130
- | # |
131
- | ##******************************************************* |
132
- 100 |-# +-|
133
- |# + + + + + |
134
- 0 +--------------------------------------------------------------------+
135
- 0 50 100 150 200 250 300
136
- ```
137
-
138
- ## Contributing
139
-
140
- 1. Fork it
141
- 2. Create your feature branch (`git checkout -b my-new-feature`)
142
- 3. Commit your changes (`git commit -am 'Add some feature'`)
143
- 4. Push to the branch (`git push origin my-new-feature`)
144
- 5. Create new Pull Request
145
-
146
- ## License
147
-
148
- Released under the MIT license.
149
-
150
- Copyright, 2012, 2014, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
151
-
152
- Permission is hereby granted, free of charge, to any person obtaining a copy
153
- of this software and associated documentation files (the "Software"), to deal
154
- in the Software without restriction, including without limitation the rights
155
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
156
- copies of the Software, and to permit persons to whom the Software is
157
- furnished to do so, subject to the following conditions:
158
-
159
- The above copyright notice and this permission notice shall be included in
160
- all copies or substantial portions of the Software.
161
-
162
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
165
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
166
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
167
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
168
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
7
-
8
- task :console do
9
- require 'pry'
10
- require_relative 'lib/plotty'
11
-
12
- Pry.start
13
- end
@@ -1,24 +0,0 @@
1
-
2
- require_relative "lib/plotty/version"
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "plotty"
6
- spec.version = Plotty::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
-
10
- spec.summary = %q{Draw graphs from data gathered by executing commands}
11
- spec.homepage = "https://github.com/ioquatix/plotty"
12
-
13
- spec.files = `git ls-files`.split($/)
14
- spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
- spec.require_paths = ["lib"]
17
-
18
- spec.add_dependency "samovar"
19
- spec.add_dependency "tty-screen"
20
-
21
- spec.add_development_dependency "bundler", "~> 1.16"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.0"
24
- end
@@ -1,9 +0,0 @@
1
- RSpec.describe Plotty do
2
- it "has a version number" do
3
- expect(Plotty::VERSION).not_to be nil
4
- end
5
-
6
- it "does something useful" do
7
- expect(false).to eq(true)
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- require "bundler/setup"
2
- require "plotty"
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
7
-
8
- # Disable RSpec exposing methods globally on `Module` and `main`
9
- config.disable_monkey_patching!
10
-
11
- config.expect_with :rspec do |c|
12
- c.syntax = :expect
13
- end
14
- end