mountain-goat 0.1.8 → 1.0.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.
Files changed (135) hide show
  1. data/README.md +119 -48
  2. data/generators/mg/mg_generator.rb +17 -9
  3. data/generators/mg/templates/create_mountain_goat_tables.rb +61 -25
  4. data/generators/mg/templates/mg.rb +1 -0
  5. data/generators/mg/templates/mountain-goat.yml +22 -3
  6. data/generators/mg/templates/mountain_goat_reports.rake +17 -0
  7. data/generators/mg/templates/update_mountain_goat_tables.rb +104 -0
  8. data/lib/mountain-goat.rb +21 -12
  9. data/lib/mountain-goat/analytics.rb +134 -0
  10. data/lib/mountain-goat/controllers/{mountain_goat/mountain_goat_converts_controller.rb → mg/converts_controller.rb} +12 -11
  11. data/lib/mountain-goat/controllers/{mountain_goat/mountain_goat_metric_variants_controller.rb → mg/metric_variants_controller.rb} +6 -5
  12. data/lib/mountain-goat/controllers/{mountain_goat/mountain_goat_metrics_controller.rb → mg/metrics_controller.rb} +8 -6
  13. data/lib/mountain-goat/controllers/mg/mg.rb +47 -0
  14. data/lib/mountain-goat/controllers/{mountain_goat → mg}/mountain_goat_controller.rb +5 -42
  15. data/lib/mountain-goat/controllers/mg/playground_controller.rb +8 -0
  16. data/lib/mountain-goat/controllers/{mountain_goat/mountain_goat_rallies_controller.rb → mg/rallies_controller.rb} +4 -26
  17. data/lib/mountain-goat/controllers/mg/report_items_controller.rb +82 -0
  18. data/lib/mountain-goat/controllers/mg/reports_controller.rb +90 -0
  19. data/lib/mountain-goat/m_g.rb +64 -0
  20. data/lib/mountain-goat/metric_tracking.rb +192 -74
  21. data/lib/mountain-goat/models/mg/ci_meta.rb +10 -0
  22. data/lib/mountain-goat/models/mg/convert.rb +147 -0
  23. data/lib/mountain-goat/models/mg/convert_meta_type.rb +20 -0
  24. data/lib/mountain-goat/models/mg/cs_meta.rb +10 -0
  25. data/lib/mountain-goat/models/{metric.rb → mg/metric.rb} +3 -5
  26. data/lib/mountain-goat/models/mg/metric_variant.rb +25 -0
  27. data/lib/mountain-goat/models/mg/mountain_goat.rb +3 -0
  28. data/lib/mountain-goat/models/{rally.rb → mg/rally.rb} +4 -3
  29. data/lib/mountain-goat/models/mg/report.rb +11 -0
  30. data/lib/mountain-goat/models/mg/report_item.rb +24 -0
  31. data/lib/mountain-goat/models/mg/report_mailer.rb +18 -0
  32. data/lib/mountain-goat/public/g-bar-min.js +7 -0
  33. data/lib/mountain-goat/public/g-dot-min.js +7 -0
  34. data/lib/mountain-goat/public/g-line-min.js +7 -0
  35. data/lib/mountain-goat/public/g-pie-min.js +1 -0
  36. data/lib/mountain-goat/public/g-raphael-min.js +7 -0
  37. data/lib/mountain-goat/public/jqModel.css +41 -0
  38. data/lib/mountain-goat/public/jqModel.js +69 -0
  39. data/lib/mountain-goat/public/jquery.raphael.js +208 -0
  40. data/lib/mountain-goat/public/mg.css +135 -26
  41. data/lib/mountain-goat/public/mg.js +53 -1
  42. data/lib/mountain-goat/public/raphael-min.js +7 -0
  43. data/lib/mountain-goat/public/utils.js +520 -0
  44. data/lib/mountain-goat/switch_variant.rb +4 -4
  45. data/lib/mountain-goat/version.rb +1 -1
  46. data/lib/mountain-goat/views/mountain_goat/layouts/_pdf.html.erb +15 -0
  47. data/lib/mountain-goat/views/mountain_goat/layouts/mountain_goat.html.erb +17 -5
  48. data/lib/mountain-goat/views/mountain_goat/layouts/xhr.html.erb +2 -0
  49. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_converts → mg/converts}/.tmp_show.html.erb.4433~ +0 -0
  50. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_converts → mg/converts}/_convert_form.html.erb +0 -0
  51. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_converts → mg/converts}/_convert_meta_type_form.html.erb +0 -0
  52. data/lib/mountain-goat/views/mountain_goat/mg/converts/edit.html.erb +13 -0
  53. data/lib/mountain-goat/views/mountain_goat/mg/converts/index.html.erb +25 -0
  54. data/lib/mountain-goat/views/mountain_goat/mg/converts/new.html.erb +13 -0
  55. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_converts → mg/converts}/show.html.erb +3 -28
  56. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_metric_variants → mg/metric_variants}/_metric_variant_form.html.erb +0 -4
  57. data/lib/mountain-goat/views/mountain_goat/mg/metric_variants/edit.html.erb +13 -0
  58. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_metric_variants → mg/metric_variants}/index.html.erb +3 -3
  59. data/lib/mountain-goat/views/mountain_goat/mg/metric_variants/new.html.erb +15 -0
  60. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_metric_variants → mg/metric_variants}/show.html.erb +4 -5
  61. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_metrics → mg/metrics}/.tmp_show.html.erb.21270~ +0 -0
  62. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_metrics → mg/metrics}/_metric_form.html.erb +0 -2
  63. data/lib/mountain-goat/views/mountain_goat/mg/metrics/edit.html.erb +13 -0
  64. data/lib/mountain-goat/views/mountain_goat/mg/metrics/index.html.erb +14 -0
  65. data/lib/mountain-goat/views/mountain_goat/mg/metrics/new.html.erb +14 -0
  66. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_metrics → mg/metrics}/show.html.erb +7 -8
  67. data/lib/mountain-goat/views/mountain_goat/{mountain_goat → mg/mountain_goat}/login.html.erb +0 -0
  68. data/lib/mountain-goat/views/mountain_goat/mg/playground/test.html.erb +14 -0
  69. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_rallies → mg/rallies}/.tmp__rally.html.erb.40484~ +0 -0
  70. data/lib/mountain-goat/views/mountain_goat/mg/rallies/_rallies.html.erb +5 -0
  71. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_rallies → mg/rallies}/_rallies_form.html.erb +0 -0
  72. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_rallies → mg/rallies}/_rally.html.erb +0 -0
  73. data/lib/mountain-goat/views/mountain_goat/mg/rallies/edit.html.erb +13 -0
  74. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_rallies → mg/rallies}/index.html.erb +1 -1
  75. data/lib/mountain-goat/views/mountain_goat/mg/rallies/new.html.erb +13 -0
  76. data/lib/mountain-goat/views/mountain_goat/{mountain_goat_rallies → mg/rallies}/show.html.erb +1 -1
  77. data/lib/mountain-goat/views/mountain_goat/mg/report_items/_chart.html.erb +18 -0
  78. data/lib/mountain-goat/views/mountain_goat/mg/report_items/_report_item_form.html.erb +10 -0
  79. data/lib/mountain-goat/views/mountain_goat/mg/report_items/_report_item_pivot_form.html.erb +14 -0
  80. data/lib/mountain-goat/views/mountain_goat/mg/report_items/_show.html.erb +29 -0
  81. data/lib/mountain-goat/views/mountain_goat/mg/report_items/_svg_chart.html.erb +4 -0
  82. data/lib/mountain-goat/views/mountain_goat/mg/report_items/edit.html.erb +19 -0
  83. data/lib/mountain-goat/views/mountain_goat/mg/report_items/new.html.erb +17 -0
  84. data/lib/mountain-goat/views/mountain_goat/mg/report_mailer/report.html.erb +27 -0
  85. data/lib/mountain-goat/views/mountain_goat/mg/reports/_report.html.erb +22 -0
  86. data/lib/mountain-goat/views/mountain_goat/mg/reports/_report_form.html.erb +21 -0
  87. data/lib/mountain-goat/views/mountain_goat/mg/reports/_report_report_items.html.erb +5 -0
  88. data/lib/mountain-goat/views/mountain_goat/mg/reports/edit.html.erb +36 -0
  89. data/lib/mountain-goat/views/mountain_goat/mg/reports/index.html.erb +26 -0
  90. data/lib/mountain-goat/views/mountain_goat/mg/reports/new.html.erb +17 -0
  91. data/lib/mountain-goat/views/mountain_goat/mg/reports/show.html.erb +21 -0
  92. data/test/fixtures/{ci_metas.yml → mg_ci_metas.yml} +0 -0
  93. data/test/fixtures/{convert_meta_types.yml → mg_convert_meta_types.yml} +0 -0
  94. data/test/fixtures/{converts.yml → mg_converts.yml} +5 -0
  95. data/test/fixtures/{cs_metas.yml → mg_cs_metas.yml} +0 -0
  96. data/test/fixtures/mg_deliveries.yml +9 -0
  97. data/test/fixtures/{metric_variants.yml → mg_metric_variants.yml} +0 -0
  98. data/test/fixtures/{metrics.yml → mg_metrics.yml} +2 -3
  99. data/test/fixtures/{rallies.yml → mg_rallies.yml} +6 -2
  100. data/test/fixtures/mg_report_items.yml +13 -0
  101. data/test/fixtures/mg_reports.yml +15 -0
  102. data/test/mg_convert_test.rb +32 -0
  103. data/test/mg_converts_controller_test.rb +47 -0
  104. data/test/mg_metric_variants_controller_test.rb +46 -0
  105. data/test/mg_metrics_controller_test.rb +52 -0
  106. data/test/mg_mountain_goat_controller_test.rb +45 -0
  107. data/test/mg_mountain_goat_test.rb +392 -0
  108. data/test/mg_playground_controller_test.rb +11 -0
  109. data/test/mg_rallies_controller_test.rb +36 -0
  110. data/test/mg_report_item_test.rb +7 -0
  111. data/test/mg_report_items_controller_test.rb +31 -0
  112. data/test/mg_report_test.rb +18 -0
  113. data/test/mg_reports_controller_test.rb +50 -0
  114. data/test/test_helper.rb +203 -0
  115. metadata +108 -55
  116. data/lib/mountain-goat/models/ci_meta.rb +0 -9
  117. data/lib/mountain-goat/models/convert.rb +0 -70
  118. data/lib/mountain-goat/models/convert_meta_type.rb +0 -19
  119. data/lib/mountain-goat/models/cs_meta.rb +0 -9
  120. data/lib/mountain-goat/models/metric_variant.rb +0 -22
  121. data/lib/mountain-goat/views/mountain_goat/mountain_goat_converts/edit.html.erb +0 -13
  122. data/lib/mountain-goat/views/mountain_goat/mountain_goat_converts/index.html.erb +0 -48
  123. data/lib/mountain-goat/views/mountain_goat/mountain_goat_converts/new.html.erb +0 -13
  124. data/lib/mountain-goat/views/mountain_goat/mountain_goat_metric_variants/edit.html.erb +0 -13
  125. data/lib/mountain-goat/views/mountain_goat/mountain_goat_metric_variants/new.html.erb +0 -15
  126. data/lib/mountain-goat/views/mountain_goat/mountain_goat_metrics/edit.html.erb +0 -13
  127. data/lib/mountain-goat/views/mountain_goat/mountain_goat_metrics/index.html.erb +0 -14
  128. data/lib/mountain-goat/views/mountain_goat/mountain_goat_metrics/new.html.erb +0 -14
  129. data/lib/mountain-goat/views/mountain_goat/mountain_goat_rallies/_rallies.html.erb +0 -5
  130. data/lib/mountain-goat/views/mountain_goat/mountain_goat_rallies/edit.html.erb +0 -13
  131. data/lib/mountain-goat/views/mountain_goat/mountain_goat_rallies/new.html.erb +0 -13
  132. data/test/ocelot_converts_controller_test.rb +0 -45
  133. data/test/ocelot_metric_variants_controller_test.rb +0 -45
  134. data/test/ocelot_metrics_controller_test.rb +0 -45
  135. data/test/ocelot_rallies_controller_test.rb +0 -8
