amee-analytics 2.0.1 → 2.1.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/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Dependencies
4
- gem "amee-data-abstraction","~> 2.0"
5
- gem "amee-data-persistence","~> 2.0"
4
+ gem "amee-data-abstraction","~> 2.2"
5
+ gem "amee-data-persistence","~> 2.1"
6
6
 
7
7
  group :development do
8
8
  gem "bundler", "~> 1.0.0"
data/Gemfile.lock CHANGED
@@ -28,18 +28,18 @@ GEM
28
28
  activemodel (= 3.0.10)
29
29
  activesupport (= 3.0.10)
30
30
  activesupport (3.0.10)
31
- amee (4.0.0)
31
+ amee (4.1.5)
32
32
  activesupport (~> 3.0.10)
33
33
  json
34
34
  log4r
35
- nokogiri (~> 1.4.3.1)
36
- amee-data-abstraction (2.0.0)
37
- amee (~> 4.0)
35
+ nokogiri (~> 1.4.4)
36
+ amee-data-abstraction (2.2.0)
37
+ amee (~> 4.1.5)
38
38
  quantify (~> 2.0.0)
39
39
  uuidtools (= 2.1.2)
40
- amee-data-persistence (2.0.0)
40
+ amee-data-persistence (2.1.0)
41
41
  activerecord (~> 3.0.10)
42
- amee-data-abstraction (~> 2.0)
42
+ amee-data-abstraction (~> 2.2.0)
43
43
  arel (2.0.10)
44
44
  builder (2.1.2)
45
45
  diff-lcs (1.1.3)
@@ -60,9 +60,9 @@ GEM
60
60
  mime-types (~> 1.16)
61
61
  treetop (~> 1.4.8)
62
62
  mime-types (1.16)
63
- nokogiri (1.4.3.1)
63
+ nokogiri (1.4.7)
64
64
  polyglot (0.3.2)
65
- quantify (2.0.0)
65
+ quantify (2.0.1)
66
66
  activesupport (~> 3.0.10)
67
67
  i18n
68
68
  rack (1.2.4)
@@ -85,8 +85,9 @@ GEM
85
85
  rdoc (~> 3.4)
86
86
  thor (~> 0.14.4)
87
87
  rake (0.9.2)
88
- rcov (0.9.10)
89
- rdoc (3.9.4)
88
+ rcov (0.9.11)
89
+ rdoc (3.11)
90
+ json (~> 1.4)
90
91
  rspec (2.6.0)
91
92
  rspec-core (~> 2.6.0)
92
93
  rspec-expectations (~> 2.6.0)
@@ -99,15 +100,15 @@ GEM
99
100
  treetop (1.4.10)
100
101
  polyglot
101
102
  polyglot (>= 0.3.1)
102
- tzinfo (0.3.29)
103
+ tzinfo (0.3.30)
103
104
  uuidtools (2.1.2)
104
105
 
105
106
  PLATFORMS
106
107
  ruby
107
108
 
108
109
  DEPENDENCIES
109
- amee-data-abstraction (~> 2.0)
110
- amee-data-persistence (~> 2.0)
110
+ amee-data-abstraction (~> 2.2)
111
+ amee-data-persistence (~> 2.1)
111
112
  bundler (~> 1.0.0)
112
113
  flexmock (~> 0.9.0)
113
114
  jeweler (~> 1.6.4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amee-analytics}
8
- s.version = "2.0.1"
8
+ s.version = "2.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["James Hetherington", "Andrew Berkeley", "James Smith", "George Palmer"]
12
- s.date = %q{2011-09-29}
11
+ s.authors = [%q{James Hetherington}, %q{Andrew Berkeley}, %q{James Smith}, %q{George Palmer}]
12
+ s.date = %q{2011-10-19}
13
13
  s.description = %q{Part of the AMEE AppKit, this gem provides the ability to do mathmatical operations over a set of calculations}
14
14
  s.email = %q{help@amee.com}
15
15
  s.extra_rdoc_files = [
@@ -34,21 +34,22 @@ Gem::Specification.new do |s|
34
34
  "spec/amee/analytics/calculation_collection_spec.rb",
35
35
  "spec/amee/analytics/term_spec.rb",
36
36
  "spec/amee/analytics/terms_list_spec.rb",
37
+ "spec/fixtures/config/calculations/calcs.rb",
37
38
  "spec/spec.opts",
38
39
  "spec/spec_helper.rb"
39
40
  ]
