automobile 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/automobile.rb +202 -0
- data/test/helper.rb +10 -0
- data/test/test_automobile.rb +7 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andy Rossmeissl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= automobile
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Andy Rossmeissl. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "automobile"
|
8
|
+
gem.summary = %Q{A carbon model}
|
9
|
+
gem.description = %Q{A software model in Ruby for the greenhouse gas emissions of an automobile}
|
10
|
+
gem.email = "andy@rossmeissl.net"
|
11
|
+
gem.homepage = "http://github.com/brighterplanet/automobile"
|
12
|
+
gem.authors = ["Andy Rossmeissl", "Seamus Abshere", "Ian Hough", "Matt Kling"]
|
13
|
+
gem.add_dependency 'leap'
|
14
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "automobile #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/automobile.rb
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
module BrighterPlanet
|
2
|
+
module Automobile
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ::Leap::Subject
|
5
|
+
base.decide :emission, :with => :characteristics do
|
6
|
+
committee :emission do # returns kg CO2
|
7
|
+
quorum 'from fuel', :needs => [:fuel_consumed, :emission_factor], :appreciates => :fuel_type do |characteristics|
|
8
|
+
if characteristics[:fuel_type].andand.code == AutomobileFuelType::CODES[:electricity]
|
9
|
+
0.0 # FIXME waiting for fuel_efficiency values in kilometres per kWh from fuel_efficiency
|
10
|
+
else
|
11
|
+
characteristics[:fuel_consumed] * characteristics[:emission_factor]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
quorum 'default' do
|
16
|
+
raise "The emission committee's default quorum should never be called"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
committee :emission_factor do # returns kilograms CO2 per litre **OR** kilograms CO2 per litre
|
21
|
+
quorum 'from fuel type', :needs => :fuel_type do |characteristics|
|
22
|
+
characteristics[:fuel_type].emission_factor
|
23
|
+
end
|
24
|
+
|
25
|
+
quorum 'default' do
|
26
|
+
AutomobileFuelType.fallback.emission_factor
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
committee :fuel_consumed do # returns litres
|
31
|
+
quorum 'from adjusted fuel_efficiency and distance', :needs => [:adjusted_fuel_efficiency, :distance] do |characteristics|
|
32
|
+
characteristics[:distance] / characteristics[:adjusted_fuel_efficiency]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
committee :distance do # returns kilometres
|
37
|
+
quorum 'from annual distance', :needs => [:annual_distance, :active_subtimeframe] do |characteristics, timeframe|
|
38
|
+
characteristics[:annual_distance] * (characteristics[:active_subtimeframe] / timeframe.year)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
committee :annual_distance do # returns kilometres
|
43
|
+
quorum 'from annual distance estimate', :needs => :annual_distance_estimate do |characteristics|
|
44
|
+
characteristics[:annual_distance_estimate]
|
45
|
+
end
|
46
|
+
|
47
|
+
quorum 'from weekly distance estimate', :needs => :weekly_distance_estimate do |characteristics, timeframe|
|
48
|
+
(characteristics[:weekly_distance_estimate] / 7 ) * timeframe.year.days
|
49
|
+
end
|
50
|
+
|
51
|
+
quorum 'from daily distance', :needs => :daily_distance do |characteristics, timeframe|
|
52
|
+
characteristics[:daily_distance] * timeframe.year.days
|
53
|
+
end
|
54
|
+
|
55
|
+
quorum 'from size class', :needs => :size_class do |characteristics|
|
56
|
+
characteristics[:size_class].annual_distance
|
57
|
+
end
|
58
|
+
|
59
|
+
quorum 'from fuel type', :needs => :fuel_type do |characteristics|
|
60
|
+
characteristics[:fuel_type].annual_distance
|
61
|
+
end
|
62
|
+
|
63
|
+
quorum 'default' do
|
64
|
+
::Automobile.fallback.annual_distance_estimate
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
committee :daily_distance do # returns kilometres
|
69
|
+
quorum 'from daily distance estimate', :needs => :daily_distance_estimate do |characteristics|
|
70
|
+
characteristics[:daily_distance_estimate]
|
71
|
+
end
|
72
|
+
|
73
|
+
quorum 'from daily duration', :needs => [:daily_duration, :speed] do |characteristics|
|
74
|
+
characteristics[:daily_duration] * characteristics[:speed]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
committee :adjusted_fuel_efficiency do # returns kilometres per litre
|
79
|
+
quorum 'from fuel efficiency', :needs => :fuel_efficiency do |characteristics|
|
80
|
+
characteristics[:fuel_efficiency]
|
81
|
+
end
|
82
|
+
|
83
|
+
quorum 'from variant', :needs => [:variant, :urbanity] do |characteristics|
|
84
|
+
fuel_efficiencies = characteristics[:variant].attributes.symbolize_keys.slice(:fuel_efficiency_city, :fuel_efficiency_highway)
|
85
|
+
urbanity = characteristics[:urbanity]
|
86
|
+
1.0 / ((urbanity / fuel_efficiencies[:fuel_efficiency_city].to_f) + ((1.0 - urbanity) / fuel_efficiencies[:fuel_efficiency_highway].to_f))
|
87
|
+
end
|
88
|
+
|
89
|
+
quorum 'from nominal fuel efficiency and multiplier', :needs => [:nominal_fuel_efficiency, :fuel_efficiency_multiplier] do |characteristics|
|
90
|
+
characteristics[:nominal_fuel_efficiency] * characteristics[:fuel_efficiency_multiplier]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
committee :fuel_efficiency_multiplier do # returns coefficient
|
95
|
+
quorum 'from_size_class_and_hybridity', :needs => [:size_class, :hybridity, :urbanity] do |characteristics|
|
96
|
+
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
97
|
+
urbanity = characteristics[:urbanity]
|
98
|
+
size_class = characteristics[:size_class]
|
99
|
+
fuel_efficiency_multipliers = {
|
100
|
+
:city => size_class.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
|
101
|
+
:highway => size_class.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
|
102
|
+
}
|
103
|
+
if fuel_efficiency_multipliers.values.any?(&:nil?)
|
104
|
+
nil
|
105
|
+
else
|
106
|
+
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
quorum 'from hybridity', :needs => [:hybridity, :urbanity] do |characteristics|
|
111
|
+
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
112
|
+
urbanity = characteristics[:urbanity]
|
113
|
+
fuel_efficiency_multipliers = {
|
114
|
+
:city => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
|
115
|
+
:highway => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
|
116
|
+
}
|
117
|
+
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
118
|
+
end
|
119
|
+
|
120
|
+
quorum 'default' do
|
121
|
+
1.0
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
committee :nominal_fuel_efficiency do # returns kilometres per litre **OR** (FIXME) kilometres per kWh
|
126
|
+
quorum 'from model', :needs => [:model, :urbanity] do |characteristics|
|
127
|
+
fuel_efficiency_city = characteristics[:model].fuel_efficiency_city.to_f
|
128
|
+
fuel_efficiency_highway = characteristics[:model].fuel_efficiency_highway.to_f
|
129
|
+
urbanity = characteristics[:urbanity]
|
130
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
131
|
+
end
|
132
|
+
|
133
|
+
quorum 'from make and model year', :needs => [:model_year] do |characteristics|
|
134
|
+
characteristics[:model_year].make_year.andand.fuel_efficiency
|
135
|
+
end
|
136
|
+
|
137
|
+
quorum 'from size class', :needs => [:size_class, :urbanity] do |characteristics|
|
138
|
+
fuel_efficiencies = characteristics[:size_class].attributes.symbolize_keys.slice(:fuel_efficiency_city, :fuel_efficiency_highway)
|
139
|
+
urbanity = characteristics[:urbanity]
|
140
|
+
1.0 / ((urbanity / fuel_efficiencies[:fuel_efficiency_city].to_f) + ((1.0 - urbanity) / fuel_efficiencies[:fuel_efficiency_highway].to_f))
|
141
|
+
end
|
142
|
+
|
143
|
+
quorum 'from model year', :needs => :model_year do |characteristics|
|
144
|
+
characteristics[:model_year].fuel_efficiency
|
145
|
+
end
|
146
|
+
|
147
|
+
quorum 'from make', :needs => :make do |characteristics|
|
148
|
+
characteristics[:make].fuel_efficiency
|
149
|
+
end
|
150
|
+
|
151
|
+
quorum 'default' do
|
152
|
+
::Automobile.fallback.fuel_efficiency
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
committee :speed do # returns kilometres per hour
|
157
|
+
quorum 'from urbanity', :needs => :urbanity do |characteristics|
|
158
|
+
1 / (characteristics[:urbanity] / ::Automobile::RESEARCH[:city_speed] + (1 - characteristics[:urbanity]) / ::Automobile::RESEARCH[:highway_speed])
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
committee :urbanity do
|
163
|
+
quorum 'default' do
|
164
|
+
::Automobile.fallback.urbanity
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
committee :fuel_type do
|
169
|
+
quorum 'from variant', :needs => :variant do |characteristics|
|
170
|
+
characteristics[:variant].fuel_type
|
171
|
+
end
|
172
|
+
|
173
|
+
quorum 'default' do
|
174
|
+
::Automobile.fallback.fuel_type
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
committee :active_subtimeframe do
|
179
|
+
quorum 'from acquisition and retirement', :needs => [:acquisition, :retirement] do |characteristics, timeframe|
|
180
|
+
Timeframe.constrained_new characteristics[:acquisition].to_date, characteristics[:retirement].to_date, timeframe
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
committee :acquisition do
|
185
|
+
quorum 'from model year or year', :appreciates => [:model_year, :year] do |characteristics|
|
186
|
+
!characteristics.empty? && Date.new((characteristics[:model_year].andand.year || characteristics[:year]).to_i - 1, 1, 1)
|
187
|
+
end
|
188
|
+
quorum 'from retirement', :appreciates => :retirement do |characteristics, timeframe|
|
189
|
+
[ timeframe.from, characteristics[:retirement] ].compact.min
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
committee :retirement do
|
194
|
+
quorum 'from acquisition', :appreciates => :acquisition do |characteristics, timeframe|
|
195
|
+
[ timeframe.to, characteristics[:acquisition] ].compact.max
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: automobile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Andy Rossmeissl
|
13
|
+
- Seamus Abshere
|
14
|
+
- Ian Hough
|
15
|
+
- Matt Kling
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-06-10 00:00:00 -04:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: leap
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thoughtbot-shoulda
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :development
|
46
|
+
version_requirements: *id002
|
47
|
+
description: A software model in Ruby for the greenhouse gas emissions of an automobile
|
48
|
+
email: andy@rossmeissl.net
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files:
|
54
|
+
- LICENSE
|
55
|
+
- README.rdoc
|
56
|
+
files:
|
57
|
+
- .document
|
58
|
+
- .gitignore
|
59
|
+
- LICENSE
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- VERSION
|
63
|
+
- lib/automobile.rb
|
64
|
+
- test/helper.rb
|
65
|
+
- test/test_automobile.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/brighterplanet/automobile
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: A carbon model
|
96
|
+
test_files:
|
97
|
+
- test/helper.rb
|
98
|
+
- test/test_automobile.rb
|