@@ -0,0 +1,17 @@
1
+
2
+ #################################################################
3
+ # Mountain Goat #
4
+ # #
5
+ # This file has been installed to add the 'mg:deliver' #
6
+ # rake task to your project. If you are not using #
7
+ # Mountain Goat Reporting, you can safely remove this file. #
8
+ # #
9
+ #################################################################
10
+
11
+ namespace :mg do
12
+
13
+ desc "deliver mountain goat reports"
14
+ task :deliver, :delivery_set, :needs => :environment do |t, args|
15
+ MG.deliver(args[:delivery_set])
16
+ end
17
+ end
@@ -0,0 +1,104 @@
1
+ class UpdateMountainGoatTables < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column :converts, :reward, :float, :default => 1.0
5
+ add_column :metric_variants, :reward, :float
6
+
7
+ rename_table :metric_variants, :mg_metric_variants
8
+
9
+ Mg::MetricVariant.all.each do |mv|
10
+ mv.update_attribute(:reward, mv.conversions.to_f )
11
+ end
12
+
13
+ remove_column :metrics, :convert_id
14
+ remove_column :mg_metric_variants, :priority
15
+
16
+ rename_table :rallies, :mg_rallies
17
+ rename_table :metrics, :mg_metrics
18
+ rename_table :converts, :mg_converts
19
+ rename_table :cs_metas, :mg_cs_metas
20
+ rename_table :ci_metas, :mg_ci_metas
21
+ rename_table :convert_meta_types, :mg_convert_meta_types
22
+
23
+ create_table "mg_report_items", :force => true do |t|
24
+ t.integer "report_id"
25
+ t.integer "reportable_id"
26
+ t.string "reportable_type"
27
+ t.integer "order"
28
+ t.datetime "created_at"
29
+ t.datetime "updated_at"
30
+ end
31
+
32
+ create_table "mg_reports", :force => true do |t|
33
+ t.string "title"
34
+ t.text "description"
35
+ t.datetime "created_at"
36
+ t.datetime "updated_at"
37
+ t.string "delivery_set"
38
+ t.string "recipients"
39
+ end
40
+
41
+ add_column :mg_converts, :deleted_at, :datetime
42
+ add_column :mg_metrics, :deleted_at, :datetime
43
+ add_column :mg_metric_variants, :deleted_at, :datetime
44
+ add_column :mg_reports, :deleted_at, :datetime
45
+
46
+ add_column :mg_report_items, :pivot_type, :string
47
+ add_column :mg_report_items, :pivot_id, :integer
48
+
49
+ add_column :mg_report_items, :filter, :string
50
+
51
+ add_column :mg_report_items, :meta_type, :string
52
+ add_column :mg_report_items, :meta_id, :integer
53
+
54
+ add_column :mg_report_items, :extra, :string
55
+ add_column :mg_report_items, :variant, :integer
56
+ add_column :mg_report_items, :subvariant, :integer
57
+ add_column :mg_report_items, :start, :datetime
58
+ add_column :mg_report_items, :end, :datetime
59
+ add_column :mg_report_items, :size, :integer
60
+
61
+ add_column :mg_reports, :theme, :string
62
+ end
63
+
64
+ def self.down
65
+ remove_column :mg_reports, :theme
66
+
67
+ remove_column :mg_report_items, :extra
68
+ remove_column :mg_report_items, :variant
69
+ remove_column :mg_report_items, :subvariant
70
+ remove_column :mg_report_items, :start
71
+ remove_column :mg_report_items, :end
72
+ remove_column :mg_report_items, :size
73
+
74
+ remove_column :mg_report_items, :meta_type
75
+ remove_column :mg_report_items, :meta_id
76
+
77
+ remove_column :mg_report_items, :filter
78
+
79
+ remove_column :mg_report_items, :pivot_type
80
+ remove_column :mg_report_items, :pivot_id
81
+
82
+ remove_column :mg_converts, :deleted_at
83
+ remove_column :mg_metrics, :deleted_at
84
+ remove_column :mg_metric_variants, :deleted_at
85
+ remove_column :mg_reports, :deleted_at
86
+
87
+ rename_table :mg_rallies, :rallies
88
+ rename_table :mg_metrics, :metrics
89
+ rename_table :mg_metric_variants, :metric_variants
90
+ rename_table :mg_converts, :converts
91
+ rename_table :mg_cs_metas, :cs_metas
92
+ rename_table :mg_ci_metas, :ci_metas
93
+ rename_table :mg_convert_meta_types, :convert_meta_types
94
+
95
+ add_column :metric_variants, :priority, :float
96
+ add_column :metrics, :convert_id, :integer
97
+ remove_column :metric_variants, :reward
98
+ remove_column :converts, :reward
99
+
100
+ drop_table :mg_reports
101
+ drop_table :mg_report_items
102
+ end
103
+
104
+ end
data/lib/mountain-goat.rb CHANGED
@@ -6,20 +6,29 @@ require 'action_controller/routing'
6
6
 