40
41
  s.homepage = %q{http://github.com/AMEE/amee-analytics}
41
- s.licenses = ["MIT"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.6.2}
42
+ s.licenses = [%q{MIT}]
43
+ s.require_paths = [%q{lib}]
44
+ s.rubygems_version = %q{1.8.6}
44
45
  s.summary = %q{Analytics module for use with AMEE AppKit}
45
46
 
46
47
  if s.respond_to? :specification_version then
47
48
  s.specification_version = 3
48
49
 
49
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<amee-data-abstraction>, ["~> 2.0"])
51
- s.add_runtime_dependency(%q<amee-data-persistence>, ["~> 2.0"])
51
+ s.add_runtime_dependency(%q<amee-data-abstraction>, ["~> 2.2"])
52
+ s.add_runtime_dependency(%q<amee-data-persistence>, ["~> 2.1"])
52
53
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
54
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
54
55
  s.add_development_dependency(%q<rails>, ["~> 3.0.10"])
@@ -57,8 +58,8 @@ Gem::Specification.new do |s|
57
58
  s.add_development_dependency(%q<rcov>, [">= 0"])
58
59
  s.add_development_dependency(%q<rdoc>, [">= 0"])
59
60
  else
60
- s.add_dependency(%q<amee-data-abstraction>, ["~> 2.0"])
61
- s.add_dependency(%q<amee-data-persistence>, ["~> 2.0"])
61
+ s.add_dependency(%q<amee-data-abstraction>, ["~> 2.2"])
62
+ s.add_dependency(%q<amee-data-persistence>, ["~> 2.1"])
62
63
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
64
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
64
65
  s.add_dependency(%q<rails>, ["~> 3.0.10"])
@@ -68,8 +69,8 @@ Gem::Specification.new do |s|
68
69
  s.add_dependency(%q<rdoc>, [">= 0"])
69
70
  end
70
71
  else
71
- s.add_dependency(%q<amee-data-abstraction>, ["~> 2.0"])
72
- s.add_dependency(%q<amee-data-persistence>, ["~> 2.0"])
72
+ s.add_dependency(%q<amee-data-abstraction>, ["~> 2.2"])
73
+ s.add_dependency(%q<amee-data-persistence>, ["~> 2.1"])
73
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
74
75
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
75
76
  s.add_dependency(%q<rails>, ["~> 3.0.10"])
@@ -250,6 +250,28 @@ module AMEE
250
250
  Result.new { label label; value value; unit unit; per_unit per_unit }
251
251
  end
252
252
 
253
+ # Move an individual term to a specified location (index) within the list.
254
+ # The specific term is selected on the basis of one of it's attributes values,
255
+ # with the attribute to use (e.g. :value, :unit) given by <tt>attr</attr>
256
+ # and value by <tt>value</tt>. The location within the list to move the term
257
+ # is given as an index integer value as the final argument.
258
+ #
259
+ def move_by(attr,value,index)
260
+ if attr == :unit || attr == :per_unit
261
+ value = Unit.for value
262
+ end
263
+ term = find {|t| t.send(attr) == value }
264
+ return if term.nil?
265
+ delete(term)
266
+ insert(index, term)
267
+ end
268
+
269
+ # Rotate the list terms by one element - shifts the first-placed term to the
270
+ # end of the list, advancing all terms forward by one place.
271
+ def rotate
272
+ push(self.shift)
273
+ end
274
+
253
275
  # Sorts the terms list in place according to the term attribute indicated by
254
276
  # <tt>attr</tt>, returning <tt>self</tt>.
255
277
  #
@@ -5,7 +5,6 @@ include AMEE::DataAbstraction
5
5
  describe CalculationCollection do
6
6
 
7
7
  before(:each) do
8
- initialize_calculation_set
9
8
  @calcs = []
10
9
  @calcs << add_elec_calc(500,240)
11
10
  @calcs << add_elec_calc(1000,480)
@@ -5,7 +5,6 @@ include AMEE::DataAbstraction
5
5
  describe TermsList do
