fnordmetric 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +69 -0
- data/Procfile +2 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/doc/example_server.rb +56 -0
- data/fnordmetric.gemspec +145 -0
- data/haml/app.haml +48 -0
- data/haml/widget.haml +9 -0
- data/lib/fnordmetric.rb +21 -0
- data/lib/fnordmetric/app.rb +70 -0
- data/lib/fnordmetric/average_metric.rb +7 -0
- data/lib/fnordmetric/cache.rb +20 -0
- data/lib/fnordmetric/combine_metric.rb +7 -0
- data/lib/fnordmetric/core.rb +66 -0
- data/lib/fnordmetric/count_metric.rb +13 -0
- data/lib/fnordmetric/dashboard.rb +30 -0
- data/lib/fnordmetric/engine.rb +3 -0
- data/lib/fnordmetric/event.rb +28 -0
- data/lib/fnordmetric/funnel_widget.rb +2 -0
- data/lib/fnordmetric/metric.rb +80 -0
- data/lib/fnordmetric/metric_api.rb +37 -0
- data/lib/fnordmetric/numbers_widget.rb +18 -0
- data/lib/fnordmetric/report.rb +29 -0
- data/lib/fnordmetric/sum_metric.rb +13 -0
- data/lib/fnordmetric/timeline_widget.rb +17 -0
- data/lib/fnordmetric/widget.rb +75 -0
- data/pub/fnordmetric/fnordmetric.css +53 -0
- data/pub/fnordmetric/fnordmetric.js +44 -0
- data/pub/fnordmetric/widget_numbers.js +71 -0
- data/pub/fnordmetric/widget_timeline.css +0 -0
- data/pub/fnordmetric/widget_timeline.js +110 -0
- data/pub/highcharts/adapters/mootools-adapter.js +12 -0
- data/pub/highcharts/adapters/mootools-adapter.src.js +243 -0
- data/pub/highcharts/adapters/prototype-adapter.js +14 -0
- data/pub/highcharts/adapters/prototype-adapter.src.js +284 -0
- data/pub/highcharts/highcharts.js +170 -0
- data/pub/highcharts/highcharts.src.js +11103 -0
- data/pub/highcharts/modules/exporting.js +22 -0
- data/pub/highcharts/modules/exporting.src.js +703 -0
- data/pub/highcharts/themes/dark-blue.js +268 -0
- data/pub/highcharts/themes/dark-green.js +268 -0
- data/pub/highcharts/themes/gray.js +262 -0
- data/pub/highcharts/themes/grid.js +97 -0
- data/pub/jquery-1.6.1.min.js +18 -0
- data/pub/sprite.png +0 -0
- data/readme.rdoc +274 -0
- data/spec/app_spec.rb +178 -0
- data/spec/cache_spec.rb +53 -0
- data/spec/combine_metric_spec.rb +19 -0
- data/spec/core_spec.rb +50 -0
- data/spec/count_metric_spec.rb +32 -0
- data/spec/dashboard_spec.rb +67 -0
- data/spec/event_spec.rb +46 -0
- data/spec/metric_spec.rb +118 -0
- data/spec/report_spec.rb +87 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/sum_metric_spec.rb +33 -0
- data/spec/widget_spec.rb +107 -0
- metadata +271 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "mongoid", "~> 2.2.0"
|
4
|
+
gem "mongo", "~> 1.4.0"
|
5
|
+
gem "bson_ext", "~> 1.4.0"
|
6
|
+
gem "sinatra", "~> 1.2.6"
|
7
|
+
gem "json"
|
8
|
+
gem "haml"
|
9
|
+
gem "rack"
|
10
|
+
gem "rack-test"
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem "delorean", ">= 0"
|
14
|
+
gem "rspec", "~> 2.6.0"
|
15
|
+
gem "shoulda", ">= 0"
|
16
|
+
gem "bundler", "~> 1.0.0"
|
17
|
+
gem "jeweler", "~> 1.5.2"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.1.0)
|
5
|
+
activesupport (= 3.1.0)
|
6
|
+
bcrypt-ruby (~> 3.0.0)
|
7
|
+
builder (~> 3.0.0)
|
8
|
+
i18n (~> 0.6)
|
9
|
+
activesupport (3.1.0)
|
10
|
+
multi_json (~> 1.0)
|
11
|
+
bcrypt-ruby (3.0.1)
|
12
|
+
bson (1.4.0)
|
13
|
+
bson_ext (1.4.0)
|
14
|
+
builder (3.0.0)
|
15
|
+
chronic (0.6.4)
|
16
|
+
delorean (1.1.0)
|
17
|
+
chronic
|
18
|
+
diff-lcs (1.1.3)
|
19
|
+
git (1.2.5)
|
20
|
+
haml (3.1.2)
|
21
|
+
i18n (0.6.0)
|
22
|
+
jeweler (1.5.2)
|
23
|
+
bundler (~> 1.0.0)
|
24
|
+
git (>= 1.2.5)
|
25
|
+
rake
|
26
|
+
json (1.6.1)
|
27
|
+
mongo (1.4.0)
|
28
|
+
bson (= 1.4.0)
|
29
|
+
mongoid (2.2.0)
|
30
|
+
activemodel (~> 3.0)
|
31
|
+
mongo (~> 1.3)
|
32
|
+
tzinfo (~> 0.3.22)
|
33
|
+
multi_json (1.0.3)
|
34
|
+
rack (1.3.0)
|
35
|
+
rack-test (0.6.0)
|
36
|
+
rack (>= 1.0)
|
37
|
+
rake (0.9.2)
|
38
|
+
rspec (2.6.0)
|
39
|
+
rspec-core (~> 2.6.0)
|
40
|
+
rspec-expectations (~> 2.6.0)
|
41
|
+
rspec-mocks (~> 2.6.0)
|
42
|
+
rspec-core (2.6.4)
|
43
|
+
rspec-expectations (2.6.0)
|
44
|
+
diff-lcs (~> 1.1.2)
|
45
|
+
rspec-mocks (2.6.0)
|
46
|
+
shoulda (2.11.3)
|
47
|
+
sinatra (1.2.6)
|
48
|
+
rack (~> 1.1)
|
49
|
+
tilt (>= 1.2.2, < 2.0)
|
50
|
+
tilt (1.3.2)
|
51
|
+
tzinfo (0.3.29)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
bson_ext (~> 1.4.0)
|
58
|
+
bundler (~> 1.0.0)
|
59
|
+
delorean
|
60
|
+
haml
|
61
|
+
jeweler (~> 1.5.2)
|
62
|
+
json
|
63
|
+
mongo (~> 1.4.0)
|
64
|
+
mongoid (~> 2.2.0)
|
65
|
+
rack
|
66
|
+
rack-test
|
67
|
+
rspec (~> 2.6.0)
|
68
|
+
shoulda
|
69
|
+
sinatra (~> 1.2.6)
|
data/Procfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "fnordmetric"
|
15
|
+
gem.homepage = "http://github.com/paulasmuth/fnordmetric"
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.summary = "FnordMetric is a Ruby Event-Tracking gem on steroids"
|
18
|
+
gem.description = "FnordMetric is a Ruby Event-Tracking gem on steroids"
|
19
|
+
gem.email = "paul@paulasmuth.com"
|
20
|
+
gem.authors = ["Paul Asmuth"]
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rspec'
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
desc "Run all examples"
|
26
|
+
task RSpec::Core::RakeTask.new('spec')
|
27
|
+
|
28
|
+
task :default => "spec"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.2
|
@@ -0,0 +1,56 @@
|
|
1
|
+
$: << ::File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "fnordmetric"
|
5
|
+
require "thin"
|
6
|
+
|
7
|
+
FnordMetric.metric(:passengers_total, :count => true, :types => [:car_seen])
|
8
|
+
FnordMetric.metric(:blubbs, :sum => :passengers, :types => [:car_seen])
|
9
|
+
FnordMetric.metric(:passengers_red_car, :sum => :passengers, :filter => { :colors => :red }, :types => [:car_seen])
|
10
|
+
FnordMetric.metric(:passengers_blue_car, :sum => :passengers, :filter => { :colors => :blue }, :types => [:car_seen])
|
11
|
+
|
12
|
+
FnordMetric.metric(:blue_to_red_ratio, :combine => lambda{ |x|
|
13
|
+
x.passengers_blue_car / x.passengers_red_car
|
14
|
+
})
|
15
|
+
|
16
|
+
|
17
|
+
FnordMetric.dashboard 'Passengers' do |passengers|
|
18
|
+
|
19
|
+
passengers.add_widget FnordMetric.widget(:passengers_total_timeline,
|
20
|
+
:metrics => :passengers_total,
|
21
|
+
:tick => 4.minutes,
|
22
|
+
:title => "Passengers total",
|
23
|
+
:type => :timeline
|
24
|
+
)
|
25
|
+
|
26
|
+
passengers.add_widget FnordMetric.widget(:passenger_blue_red_timeline,
|
27
|
+
:metrics => [:passengers_blue_car, :passengers_red_car],
|
28
|
+
:title => "Passengers (red/blue)",
|
29
|
+
:type => :timeline
|
30
|
+
)
|
31
|
+
|
32
|
+
passengers.add_widget FnordMetric.widget(:passenger_br_ratio_timeline,
|
33
|
+
:metrics => :blue_to_red_ratio,
|
34
|
+
:title => "Passenger blue/red Ratio",
|
35
|
+
:type => :timeline
|
36
|
+
)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
FnordMetric.dashboard 'Cars & Bikes' do |cars|
|
41
|
+
|
42
|
+
cars.add_widget FnordMetric.widget(:passenger_br_ratio_timeline,
|
43
|
+
:metrics => :blue_to_red_ratio,
|
44
|
+
:title => "Passenger blue/red Ratio",
|
45
|
+
:type => :timeline
|
46
|
+
)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
Mongoid.configure do |c|
|
52
|
+
c.master = Mongo::Connection.new.db("myfnordmetric")
|
53
|
+
end
|
54
|
+
|
55
|
+
app = FnordMetric::App.new
|
56
|
+
Thin::Server.start('127.0.0.1', 2323, app)
|
data/fnordmetric.gemspec
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fnordmetric}
|
8
|
+
s.version = "0.3.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paul Asmuth"]
|
12
|
+
s.date = %q{2011-11-05}
|
13
|
+
s.description = %q{FnordMetric is a Ruby Event-Tracking gem on steroids}
|
14
|
+
s.email = %q{paul@paulasmuth.com}
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
"Gemfile",
|
18
|
+
"Gemfile.lock",
|
19
|
+
"Procfile",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"doc/example_server.rb",
|
23
|
+
"fnordmetric.gemspec",
|
24
|
+
"haml/app.haml",
|
25
|
+
"haml/widget.haml",
|
26
|
+
"lib/fnordmetric.rb",
|
27
|
+
"lib/fnordmetric/app.rb",
|
28
|
+
"lib/fnordmetric/average_metric.rb",
|
29
|
+
"lib/fnordmetric/cache.rb",
|
30
|
+
"lib/fnordmetric/combine_metric.rb",
|
31
|
+
"lib/fnordmetric/core.rb",
|
32
|
+
"lib/fnordmetric/count_metric.rb",
|
33
|
+
"lib/fnordmetric/dashboard.rb",
|
34
|
+
"lib/fnordmetric/engine.rb",
|
35
|
+
"lib/fnordmetric/event.rb",
|
36
|
+
"lib/fnordmetric/funnel_widget.rb",
|
37
|
+
"lib/fnordmetric/metric.rb",
|
38
|
+
"lib/fnordmetric/metric_api.rb",
|
39
|
+
"lib/fnordmetric/numbers_widget.rb",
|
40
|
+
"lib/fnordmetric/report.rb",
|
41
|
+
"lib/fnordmetric/sum_metric.rb",
|
42
|
+
"lib/fnordmetric/timeline_widget.rb",
|
43
|
+
"lib/fnordmetric/widget.rb",
|
44
|
+
"pub/fnordmetric/fnordmetric.css",
|
45
|
+
"pub/fnordmetric/fnordmetric.js",
|
46
|
+
"pub/fnordmetric/widget_numbers.js",
|
47
|
+
"pub/fnordmetric/widget_timeline.css",
|
48
|
+
"pub/fnordmetric/widget_timeline.js",
|
49
|
+
"pub/highcharts/adapters/mootools-adapter.js",
|
50
|
+
"pub/highcharts/adapters/mootools-adapter.src.js",
|
51
|
+
"pub/highcharts/adapters/prototype-adapter.js",
|
52
|
+
"pub/highcharts/adapters/prototype-adapter.src.js",
|
53
|
+
"pub/highcharts/highcharts.js",
|
54
|
+
"pub/highcharts/highcharts.src.js",
|
55
|
+
"pub/highcharts/modules/exporting.js",
|
56
|
+
"pub/highcharts/modules/exporting.src.js",
|
57
|
+
"pub/highcharts/themes/dark-blue.js",
|
58
|
+
"pub/highcharts/themes/dark-green.js",
|
59
|
+
"pub/highcharts/themes/gray.js",
|
60
|
+
"pub/highcharts/themes/grid.js",
|
61
|
+
"pub/jquery-1.6.1.min.js",
|
62
|
+
"pub/sprite.png",
|
63
|
+
"readme.rdoc",
|
64
|
+
"spec/app_spec.rb",
|
65
|
+
"spec/cache_spec.rb",
|
66
|
+
"spec/combine_metric_spec.rb",
|
67
|
+
"spec/core_spec.rb",
|
68
|
+
"spec/count_metric_spec.rb",
|
69
|
+
"spec/dashboard_spec.rb",
|
70
|
+
"spec/event_spec.rb",
|
71
|
+
"spec/metric_spec.rb",
|
72
|
+
"spec/report_spec.rb",
|
73
|
+
"spec/spec_helper.rb",
|
74
|
+
"spec/sum_metric_spec.rb",
|
75
|
+
"spec/widget_spec.rb"
|
76
|
+
]
|
77
|
+
s.homepage = %q{http://github.com/paulasmuth/fnordmetric}
|
78
|
+
s.licenses = ["MIT"]
|
79
|
+
s.require_paths = ["lib"]
|
80
|
+
s.rubygems_version = %q{1.6.2}
|
81
|
+
s.summary = %q{FnordMetric is a Ruby Event-Tracking gem on steroids}
|
82
|
+
s.test_files = [
|
83
|
+
"spec/app_spec.rb",
|
84
|
+
"spec/cache_spec.rb",
|
85
|
+
"spec/combine_metric_spec.rb",
|
86
|
+
"spec/core_spec.rb",
|
87
|
+
"spec/count_metric_spec.rb",
|
88
|
+
"spec/dashboard_spec.rb",
|
89
|
+
"spec/event_spec.rb",
|
90
|
+
"spec/metric_spec.rb",
|
91
|
+
"spec/report_spec.rb",
|
92
|
+
"spec/spec_helper.rb",
|
93
|
+
"spec/sum_metric_spec.rb",
|
94
|
+
"spec/widget_spec.rb"
|
95
|
+
]
|
96
|
+
|
97
|
+
if s.respond_to? :specification_version then
|
98
|
+
s.specification_version = 3
|
99
|
+
|
100
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
101
|
+
s.add_runtime_dependency(%q<mongoid>, ["~> 2.2.0"])
|
102
|
+
s.add_runtime_dependency(%q<mongo>, ["~> 1.4.0"])
|
103
|
+
s.add_runtime_dependency(%q<bson_ext>, ["~> 1.4.0"])
|
104
|
+
s.add_runtime_dependency(%q<sinatra>, ["~> 1.2.6"])
|
105
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
106
|
+
s.add_runtime_dependency(%q<haml>, [">= 0"])
|
107
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
108
|
+
s.add_runtime_dependency(%q<rack-test>, [">= 0"])
|
109
|
+
s.add_development_dependency(%q<delorean>, [">= 0"])
|
110
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
111
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
112
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
113
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
114
|
+
else
|
115
|
+
s.add_dependency(%q<mongoid>, ["~> 2.2.0"])
|
116
|
+
s.add_dependency(%q<mongo>, ["~> 1.4.0"])
|
117
|
+
s.add_dependency(%q<bson_ext>, ["~> 1.4.0"])
|
118
|
+
s.add_dependency(%q<sinatra>, ["~> 1.2.6"])
|
119
|
+
s.add_dependency(%q<json>, [">= 0"])
|
120
|
+
s.add_dependency(%q<haml>, [">= 0"])
|
121
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
122
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
123
|
+
s.add_dependency(%q<delorean>, [">= 0"])
|
124
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
125
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
126
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
127
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
128
|
+
end
|
129
|
+
else
|
130
|
+
s.add_dependency(%q<mongoid>, ["~> 2.2.0"])
|
131
|
+
s.add_dependency(%q<mongo>, ["~> 1.4.0"])
|
132
|
+
s.add_dependency(%q<bson_ext>, ["~> 1.4.0"])
|
133
|
+
s.add_dependency(%q<sinatra>, ["~> 1.2.6"])
|
134
|
+
s.add_dependency(%q<json>, [">= 0"])
|
135
|
+
s.add_dependency(%q<haml>, [">= 0"])
|
136
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
137
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
138
|
+
s.add_dependency(%q<delorean>, [">= 0"])
|
139
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
140
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
141
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
142
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
data/haml/app.haml
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
|
4
|
+
%head
|
5
|
+
%title Fnordmetric Dashboard
|
6
|
+
%script(type="text/javascript" src="#{path_prefix}/jquery-1.6.1.min.js")
|
7
|
+
%link(type="text/css" rel="stylesheet" href="#{path_prefix}/fnordmetric/fnordmetric.css")
|
8
|
+
%script(type="text/javascript" src="#{path_prefix}/fnordmetric/fnordmetric.js")
|
9
|
+
:javascript
|
10
|
+
FnordMetric.p = '#{path_prefix}';
|
11
|
+
|
12
|
+
%body
|
13
|
+
#wrap
|
14
|
+
#tabs
|
15
|
+
%ul
|
16
|
+
-FnordMetric.dashboards.each do |dashboard|
|
17
|
+
%li{:rel => dashboard.token}
|
18
|
+
.picto.piechart
|
19
|
+
=h dashboard.title
|
20
|
+
|
21
|
+
#viewport
|
22
|
+
-unless @dashboard
|
23
|
+
no dashboard selected
|
24
|
+
|
25
|
+
-@dashboard.widgets.each do |widget|
|
26
|
+
-elem_id = "fw#{(rand*9999).to_i}"
|
27
|
+
%div{:id => elem_id, :style => "margin-bottom:10px;"}
|
28
|
+
=widget.render(elem_id)
|
29
|
+
|
30
|
+
|
31
|
+
:javascript
|
32
|
+
$(document).ready(function(){
|
33
|
+
|
34
|
+
$('#tabs li').click(function(){
|
35
|
+
document.location.href = '#{path_prefix}/dashboard/' + $(this).attr('rel');
|
36
|
+
});
|
37
|
+
|
38
|
+
function resizeViewport(){
|
39
|
+
var viewport_width = window.innerWidth-310
|
40
|
+
$('#viewport').width(viewport_width);
|
41
|
+
}
|
42
|
+
resizeViewport();
|
43
|
+
$(window).resize(resizeViewport);
|
44
|
+
|
45
|
+
});
|
46
|
+
|
47
|
+
|
48
|
+
|
data/haml/widget.haml
ADDED
data/lib/fnordmetric.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mongoid'
|
3
|
+
require 'haml'
|
4
|
+
require 'sinatra/base'
|
5
|
+
|
6
|
+
require "fnordmetric/core"
|
7
|
+
require "fnordmetric/app"
|
8
|
+
require "fnordmetric/metric_api"
|
9
|
+
require "fnordmetric/dashboard"
|
10
|
+
require "fnordmetric/event"
|
11
|
+
require "fnordmetric/cache"
|
12
|
+
require "fnordmetric/report"
|
13
|
+
require "fnordmetric/metric"
|
14
|
+
require "fnordmetric/average_metric"
|
15
|
+
require "fnordmetric/count_metric"
|
16
|
+
require "fnordmetric/combine_metric"
|
17
|
+
require "fnordmetric/sum_metric"
|
18
|
+
require "fnordmetric/widget"
|
19
|
+
require "fnordmetric/numbers_widget"
|
20
|
+
require "fnordmetric/timeline_widget"
|
21
|
+
require "fnordmetric/funnel_widget"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class FnordMetric::App < Sinatra::Base
|
2
|
+
|
3
|
+
@@sessions = Hash.new
|
4
|
+
|
5
|
+
#use Rack::Reloader, 0
|
6
|
+
|
7
|
+
enable :session
|
8
|
+
|
9
|
+
set :haml, :format => :html5
|
10
|
+
set :views, ::File.expand_path('../../../haml', __FILE__)
|
11
|
+
set :public, ::File.expand_path('../../../pub', __FILE__)
|
12
|
+
|
13
|
+
helpers do
|
14
|
+
include Rack::Utils
|
15
|
+
alias_method :h, :escape_html
|
16
|
+
|
17
|
+
def path_prefix
|
18
|
+
request.env["SCRIPT_NAME"]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
if ENV['RACK_ENV'] == "test"
|
24
|
+
set :raise_errors, true
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/' do
|
28
|
+
redirect "#{request.env["SCRIPT_NAME"]}/dashboard/default"
|
29
|
+
end
|
30
|
+
|
31
|
+
get '/dashboard/:name' do
|
32
|
+
@dashboard = FnordMetric.dashboards.detect{|d| d.token == params[:name] }
|
33
|
+
@dashboard ||= FnordMetric.dashboards.first
|
34
|
+
haml :app
|
35
|
+
end
|
36
|
+
|
37
|
+
get '/metric/:name' do
|
38
|
+
content_type 'application/json'
|
39
|
+
FnordMetric::MetricAPI.new(params).render
|
40
|
+
end
|
41
|
+
|
42
|
+
get '/widget/:name' do
|
43
|
+
@dashboard = FnordMetric.dashboards.first
|
44
|
+
@widget = @dashboard.widgets.first
|
45
|
+
haml :widget
|
46
|
+
end
|
47
|
+
|
48
|
+
post '/events' do
|
49
|
+
halt 400, 'please specify the event_type' unless params["type"]
|
50
|
+
event_type = params.delete("type")
|
51
|
+
FnordMetric.track(event_type, parse_params(params))
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def parse_params(hash)
|
57
|
+
hash.tap do |h|
|
58
|
+
h.keys.each{ |k| h[k] = parse_param(h[k]) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_param(object)
|
63
|
+
return object unless object.is_a?(String)
|
64
|
+
return object.to_f if object.match(/^[0-9]+[,\.][0-9]+$/)
|
65
|
+
return object.to_i if object.match(/^[0-9]+$/)
|
66
|
+
object
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|