bodhi 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bodhi.gemspec +1 -0
- data/lib/bodhi/definitions/count.rb +1 -1
- data/lib/bodhi/helpers/bodhi_helpers.rb +32 -0
- data/lib/bodhi/version.rb +1 -1
- metadata +3 -2
data/bodhi.gemspec
CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/bodhi/definitions/aggregate.rb",
|
37
37
|
"lib/bodhi/definitions/count.rb",
|
38
38
|
"lib/bodhi/storage/metric_value.rb",
|
39
|
+
"lib/bodhi/helpers/bodhi_helpers.rb",
|
39
40
|
"spec/support/mock_model.rb",
|
40
41
|
"spec/support/persistence_spec.rb",
|
41
42
|
"spec/aggregate_metrics_spec.rb",
|
@@ -2,7 +2,7 @@ module Bodhi
|
|
2
2
|
module CountMetrics
|
3
3
|
def count (*args)
|
4
4
|
options = args.extract_options!
|
5
|
-
options[:model_name] = args[0] if args[0].is_a? Symbol
|
5
|
+
options[:model_name] = args[0] if args[0].is_a? Symbol || args[0].is_a? String
|
6
6
|
count_type = args[1] || options[:count_type] || :total
|
7
7
|
options[:block] = get_block(count_type)
|
8
8
|
options[:name] ||= "#{options[:model_name]}_count_#{count_type}"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Bodhi
|
2
|
+
module Helpers
|
3
|
+
def chart_for(*args)
|
4
|
+
options = args.extract_options!
|
5
|
+
|
6
|
+
metric = Bodhi::Metric[args[0]]
|
7
|
+
start_date = options[:start] || 1.month.ago
|
8
|
+
end_date = options[:end] || Time.now
|
9
|
+
width = options[:width] || "500px"
|
10
|
+
height = options[:height] || "200px"
|
11
|
+
|
12
|
+
chart_tag(metric, start_date, end_date, {:width => width, :height => height}).html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def chart_tag(metric, start_date, end_date, data_params)
|
17
|
+
values = metric.for_period(start_date, end_date)
|
18
|
+
data_string = data_params.map{ |k,v| "data-#{k}='#{v}'" }.join(" ")
|
19
|
+
|
20
|
+
res = "<table class='bodhi-chart' data-metric='#{metric.name}' #{data_string} >"
|
21
|
+
values.each do |v|
|
22
|
+
res += "<tr><th>#{v.start.strftime("%Y-%m-%d")}</th><td>#{v.value}</td></tr>"
|
23
|
+
end
|
24
|
+
res += "</table>"
|
25
|
+
res
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
data/lib/bodhi/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ryan Brunner
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/bodhi/definitions/aggregate.rb
|
107
107
|
- lib/bodhi/definitions/count.rb
|
108
108
|
- lib/bodhi/storage/metric_value.rb
|
109
|
+
- lib/bodhi/helpers/bodhi_helpers.rb
|
109
110
|
- spec/support/mock_model.rb
|
110
111
|
- spec/support/persistence_spec.rb
|
111
112
|
- spec/aggregate_metrics_spec.rb
|