6
6
 
7
7
  before(:each) do
8
- initialize_calculation_set
9
8
  calcs = []
10
9
  calcs << add_elec_calc(500,240)
11
10
  calcs << add_elec_calc(1000,480)
@@ -369,6 +368,56 @@ describe TermsList do
369
368
  list.last.to_s.should eql'Zambia'
370
369
  end
371
370
 
371
+ it "should move a term on the basis of value" do
372
+ @list=@list.co2
373
+ @list.first.to_s.should eql "240.0 t"
374
+ @list[1].to_s.should eql "480.0 t"
375
+ @list.last.to_s.should eql "600.0 t"
376
+ @list.move_by(:value, 600.0,0)
377
+ @list.first.to_s.should eql "600.0 t"
378
+ @list[1].to_s.should eql "240.0 t"
379
+ @list.last.to_s.should eql "480.0 t"
380
+ end
381
+
382
+ it "should move a term on the basis of unit object" do
383
+ @list=@list.co2
384
+ @list.first.unit 't'
385
+ @list[1].unit 'lb'
386
+ @list.last.unit 'kg'
387
+ @list.first.to_s.should eql "240.0 t"
388
+ @list[1].to_s.should eql "480.0 lb"
389
+ @list.last.to_s.should eql "600.0 kg"
390
+ @list.move_by(:unit, Unit.kg,1)
391
+ @list.first.to_s.should eql "240.0 t"
392
+ @list[1].to_s.should eql "600.0 kg"
393
+ @list.last.to_s.should eql "480.0 lb"
394
+ end
395
+
396
+ it "should move a term on the basis of unit label" do
397
+ @list=@list.co2
398
+ @list.first.unit 't'
399
+ @list[1].unit 'lb'
400
+ @list.last.unit 'kg'
401
+ @list.first.to_s.should eql "240.0 t"
402
+ @list[1].to_s.should eql "480.0 lb"
403
+ @list.last.to_s.should eql "600.0 kg"
404
+ @list.move_by(:unit, :t,-1)
405
+ @list.first.to_s.should eql "480.0 lb"
406
+ @list[1].to_s.should eql "600.0 kg"
407
+ @list.last.to_s.should eql "240.0 t"
408
+ end
409
+
410
+ it "should rotate terms" do
411
+ @list=@list.co2
412
+ @list.first.to_s.should eql "240.0 t"
413
+ @list[1].to_s.should eql "480.0 t"
414
+ @list.last.to_s.should eql "600.0 t"
415
+ @list.rotate
416
+ @list.first.to_s.should eql "480.0 t"
417
+ @list[1].to_s.should eql "600.0 t"
418
+ @list.last.to_s.should eql "240.0 t"
419
+ end
420
+
372
421
  it "should return a new TermList for numeric only terms" do
373
422
  @list=@list.co2.numeric_terms.should be_a TermsList
374
423
  end
@@ -0,0 +1,57 @@
1
+ calculation{
2
+
3
+ name 'Electricity'
4
+ label :electricity
5
+ path '/business/energy/electricity/grid'
6
+ drill {
7
+ label :country
8
+ path 'country'
9
+ value 'Argentina'
10
+ }
11
+ profile {
12
+ label :usage
13
+ name 'Electricity Used'
14
+ path 'energyPerTime'
15
+ default_unit :kWh
16
+ }
17
+ output {
18
+ label :co2
19
+ name 'Carbon Dioxide'
20
+ path 'default'
21
+ default_unit :t
22
+ }
23
+ }
24
+
25
+ calculation{
26
+
27
+ name 'Transport'
28
+ label :transport
29
+ path '/transport/defra/vehicle'
30
+ drill {
31
+ label :type
32
+ path 'type'
33
+ name 'Type'
34
+ }
35
+ drill {
36
+ label :size
37
+ path 'size'
38
+ name 'Size'
39
+ }
40
+ drill {
41
+ label :fuel
42
+ path 'fuel'
43
+ name 'Fuel'
44
+ }
45
+ profile {
46
+ label :distance
47
+ name 'distance'
48
+ path 'distance'
49
+ default_unit :km
50
+ }
51
+ output {
52
+ label :co2
53
+ name 'Carbon Dioxide'
54
+ path 'default'
55
+ default_unit :t
56
+ }
57
+ }
data/spec/spec_helper.rb CHANGED
@@ -2,80 +2,25 @@ require 'rubygems'
2
2
  require 'rspec'