7
7
  require File.join([File.dirname(__FILE__), 'mgflotilla'])
8
8
 
9
- require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mountain_goat/mountain_goat_controller'])
10
- require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mountain_goat/mountain_goat_metrics_controller'])
11
- require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mountain_goat/mountain_goat_metric_variants_controller'])
12
- require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mountain_goat/mountain_goat_converts_controller'])
13
- require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mountain_goat/mountain_goat_rallies_controller'])
9
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/mg'])
10
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/mountain_goat_controller'])
11
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/metrics_controller'])
12
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/metric_variants_controller'])
13
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/converts_controller'])
14
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/rallies_controller'])
15
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/reports_controller'])
16
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/report_items_controller'])
17
+ require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/playground_controller'])
14
18
 
19
+ require File.join([File.dirname(__FILE__), 'mountain-goat/m_g'])
20
+ require File.join([File.dirname(__FILE__), 'mountain-goat/analytics'])
15
21
  require File.join([File.dirname(__FILE__), 'mountain-goat/metric_tracking'])
16
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/metric'])
17
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/metric_variant'])
18
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/convert'])
19
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/convert_meta_type'])
20
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/cs_meta'])
21
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/ci_meta'])
22
- require File.join([File.dirname(__FILE__), 'mountain-goat/models/rally'])
22
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/metric'])
23
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/metric_variant'])
24
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/convert'])
25
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/convert_meta_type'])
26
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/cs_meta'])
27
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/ci_meta'])
28
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/rally'])
29
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/report'])
30
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/report_mailer'])
31
+ require File.join([File.dirname(__FILE__), 'mountain-goat/models/mg/report_item'])
23
32
 
