Sha256: aed3ca0ded734a8fa647a023462d96ff2ca1e0fc4ddb4c87e8e70d1f47cac3cb

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

require 'tronprint/statistics_formatter'

# Rails helper for displaying footprint data.
module TronprintHelper
  include Tronprint::StatisticsFormatter

  # The total amount of CO2e generated by the application.
  def total_footprint
    total_estimate.to_f
  end

  # The total amount of electricity used by the application.
  def total_electricity
    total_estimate.electricity_use.to_f
  end

  # A URL for the methodology statement of the emissions calculation.
  def footprint_methodology
    Tronprint.statistics.total_footprint_methodology
  end

  # An informational badge displaying total energy, footprint, CO2/minute
  def footprint_badge
    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="cm1-footprint">
        <span class="cm1-total-footprint">Total site footprint: #{total_electricity.to_i}W, #{footprint}lbs CO<sub>2</sub>e</span>
        |
        <span class="cm1-current-footprint">Current footprint: #{rate}lbs CO<sub>2</sub>e/min</span>
      </p>
    HTML

    text.html_safe
  end

  # A link to more information about Tronprint
  def tronprint_badge
    %q{<p class="cm1-tronprint-link">Site footprint calculated by <a href="http://brighterplanet.github.com/tronprint">Tronprint</a></p>}.html_safe
  end

  # Let the world know that your app is powered by CM1
  def cm1_badge
    %q{<script type="text/javascript" src="http://carbon.brighterplanet.com/badge.js"></script>}.
      html_safe
  end
  
  def total_estimate
    @total_estimate ||= Tronprint.statistics.emission_estimate
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tronprint-1.1.4 lib/tronprint/rails/tronprint_helper.rb
tronprint-1.1.3 lib/tronprint/rails/tronprint_helper.rb
tronprint-1.1.2 lib/tronprint/rails/tronprint_helper.rb
tronprint-1.1.1 lib/tronprint/rails/tronprint_helper.rb
tronprint-1.1.0 lib/tronprint/rails/tronprint_helper.rb
tronprint-1.0.5 lib/tronprint/rails/tronprint_helper.rb
tronprint-1.0.4 lib/tronprint/rails/tronprint_helper.rb