3
3
  require 'amee-analytics'
4
4
 
5
- RAILS_ROOT = '.'
5
+ class Rails
6
+ def self.root
7
+ File.dirname(__FILE__) + '/fixtures'
8
+ end
9
+ end
6
10
 
7
11
  RSpec.configure do |config|
8
12
  config.mock_with :flexmock
9
13
  end
10
14
 
11
- def initialize_calculation_set
12
- eval "Calculations = AMEE::DataAbstraction::CalculationSet.new {
13
- calculation{
14
- name 'Electricity'
15
- label :electricity
16
- path '/business/energy/electricity/grid'
17
- drill {
18
- label :country
19
- path 'country'
20
- value 'Argentina'
21
- }
22
- profile {
23
- label :usage
24
- name 'Electricity Used'
25
- path 'energyPerTime'
26
- default_unit :kWh
27
- }
28
- output {
29
- label :co2
30
- name 'Carbon Dioxide'
31
- path :default
32
- default_unit :t
33
- }
34
- }
35
- calculation{
36
- name 'Transport'
37
- label :transport
38
- path '/transport/defra/vehicle'
39
- drill {
40
- label :type
41
- path 'type'
42
- name 'Type'
43
- }
44
- drill {
45
- label :size
46
- path 'size'
47
- name 'Size'
48
- }
49
- drill {
50
- label :fuel
51
- path 'fuel'
52
- name 'Fuel'
53
- }
54
- profile {
55
- label :distance
56
- name 'distance'
57
- path 'distance'
58
- default_unit :km
59
- }
60
- output {
61
- label :co2
62
- name 'Carbon Dioxide'
63
- path :default
64
- default_unit :t
65
- }
66
- }
67
- }"
68
- end
69
-
70
15
  def add_elec_calc(act,res)
71
- calc = Calculations[:electricity].begin_calculation
16
+ calc = CalculationSet.find("calcs")[:electricity].begin_calculation
72
17
  calc['usage'].value act
73
18
  calc['co2'].value res
74
19
  return calc
75
20
  end
76
21
 
77
22
  def add_transport_calc(act,res)
78
- calc = Calculations[:transport].begin_calculation
23
+ calc = CalculationSet.find("calcs")[:transport].begin_calculation
79
24
  calc['distance'].value act
80
25
  calc['co2'].value res
81
26
  return calc
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amee-analytics
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 0
9
8
  - 1
10
- version: 2.0.1
9
+ - 0
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Hetherington
@@ -18,41 +18,39 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-09-29 00:00:00 +01:00
22
- default_executable:
21
+ date: 2011-10-19 00:00:00 Z
23
22
  dependencies:
24
23
  - !ruby/object:Gem::Dependency
25
- prerelease: false
26
24
  type: :runtime
27
25
  requirement: &id001 !ruby/object:Gem::Requirement
28
26
  none: false
29
27
  requirements:
30
28
  - - ~>
31
29
  - !ruby/object:Gem::Version
32
- hash: 3
30
+ hash: 7
33
31
  segments:
34
32
  - 2
35
- - 0
36
- version: "2.0"
37
- name: amee-data-abstraction
33
+ - 2
34
+ version: "2.2"
38
35
  version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
36
+ name: amee-data-abstraction
40
37
  prerelease: false
38
+ - !ruby/object:Gem::Dependency
41
39
  type: :runtime
42
40
  requirement: &id002 !ruby/object:Gem::Requirement
43
41
  none: false
44
42
  requirements:
45
43
  - - ~>
46
44
  - !ruby/object:Gem::Version
47
- hash: 3
45
+ hash: 1
48
46
  segments:
49
47
  - 2
50
- - 0
51
- version: "2.0"
52
- name: amee-data-persistence
48
+ - 1
49
+ version: "2.1"
53
50
  version_requirements: *id002
54
- - !ruby/object:Gem::Dependency
51
+ name: amee-data-persistence
55
52
  prerelease: false
53
+ - !ruby/object:Gem::Dependency
56
54
  type: :development
