plotlyrb 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +9 -4
- data/lib/plotlyrb/plot_image.rb +60 -2
- data/lib/plotlyrb/plotly.rb +4 -0
- data/lib/plotlyrb/response.rb +4 -0
- data/lib/plotlyrb/version.rb +1 -1
- data/plotlyrb.gemspec +1 -1
- metadata +45 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: 800dc5d4e276d7267da72d1ce0b0be54ae07961c0d00c885c9108aee834d62c834037ced8018c2d11c899ca20bac1d1212261d99b566c91e190651c814309afc
|
4
|
+
data.tar.gz: b6915dbeb3231e5743083e004c4dae19ca3ecb95208fba9e30e079234dab1de06336c5aaaa1a9fd2c9720ff305b0d8b2906ee1b2a2aff0e62a373d1b76a45d24
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: d551fc4bd00bacd85645dad7d3487e375fbe6684
|
7
|
+
data.tar.gz: 12ab89f47031615e1d241dbc5aa48a5674746b5b
|
data/README.md
CHANGED
@@ -43,19 +43,18 @@ data = [
|
|
43
43
|
{
|
44
44
|
:x => ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
|
45
45
|
:y => [3, 4, 9],
|
46
|
-
:type => 'scatter'
|
46
|
+
:type => 'scatter',
|
47
47
|
:name => 'Andrew N'
|
48
48
|
}
|
49
49
|
]
|
50
50
|
|
51
51
|
layout = {
|
52
52
|
:xaxis => { :title => 'times' },
|
53
|
-
:yaxis => { :title => 'pokemon caught', :range => [0,
|
53
|
+
:yaxis => { :title => 'pokemon caught', :range => [0, 10] },
|
54
54
|
}
|
55
55
|
|
56
56
|
plot_spec = {
|
57
|
-
:figure => {:data => data},
|
58
|
-
:layout => layout,
|
57
|
+
:figure => {:data => data, :layout => layout},
|
59
58
|
:format => :svg
|
60
59
|
}
|
61
60
|
|
@@ -75,6 +74,12 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
|
|
75
74
|
|
76
75
|
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).
|
77
76
|
|
77
|
+
If `bundle exec rake release` hangs after pushing changes and tags, you may need to kill it and authenticate against rubygems.org before trying again. First, make sure you have a rubygems account and have been added as an owner of the gem. Then you may authenticate from the command line by doing the following (sourced from [stack overflow](http://stackoverflow.com/a/20284960/510722) of course)
|
78
|
+
|
79
|
+
```bash
|
80
|
+
curl -u <rubygems-handle> https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
|
81
|
+
```
|
82
|
+
|
78
83
|
## Contributing
|
79
84
|
|
80
85
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plotlyrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/lib/plotlyrb/plot_image.rb
CHANGED
@@ -22,8 +22,66 @@ module Plotlyrb
|
|
22
22
|
|
23
23
|
request = Net::HTTP::Post.new(ApiV2::IMAGES.path, @headers)
|
24
24
|
request.body = plot_image_spec.to_json
|
25
|
-
response = @https.request(request)
|
26
|
-
IO.binwrite(image_path, response.body)
|
25
|
+
response = Response.from_http_response(@https.request(request))
|
26
|
+
IO.binwrite(image_path, response.body) if response.success
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
30
|
+
SpecPath = Struct.new(:spec, :path)
|
31
|
+
AsyncJobResult = Struct.new(:success, :message, :spec_path)
|
32
|
+
|
33
|
+
class AsyncJob < Struct.new(:thread, :spec_path, :start_time, :timeout)
|
34
|
+
def self.from_spec_path(pi, spec_path, timeout)
|
35
|
+
thread = Thread.new { pi.plot_image(spec_path.spec, spec_path.path) }
|
36
|
+
new(thread, spec_path, Time.new, timeout)
|
37
|
+
end
|
38
|
+
|
39
|
+
def join
|
40
|
+
now = Time.new
|
41
|
+
join_wait = (self.timeout - (now - self.start_time)).to_i + 1
|
42
|
+
|
43
|
+
def fail(msg)
|
44
|
+
AsyncJobResult.new(false, msg, spec_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Joining should bubble any exceptions, so catch them and report the failure as an error
|
48
|
+
begin
|
49
|
+
if thread.join(join_wait).nil?
|
50
|
+
thread.exit
|
51
|
+
return fail("thread didn't finish within timeout (#{timeout}s)")
|
52
|
+
end
|
53
|
+
|
54
|
+
response = thread.value
|
55
|
+
unless response.success
|
56
|
+
return fail("Plotly returned error response: #{response}")
|
57
|
+
end
|
58
|
+
|
59
|
+
unless File.exist?(spec_path.path)
|
60
|
+
return fail("Output file (#{spec_path.path}) not found")
|
61
|
+
end
|
62
|
+
rescue => e
|
63
|
+
return fail(e.message)
|
64
|
+
end
|
65
|
+
|
66
|
+
AsyncJobResult.new(true, '', spec_path)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Given an array of SpecPaths, run each plot_image request in a separate thread, wait timeout
|
71
|
+
# for each, then return AsyncJobResults for any inputs that failed after the given number of
|
72
|
+
# retries
|
73
|
+
def self.plot_images(headers, spec_paths, timeout, retries)
|
74
|
+
raise 'Retries must be an integer >= 0' unless (retries.class == Fixnum && retries >= 0)
|
75
|
+
return [] if spec_paths.empty?
|
76
|
+
|
77
|
+
input_results = spec_paths.map { |sp| AsyncJobResult.new(false, 'not run yet', sp) }
|
78
|
+
(0..retries).to_a.inject(input_results) { |ajrs, _|
|
79
|
+
# While you might be tempted to fuse these map calls, we want all the jobs to get started
|
80
|
+
# before we start joining them, so don't do that.
|
81
|
+
rs = ajrs.map { |ajr| AsyncJob.from_spec_path(PlotImage.new(headers), ajr.spec_path, timeout) }.
|
82
|
+
map(&:join).
|
83
|
+
reject(&:success)
|
84
|
+
}
|
27
85
|
end
|
28
86
|
end
|
29
87
|
end
|
data/lib/plotlyrb/plotly.rb
CHANGED
data/lib/plotlyrb/response.rb
CHANGED
data/lib/plotlyrb/version.rb
CHANGED
data/plotlyrb.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["developers@veitchlister.com.au"]
|
11
11
|
|
12
12
|
spec.summary = %q{A Ruby wrapper around the Plotly RESTful API.}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{Plotly features added as needed. Uses Python Library as a reference https://github.com/plotly/plotly.py/tree/master/plotly/plotly}
|
14
14
|
spec.homepage = "https://github.com/vlc/plotlyrb"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,53 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: plotlyrb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Veitch Lister Consulting
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2017-03-08 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.11'
|
20
|
-
type: :development
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10.0'
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "1.11"
|
34
22
|
type: :development
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rake
|
35
26
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
|
42
|
-
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "10.0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id002
|
34
|
+
description: Plotly features added as needed. Uses Python Library as a reference https://github.com/plotly/plotly.py/tree/master/plotly/plotly
|
35
|
+
email:
|
43
36
|
- developers@veitchlister.com.au
|
44
37
|
executables: []
|
45
|
-
|
38
|
+
|
39
|
+
extensions:
|
46
40
|
- ext/mkrf_conf.rb
|
47
41
|
extra_rdoc_files: []
|
48
|
-
|
49
|
-
|
50
|
-
-
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .ruby-version
|
51
46
|
- CODE_OF_CONDUCT.md
|
52
47
|
- Gemfile
|
53
48
|
- Gemfile.lock
|
@@ -67,28 +62,31 @@ files:
|
|
67
62
|
- lib/plotlyrb/version.rb
|
68
63
|
- plotlyrb.gemspec
|
69
64
|
homepage: https://github.com/vlc/plotlyrb
|
70
|
-
licenses:
|
65
|
+
licenses:
|
71
66
|
- MIT
|
72
|
-
metadata:
|
67
|
+
metadata:
|
73
68
|
allowed_push_host: https://rubygems.org
|
74
69
|
post_install_message:
|
75
70
|
rdoc_options: []
|
76
|
-
|
71
|
+
|
72
|
+
require_paths:
|
77
73
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
80
76
|
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
77
|
+
- !ruby/object:Gem::Version
|
82
78
|
version: 1.8.7
|
83
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
85
81
|
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
88
84
|
requirements: []
|
85
|
+
|
89
86
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.0.17
|
91
88
|
signing_key:
|
92
89
|
specification_version: 4
|
93
90
|
summary: A Ruby wrapper around the Plotly RESTful API.
|
94
91
|
test_files: []
|
92
|
+
|