24
33
  #$VERBOSE = nil
25
34
  #Dir["#{Gem.searcher.find('mountain-goat').full_gem_path}/lib/tasks/*.rake"].each { |ext| load ext }
@@ -0,0 +1,134 @@
1
+ class Analytics
2
+ #extend Garb::Model
3
+
4
+ #metrics :exits, :pageviews, :unique_pageviews
5
+ #dimensions :page_path, :date
6
+
7
+ #filters do
8
+ # contains(:page_path, '/xxx')
9
+ #end
10
+
11
+ def self.pivot(item, dimension)
12
+ item.sort! do |x,y|
13
+ #logger.warn "x: #{x.send(:date)}, y: #{y.send(:date)}"
14
+ x.send(dimension) <=> y.send(dimension)
15
+ end
16
+
17
+ item
18
+ #item.map { |res| { dimension => res.send(dimension), value => res.send(value) } }
19
+ end
20
+
21
+ def self.insert_missing_dates_as_zero_through_today(item, dimension, start, valuemap)
22
+ #assume sorted object-- and that dates are on day-intervals
23
+
24
+ result = []
25
+ running_date = start #item[0].send(dimension)
26
+ i = 0
27
+
28
+ while running_date < ( Date.today + 1 )
29
+ if i >= item.count
30
+ break if running_date >= Date.today #skip missing data for today
31
+ result.push( { dimension => running_date }.merge(valuemap) )
32
+ else
33
+ if running_date < item[i].send(dimension)
34
+ result.push( { dimension => running_date }.merge(valuemap) )
35
+ elsif running_date == item[i].send(dimension)
36
+ map = { dimension => running_date }
37
+ valuemap.each do |dim, val|
38
+ map[dim] = item[i].send(dim)
39
+ end
40
+ result.push(map)
41
+ i += 1
42
+ else
43
+ raise "Dates dont align on time"
44
+ #running_date > item[i], we've run over the end of the list
45
+ end
46
+ end
47
+
48
+ running_date = running_date + 1
49
+ end
50
+
51
+ result
52
+ end
53
+
54
+ def self.convert_date_to_javascript_time(item, dimension)
55
+ item.each do |i|
56
+ date = i.send(dimension)
57
+ i[dimension] = Time.utc(date.year, date.month, date.day).to_i * 1000
58
+ end
59
+ end
60
+
61
+ def self.pivot_hash_to_titled(map)
62
+ res = []
63
+ res_titles = {}
64
+ i = 0
65
+
66
+ map.each do |k,v|
67
+ res.push( { :name => i, :val => v.to_i } )
68
+ res_titles.merge!({ i => k })
69
+ end
70
+
71
+ [res, res_titles]
72
+ end
73
+
74
+ def self.options_for_titled_chart(h, t)
75
+ { :collection => h, :x => :name, :y => :val }
76
+ end
77
+
78
+ def self.options_for_pie_chart(h)
79
+ res = {}
80
+ h.each do |k, v|
81
+ res.merge!( k => { :collection => [{ :x => 1, :val => v.to_i }], :x => :x, :y => :val, :options => { :color => "##{hash_color( k )}" } })
82
+ end
83
+ res
84
+ end
85
+
86
+ def self.options_for_line_chart(h)
87
+ res = {}
88
+ h.each do |k, v|
89
+ title = k || "Direct"
90
+ res.merge!( title => { :collection => v, :x => :x, :y => :y, :options => { :color => "##{hash_color( title )}" }} )
91
+ end
92
+
93
+ res
94
+ end
95
+
96
+
97
+ def self.hash_color(str)
98
+ s = ( ( 7.times.map { str }.join.hash ** 2 ) % 2**24 ).to_s(16)
99
+ (6 - s.length).times.map { "0" }.join << s
100
+ end
101
+
102
+ def self.pivot_by_date(collection, start_date, end_date = Time.zone.now)
103
+ #assume sorted object-- and that dates are on day-intervals
104
+
105
+ result = {}
106
+ start_date -= 60 * 60 * 24 #no day 0??
107
+ end_date += 60 * 60 * 30 #let's just push this forward a bit..
108
+
109
+ running_date = Date.new(start_date.year, start_date.month, start_date.day) #item[0].send(dimension)
110
+ end_date = Date.new(end_date.year, end_date.month, end_date.day) #item[0].send(dimension)
111
+ indices = {}
112
+ collection.each { |source,dates| indices.merge!({ source => 0 }); result[source] = [] }
113
+ #puts indices.inspect
114
+ while running_date < end_date
115
+ collection.each do |source, value|
116
+ #Get the index in the current channel
117
+ i = indices[source]
118
+
119
+ #Otherwise, let's count the dates
120
+ v = 0
121
+ v += 1 and i += 1 while i < value.length && value[i] > running_date && value[i] < (running_date + 1)
122
+
123
+ #Store results back
124
+ indices[source] = i
125
+ result[source].push( { :x => running_date, :y => v } )
126
+ end
127
+
128
+ running_date = running_date + 1
129
+ end
130
+
131
+ #result.each { |s| s.sort }
132
+ result
133
+ end
134
+ end
@@ -1,9 +1,10 @@
1
- class MountainGoatConvertsController < MountainGoatController
2
-
1
+
2
+ class Mg::ConvertsController < Mg
3
+
3
4
  # GET /converts