57
55
  requirement: &id003 !ruby/object:Gem::Requirement
58
56
  none: false
@@ -65,10 +63,10 @@ dependencies:
65
63
  - 0
66
64
  - 0
67
65
  version: 1.0.0
68
- name: bundler
69
66
  version_requirements: *id003
70
- - !ruby/object:Gem::Dependency
67
+ name: bundler
71
68
  prerelease: false
69
+ - !ruby/object:Gem::Dependency
72
70
  type: :development
73
71
  requirement: &id004 !ruby/object:Gem::Requirement
74
72
  none: false
@@ -81,10 +79,10 @@ dependencies:
81
79
  - 6
82
80
  - 4
83
81
  version: 1.6.4
84
- name: jeweler
85
82
  version_requirements: *id004
86
- - !ruby/object:Gem::Dependency
83
+ name: jeweler
87
84
  prerelease: false
85
+ - !ruby/object:Gem::Dependency
88
86
  type: :development
89
87
  requirement: &id005 !ruby/object:Gem::Requirement
90
88
  none: false
@@ -97,10 +95,10 @@ dependencies:
97
95
  - 0
98
96
  - 10
99
97
  version: 3.0.10
100
- name: rails
101
98
  version_requirements: *id005
102
- - !ruby/object:Gem::Dependency
99
+ name: rails
103
100
  prerelease: false
101
+ - !ruby/object:Gem::Dependency
104
102
  type: :development
105
103
  requirement: &id006 !ruby/object:Gem::Requirement
106
104
  none: false
@@ -113,10 +111,10 @@ dependencies:
113
111
  - 6
114
112
  - 0
115
113
  version: 2.6.0
116
- name: rspec
117
114
  version_requirements: *id006
118
- - !ruby/object:Gem::Dependency
115
+ name: rspec
119
116
  prerelease: false
117
+ - !ruby/object:Gem::Dependency
120
118
  type: :development
121
119
  requirement: &id007 !ruby/object:Gem::Requirement
122
120
  none: false
@@ -129,10 +127,10 @@ dependencies:
129
127
  - 9
130
128
  - 0
131
129
  version: 0.9.0
132
- name: flexmock
133
130
  version_requirements: *id007
134
- - !ruby/object:Gem::Dependency
131
+ name: flexmock
135
132
  prerelease: false
133
+ - !ruby/object:Gem::Dependency
136
134
  type: :development
137
135
  requirement: &id008 !ruby/object:Gem::Requirement
138
136
  none: false
@@ -143,10 +141,10 @@ dependencies:
143
141
  segments:
144
142
  - 0
145
143
  version: "0"
146
- name: rcov
147
144
  version_requirements: *id008
148
- - !ruby/object:Gem::Dependency
145
+ name: rcov
149
146
  prerelease: false
147
+ - !ruby/object:Gem::Dependency
150
148
  type: :development
151
149
  requirement: &id009 !ruby/object:Gem::Requirement
152
150
  none: false
@@ -157,8 +155,9 @@ dependencies:
157
155
  segments:
158
156
  - 0
159
157
  version: "0"
160
- name: rdoc
161
158
  version_requirements: *id009
159
+ name: rdoc
160
+ prerelease: false
162
161
  description: Part of the AMEE AppKit, this gem provides the ability to do mathmatical operations over a set of calculations
163
162
  email: help@amee.com
164
163
  executables: []
@@ -186,9 +185,9 @@ files:
186
185
  - spec/amee/analytics/calculation_collection_spec.rb
187
186
  - spec/amee/analytics/term_spec.rb
188
187
  - spec/amee/analytics/terms_list_spec.rb
188
+ - spec/fixtures/config/calculations/calcs.rb
189
189
  - spec/spec.opts
190
190
  - spec/spec_helper.rb
191
- has_rdoc: true
192
191
  homepage: http://github.com/AMEE/amee-analytics
193
192
  licenses:
194
193
  - MIT
@@ -218,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
217
  requirements: []
219
218
 
220
219
  rubyforge_project:
221
- rubygems_version: 1.6.2
220
+ rubygems_version: 1.8.6
222
221
  signing_key:
223
222
  specification_version: 3
224
223
  summary: Analytics module for use with AMEE AppKit