plotty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e23e114429e1fbd71981ddf4091978cf0e3b1fb
4
+ data.tar.gz: 3b7205cc26a63509e9613b048a805b7ef87e40f5
5
+ SHA512:
6
+ metadata.gz: d2d36080766010086ce0e4e981d86946049c6982406c3b9e43644ebb641c6db0192fb295f4bedabaf1f969f4a3376c10e46348fd3963a3776bb9631588a19854
7
+ data.tar.gz: bc36b92e54ec8baa7b6236afbc11f975b957af1c5b93f5f7b76410bf155a5e167e0442fd8172924adef81e88e99282fe8c9e47ec13cbeb8e0122cfe0fcb9a44a
@@ -0,0 +1,11 @@
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 ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :develoment do
6
+ gem 'pry'
7
+ end
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ plotty (0.1.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.0
@@ -0,0 +1,35 @@
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
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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
+
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
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plotty.
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative '../lib/plotty/command'
24
+
25
+ Plotty::Command.parse(ARGV).invoke
@@ -0,0 +1,3 @@
1
+
2
+ require_relative "plotty/version"
3
+ require_relative "plotty/graph"
@@ -0,0 +1,59 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'samovar'
22
+
23
+ require_relative 'graph'
24
+
25
+ module Plotty
26
+ module Command
27
+ def self.parse(*args)
28
+ Top.parse(*args)
29
+ end
30
+
31
+ class Top < Samovar::Command
32
+ self.description = "Render graphs by executing commands."
33
+
34
+ options do
35
+ option "-x <axis>", "Specify the x axis explicitly", default: "1:10"
36
+ option "-y <axis>", "Specify the y axis explicitly"
37
+
38
+ option '-h/--help', "Print out help information."
39
+ option '-v/--version', "Print out the application version."
40
+ end
41
+
42
+ split :command
43
+
44
+ def plot_graph
45
+ Graph.parse(options[:x], options[:y], @command).plot!
46
+ end
47
+
48
+ def invoke(program_name: File.basename($0))
49
+ if @options[:version]
50
+ puts "plotty v#{Teapot::VERSION}"
51
+ elsif @options[:help] or @command.nil?
52
+ print_usage(program_name)
53
+ else
54
+ plot_graph
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,121 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'samovar'
22
+ require 'tty/screen'
23
+
24
+ module Plotty
25
+ class Sequence
26
+ Linear = Struct.new(:min, :max, :step) do
27
+ def each(&block)
28
+ return to_enum unless block_given?
29
+
30
+ (min..max).step(step, &block)
31
+ end
32
+ end
33
+
34
+ Scalar = Struct.new(:min, :max, :scale) do
35
+ def each
36
+ return to_enum unless block_given?
37
+
38
+ i = min
39
+ while i <= max
40
+ yield i
41
+ i *= scale
42
+ end
43
+ end
44
+ end
45
+
46
+ def self.parse(command)
47
+ case command
48
+ when /^(.*?):\*(.*?):(.*?)$/
49
+ Scalar.new($1.to_i, $3.to_i, $2.to_i)
50
+ when /^(.*?):(.*?):(.*?)$/
51
+ Linear.new($1.to_i, $3.to_i, $2.to_i)
52
+ when command =~ /^(.*?):(.*?)$/
53
+ Linear.new($1.to_i, $2.to_i, 1)
54
+ end
55
+ end
56
+ end
57
+
58
+ class Function
59
+ def initialize(pattern, command)
60
+ @pattern = Regexp.new(pattern)
61
+ @command = command
62
+ end
63
+
64
+ def call(value)
65
+ r, w = IO.pipe
66
+
67
+ puts "Running #{@command} with x = #{value}..."
68
+
69
+ pid = Process.spawn({'x' => value.to_s}, @command, out: w, err: STDERR)
70
+
71
+ w.close
72
+
73
+ buffer = r.read
74
+
75
+ Process.waitpid pid
76
+
77
+ if match = @pattern.match(buffer)
78
+ result = match[1] || match[0]
79
+
80
+ puts "\tresult = #{result}"
81
+
82
+ return result
83
+ end
84
+ end
85
+ end
86
+
87
+ class Graph
88
+ def initialize(x, y)
89
+ @x = x
90
+ @y = y
91
+ end
92
+
93
+ def self.parse(x, y, command)
94
+ self.new(
95
+ Sequence.parse(x),
96
+ Function.new(y, command.first),
97
+ )
98
+ end
99
+
100
+ def size
101
+ TTY::Screen.size.reverse
102
+ end
103
+
104
+ def plot!
105
+ r, w = IO.pipe
106
+
107
+ pid = Process.spawn({'GNUTERM' => 'dumb'}, "gnuplot -p -e \"set terminal dumb #{size.join(' ')}; plot '<cat' with lines notitle\"", in: r, out: STDOUT, err: STDERR)
108
+
109
+ r.close
110
+
111
+ @x.each do |x|
112
+ y = @y.call(x)
113
+ w.puts "#{x} #{y}"
114
+ end
115
+
116
+ w.close
117
+
118
+ Process.waitpid pid
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,3 @@
1
+ module Plotty
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,14 @@
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
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plotty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: samovar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-screen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - samuel.williams@oriontransfer.co.nz
86
+ executables:
87
+ - plotty
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - README.md
97
+ - Rakefile
98
+ - bin/plotty
99
+ - lib/plotty.rb
100
+ - lib/plotty/command.rb
101
+ - lib/plotty/graph.rb
102
+ - lib/plotty/version.rb
103
+ - plotty.gemspec
104
+ - spec/plotty_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/ioquatix/plotty
107
+ licenses: []
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.12
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Draw graphs from data gathered by executing commands
129
+ test_files:
130
+ - spec/plotty_spec.rb
131
+ - spec/spec_helper.rb