metrify 0.1.0 → 0.2.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.
- data/README.rdoc +108 -2
- data/lib/metrify.rb +3 -3
- data/spec/debug.log +10 -0
- data/spec/metrify_spec.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
|
@@ -1,8 +1,114 @@
|
|
|
1
1
|
= metrify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Via the creation of a YAML file specifying statistics to track, and an extension class to specify the way to find those statistics, Metrify provides an easy way to aggregate and display statistics over time.
|
|
4
|
+
|
|
5
|
+
If Highcharts is used in your project, functionality is included to immediately use a default chart.
|
|
6
|
+
|
|
7
|
+
Install metrify:
|
|
8
|
+
|
|
9
|
+
$ gem install metrify
|
|
10
|
+
|
|
11
|
+
To add the ability for a class to generate aggregated statistics over time, perform the following steps:
|
|
12
|
+
|
|
13
|
+
1. Create .yml file defining metrics, and optional metric grouping filters
|
|
14
|
+
2. Include module functionality in class that will calculate metrics, and provide a method for each metric to be calulated.
|
|
15
|
+
|
|
16
|
+
You can create multiple classes that use this module. By default, the YML file loaded for the class will be on /config/<classname>_metrify.yml. Otherwise, specify the filename as an argument when calling "acts_as_metrify" within the class (shown below). RAILS_ROOT will be prepended.
|
|
17
|
+
|
|
18
|
+
Example YML file:
|
|
19
|
+
|
|
20
|
+
stats:
|
|
21
|
+
element_a_count:
|
|
22
|
+
display_name: Element A Count
|
|
23
|
+
element_b_count:
|
|
24
|
+
display_name: Element B Count
|
|
25
|
+
element_1_count:
|
|
26
|
+
display_name: Element 1 Count
|
|
27
|
+
element_cat_count:
|
|
28
|
+
display_name: Cat Count
|
|
29
|
+
element_dog_count:
|
|
30
|
+
display_name: Dog Count
|
|
31
|
+
|
|
32
|
+
filters:
|
|
33
|
+
type:
|
|
34
|
+
numbers:
|
|
35
|
+
set: [element_1_count]
|
|
36
|
+
description: 'Numbers'
|
|
37
|
+
letters:
|
|
38
|
+
set: [element_a_count, element_b_count]
|
|
39
|
+
description: 'Letts'
|
|
40
|
+
animals:
|
|
41
|
+
set: [element_cat_count, element_dog_count]
|
|
42
|
+
description: 'Animals'
|
|
43
|
+
furriness:
|
|
44
|
+
furry:
|
|
45
|
+
set: [element_cat_count, element_dog_count]
|
|
46
|
+
description: 'Furry'
|
|
47
|
+
not_furry:
|
|
48
|
+
set: [element_1_count, element_a_count, element_b_count, element_c_count]
|
|
49
|
+
description: 'Not Furry'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Example Class, implementing calculation methods for metrics defined in YML file:
|
|
53
|
+
|
|
54
|
+
class MetricsClass < ActiveRecord::Base
|
|
55
|
+
include Metrify
|
|
56
|
+
acts_as_metrify
|
|
57
|
+
|
|
58
|
+
class << self
|
|
59
|
+
def element_a_count(start_date, end_date)
|
|
60
|
+
# Code calculating number (probably a SQL query using start and end dates)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
...(more methods, one for each defined metric)
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
== Using with Highcharts for instant views
|
|
69
|
+
|
|
70
|
+
Assuming your application is configured to use Highcharts, optional controller, view, and helper components are included to provide charts with filters. To use:
|
|
71
|
+
|
|
72
|
+
1. Include MetrifyController module in controller and implement 'metrified_class' and 'set_classname'.
|
|
73
|
+
2. Include partials (graph and/or chart) in views
|
|
74
|
+
|
|
75
|
+
Example Controller:
|
|
76
|
+
|
|
77
|
+
class DashboardController < ApplicationController
|
|
78
|
+
include MetrifyController
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
def metrified_class
|
|
82
|
+
@metrified_class || @metrified_class = MetricsClass.new
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def set_classname
|
|
86
|
+
@classname || @classname = Dashboard.name.downcase
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
Example View for graph:
|
|
92
|
+
|
|
93
|
+
<style type="text/css" media="screen">
|
|
94
|
+
.metrify_graph {width:auto;height:400px;background-color:white}
|
|
95
|
+
|
|
96
|
+
</style>
|
|
97
|
+
<%= render :partial => "metrify/graph" %>
|
|
98
|
+
|
|
99
|
+
Example View for chart:
|
|
100
|
+
|
|
101
|
+
<style type="text/css" media="screen">
|
|
102
|
+
.metrify_chart {width: auto; background: white; color: black; overflow:auto;}
|
|
103
|
+
.metrify_chart thead td {font-weight:bold;background-color:#ddd;}
|
|
104
|
+
.metrify_chart thead td a {color:#116;}
|
|
105
|
+
.metrify_chart table, th, td {border: 1px solid #ccc; border-width:0 1px 1px 0;}
|
|
106
|
+
.metrify_chart tr:first-child td {border-top-width:1px;}
|
|
107
|
+
.metrify_chart td:first-child {border-left-width:1px;}
|
|
108
|
+
.metrify_chart td {padding:5px;}
|
|
109
|
+
</style>
|
|
110
|
+
<%= render :partial => "metrify/chart" %>
|
|
4
111
|
|
|
5
|
-
A month is 30 days (not calendar month) or not...
|
|
6
112
|
== Note on Patches/Pull Requests
|
|
7
113
|
|
|
8
114
|
* Fork the project.
|
data/lib/metrify.rb
CHANGED
|
@@ -21,13 +21,13 @@ module Metrify
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
module ClassMethods
|
|
24
|
-
#def
|
|
24
|
+
#def acts_as_metrify(file)
|
|
25
25
|
|
|
26
|
-
def
|
|
26
|
+
def acts_as_metrify(file = self.name.underscore + '_metrify.yml', test = false)
|
|
27
27
|
serialize :stat_hash, Hash
|
|
28
28
|
send :include, InstanceMethods
|
|
29
29
|
if test
|
|
30
|
-
self.metrify_data = YAML::
|
|
30
|
+
self.metrify_data = YAML::load_file(File.join(RAILS_ROOT, file))
|
|
31
31
|
else
|
|
32
32
|
self.metrify_data = YAML.load_file(File.join(RAILS_ROOT, 'config', file))
|
|
33
33
|
end
|
data/spec/debug.log
CHANGED
|
@@ -2846,3 +2846,13 @@
|
|
|
2846
2846
|
[4;35;1mSQL (0.2ms)[0m [0mBEGIN[0m
|
|
2847
2847
|
[4;36;1mMetric Update (0.3ms)[0m [0;1mUPDATE `invalid_metrics` SET `stat_hash` = '--- \nelement_4_count: 15\nelement_b_count: 5\nelement_3_count: 15\nelement_a_count: 23\nelement_c_count: 15\nelement_cat_count: 15\nelement_dog_count: 15\nelement_1_count: 15\nelement_2_count: 15\n' WHERE `id` = 16[0m
|
|
2848
2848
|
[4;35;1mSQL (0.5ms)[0m [0mCOMMIT[0m
|
|
2849
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mSET NAMES 'utf8'[0m
|
|
2850
|
+
[4;35;1mSQL (0.1ms)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
|
|
2851
|
+
[4;36;1mSQL (47.0ms)[0m [0;1mSHOW TABLES[0m
|
|
2852
|
+
[4;35;1mSQL (36.3ms)[0m [0mDROP TABLE `metrics`[0m
|
|
2853
|
+
[4;36;1mSQL (115.2ms)[0m [0;1mCREATE TABLE `metrics` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `finish_date` date, `number_of_days` int(11), `stat_hash` varchar(255)) ENGINE=InnoDB[0m
|
|
2854
|
+
[4;35;1mSQL (0.4ms)[0m [0mSHOW TABLES[0m
|
|
2855
|
+
[4;36;1mSQL (1.6ms)[0m [0;1mDROP TABLE `invalid_metrics`[0m
|
|
2856
|
+
[4;35;1mSQL (201.8ms)[0m [0mCREATE TABLE `invalid_metrics` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `finish_date` date, `number_of_days` int(11), `stat_hash` varchar(255)) ENGINE=InnoDB[0m
|
|
2857
|
+
[4;36;1mSQL (0.5ms)[0m [0;1mSHOW TABLES[0m
|
|
2858
|
+
[4;35;1mSQL (0.2ms)[0m [0mSELECT version FROM `schema_migrations`[0m
|
data/spec/metrify_spec.rb
CHANGED
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:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 2
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.2.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-10-
|
|
18
|
+
date: 2010-10-27 00:00:00 -04:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|