metrify 0.5.0 → 0.6.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.
@@ -1,8 +1,15 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'metrify'
4
- require 'spec'
5
- require 'spec/autorun'
4
+ if Rails::VERSION::MAJOR == 3
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
+
8
+ else
9
+ require 'spec'
10
+ require 'spec/autorun'
11
+ end
12
+
6
13
  require 'rubygems'
7
14
  require 'active_record'
8
15
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stephen Abrams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-01 00:00:00 -05:00
18
+ date: 2010-12-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,11 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 13
29
+ hash: 3
30
30
  segments:
31
- - 1
32
31
  - 2
33
- - 9
34
- version: 1.2.9
32
+ - 0
33
+ version: "2.0"
35
34
  type: :development
36
35
  version_requirements: *id001
37
36
  description: Framework to aggregate and display data over time. Assumes highcharts installation.
@@ -45,8 +44,8 @@ extra_rdoc_files:
45
44
  - README.rdoc
46
45
  files:
47
46
  - README.rdoc
48
- - app/controllers/metrify_controller.rb
49
- - app/helpers/metrify_helper.rb
47
+ - app/controllers/metrify/metrify_controller.rb
48
+ - app/helpers/metrify/metrify_helper.rb
50
49
  - app/views/metrify/_chart.html.erb
51
50
  - app/views/metrify/_graph.html.erb
52
51
  - app/views/metrify/_mailer_charts_summary.html.erb
@@ -66,8 +65,8 @@ homepage: http://github.com/sabrams/metrify
66
65
  licenses: []
67
66
 
68
67
  post_install_message:
69
- rdoc_options:
70
- - --charset=UTF-8
68
+ rdoc_options: []
69
+
71
70
  require_paths:
72
71
  - lib
73
72
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,94 +0,0 @@
1
- module MetrifyController
2
-
3
- def self.included(base)
4
- base.class_eval do
5
- before_filter :set_metrify_class
6
- end
7
- base.extend ClassMethods
8
- base.send :include, InstanceMethods
9
- base.helper MetrifyHelper
10
- end
11
-
12
- module InstanceMethods
13
- def index
14
- setup_historical_stats
15
- @stat_names = @metrified_class.stat_names
16
- @historical_site_stats.reverse!
17
- end
18
-
19
- def set_metrify_class
20
- @metrified_class = metrify_model
21
- end
22
-
23
- def setup_historical_stats
24
- @unit = unit
25
- @number_of_stats = number_of_stats
26
- @historical_site_stats = @metrified_class.historical_values(Time.zone.now.beginning_of_week, number_of_stats, unit)
27
- end
28
-
29
- def number_of_stats
30
-
31
- number = case unit.to_sym
32
- when :month then 12
33
- when :week then 52
34
- when :day then 30
35
- else 48 #hour
36
- end
37
-
38
- end
39
-
40
- def unit
41
- params[:unit] || :week
42
- end
43
-
44
- def graph_stats
45
- prepare_for_graph
46
-
47
- @stat_names = parsed_stat_names
48
- end
49
-
50
- def parsed_stat_names
51
- !params[:stat_names].blank? ? params[:stat_names].split(',') : @metrified_class.stat_names
52
- end
53
-
54
- # chart_data.json?filters[type][]=letters&filters[type][]=animals&filters[furriness][]=not_furry
55
- def chart_data
56
- @stat_names = @metrified_class.stat_names(parsed_stat_names, params[:filters])
57
- @unit = params[:unit] || unit
58
-
59
- @number_of_stats = params[:number_of_stats] || number_of_stats
60
- @historical_site_stats = @metrified_class.historical_values(Time.zone.now.beginning_of_week, number_of_stats, unit)
61
-
62
- json = @stat_names.map{|s| {:name => @metrified_class.display_name(s),
63
- :pointInterval => (1.send(@unit) * 1000),
64
- :pointStart => (@number_of_stats.send(@unit).ago.to_i * 1000),
65
- :data => @historical_site_stats.map{|h| h.send(s)}}}
66
-
67
- setup_historical_stats
68
- respond_to do |format|
69
- format.json {
70
- render :layout => false , :json => @stat_names.map{|s| {:name => @metrified_class.display_name(s),
71
- :pointInterval => (1.send(@unit) * 1000),
72
- :pointStart => (@number_of_stats.send(@unit).ago.to_i * 1000),
73
- :data => @template.get_stat_arr(s, @historical_site_stats)}}.to_json
74
- }
75
- end
76
-
77
- end
78
-
79
- # def set_metrify_model; end
80
-
81
- private
82
-
83
- def prepare_for_graph
84
- setup_historical_stats
85
- end
86
-
87
- end
88
-
89
-
90
- module ClassMethods
91
-
92
- end
93
- end
94
-
@@ -1,40 +0,0 @@
1
- module MetrifyHelper
2
-
3
- def get_stat_arr(stat, historical_stats = @historical_site_stats)
4
- stat_over_time = []
5
- historical_stats.each do |s|
6
- value = s.send(stat)
7
- value = 0 if !value
8
- stat_over_time << value
9
- end
10
- stat_over_time
11
- end
12
-
13
- def sorted_stat_names
14
- @metrified_class.sorted_stat_names(@stat_names)
15
- end
16
-
17
- def print_stat_value(stat, stat_name, previous_stat = nil)
18
- val = stat.send(stat_name)
19
- val = number_with_precision(val, :precision => @metrified_class.value_precision(stat_name)) if @metrified_class.value_precision(stat_name)
20
- if @metrified_class.value_type(stat_name) == "currency"
21
- str = number_to_currency(val)
22
- else
23
- str = val.to_s
24
- end
25
- str += colorized_percent_diff(previous_stat.send(stat_name).to_f, stat.send(stat_name).to_f) if @metrified_class.show_variance(stat_name) && previous_stat && previous_stat.send(stat_name) != 0 && stat.send(stat_name) != 0 && previous_stat.send(stat_name) != stat.send(stat_name)
26
- str
27
- end
28
-
29
- def colorized_percent_diff(prev, cur)
30
- val = percent_diff(prev, cur)
31
- str = "<span class="
32
- str += val >= 0 ? "stat_increase" : "stat_decrease"
33
- str += "> (" + number_to_percentage(val, :precision => 2) + ")</span>"
34
- end
35
-
36
- def percent_diff(prev, cur)
37
- (cur-prev)*100/prev
38
- end
39
-
40
- end