4
5
  # GET /converts.xml
5
6
  def index
6
- @converts = Convert.all
7
+ @converts = Mg::Convert.all
7
8
 
8
9
  respond_to do |format|
9
10
  format.html # index.html.erb
@@ -14,7 +15,7 @@ class MountainGoatConvertsController < MountainGoatController
14
15
  # GET /converts/1
15
16
  # GET /converts/1.xml
16
17
  def show
17
- @convert = Convert.find(params[:id])
18
+ @convert = Mg::Convert.find(params[:id])
18
19
 
19
20
  @results_per_day = []
20
21
  created_at = @convert.created_at
@@ -54,7 +55,7 @@ class MountainGoatConvertsController < MountainGoatController
54
55
  # GET /converts/new
55
56
  # GET /converts/new.xml
56
57
  def new
57
- @convert = Convert.new
58
+ @convert = Mg::Convert.new
58
59
 
59
60
  respond_to do |format|
60
61
  format.html # new.html.erb
@@ -70,11 +71,11 @@ class MountainGoatConvertsController < MountainGoatController
70
71
  # POST /converts
71
72
  # POST /converts.xml
72
73
  def create
73
- @convert = Convert.new(params[:convert])
74
+ @convert = Mg::Convert.new(params[:convert])
74
75
 
