gem_velocity 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -2
- data/TODO +7 -22
- data/lib/gem_velocity/gem_data.rb +15 -25
- data/lib/gem_velocity/gruff_builder.rb +3 -1
- data/lib/gem_velocity/velocitators/aggregated_velocitator.rb +48 -0
- data/lib/gem_velocity/velocitators/all.rb +1 -0
- data/lib/gem_velocity/velocitators/base_velocitator.rb +60 -19
- data/lib/gem_velocity/velocitators/multiple_velocitator.rb +5 -10
- data/lib/gem_velocity/velocitators/single_velocitator.rb +18 -6
- data/lib/gem_velocity/version.rb +1 -1
- data/spec/gem_data_spec.rb +3 -2
- data/spec/gruff_builder_spec.rb +1 -0
- data/spec/no_time_cop_spec.rb +42 -3
- data/spec/spec_helper.rb +11 -8
- data/spec/velocitator_spec.rb +108 -38
- metadata +5 -4
data/README.md
CHANGED
@@ -4,6 +4,14 @@ A way to see gem velocity. Right now it's just aggregated totals.
|
|
4
4
|
|
5
5
|
So, not a number of downloads each day, but rather just the general timeline of total downloads.
|
6
6
|
|
7
|
+
## Note
|
8
|
+
|
9
|
+
The data is currently somewhat incorrect, due to inconstancies outlined in:
|
10
|
+
|
11
|
+
[https://gist.github.com/shaiguitar/d2af997b7f58e24fd305](https://gist.github.com/shaiguitar/d2af997b7f58e24fd305)
|
12
|
+
|
13
|
+
I'm investigating though with the help of the rubygems team as per [this](https://github.com/rubygems/rubygems.org/pull/606) and will hopefully have some progress soon.
|
14
|
+
|
7
15
|
## Requirements
|
8
16
|
|
9
17
|
It draws graphs. So...you'll need imagemagick/rmagick. I'm sure you'll survive. Any problems with installation let me know and I'll try to help out.
|
@@ -15,7 +23,7 @@ Here's one: [celluloid](https://gist.github.com/shaiguitar/7e6d95971c5254fa3665)
|
|
15
23
|
Here's some more:
|
16
24
|
|
17
25
|
<pre>
|
18
|
-
velocitator =
|
26
|
+
velocitator = MultipleVelocitator.new("rails", ["4.0.0","3.2.14","2.3.5"])
|
19
27
|
file = velocitator.graph("/tmp")
|
20
28
|
</pre>
|
21
29
|
|
@@ -26,7 +34,7 @@ Produces:
|
|
26
34
|
Notice the date range:
|
27
35
|
|
28
36
|
<pre>
|
29
|
-
velocitator =
|
37
|
+
velocitator = MultipleVelocitator.new("rails", ["4.0.0","3.2.14","0.9.1"])
|
30
38
|
file = velocitator.graph("/tmp", [3.months.ago, Time.now])
|
31
39
|
</pre>
|
32
40
|
|
data/TODO
CHANGED
@@ -1,29 +1,14 @@
|
|
1
|
-
|
2
|
-
change readme.md to have one example with different options to populate
|
3
|
-
Add an aggregate method to add #graph for a point version? (e.g, 0.n.x graph for all n versions. maybe just major, maybe minor, whatever).
|
4
|
-
|
5
|
-
web ui/embeddable links with those images.
|
1
|
+
Web ui/embeddable links with those images.
|
6
2
|
can't remove images
|
7
3
|
have uniq name: hash the date_range,max,min,name,versions. (and time?)
|
8
4
|
shard the directories of where the image goes so it doesn't bomb out?
|
9
5
|
|
10
|
-
|
11
|
-
SingleVersionsVelocitator has a shortcut for displaying all versions in a major?
|
12
|
-
MajorVersionsVelocitator takes one major version
|
13
|
-
AllVersionsVelocitator takes no version, dispalys all stats
|
14
|
-
|
15
|
-
I want to be able to have a line be one version, or a few versions in one, mix those/not, then decide to display them in the end
|
16
|
-
line_datas needs to be abstracted away. actually the versions concepts should be eliminated??
|
17
|
-
so I need to have something abstract a version but it could be a few of them...
|
18
|
-
move all the logic of changing version -> line_data into something and have that able to handle 1 or n.
|
19
|
-
|
20
|
-
the only thing that it implmeents is .graph() which returns the line_data result/info whatever.
|
21
|
-
then there's something in the middle that takes that and calls out to gruff builder.
|
22
|
-
|
6
|
+
Add a Version?
|
23
7
|
|
24
|
-
|
8
|
+
currently, the versions in the base class are single versions, but they are essentially used for representing a specific line
|
9
|
+
in default_line_datas.
|
10
|
+
(and then used for titles, abd bs).
|
25
11
|
|
26
|
-
|
27
|
-
n times whatever.
|
12
|
+
if rubygems 606 isn't solved, why not just put a total on there and let the inconsistnecies just be with some notice?
|
28
13
|
|
29
|
-
|
14
|
+
rename time_format_str_small alias
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'gems'
|
2
2
|
|
3
3
|
class GemData
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
attr_reader :gem_name
|
6
|
+
|
7
|
+
def initialize(gem_name)
|
8
|
+
@gem_name = gem_name
|
6
9
|
end
|
7
10
|
|
8
11
|
def versions
|
@@ -15,28 +18,9 @@ class GemData
|
|
15
18
|
h
|
16
19
|
end
|
17
20
|
|
18
|
-
# todo rename method? aggregated downloads per day
|
19
|
-
def downloads_day(version, start_time = nil, end_time = Time.now)
|
20
|
-
start_time = start_time || versions_built_at[version]
|
21
|
-
total_so_far = 0
|
22
|
-
found_first_download = false
|
23
|
-
ret = downloads_metadata(version, start_time, end_time).map do |day,downloads_that_day|
|
24
|
-
if found_first_download
|
25
|
-
total_so_far += downloads_that_day
|
26
|
-
[day, total_so_far]
|
27
|
-
else
|
28
|
-
if !downloads_that_day.zero?
|
29
|
-
found_first_download = true
|
30
|
-
total_so_far += downloads_that_day
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end.compact
|
35
|
-
end
|
36
|
-
|
37
21
|
def versions_metadata
|
38
22
|
# cache api call.
|
39
|
-
@versions_metadata ||= Gems.versions(
|
23
|
+
@versions_metadata ||= Gems.versions(gem_name)
|
40
24
|
# it should be a hash
|
41
25
|
if @versions_metadata.is_a?(String)
|
42
26
|
if @versions_metadata.match(/This rubygem could not be found/)
|
@@ -46,13 +30,19 @@ class GemData
|
|
46
30
|
@versions_metadata
|
47
31
|
end
|
48
32
|
|
49
|
-
|
33
|
+
def total_for_version(version)
|
34
|
+
@total_for_version ||= {}
|
35
|
+
key = "#{version}"
|
36
|
+
return @total_for_version[key] if @total_for_version[key]
|
37
|
+
@total_for_version[key] ||= Gems.total_downloads(gem_name, version)
|
38
|
+
end
|
50
39
|
|
51
40
|
def downloads_metadata(version, start_time, end_time)
|
52
41
|
# cache api call.
|
53
42
|
@downloads_metadata ||= {}
|
54
|
-
|
55
|
-
@downloads_metadata[
|
43
|
+
key = "#{version}-#{start_time}-#{end_time}"
|
44
|
+
return @downloads_metadata[key] if @downloads_metadata[key]
|
45
|
+
@downloads_metadata[key] ||= Gems.downloads(gem_name, version, start_time, end_time).to_a
|
56
46
|
end
|
57
47
|
|
58
48
|
|
@@ -11,7 +11,7 @@ class GruffBuilder
|
|
11
11
|
MAX_VALUE = 300
|
12
12
|
|
13
13
|
attr_accessor :root, :relative_path, :versions, :gem_name
|
14
|
-
attr_accessor :title, :labels, :line_datas, :min_value, :max_value
|
14
|
+
attr_accessor :title, :labels, :line_datas, :min_value, :max_value, :hide_legend
|
15
15
|
|
16
16
|
def initialize(root, relative_path, versions, gem_name, gruff_options = {})
|
17
17
|
@root = root || raise(ArgumentError,"you must set a root. default is root/public/images")
|
@@ -23,6 +23,7 @@ class GruffBuilder
|
|
23
23
|
@line_datas = gruff_options[:line_datas]
|
24
24
|
@min_value = gruff_options[:min_value] || MIN_VALUE
|
25
25
|
@max_value = gruff_options[:max_value] || MAX_VALUE
|
26
|
+
@hide_legend = gruff_options[:hide_legend] || false
|
26
27
|
end
|
27
28
|
|
28
29
|
def relative_filename
|
@@ -47,6 +48,7 @@ class GruffBuilder
|
|
47
48
|
end
|
48
49
|
gruff.minimum_value = @min_value
|
49
50
|
gruff.maximum_value = @max_value
|
51
|
+
gruff.hide_legend = @hide_legend
|
50
52
|
gruff.write(absolute_filename)
|
51
53
|
absolute_filename
|
52
54
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class AggregatedVelocitator < BaseVelocitator
|
2
|
+
|
3
|
+
attr_reader :aggregated_versions
|
4
|
+
def initialize(gem_name, top_level_ver)
|
5
|
+
@gem_name = gem_name
|
6
|
+
@top_level_ver = top_level_ver
|
7
|
+
@aggregated_versions = gem_data.versions.select{|v| v.match(/^#{Regexp.escape(top_level_ver)}/) }
|
8
|
+
super(gem_name, @aggregated_versions)
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_start
|
12
|
+
base_earliest_time_for(@aggregated_versions)
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_max_value
|
16
|
+
base_max_for(@aggregated_versions) * @aggregated_versions.size
|
17
|
+
end
|
18
|
+
|
19
|
+
def graph_options
|
20
|
+
opts = {
|
21
|
+
:title => title,
|
22
|
+
:labels => ({1 => time_format_str_small(effective_start_time), (line_datas.first.size-2) => time_format_str_small(effective_end_time) }),
|
23
|
+
:max_value => effective_max_value,
|
24
|
+
:min_value => effective_min_value,
|
25
|
+
:line_datas => line_datas,
|
26
|
+
:hide_legend => true
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def line_datas
|
31
|
+
ret = Hash.new(0)
|
32
|
+
@aggregated_versions.each do |v|
|
33
|
+
effective_days_in_range.each do |d|
|
34
|
+
ret[d] += downloads_per_day(v)[d] || 0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
[effective_days_in_range.map{|d| ret[d] }]
|
38
|
+
end
|
39
|
+
|
40
|
+
def title
|
41
|
+
"#{@gem_name}: #{@top_level_ver}X"
|
42
|
+
end
|
43
|
+
|
44
|
+
def totals
|
45
|
+
super.map {|x| x[:version_downloads]}.sum
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -15,15 +15,30 @@ class BaseVelocitator
|
|
15
15
|
gruff_builder.write
|
16
16
|
end
|
17
17
|
|
18
|
-
# modifiers on the end result image being rendered.
|
18
|
+
# modifiers on the end result image being rendered. Essentially these are the boundries
|
19
|
+
# of the graph
|
19
20
|
attr_reader :date_range, :max_value, :min_value, :root
|
20
|
-
def date_range=(args); @
|
21
|
-
def max_value=(max); @
|
22
|
-
def min_value=(min); @
|
21
|
+
def date_range=(args); @passed_date_range = args && args.map{|t| time_format_str(t) } ;end
|
22
|
+
def max_value=(max); @passed_max_value = max ;end
|
23
|
+
def min_value=(min); @passed_min_value = min ;end
|
23
24
|
def root=(path); @root = path ;end
|
24
25
|
|
25
26
|
def effective_date_range
|
26
|
-
@
|
27
|
+
@passed_date_range || default_date_range
|
28
|
+
end
|
29
|
+
|
30
|
+
def effective_max_value
|
31
|
+
@passed_max_value || default_max_value
|
32
|
+
end
|
33
|
+
|
34
|
+
def effective_min_value
|
35
|
+
@passed_min_value || default_min_value
|
36
|
+
end
|
37
|
+
|
38
|
+
def totals
|
39
|
+
versions.map do |v|
|
40
|
+
gem_data.total_for_version(v)
|
41
|
+
end
|
27
42
|
end
|
28
43
|
|
29
44
|
private
|
@@ -46,8 +61,6 @@ class BaseVelocitator
|
|
46
61
|
gem_data.versions_metadata
|
47
62
|
end
|
48
63
|
|
49
|
-
# if it's nil, the defaults will be used
|
50
|
-
# basically these are the graph boundries
|
51
64
|
def set_overwritable_attrs(root_arg,range,min,max)
|
52
65
|
self.date_range = range
|
53
66
|
self.root = root_arg
|
@@ -59,32 +72,60 @@ class BaseVelocitator
|
|
59
72
|
default_end = time_format_str(Time.now)
|
60
73
|
end
|
61
74
|
|
75
|
+
def default_date_range
|
76
|
+
[ default_start, default_end ]
|
77
|
+
end
|
78
|
+
|
62
79
|
def default_min_value
|
63
80
|
0
|
64
81
|
end
|
65
82
|
|
66
83
|
def default_line_datas
|
67
|
-
# refactor me?
|
68
84
|
versions.map do |v|
|
69
|
-
|
70
|
-
|
71
|
-
if gem_data.downloads_day(v).map {|day,total| day}.include?(day_in_range)
|
72
|
-
# get the total for that day
|
73
|
-
total = Hash[gem_data.downloads_day(v)][day_in_range]
|
74
|
-
else
|
75
|
-
0
|
76
|
-
end
|
85
|
+
effective_days_in_range.map do |d|
|
86
|
+
downloads_per_day(v)[d] || 0
|
77
87
|
end
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
91
|
+
def base_earliest_time_for(verzionz)
|
92
|
+
earliest_start = verzionz.map{|v| Date.parse(time_built(v)) }.min
|
93
|
+
default_start = time_format_str(earliest_start)
|
94
|
+
end
|
95
|
+
|
96
|
+
def base_max_for(verzionz)
|
97
|
+
totals = []
|
98
|
+
verzionz.each {|v|
|
99
|
+
totals << downloads_per_day(v).map {|day,total| total}
|
100
|
+
}
|
101
|
+
totals.flatten.compact.max
|
102
|
+
end
|
103
|
+
|
104
|
+
def downloads_per_day(version)
|
105
|
+
# returns # "2013-10-10" => 45
|
106
|
+
accumulated_downloads_per_day(version)
|
107
|
+
end
|
108
|
+
|
109
|
+
def accumulated_downloads_per_day(version)
|
110
|
+
# downloads_metadata comes back ordered by date
|
111
|
+
ret = Hash.new(0)
|
112
|
+
gem_data.downloads_metadata(version, default_start, default_end).each_cons(2) do |p,n|
|
113
|
+
#day,total pairs
|
114
|
+
curr_total = n.last
|
115
|
+
day = n.first
|
116
|
+
previous_day = p.first
|
117
|
+
ret[day] = curr_total + ret[previous_day]
|
118
|
+
end
|
119
|
+
ret
|
120
|
+
end
|
121
|
+
|
81
122
|
# a little sugar
|
82
123
|
def effective_start_time; effective_date_range.first ;end
|
83
124
|
def effective_end_time; effective_date_range.last ;end
|
84
125
|
|
85
126
|
# helper method to convert [start,end] into a
|
86
|
-
# start..end range of
|
87
|
-
def
|
127
|
+
# start..end range of days like "2013-10-10"
|
128
|
+
def effective_days_in_range
|
88
129
|
all_days = []
|
89
130
|
s = Date.parse(effective_start_time)
|
90
131
|
e = Date.parse(effective_end_time)
|
@@ -93,7 +134,7 @@ class BaseVelocitator
|
|
93
134
|
all_days << i
|
94
135
|
i += 1.day
|
95
136
|
end
|
96
|
-
all_days
|
137
|
+
all_days.map{|d| time_format_str_small(d)}
|
97
138
|
end
|
98
139
|
|
99
140
|
def gem_data
|
@@ -5,24 +5,19 @@ class MultipleVelocitator < BaseVelocitator
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def default_start
|
8
|
-
|
9
|
-
default_start = time_format_str(earliest_start)
|
8
|
+
base_earliest_time_for(versions)
|
10
9
|
end
|
11
10
|
|
12
11
|
def default_max_value
|
13
|
-
|
14
|
-
versions.each {|v|
|
15
|
-
totals << gem_data.downloads_day(v).map {|day,total| total}
|
16
|
-
}
|
17
|
-
totals.flatten.compact.max
|
12
|
+
base_max_for(versions)
|
18
13
|
end
|
19
14
|
|
20
15
|
def graph_options
|
21
16
|
opts = {
|
22
17
|
:title => title,
|
23
18
|
:labels => ({1 => time_format_str_small(effective_start_time), (line_datas.first.size-2) => time_format_str_small(effective_end_time) }),
|
24
|
-
:max_value =>
|
25
|
-
:min_value =>
|
19
|
+
:max_value => effective_max_value,
|
20
|
+
:min_value => effective_min_value,
|
26
21
|
:line_datas => line_datas
|
27
22
|
}
|
28
23
|
end
|
@@ -32,7 +27,7 @@ class MultipleVelocitator < BaseVelocitator
|
|
32
27
|
end
|
33
28
|
|
34
29
|
def title
|
35
|
-
"
|
30
|
+
"#{gem_name}"
|
36
31
|
end
|
37
32
|
|
38
33
|
|
@@ -1,25 +1,33 @@
|
|
1
1
|
class SingleVelocitator < BaseVelocitator
|
2
2
|
|
3
|
+
attr_reader :version
|
4
|
+
|
3
5
|
def initialize(gem_name, version)
|
4
6
|
@version = version
|
5
7
|
super(gem_name, [version])
|
6
8
|
end
|
7
9
|
|
8
10
|
def default_start
|
9
|
-
time_format_str(Date.parse(time_built
|
11
|
+
time_format_str(Date.parse(time_built))
|
12
|
+
end
|
13
|
+
|
14
|
+
def time_built
|
15
|
+
super(@version)
|
10
16
|
end
|
11
17
|
|
12
18
|
def default_max_value
|
13
|
-
|
19
|
+
accumulated_downloads_per_day(@version).map {|day,total| total}.max
|
14
20
|
end
|
15
21
|
|
16
22
|
def graph_options
|
17
23
|
opts = {
|
18
24
|
:title => title,
|
25
|
+
# todo change the -2 to -4? so if ifits in? if it's abvoe 4 fcors
|
19
26
|
:labels => ({1 => time_format_str_small(effective_start_time), (line_datas.first.size-2) => time_format_str_small(effective_end_time) }),
|
20
|
-
:max_value =>
|
21
|
-
:min_value =>
|
22
|
-
:line_datas => line_datas
|
27
|
+
:max_value => effective_max_value,
|
28
|
+
:min_value => effective_min_value,
|
29
|
+
:line_datas => line_datas,
|
30
|
+
:hide_legend => true
|
23
31
|
}
|
24
32
|
end
|
25
33
|
|
@@ -28,7 +36,11 @@ class SingleVelocitator < BaseVelocitator
|
|
28
36
|
end
|
29
37
|
|
30
38
|
def title
|
31
|
-
"
|
39
|
+
"#{gem_name}-#{version}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def totals
|
43
|
+
super.first
|
32
44
|
end
|
33
45
|
|
34
46
|
end
|
data/lib/gem_velocity/version.rb
CHANGED
data/spec/gem_data_spec.rb
CHANGED
@@ -10,8 +10,9 @@ describe GemData do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "can show download information" do
|
13
|
-
|
14
|
-
result
|
13
|
+
gem_data = GemData.new("haml-i18n-extractor")
|
14
|
+
result = gem_data.downloads_metadata("0.0.17", gem_data.versions_built_at["0.0.17"],Time.now)
|
15
|
+
result.should == [["2013-06-16", 38], ["2013-06-17", 16], ["2013-06-18", 3], ["2013-06-19", 1], ["2013-06-20", 4], ["2013-06-21", 1], ["2013-06-22", 5], ["2013-06-23", 2], ["2013-06-24", 3], ["2013-06-25", 9], ["2013-06-26", 161], ["2013-06-27", 3], ["2013-06-28", 2], ["2013-06-29", 0], ["2013-06-30", 0], ["2013-07-01", 0], ["2013-07-02", 7], ["2013-07-03", 3], ["2013-07-04", 2], ["2013-07-05", 0], ["2013-07-06", 3], ["2013-07-07", 0], ["2013-07-08", 2], ["2013-07-09", 1], ["2013-07-10", 2], ["2013-07-11", 3], ["2013-07-12", 2], ["2013-07-13", 1], ["2013-07-14", 0], ["2013-07-15", 2], ["2013-07-16", 2], ["2013-07-17", 6], ["2013-07-18", 0], ["2013-07-19", 3], ["2013-07-20", 1], ["2013-07-21", 0], ["2013-07-22", 2], ["2013-07-23", 1], ["2013-07-24", 6], ["2013-07-25", 0], ["2013-07-26", 0], ["2013-07-27", 0], ["2013-07-28", 0], ["2013-07-29", 1], ["2013-07-30", 2], ["2013-07-31", 2], ["2013-08-01", 0], ["2013-08-02", 0], ["2013-08-03", 0], ["2013-08-04", 0], ["2013-08-05", 2], ["2013-08-06", 0], ["2013-08-07", 0], ["2013-08-08", 3], ["2013-08-09", 0], ["2013-08-10", 0], ["2013-08-11", 0], ["2013-08-12", 1], ["2013-08-13", 2], ["2013-08-14", 1], ["2013-08-15", 2], ["2013-08-16", 0], ["2013-08-17", 1], ["2013-08-18", 0], ["2013-08-19", 0], ["2013-08-20", 0], ["2013-08-21", 1], ["2013-08-22", 2], ["2013-08-23", 4], ["2013-08-24", 0], ["2013-08-25", 1], ["2013-08-26", 0], ["2013-08-27", 2], ["2013-08-28", 0], ["2013-08-29", 2], ["2013-08-30", 0], ["2013-08-31", 0], ["2013-09-01", 2], ["2013-09-02", 2], ["2013-09-03", 1], ["2013-09-04", 0], ["2013-09-05", 2], ["2013-09-06", 2], ["2013-09-07", 0], ["2013-09-08", 0], ["2013-09-09", 1], ["2013-09-10", 0], ["2013-09-11", 0], ["2013-09-12", 5], ["2013-09-13", 0], ["2013-09-14", 0], ["2013-09-15", 0], ["2013-09-16", 1], ["2013-09-17", 0], ["2013-09-18", 0], ["2013-09-19", 1], ["2013-09-20", 1]]
|
15
16
|
end
|
16
17
|
|
17
18
|
|
data/spec/gruff_builder_spec.rb
CHANGED
data/spec/no_time_cop_spec.rb
CHANGED
@@ -5,16 +5,55 @@ describe 'with no time stubbing', :do_not_use_time_cop do
|
|
5
5
|
# hax slow internet connections make this slow.
|
6
6
|
if ENV['VELOCITATOR_REAL_LONG']
|
7
7
|
it "has a shortcut graph method #1" do
|
8
|
-
velocitator =
|
8
|
+
velocitator = SingleVelocitator.new("rails", "2.3.5")
|
9
|
+
# WTF all is shit
|
10
|
+
# https://rubygems.org/gems/rails/versions/2.3.5
|
11
|
+
# should be close to 1m!!
|
12
|
+
#
|
13
|
+
# gb = velocitator.send(:gruff_builder)
|
14
|
+
# gb.line_datas.first.index{|z| z.nonzero?}
|
15
|
+
# => 1199
|
16
|
+
# gb.line_datas.first.size #[1199]
|
17
|
+
# => 1417
|
18
|
+
# 1417 - 1199
|
19
|
+
# => 218
|
20
|
+
#
|
21
|
+
# velocitator.send(:gem_data).send(:downloads_metadata, velocitator.versions.first,velocitator.effective_date_range.first, velocitator.effective_date_range.last).size
|
22
|
+
# => 1417
|
23
|
+
# velocitator.send(:gem_data).downloads_day(velocitator.versions.first,velocitator.effective_date_range.first, velocitator.effective_date_range.last).size
|
24
|
+
# => 218
|
25
|
+
# x = Gems.downloads(velocitator.gem_name, velocitator.versions.first, velocitator.effective_date_range.first, velocitator.effective_date_range.last)
|
26
|
+
# x.to_a.index{|z| z.last.nonzero?}
|
27
|
+
# => 1198
|
28
|
+
velocitator = SingleVelocitator.new("rails", "2.3.5")
|
29
|
+
#x.to_a.index{|z| z.last.nonzero?}
|
30
|
+
#binding.pry
|
9
31
|
file = velocitator.graph("/tmp")
|
10
|
-
|
32
|
+
raise 'wtf'
|
11
33
|
end
|
12
34
|
|
13
35
|
it "has a shortcut graph method #2" do
|
14
|
-
velocitator =
|
36
|
+
velocitator = MultipleVelocitator.new("rails", ["4.0.0","3.2.14","0.9.1"])
|
15
37
|
file = velocitator.graph("/tmp", [3.months.ago, Time.now])
|
16
38
|
File.exist?(file).should be_true
|
17
39
|
end
|
40
|
+
|
41
|
+
it "has a shortcut graph method #3" do
|
42
|
+
velocitator = AggregatedVelocitator.new("rails", "4")
|
43
|
+
puts velocitator.versions
|
44
|
+
puts velocitator.totals.inspect
|
45
|
+
file = velocitator.graph("/tmp")
|
46
|
+
File.exist?(file).should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has a shortcut graph method #4" do
|
50
|
+
velocitator = AggregatedVelocitator.new("haml-i18n-extractor", "0") # all of it
|
51
|
+
puts velocitator.aggregated_versions
|
52
|
+
puts velocitator.versions
|
53
|
+
file = velocitator.graph("/tmp")
|
54
|
+
puts file.inspect
|
55
|
+
File.exist?(file).should be_true
|
56
|
+
end
|
18
57
|
end
|
19
58
|
|
20
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,6 +19,17 @@ end
|
|
19
19
|
|
20
20
|
RSpec.configure do |c|
|
21
21
|
c.treat_symbols_as_metadata_keys_with_true_values = true
|
22
|
+
|
23
|
+
c.around(:each) do |example|
|
24
|
+
example_hashified = example.metadata[:description_args].first.unpack("s").first
|
25
|
+
puts "\nRunning example: #{example.metadata[:description_args]}\n"
|
26
|
+
orig_time = Time.now
|
27
|
+
VCR.use_cassette("rspec-example-#{(example_hashified)}") do
|
28
|
+
example.run
|
29
|
+
end
|
30
|
+
puts "finished in ~#{Time.now.to_i - orig_time.to_i}s"
|
31
|
+
end
|
32
|
+
|
22
33
|
c.around(:each) do |example|
|
23
34
|
#freeze time unless explicitly said not to!
|
24
35
|
unless example.metadata[:do_not_use_time_cop]
|
@@ -31,14 +42,6 @@ RSpec.configure do |c|
|
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
34
|
-
c.around(:each) do |example|
|
35
|
-
example_hashified = example.metadata[:description_args].first.unpack("s").first
|
36
|
-
puts "\nRunning example: #{example.metadata[:description_args]}\n"
|
37
|
-
VCR.use_cassette("rspec-example-#{(example_hashified)}") do
|
38
|
-
example.run
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
45
|
c.after(:suite) do
|
43
46
|
FileUtils.rm_rf(SpecHelper.tmpdir)
|
44
47
|
end
|
data/spec/velocitator_spec.rb
CHANGED
@@ -1,7 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
# https://github.com/shaiguitar/rubygems.org/compare/api_not_returning_all_results_over_90_days?expand=1
|
4
|
+
|
5
|
+
describe "a Velocitator rendering graphs" do
|
6
|
+
|
7
|
+
# testing single_velocitator is enough to test base
|
8
|
+
it "can render a graph" do
|
9
|
+
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
10
|
+
velocitator.date_range = [ 7.days.ago, 3.days.ago ]
|
11
|
+
velocitator.root = SpecHelper.tmpdir
|
12
|
+
|
13
|
+
# Plausible to change this?
|
14
|
+
# the values for the two days mentioned in the date range.
|
15
|
+
# should this be the specific date range values?? aggregated since when? not aggregated?
|
16
|
+
velocitator.graph_options[:line_datas].should == [[303, 303, 303, 304, 304]]
|
17
|
+
|
18
|
+
velocitator.graph_options[:title].should == "haml-i18n-extractor-0.0.17"
|
19
|
+
velocitator.graph_options[:labels].should == ({1=>"2013-09-13", (velocitator.line_datas.first.size-2) =>"2013-09-17"})
|
20
|
+
velocitator.graph_options[:max_value].should == 306 # the max in the range (time.now)
|
21
|
+
velocitator.graph_options[:min_value].should == 0
|
22
|
+
|
23
|
+
file = velocitator.graph
|
24
|
+
File.exist?(file).should be_true
|
25
|
+
#`open #{file} -a preview.app`
|
26
|
+
#Kernel.sleep(10)
|
27
|
+
end
|
4
28
|
|
29
|
+
it "has a shortcut graph method #1" do
|
30
|
+
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
31
|
+
file = velocitator.graph(SpecHelper.tmpdir,[1.day.ago, Time.now])
|
32
|
+
File.exist?(file).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a shortcut graph method #2" do
|
36
|
+
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
37
|
+
file = velocitator.graph
|
38
|
+
File.exist?(file).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has a shortcut graph metho #3" do
|
42
|
+
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
43
|
+
file = velocitator.graph(nil,nil,0,1000)
|
44
|
+
File.exist?(file).should be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe SingleVelocitator do
|
5
49
|
it 'raises if you dont pass name and version(s)' do
|
6
50
|
lambda { SingleVelocitator.new(nil,nil) }.should raise_error ArgumentError
|
7
51
|
end
|
@@ -14,6 +58,12 @@ describe SingleVelocitator do
|
|
14
58
|
lambda { SingleVelocitator.new("haml-i18n-extractor","100.999.42.666.pre") }.should raise_error NoSuchVersion
|
15
59
|
end
|
16
60
|
|
61
|
+
it "holds the totals of the gem" do
|
62
|
+
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
63
|
+
velocitator.totals.should == {:total_downloads=>5355, :version_downloads=>377}
|
64
|
+
#binding.pry
|
65
|
+
end
|
66
|
+
|
17
67
|
it "sets a specific date range according to the gem's info" do
|
18
68
|
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
19
69
|
velocitator.effective_date_range.should eq ["2013-06-16T00:00:00Z", "2013-09-20T00:00:00Z"]
|
@@ -38,46 +88,11 @@ describe SingleVelocitator do
|
|
38
88
|
velocitator.line_datas.size.should eq (velocitator.versions.size)
|
39
89
|
end
|
40
90
|
|
41
|
-
it "can render a graph" do
|
42
|
-
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
43
|
-
velocitator.date_range = [1.day.ago, Time.now]
|
44
|
-
velocitator.root = SpecHelper.tmpdir
|
45
|
-
# FIX spec don't call out to gruff_builder, check the specific attrs in graph_options or such.
|
46
|
-
builder = velocitator.gruff_builder
|
47
|
-
# https://github.com/shaiguitar/rubygems.org/compare/api_not_returning_all_results_over_90_days?expand=1
|
48
|
-
builder.line_datas.should == [[343, 344]]
|
49
|
-
builder.title.should == "haml-i18n-extractor-0.0.17"
|
50
|
-
builder.labels.should == ({1=>"2013-09-19", (builder.line_datas.first.size-2) =>"2013-09-20"})
|
51
|
-
builder.max_value.should == 344
|
52
|
-
builder.min_value.should == 0
|
53
|
-
|
54
|
-
file = builder.write
|
55
|
-
File.exist?(file).should be_true
|
56
|
-
#`open #{file} -a preview.app`
|
57
|
-
#Kernel.sleep(10)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "has a shortcut graph method #1" do
|
61
|
-
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
62
|
-
file = velocitator.graph(SpecHelper.tmpdir,[1.day.ago, Time.now])
|
63
|
-
File.exist?(file).should be_true
|
64
|
-
end
|
65
|
-
|
66
|
-
it "has a shortcut graph method #2" do
|
67
|
-
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
68
|
-
file = velocitator.graph
|
69
|
-
File.exist?(file).should be_true
|
70
|
-
end
|
71
|
-
|
72
|
-
it "has a shortcut graph metho #3" do
|
73
|
-
velocitator = SingleVelocitator.new("haml-i18n-extractor", "0.0.17")
|
74
|
-
file = velocitator.graph(nil,nil,0,1000)
|
75
|
-
File.exist?(file).should be_true
|
76
|
-
end
|
77
91
|
end
|
78
92
|
|
93
|
+
|
79
94
|
describe MultipleVelocitator do
|
80
|
-
before do
|
95
|
+
before do
|
81
96
|
@some_versions = ["0.0.17", "0.0.5","0.0.10"]
|
82
97
|
end
|
83
98
|
|
@@ -86,6 +101,11 @@ describe MultipleVelocitator do
|
|
86
101
|
velocitator.versions.should == @some_versions
|
87
102
|
end
|
88
103
|
|
104
|
+
it "holds the totals of the gem" do
|
105
|
+
velocitator = MultipleVelocitator.new("haml-i18n-extractor", ["0.0.17"])
|
106
|
+
velocitator.totals.should eq [{:total_downloads=>5355, :version_downloads=>377}]
|
107
|
+
end
|
108
|
+
|
89
109
|
it "sets the earliest start range from to all of the versions info" do
|
90
110
|
# some_versions.map{|v| GemData.new("haml-i18n-extractor").versions_built_at[v]}
|
91
111
|
# => ["2013-06-16T00:00:00Z", "2013-03-22T00:00:00Z", "2013-05-06T00:00:00Z"]
|
@@ -117,3 +137,53 @@ describe MultipleVelocitator do
|
|
117
137
|
end
|
118
138
|
end
|
119
139
|
|
140
|
+
describe AggregatedVelocitator do
|
141
|
+
before do
|
142
|
+
@gem_name = "haml-i18n-extractor"
|
143
|
+
@major_version = "0"
|
144
|
+
@minor_version = "0.4"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "can initialize and find out about all versions in a major" do
|
148
|
+
velocitator = AggregatedVelocitator.new(@gem_name, @major_version)
|
149
|
+
velocitator.aggregated_versions.should == ["0.5.9", "0.5.8", "0.5.6", "0.5.5", "0.5.4", "0.5.3", "0.5.2", "0.5.1", "0.5.0", "0.4.3", "0.4.2", "0.4.1", "0.4.0", "0.3.5", "0.3.4", "0.3.2", "0.3.0", "0.2.1", "0.2.0", "0.1.0", "0.0.21", "0.0.20", "0.0.19", "0.0.18", "0.0.17", "0.0.16", "0.0.15", "0.0.12", "0.0.10", "0.0.9", "0.0.5"]
|
150
|
+
end
|
151
|
+
|
152
|
+
it "can initialize and find out about all versions in specific a minor" do
|
153
|
+
velocitator = AggregatedVelocitator.new(@gem_name, @minor_version)
|
154
|
+
velocitator.aggregated_versions.should == ["0.4.3", "0.4.2", "0.4.1", "0.4.0"]
|
155
|
+
end
|
156
|
+
|
157
|
+
it "sends the first and last version passed as versions though" do
|
158
|
+
velocitator = AggregatedVelocitator.new(@gem_name, @minor_version)
|
159
|
+
velocitator.versions = ["0.4.3","0.4.0"]
|
160
|
+
end
|
161
|
+
|
162
|
+
it "sends only one graph that is the total of those versions" do
|
163
|
+
velocitator = AggregatedVelocitator.new(@gem_name, @minor_version)
|
164
|
+
velocitator.line_datas.first.size == 1 # [[1,2,3]] but not [[1,2,3][1,4,8]]
|
165
|
+
end
|
166
|
+
|
167
|
+
it "sets the max to the multiple of one of its members max * the amount of versions" do
|
168
|
+
velocitator = AggregatedVelocitator.new(@gem_name, @minor_version)
|
169
|
+
velocitator.default_max_value.should eq 356
|
170
|
+
end
|
171
|
+
|
172
|
+
it "sends only one graph and can draw a graph of it" do
|
173
|
+
velocitator = AggregatedVelocitator.new(@gem_name, @minor_version)
|
174
|
+
file = velocitator.graph
|
175
|
+
end
|
176
|
+
|
177
|
+
it "hides the legend caption" do
|
178
|
+
velocitator = AggregatedVelocitator.new(@gem_name, "0.0.17")
|
179
|
+
velocitator.graph_options[:hide_legend].should == true
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should accumlate the same data as a single_velocitator" do
|
183
|
+
a_velocitator = AggregatedVelocitator.new(@gem_name, "0.0.17")
|
184
|
+
s_velocitator = SingleVelocitator.new(@gem_name, "0.0.17")
|
185
|
+
a_velocitator.versions.should == s_velocitator.versions
|
186
|
+
a_velocitator.graph_options[:line_datas].should == s_velocitator.graph_options[:line_datas]
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_velocity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shai Rosenfeld
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-10-
|
18
|
+
date: 2013-10-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: gruff
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/gem_velocity/gem_data.rb
|
212
212
|
- lib/gem_velocity/gruff_builder.rb
|
213
213
|
- lib/gem_velocity/helpers.rb
|
214
|
+
- lib/gem_velocity/velocitators/aggregated_velocitator.rb
|
214
215
|
- lib/gem_velocity/velocitators/all.rb
|
215
216
|
- lib/gem_velocity/velocitators/base_velocitator.rb
|
216
217
|
- lib/gem_velocity/velocitators/multiple_velocitator.rb
|