Module: TronprintHelper
- Includes:
- Tronprint::StatisticsFormatter
- Defined in:
- lib/tronprint/rails/tronprint_helper.rb
Overview
Rails helper for displaying footprint data.
Instance Method Summary (collapse)
-
- (Object) cm1_badge
Let the world know that your app is powered by CM1.
-
- (Object) footprint_badge(options = {})
An informational badge displaying total energy, footprint, CO2/minute.
-
- (Object) footprint_methodology
A URL for the methodology statement of the emissions calculation.
-
- (Object) total_electricity
The total amount of electricity used by the application.
- - (Object) total_estimate
-
- (Object) total_footprint
The total amount of CO2e generated by the application.
-
- (Object) tronprint_attribution
Tronprint attribution.
-
- (Object) tronprint_badge
A link to more information about Tronprint.
Methods included from Tronprint::StatisticsFormatter
Instance Method Details
- (Object) cm1_badge
Let the world know that your app is powered by CM1
76 77 78 79 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 76 def cm1_badge %q{<script type="text/javascript" src="http://impact.brighterplanet.com/badge.js"></script>}. html_safe end |
- (Object) footprint_badge(options = {})
An informational badge displaying total energy, footprint, CO2/minute
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 24 def footprint_badge( = {}) text = nil if Tronprint.connected? begin footprint = pounds_with_precision total_estimate two_hr_emissions = Tronprint.statistics. emission_estimate(Time.now - 7200, Time.now).to_f rate = two_hr_emissions / 120 # kgs CO2 per minute over last 2 hours rate = rate < 0.0001 ? "< 0.0001" : pounds_with_precision(rate) text = <<-HTML <p class="tronprint-footprint"> <span class="tronprint-total-footprint"> <span class="tronprint-label">Total app footprint:</span> <span class="tronprint-value">#{total_electricity.to_i}</span> <span class="tronprint-units">W</span>, <span class="tronprint-value">#{footprint}</span> <span class="tronprint-units">lbs. CO<sub>2</sub>e</span> </span> <span class="tronprint-separator">·</span> <span class="tronprint-current-footprint"> <span class="tronprint-label">Current footprint:</span> <span class="tronprint-value">#{rate}</span> <span class="tronprint-units">lbs. CO<sub>2</sub>e/min.</span> </span> <span class="tronprint-attribution">#{tronprint_attribution if [:attribution]}</span> </p> HTML rescue Timeout::Error => e rescue => e end end text ||= <<-HTML <p class="tronprint-footprint">App footprint unavailable</p> HTML text.html_safe end |
- (Object) footprint_methodology
A URL for the methodology statement of the emissions calculation.
19 20 21 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 19 def footprint_methodology Tronprint.statistics.total_footprint_methodology end |
- (Object) total_electricity
The total amount of electricity used by the application.
14 15 16 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 14 def total_electricity total_estimate.electricity_use.to_f end |
- (Object) total_estimate
81 82 83 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 81 def total_estimate @total_estimate ||= Tronprint.statistics.emission_estimate end |
- (Object) total_footprint
The total amount of CO2e generated by the application.
9 10 11 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 9 def total_footprint total_estimate.to_f end |
- (Object) tronprint_attribution
Tronprint attribution
66 67 68 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 66 def tronprint_attribution %q{App footprint calculated by <a href="http://brighterplanet.github.com/tronprint">Tronprint</a>} end |
- (Object) tronprint_badge
A link to more information about Tronprint
71 72 73 |
# File 'lib/tronprint/rails/tronprint_helper.rb', line 71 def tronprint_badge %Q{<p class="tronprint-link">#{tronprint_attribution}</p>}.html_safe end |