75
76
  if @convert.save
76
77
  flash[:notice] = 'Convert was successfully created.'
77
- redirect_to mountain_goat_convert_url :id => @convert.id
78
+ redirect_to mg_convert_url :id => @convert.id
78
79
  else
79
80
  render :action => "new"
80
81
  end
@@ -83,11 +84,11 @@ class MountainGoatConvertsController < MountainGoatController
83
84
  # PUT /converts/1
84
85
  # PUT /converts/1.xml
85
86
  def update
86
- @convert = Convert.find(params[:id])
87
+ @convert = Mg::Convert.find(params[:id])
87
88
 
88
89
  if @convert.update_attributes(params[:convert])
89
90
  flash[:notice] = 'Convert was successfully updated.'
90
- redirect_to mountain_goat_convert_url :id => @convert.id
91
+ redirect_to mg_convert_url :id => @convert.id
91
92
  else
92
93
  render :action => "edit"
93
94
  end
@@ -96,11 +97,11 @@ class MountainGoatConvertsController < MountainGoatController
96
97
  # DELETE /converts/1
97
98
  # DELETE /converts/1.xml
98
99
  def destroy
99
- @convert = Convert.find(params[:id])
100
+ @convert = Mg::Convert.find(params[:id])
100
101
  @convert.destroy
101
102
 
102
103
  respond_to do |format|
103
- format.html { redirect_to mountain_goat_converts_url }
104
+ format.html { redirect_to mg_converts_url }
104
105
  format.xml { head :ok }
105
106
  end
106
107
  end
@@ -1,4 +1,5 @@
1
- class MountainGoatMetricVariantsController < MountainGoatController
1
+
2
+ class Mg::MetricVariantsController < Mg
2
3
 
3
4
  # GET /metric_variants
4
5
  # GET /metric_variants.xml
@@ -25,7 +26,7 @@ class MountainGoatMetricVariantsController < MountainGoatController
25
26
  # GET /metric_variants/new
26
27
  # GET /metric_variants/new.xml
27
28
  def new
28
- @metric = Metric.find( params[:mountain_goat_metric_id] )
29
+ @metric = Metric.find( params[:metric_id] )
29
30
  @metric_variant = MetricVariant.new( :metric_id => @metric.id )
30
31
 
31
32
  respond_to do |format|
@@ -47,7 +48,7 @@ class MountainGoatMetricVariantsController < MountainGoatController
47
48
 
48
49
  if @metric_variant.save
49
50
  flash[:notice] = 'Metric variant was successfully created.'
50
- redirect_to mountain_goat_metric_url :id => @metric_variant.metric.id
51
+ redirect_to mg_metric_url :id => @metric_variant.metric.id
51
52
  else
52
53
  render :action => "new"
53
54
  end
@@ -60,7 +61,7 @@ class MountainGoatMetricVariantsController < MountainGoatController
60
61
 
61
62
  if @metric_variant.update_attributes(params[:metric_variant])
62
63
  flash[:notice] = 'Metric variant was successfully updated.'
63
- redirect_to mountain_goat_metric_url :id => @metric_variant.metric.id
64
+ redirect_to mg_metric_url :id => @metric_variant.metric.id
64
65
  else
65
66
  render :action => "edit"
66
67
  end
@@ -73,7 +74,7 @@ class MountainGoatMetricVariantsController < MountainGoatController
73
74
  @metric_variant.destroy
74
75
 
75
76
  respond_to do |format|
76
- format.html { redirect_to mountain_goat_metric_variants_url }
77
+ format.html { redirect_to mg_metric_variants_url }
77
78
  format.xml { head :ok }
78
79
  end
79
80
  end
@@ -1,4 +1,5 @@
1
- class MountainGoatMetricsController < MountainGoatController
1
+
2
+ class Mg::MetricsController < Mg
2
3
 
3
4
  # GET /metrics
4
5
  # GET /metrics.xml
@@ -41,8 +42,7 @@ class MountainGoatMetricsController < MountainGoatController
41
42
  # GET /metrics/new
42
43
  # GET /metrics/new.xml
43
44
  def new
44
- @convert = Convert.find(params[:mountain_goat_convert_id])
45
- @metric = Metric.new(:convert_id => @convert.id)
45
+ @metric = Metric.new
46
46
 
47
47
  respond_to do |format|
48
48
  format.html # new.html.erb
@@ -62,7 +62,7 @@ class MountainGoatMetricsController < MountainGoatController
62
62
 
63
63
  if @metric.save
64
64
  flash[:notice] = 'Metric was successfully created.'
65
- redirect_to mountain_goat_metric_url :id => @metric.id
65
+ redirect_to mg_metric_url :id => @metric.id
66
66
  else
67
67
  render :action => "new"
68
68
  end
@@ -75,7 +75,7 @@ class MountainGoatMetricsController < MountainGoatController
75
75
 
76
76
  if @metric.update_attributes(params[:metric])
77
77
  flash[:notice] = 'Metric was successfully updated.'
78
- redirect_to mountain_goat_metric_url :id => @metric.id
78
+ redirect_to mg_metric_url :id => @metric.id
79
79
  else
80
80
  render :action => "edit"
81
81
  end
@@ -88,11 +88,12 @@ class MountainGoatMetricsController < MountainGoatController
88
88
  @metric.destroy
89
89
 
90
90
  respond_to do |format|
91
- format.html { redirect_to(mountain_goat_metrics_url) }
91
+ format.html { redirect_to(mg_metrics_url) }
92
92
  format.xml { head :ok }
93
93
  end
94
94
  end
95
95
 
96
+ #TODO: This only works if we are using cookie storage? Clear session as well
96
97
  def fresh_metrics
97
98
  #clear metrics
98
99
  #logger.warn "Headerish #{response.headers['cookie']}"
@@ -102,6 +103,7 @@ class MountainGoatMetricsController < MountainGoatController
102
103
  cookies.delete cookie[0], :domain => WILD_DOMAIN
103
104
  end
104
105
  end
106
+
105
107
  flash[:notice] = "Your metrics have been cleared from cookies."
106
108
  redirect_to :back
107
109
  end